Mercurial > hg > beaglert
diff projects/oscillator_bank/render.cpp @ 52:a6d223473ea2 newapi
Updated examples for new API. tank_wars not yet updated; audio_in_FFT and oscillator_bank not working properly yet.
author | andrewm |
---|---|
date | Sun, 31 May 2015 02:13:39 -0500 |
parents | 643cbee74eda |
children | 3c3a1357657d |
line wrap: on
line diff
--- a/projects/oscillator_bank/render.cpp Sat May 30 13:25:51 2015 -0500 +++ b/projects/oscillator_bank/render.cpp Sun May 31 02:13:39 2015 -0500 @@ -6,7 +6,7 @@ */ -#include "../../include/RTAudio.h" +#include "../../include/BeagleRT.h" #include "../../include/Utilities.h" #include <rtdk.h> #include <cstdlib> @@ -58,15 +58,11 @@ // in from the call to initAudio(). // // Return true on success; returning false halts the program. -bool initialise_render(int numMatrixChannels, int numDigitalChannels, int numAudioChannels, - int numMatrixFramesPerPeriod, - int numAudioFramesPerPeriod, - float matrixSampleRate, float audioSampleRate, - void *userData, RTAudioSettings* settings) +bool initialise_render(BeagleRTContext *context, void *userData) { srandom(time(NULL)); - if(numAudioChannels != 2) { + if(context->audioChannels != 2) { rt_printf("Error: this example needs stereo audio enabled\n"); return false; } @@ -109,7 +105,7 @@ for(int n = 0; n < gNumOscillators; n++) { gPhases[n] = 0.0; - if(numMatrixFramesPerPeriod == 0) { + if(context->analogFrames == 0) { // Random frequencies when used without matrix gFrequencies[n] = kMinimumFrequency + (kMaximumFrequency - kMinimumFrequency) * ((float)random() / (float)RAND_MAX); } @@ -120,7 +116,7 @@ } // For efficiency, frequency is expressed in change in wavetable position per sample, not Hz or radians - gFrequencies[n] *= (float)gWavetableLength / audioSampleRate; + gFrequencies[n] *= (float)gWavetableLength / context->audioSampleRate; gAmplitudes[n] = ((float)random() / (float)RAND_MAX) / (float)gNumOscillators; gDFrequencies[n] = gDAmplitudes[n] = 0.0; } @@ -135,19 +131,19 @@ float newFreq = freq * randScale; // For efficiency, frequency is expressed in change in wavetable position per sample, not Hz or radians - gFrequencies[n] = newFreq * (float)gWavetableLength / audioSampleRate; + gFrequencies[n] = newFreq * (float)gWavetableLength / context->audioSampleRate; freq += increment; } // Initialise auxiliary tasks - if((gFrequencyUpdateTask = createAuxiliaryTask(&recalculate_frequencies, 90, "beaglert-update-frequencies")) == 0) + if((gFrequencyUpdateTask = BeagleRT_createAuxiliaryTask(&recalculate_frequencies, 85, "beaglert-update-frequencies")) == 0) return false; - for(int n = 0; n < gNumOscillators; n++) - rt_printf("%f\n", gFrequencies[n]); + //for(int n = 0; n < gNumOscillators; n++) + // rt_printf("%f\n", gFrequencies[n]); - gAudioSampleRate = audioSampleRate; + gAudioSampleRate = context->audioSampleRate; gSampleCount = 0; return true; @@ -158,23 +154,22 @@ // ADCs and DACs (if available). If only audio is available, numMatrixFrames // will be 0. -void render(int numAnalogFrames, int numAudioFrames, int numDigitalFrames, float *audioIn, float *audioOut, - float *analogIn, float *analogOut, uint32_t *digital) +void render(BeagleRTContext *context, void *userData) { // Initialise buffer to 0 - memset(audioOut, 0, 2 * numAudioFrames * sizeof(float)); + memset(context->audioOut, 0, 2 * context->audioFrames * sizeof(float)); // Render audio frames - oscillator_bank_neon(numAudioFrames, audioOut, + oscillator_bank_neon(context->audioFrames, context->audioOut, gNumOscillators, gWavetableLength, gPhases, gFrequencies, gAmplitudes, gDFrequencies, gDAmplitudes, gWavetable); - if(numAnalogFrames != 0 && (gSampleCount += numAudioFrames) >= 128) { + if(context->analogFrames != 0 && (gSampleCount += context->audioFrames) >= 128) { gSampleCount = 0; - gNewMinFrequency = map(analogIn[0], 0, 1.0, 1000.0f, 8000.0f); - gNewMaxFrequency = map(analogIn[1], 0, 1.0, 1000.0f, 8000.0f); + gNewMinFrequency = map(context->analogIn[0], 0, 1.0, 1000.0f, 8000.0f); + gNewMaxFrequency = map(context->analogIn[1], 0, 1.0, 1000.0f, 8000.0f); // Make sure max >= min if(gNewMaxFrequency < gNewMinFrequency) { @@ -184,7 +179,7 @@ } // Request that the lower-priority task run at next opportunity - //scheduleAuxiliaryTask(gFrequencyUpdateTask); + //BeagleRT_scheduleAuxiliaryTask(gFrequencyUpdateTask); } } @@ -215,7 +210,7 @@ // cleanup_render() is called once at the end, after the audio has stopped. // Release any resources that were allocated in initialise_render(). -void cleanup_render() +void cleanup_render(BeagleRTContext *context, void *userData) { free(gWavetable); free(gPhases);