Created
April 13, 2015 19:22
-
-
Save jonbro/aabf26e743c35bba0f98 to your computer and use it in GitHub Desktop.
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
| void lipsynth_module_sine_update(void *self, lipsynth_context *ctx, lipsynth_AudioMemory *outputBuffer){ | |
| lipsynth_module_sine* module = self; | |
| // fill up the output buffer with a sine wave! | |
| for(int i=0;i<ctx->bufferLength/2;i++){ | |
| // must be called before any parameters are read | |
| if(module->_(lipsynth_Module_update_parameters)(self, ctx)){ | |
| if(module->_(lipsynth_Module_has_parameter_value)(self, ctx, NOTE)){ | |
| int noteVal = module->_(lipsynth_Module_get_parameter_value)(self, ctx, NOTE); | |
| module->freqVal = pow(2.0, (noteVal)/12.0f)*440.0f; | |
| } | |
| } | |
| module->sineCounter += 1.0f/44100.0f*module->freqVal; | |
| module->sineCounter = module->sineCounter-floorf(module->sineCounter); | |
| outputBuffer->data[i*2] = outputBuffer->data[i*2+1] = sinf(module->sineCounter*M_PI); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment