Last active
January 3, 2016 11:29
-
-
Save enigmaticape/8456110 to your computer and use it in GitHub Desktop.
More general form of sine wave sample data generation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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