Skip to content

Instantly share code, notes, and snippets.

@enigmaticape
Last active January 3, 2016 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enigmaticape/8456110 to your computer and use it in GitHub Desktop.
Save enigmaticape/8456110 to your computer and use it in GitHub Desktop.
More general form of sine wave sample data generation
typedef struct _WaveState {
double amplitude;
double increment;
double theta;
} WaveState;
void fillWaveSamples( WaveState * state, UInt32 number_of_samples, Float32 * buffer) {
for(UInt32 i = 0; i < number_of_samples; ++i) {
buffer[ i ] = state->amplitude * sin( state->theta );
state->theta = fmod( state->theta + state->increment, 2.0 * M_PI );
}
}
void initialiseWave( WaveState *state, double frequency, double sample_rate, double amplitude ) {
state->amplitude = amplitude;
state->increment = 2.0 * M_PI * (frequency / sample_rate);
state->theta = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment