PortAudio
2.0
|
Generate Pink Noise using Gardner method, and make "waves". Provides an example of how to post stuff to/from the audio callback using lock-free FIFOs implemented by the PA ringbuffer. More...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include "portaudio.h"
#include "pa_ringbuffer.h"
#include "pa_util.h"
Data Structures | |
struct | PinkNoise |
struct | BiQuad |
struct | OceanWave |
struct | paTestData |
Macros | |
#define | PINK_MAX_RANDOM_ROWS (30) |
#define | PINK_RANDOM_BITS (24) |
#define | PINK_RANDOM_SHIFT ((sizeof(long)*8)-PINK_RANDOM_BITS) |
#define | NEW_ROW_SIZE (12 + (8*rand())/RAND_MAX) |
Enumerations | |
enum | EnvState { State_kAttack, State_kPreDecay, State_kDecay, State_kCnt } |
Functions | |
void | InitializePinkNoise (PinkNoise *pink, int numRows) |
float | GeneratePinkNoise (PinkNoise *pink) |
unsigned | GenerateWave (OceanWave *wave, float *output, unsigned noOfFrames) |
float | ProcessBiquad (const BiQuad *coeffs, float *memory, float input) |
OceanWave * | InitializeWave (double SR, float attackInSeconds, float maxLevel, float positionLeftRight) |
int | main (void) |
Generate Pink Noise using Gardner method, and make "waves". Provides an example of how to post stuff to/from the audio callback using lock-free FIFOs implemented by the PA ringbuffer.
Optimization suggested by James McCartney uses a tree to select which random value to replace.
x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
Tree is generated by counting trailing zeros in an increasing index. When the index is zero, no random number is selected.
#define NEW_ROW_SIZE (12 + (8*rand())/RAND_MAX) |
Referenced by InitializeWave().
#define PINK_MAX_RANDOM_ROWS (30) |
#define PINK_RANDOM_BITS (24) |
Referenced by InitializePinkNoise().
#define PINK_RANDOM_SHIFT ((sizeof(long)*8)-PINK_RANDOM_BITS) |
Referenced by GeneratePinkNoise().
enum EnvState |
float GeneratePinkNoise | ( | PinkNoise * | pink | ) |
References PinkNoise::pink_Index, PinkNoise::pink_IndexMask, PINK_RANDOM_SHIFT, PinkNoise::pink_Rows, PinkNoise::pink_RunningSum, and PinkNoise::pink_Scalar.
Referenced by GenerateWave().
unsigned GenerateWave | ( | OceanWave * | wave, |
float * | output, | ||
unsigned | noOfFrames | ||
) |
References BiQuad::bq_a1, BiQuad::bq_a2, BiQuad::bq_b0, BiQuad::bq_b1, BiQuad::bq_b2, GeneratePinkNoise(), ProcessBiquad(), State_kAttack, State_kDecay, State_kPreDecay, OceanWave::wave_attack_incr, OceanWave::wave_bq_coeffs, OceanWave::wave_bq_left, OceanWave::wave_bq_right, OceanWave::wave_decay_incr, OceanWave::wave_envelope_level, OceanWave::wave_envelope_max_level, OceanWave::wave_envelope_state, OceanWave::wave_left, OceanWave::wave_pan_left, OceanWave::wave_pan_right, and OceanWave::wave_right.
void InitializePinkNoise | ( | PinkNoise * | pink, |
int | numRows | ||
) |
References PinkNoise::pink_Index, PinkNoise::pink_IndexMask, PINK_RANDOM_BITS, PinkNoise::pink_Rows, PinkNoise::pink_RunningSum, and PinkNoise::pink_Scalar.
Referenced by InitializeWave().
OceanWave* InitializeWave | ( | double | SR, |
float | attackInSeconds, | ||
float | maxLevel, | ||
float | positionLeftRight | ||
) |
References InitializePinkNoise(), NEW_ROW_SIZE, PaUtil_AllocateMemory(), State_kAttack, OceanWave::wave_attack_incr, OceanWave::wave_decay_incr, OceanWave::wave_envelope_level, OceanWave::wave_envelope_max_level, OceanWave::wave_envelope_state, OceanWave::wave_left, OceanWave::wave_pan_left, OceanWave::wave_pan_right, and OceanWave::wave_right.
int main | ( | void | ) |
float ProcessBiquad | ( | const BiQuad * | coeffs, |
float * | memory, | ||
float | input | ||
) |
References BiQuad::bq_a1, BiQuad::bq_a2, BiQuad::bq_b0, BiQuad::bq_b1, and BiQuad::bq_b2.
Referenced by GenerateWave().