PortAudio 2.0
paex_ocean_shore.c File Reference

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"

Go to the source code of this file.

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)
 
OceanWaveInitializeWave (double SR, float attackInSeconds, float maxLevel, float positionLeftRight)
 
int main (void)
 

Detailed Description

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.

Author
Phil Burk http://www.softsynth.com Robert Bielik

Definition in file paex_ocean_shore.c.

Macro Definition Documentation

◆ NEW_ROW_SIZE

#define NEW_ROW_SIZE   (12 + (8*rand())/RAND_MAX)

Definition at line 362 of file paex_ocean_shore.c.

◆ PINK_MAX_RANDOM_ROWS

#define PINK_MAX_RANDOM_ROWS   (30)

Definition at line 69 of file paex_ocean_shore.c.

◆ PINK_RANDOM_BITS

#define PINK_RANDOM_BITS   (24)

Definition at line 70 of file paex_ocean_shore.c.

◆ PINK_RANDOM_SHIFT

#define PINK_RANDOM_SHIFT   ((sizeof(long)*8)-PINK_RANDOM_BITS)

Definition at line 71 of file paex_ocean_shore.c.

Enumeration Type Documentation

◆ EnvState

enum EnvState

Definition at line 92 of file paex_ocean_shore.c.

Function Documentation

◆ GeneratePinkNoise()

float GeneratePinkNoise ( PinkNoise * pink)

Definition at line 152 of file paex_ocean_shore.c.

◆ GenerateWave()

unsigned GenerateWave ( OceanWave * wave,
float * output,
unsigned noOfFrames )

Definition at line 201 of file paex_ocean_shore.c.

◆ InitializePinkNoise()

void InitializePinkNoise ( PinkNoise * pink,
int numRows )

Definition at line 137 of file paex_ocean_shore.c.

◆ InitializeWave()

OceanWave * InitializeWave ( double SR,
float attackInSeconds,
float maxLevel,
float positionLeftRight )

Definition at line 364 of file paex_ocean_shore.c.

◆ main()

int main ( void )

Definition at line 397 of file paex_ocean_shore.c.

◆ ProcessBiquad()

float ProcessBiquad ( const BiQuad * coeffs,
float * memory,
float input )

Definition at line 189 of file paex_ocean_shore.c.