Mercurial > hg > beaglert
changeset 52:a6d223473ea2 newapi
Updated examples for new API. tank_wars not yet updated; audio_in_FFT and oscillator_bank not working properly yet.
line wrap: on
line diff
--- a/.cproject Sat May 30 13:25:51 2015 -0500 +++ b/.cproject Sun May 31 02:13:39 2015 -0500 @@ -92,7 +92,7 @@ <sourceEntries> <entry excluding="audio_routines_old.S" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="core"/> <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="include"/> - <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="projects/d-box"/> + <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="projects/oscillator_bank"/> <entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="source"/> </sourceEntries> </configuration> @@ -161,6 +161,7 @@ </option> <option id="gnu.cpp.link.option.libs.1930118082" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" valueType="libs"> <listOptionValue builtIn="false" value="rt"/> + <listOptionValue builtIn="false" value="sndfile"/> <listOptionValue builtIn="false" value="native"/> <listOptionValue builtIn="false" value="xenomai"/> </option> @@ -182,7 +183,7 @@ <sourceEntries> <entry excluding="audio_routines_old.S" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="core"/> <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="include"/> - <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="projects/d-box"/> + <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="projects/oscillator_bank"/> <entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="source"/> </sourceEntries> </configuration>
--- a/core/PRU.cpp Sat May 30 13:25:51 2015 -0500 +++ b/core/PRU.cpp Sun May 31 02:13:39 2015 -0500 @@ -616,6 +616,9 @@ pru_buffer_audio_dac[n + pru_audio_offset] = (int16_t)out; } + // Increment total number of samples that have elapsed + context->audioSampleCount += context->audioFrames; + if(xenomai_gpio != 0) { // Set the test pin high xenomai_gpio[GPIO_CLEARDATAOUT] = TEST_PIN_MASK;
--- a/core/RTAudioCommandLine.cpp Sat May 30 13:25:51 2015 -0500 +++ b/core/RTAudioCommandLine.cpp Sun May 31 02:13:39 2015 -0500 @@ -223,14 +223,13 @@ std::cerr << " --adc-level [-A] dBs: Set the ADC input level (0dB max; -12dB min)\n"; std::cerr << " --hp-level [-H] dBs: Set the headphone output level (0dB max; -63.5dB min)\n"; std::cerr << " --mute-speaker [-M] val: Set whether to mute the speaker initially (default: no)\n"; - std::cerr << " --use-analog [-m] val: Set whether to use ADC/DAC analog (default: yes)\n"; - std::cerr << " --use-digital [-g] val: Set whether to use digital GPIO channels (default: yes)\n"; + std::cerr << " --use-analog [-N] val: Set whether to use ADC/DAC analog (default: yes)\n"; + std::cerr << " --use-digital [-G] val: Set whether to use digital GPIO channels (default: yes)\n"; std::cerr << " --analog-channels [-C] val: Set the number of ADC/DAC channels (default: 8)\n"; - std::cerr << " --digital-channels [-G] val: Set the number of GPIO channels (default: 16)\n"; - std::cerr << " --digital-channels [-G] val: Set the number of digital GPIO channels (default: 16)\n"; - std::cerr << " --receive-port [-r] val: Set the receive port (default: 9998)\n"; - std::cerr << " --transmit-port [-t] val: Set the transmit port (default: 9999)\n"; - std::cerr << " --server-name [-s] val: Set the destination server name (default: '127.0.0.1')\n"; + std::cerr << " --digital-channels [-B] val: Set the number of GPIO channels (default: 16)\n"; + std::cerr << " --receive-port [-R] val: Set the receive port (default: 9998)\n"; + std::cerr << " --transmit-port [-T] val: Set the transmit port (default: 9999)\n"; + std::cerr << " --server-name [-S] val: Set the destination server name (default: '127.0.0.1')\n"; std::cerr << " --pru-file val: Set an optional external file to use for the PRU binary code\n"; std::cerr << " --verbose [-v]: Enable verbose logging information\n"; }
--- a/core/Utilities.cpp Sat May 30 13:25:51 2015 -0500 +++ b/core/Utilities.cpp Sun May 31 02:13:39 2015 -0500 @@ -10,7 +10,7 @@ // analogReadFrame() // // Returns the value of the given analog input at the given frame number. -inline float analogReadFrame(BeagleRTContext *context, int frame, int channel) { +float analogReadFrame(BeagleRTContext *context, int frame, int channel) { return context->analogIn[frame * context->analogChannels + channel]; } @@ -18,7 +18,7 @@ // // Sets a given channel to a value for the current frame and, if persistent outputs are // enabled, for all subsequent frames -inline void analogWriteFrame(BeagleRTContext *context, int frame, int channel, float value) { +void analogWriteFrame(BeagleRTContext *context, int frame, int channel, float value) { if(context->flags & BEAGLERT_FLAG_ANALOG_OUTPUTS_PERSIST) { for(unsigned int f = frame; f < context->analogFrames; f++) context->analogOut[frame * context->analogChannels + channel] = value; @@ -30,21 +30,21 @@ // analogWriteFrameOnce() // // Sets a given channel to a value for only the current frame -inline void analogWriteFrameOnce(BeagleRTContext *context, int frame, int channel, float value) { +void analogWriteFrameOnce(BeagleRTContext *context, int frame, int channel, float value) { context->analogOut[frame * context->analogChannels + channel] = value; } // digitalReadFrame() // // Returns the value of a given digital input at the given frame number -inline int digitalReadFrame(BeagleRTContext *context, int frame, int channel) { +int digitalReadFrame(BeagleRTContext *context, int frame, int channel) { return getBit(context->digital[frame], channel + 16); } // digitalWriteFrame() // // Sets a given digital output channel to a value for the current frame and all subsequent frames -inline void digitalWriteFrame(BeagleRTContext *context, int frame, int channel, int value) { +void digitalWriteFrame(BeagleRTContext *context, int frame, int channel, int value) { for(unsigned int f = frame; f < context->digitalFrames; f++) { if(value) context->digital[f] |= 1 << (channel + 16); @@ -56,7 +56,7 @@ // digitalWriteFrameOnce() // // Sets a given digital output channel to a value for the current frame only -inline void digitalWriteFrameOnce(BeagleRTContext *context, int frame, int channel, int value) { +void digitalWriteFrameOnce(BeagleRTContext *context, int frame, int channel, int value) { if(value) context->digital[frame] |= 1 << (channel + 16); else @@ -66,7 +66,7 @@ // pinModeFrame() // // Sets the direction of a digital pin for the current frame and all subsequent frames -inline void pinModeFrame(BeagleRTContext *context, int frame, int channel, int mode) { +void pinModeFrame(BeagleRTContext *context, int frame, int channel, int mode) { for(unsigned int f = frame; f < context->digitalFrames; f++) { if(mode) context->digital[f] |= (1 << channel); @@ -78,7 +78,7 @@ // pinModeFrameOnce() // // Sets the direction of a digital pin for the current frame only -inline void pinModeFrameOnce(BeagleRTContext *context, int frame, int channel, int mode) { +void pinModeFrameOnce(BeagleRTContext *context, int frame, int channel, int mode) { if(mode) context->digital[frame] |= (1 << channel); else @@ -91,7 +91,7 @@ // x is the value to scale; in_min and in_max are the input range; out_min and out_max // are the output range. -inline float map(float x, float in_min, float in_max, float out_min, float out_max) +float map(float x, float in_min, float in_max, float out_min, float out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } @@ -101,7 +101,7 @@ // Clips an input value to be between two end points // x is the value to constrain; min_val and max_val are the range -inline float constrain(float x, float min_val, float max_val) +float constrain(float x, float min_val, float max_val) { if(x < min_val) return min_val; if(x > max_val) return max_val;
--- a/projects/analogDigitalDemo/main.cpp Sat May 30 13:25:51 2015 -0500 +++ b/projects/analogDigitalDemo/main.cpp Sun May 31 02:13:39 2015 -0500 @@ -14,7 +14,7 @@ #include <libgen.h> #include <signal.h> #include <getopt.h> -#include "../../include/RTAudio.h" +#include "../../include/BeagleRT.h" #include <unistd.h> #include <stdlib.h> #include <fcntl.h> @@ -39,7 +39,7 @@ int main(int argc, char *argv[]) { - RTAudioSettings settings; // Standard audio settings + BeagleRTInitSettings settings; // Standard audio settings float frequency = 1000.0; // Frequency of crossover struct option customOptions[] =
--- a/projects/analogDigitalDemo/render.cpp Sat May 30 13:25:51 2015 -0500 +++ b/projects/analogDigitalDemo/render.cpp Sun May 31 02:13:39 2015 -0500 @@ -1,13 +1,11 @@ /* * - * First assignment for ECS732 RTDSP, to implement a 2-way audio crossover - * using the BeagleBone Black. - * * Andrew McPherson and Victor Zappi * Queen Mary, University of London */ -#include "../../include/render.h" +#include "../../include/BeagleRT.h" +#include "../../include/Utilities.h" #include <cmath> #include <rtdk.h> @@ -21,15 +19,9 @@ // in from the call to initAudio(). // // Return true on success; returning false halts the program. -int gNumDigitalFrames=0; -bool initialise_render(int numAnalogChannels, int numDigitalChannels, int numAudioChannels, - int numAnalogFramesPerPeriod, - int numAudioFramesPerPeriod, - float analogSampleRate, float audioSampleRate, - void *userData, RTAudioSettings* settings) + +bool initialise_render(BeagleRTContext *context, void *userData) { - gNumAnalogChannels=numAnalogChannels; - gNumDigitalChannels=numDigitalChannels; return true; } @@ -38,53 +30,51 @@ // ADCs and DACs (if available). If only audio is available, numAnalogFrames // will be 0. -long int gCountFrames=0; -void render(int numAnalogFrames, int numDigitalFrames, int numAudioFrames, float *audioIn, float *audioOut, - float *analogIn, float *analogOut, uint32_t *digital) +void render(BeagleRTContext *context, void *userData) /* we assume that gNumAnalogChannels=8, numAnalogFrames==8 and numDigitalFrames==numAudioFrames * */ { - if((gCountFrames&31)==0){ //every 32 frames... + if((context->audioSampleCount&31)==0){ //every 32 frames... //ANALOG channels - analogWrite(0, 0, analogRead(0,0)); // read the input0 at frame0 and write it to output0 frame0. Using analogWrite will fill the rest of the buffer with the same value + analogWriteFrame(context, 0, 0, analogReadFrame(context, 0,0)); + // read the input0 at frame0 and write it to output0 frame0. Using analogWrite will fill the rest of the buffer with the same value // The value at the last frame will persist through the successive buffers until is set again. // This effectively is a pass-through with downsampling by 32 times - analogWrite(3, 0, 1.0); // write 1.0 to channel3 from frame0 to the end of the buffer - analogWrite(3, 4, 0.1); // write 0.1 to channel3 from frame4 to the end of the buffer - analogWriteFrame(3,6,0.2); //write 0.2 to channel3 only on frame 6 + analogWriteFrame(context, 0, 3, 1.0); // write 1.0 to channel3 from frame0 to the end of the buffer + analogWriteFrame(context, 4, 3, 0.1); // write 0.1 to channel3 from frame4 to the end of the buffer + analogWriteFrameOnce(context, 6, 3, 0.2); //write 0.2 to channel3 only on frame 6 //this buffer for channel 3 will look like this: 1 1 1 1 0.1 0.1 0.2 0.1 //the next buffers for channel 3 will be filled up with 0.1 .... //DIGITAL channels - digitalWrite(P8_07,0,GPIO_HIGH); //sets all the frames to HIGH for channel 0 - digitalWriteFrame(P8_07,4,GPIO_LOW); //only frame 4 will be LOW for channel 0 + digitalWriteFrame(context, 0, P8_07, GPIO_HIGH); //sets all the frames to HIGH for channel 0 + digitalWriteFrameOnce(context, 4, P8_07, GPIO_LOW); //only frame 4 will be LOW for channel 0 // in this buffer the frames of channel 0 will look like this: 1 1 1 1 0 1 1 1 ...... 1 // in the next buffer each frame of channel 0 will be initialized to 1 (the last value of this buffer) - digitalWrite(P8_08,0,GPIO_HIGH); - digitalWrite(P8_08,2,GPIO_LOW); - digitalWrite(P8_08,4,GPIO_HIGH); - digitalWrite(P8_08,5,GPIO_LOW); - setDigitalDirection(P9_16,0,GPIO_INPUT); // set channel 10 to input + digitalWriteFrame(context, 0, P8_08, GPIO_HIGH); + digitalWriteFrame(context, 2, P8_08, GPIO_LOW); + digitalWriteFrame(context, 4, P8_08, GPIO_HIGH); + digitalWriteFrame(context, 5, P8_08, GPIO_LOW); + pinModeFrame(context, 0, P9_16, GPIO_INPUT); // set channel 10 to input // in this buffer the frames of channel 1 will look like this: 1 1 0 0 1 0 0 0 .... 0 // in the next buffer each frame of channel 1 will be initialized to 0 (the last value of this buffer) } - for(int n=0; n<numAudioFrames; n++){ - for(int c=0; c<gNumAudioChannels; c++){ - audioOut[n*gNumAudioChannels + c]=audioIn[n*gNumAudioChannels + c]; + for(unsigned int n=0; n<context->audioFrames; n++){ + for(unsigned int c=0; c<context->audioChannels; c++){ + context->audioOut[n*context->audioChannels + c]=context->audioIn[n*context->audioChannels + c]; } //use digital channels 2-8 to create a 7 bit binary counter - digital[n]=digital[n] & (~0b111111100); // set to zero (GPIO_OUTPUT) the bits in the lower word - digital[n]=digital[n] & ((~0b111111100<<16) | 0xffff ); //initialize to zero the bits in the higher word (output value) - digital[n]=digital[n] | ( ((gCountFrames&0b1111111)<<(16+2)) ) ; // set the bits in the higher word to the desired output value, keeping the lower word unchanged - digitalWriteFrame(P8_29,n,digitalRead(P8_30,n)); // echo the input from from channel 15 to channel 14 - digitalWriteFrame(P8_28,n,digitalRead(P9_16,n)); // echo the input from from channel 10 to channel 13 - setDigitalDirection(P8_30,0,GPIO_INPUT); //set channel 15 to input - gCountFrames++; + context->digital[n]=context->digital[n] & (~0b111111100); // set to zero (GPIO_OUTPUT) the bits in the lower word + context->digital[n]=context->digital[n] & ((~0b111111100<<16) | 0xffff ); //initialize to zero the bits in the higher word (output value) + context->digital[n]=context->digital[n] | ( ((context->audioSampleCount&0b1111111)<<(16+2)) ) ; // set the bits in the higher word to the desired output value, keeping the lower word unchanged + digitalWriteFrame(context, n, P8_29, digitalReadFrame(context, n, P8_30)); // echo the input from from channel 15 to channel 14 + digitalWriteFrame(context, n, P8_28, digitalReadFrame(context, n, P9_16)); // echo the input from from channel 10 to channel 13 + pinModeFrame(context, 0, P8_30, 0); //set channel 15 to input } - for(int n=0; n<numAnalogFrames; n++){ - analogWriteFrame(1,n,(gCountFrames&8191)/8192.0); // writes a single frame. channel 1 is a ramp that follows gCountFrames - analogWriteFrame(2,n,analogRead(2,n)); // writes a single frame. channel2 is just a passthrough + for(unsigned int n=0; n<context->analogFrames; n++){ + analogWriteFrame(context, n, 1, (context->audioSampleCount&8191)/8192.0); // writes a single frame. channel 1 is a ramp that follows gCountFrames + analogWriteFrame(context, n, 2, analogReadFrame(context, n, 2)); // writes a single frame. channel2 is just a passthrough // rt_printf("Analog out frame %d :",n); // for(int c=0; c<gNumAnalogChannels; c++) // rt_printf("%.1f ",analogOut[n*gNumAnalogChannels + c]); @@ -96,7 +86,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) { /* TASK: * If you allocate any memory, be sure to release it here.
--- a/projects/audio_in_FFT/main.cpp Sat May 30 13:25:51 2015 -0500 +++ b/projects/audio_in_FFT/main.cpp Sun May 31 02:13:39 2015 -0500 @@ -10,7 +10,7 @@ #include <libgen.h> #include <signal.h> #include <getopt.h> -#include "../../include/RTAudio.h" +#include "../../include/BeagleRT.h" using namespace std; @@ -33,7 +33,7 @@ int main(int argc, char *argv[]) { - RTAudioSettings settings; // Standard audio settings + BeagleRTInitSettings settings; // Standard audio settings int fftSize = 64; // Size of the FFT, in samples struct option customOptions[] = @@ -46,7 +46,7 @@ // Set default settings BeagleRT_defaultSettings(&settings); - settings.useMatrix = 0; // No matrix usage by default + settings.useAnalog = 0; // No matrix usage by default // Parse command-line arguments while (1) {
--- a/projects/audio_in_FFT/render.cpp Sat May 30 13:25:51 2015 -0500 +++ b/projects/audio_in_FFT/render.cpp Sun May 31 02:13:39 2015 -0500 @@ -6,7 +6,7 @@ */ -#include "../../include/render.h" +#include "../../include/BeagleRT.h" #include <rtdk.h> #include <NE10.h> // neon library #include <cmath> @@ -32,11 +32,7 @@ // // Return true on success; returning false halts the program. -bool initialise_render(int numMatrixChannels, int numAudioChannels, - int numMatrixFramesPerPeriod, - int numAudioFramesPerPeriod, - float matrixSampleRate, float audioSampleRate, - void *userData) +bool initialise_render(BeagleRTContext *context, void *userData) { // Retrieve a parameter passed in from the initAudio() call gFFTSize = *(int *)userData; @@ -57,11 +53,11 @@ // ADCs and DACs (if available). If only audio is available, numMatrixFrames // will be 0. -void render(int numMatrixFrames, int numAudioFrames, float *audioIn, float *audioOut, - uint16_t *matrixIn, uint16_t *matrixOut) +void render(BeagleRTContext *context, void *userData) { - for(int n = 0; n < numAudioFrames; n++) { - timeDomainIn[gReadPointer].r = (ne10_float32_t) ((audioIn[n*gNumAudioChannels] + audioIn[n*gNumAudioChannels+1]) * 0.5); + for(unsigned int n = 0; n < context->audioFrames; n++) { + timeDomainIn[gReadPointer].r = (ne10_float32_t) ((context->audioIn[n*context->audioChannels] + + context->audioIn[n*context->audioChannels+1]) * 0.5); timeDomainIn[gReadPointer].i = 0; if(++gReadPointer >= gFFTSize) @@ -78,8 +74,8 @@ gWritePointer = 0; } - for(int channel = 0; channel < gNumAudioChannels; channel++) - audioOut[n * gNumAudioChannels + channel] = (float) timeDomainOut[gWritePointer].r * gFFTScaleFactor; + for(int channel = 0; channel < context->audioChannels; channel++) + context->audioOut[n * context->audioChannels + channel] = (float) timeDomainOut[gWritePointer].r * gFFTScaleFactor; gWritePointer++; } } @@ -87,7 +83,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) { NE10_FREE(timeDomainIn); NE10_FREE(timeDomainOut);
--- a/projects/basic_analog_output/main.cpp Sat May 30 13:25:51 2015 -0500 +++ b/projects/basic_analog_output/main.cpp Sun May 31 02:13:39 2015 -0500 @@ -10,7 +10,7 @@ #include <libgen.h> #include <signal.h> #include <getopt.h> -#include "../../include/RTAudio.h" +#include "../../include/BeagleRT.h" using namespace std; @@ -33,7 +33,7 @@ int main(int argc, char *argv[]) { - RTAudioSettings settings; // Standard audio settings + BeagleRTInitSettings settings; // Standard audio settings float frequency = 1.0; // Frequency of LED fades struct option customOptions[] =
--- a/projects/basic_analog_output/render.cpp Sat May 30 13:25:51 2015 -0500 +++ b/projects/basic_analog_output/render.cpp Sun May 31 02:13:39 2015 -0500 @@ -6,14 +6,14 @@ */ -#include "../../include/render.h" +#include "../../include/BeagleRT.h" #include "../../include/Utilities.h" #include <rtdk.h> #include <cmath> // Set range for analog outputs designed for driving LEDs -const float kMinimumAmplitude = (1.5 / 5.0) * MATRIX_MAX; -const float kAmplitudeRange = MATRIX_MAX - kMinimumAmplitude; +const float kMinimumAmplitude = (1.5 / 5.0); +const float kAmplitudeRange = 1.0 - kMinimumAmplitude; float gFrequency; float gPhase; @@ -28,21 +28,17 @@ // // Return true on success; returning false halts the program. -bool initialise_render(int numMatrixChannels, int numAudioChannels, - int numMatrixFramesPerPeriod, - int numAudioFramesPerPeriod, - float matrixSampleRate, float audioSampleRate, - void *userData) +bool initialise_render(BeagleRTContext *context, void *userData) { // Retrieve a parameter passed in from the initAudio() call gFrequency = *(float *)userData; - if(numMatrixFramesPerPeriod == 0) { + if(context->analogFrames == 0) { rt_printf("Error: this example needs the matrix enabled\n"); return false; } - gInverseSampleRate = 1.0 / matrixSampleRate; + gInverseSampleRate = 1.0 / context->analogSampleRate; gPhase = 0.0; return true; @@ -53,18 +49,15 @@ // ADCs and DACs (if available). If only audio is available, numMatrixFrames // will be 0. -void render(int numMatrixFrames, int numAudioFrames, float *audioIn, float *audioOut, - uint16_t *matrixIn, uint16_t *matrixOut) +void render(BeagleRTContext *context, void *userData) { - for(int n = 0; n < numMatrixFrames; n++) { + for(int n = 0; n < context->analogFrames; n++) { // Set LED to different phase for each matrix channel float relativePhase = 0.0; - for(int channel = 0; channel < gNumMatrixChannels; channel++) { + for(int channel = 0; channel < context->analogChannels; channel++) { float out = kMinimumAmplitude + kAmplitudeRange * 0.5f * (1.0f + sinf(gPhase + relativePhase)); - if(out > MATRIX_MAX) - out = MATRIX_MAX; - analogWrite(channel, n, out); + analogWriteFrame(context, n, channel, out); // Advance by pi/4 (1/8 of a full rotation) for each channel relativePhase += M_PI * 0.25; @@ -79,7 +72,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) { }
--- a/projects/basic_passthru/main.cpp Sat May 30 13:25:51 2015 -0500 +++ b/projects/basic_passthru/main.cpp Sun May 31 02:13:39 2015 -0500 @@ -10,7 +10,7 @@ #include <libgen.h> #include <signal.h> #include <getopt.h> -#include "../../include/RTAudio.h" +#include "../../include/BeagleRT.h" using namespace std; @@ -32,7 +32,7 @@ int main(int argc, char *argv[]) { - RTAudioSettings settings; // Standard audio settings + BeagleRTInitSettings settings; // Standard audio settings struct option customOptions[] = {
--- a/projects/basic_passthru/render.cpp Sat May 30 13:25:51 2015 -0500 +++ b/projects/basic_passthru/render.cpp Sun May 31 02:13:39 2015 -0500 @@ -6,7 +6,7 @@ */ -#include "../../include/render.h" +#include "../../include/BeagleRT.h" #include "../../include/Utilities.h" #include <rtdk.h> @@ -19,11 +19,7 @@ // // Return true on success; returning false halts the program. -bool initialise_render(int numMatrixChannels, int numAudioChannels, - int numMatrixFramesPerPeriod, - int numAudioFramesPerPeriod, - float matrixSampleRate, float audioSampleRate, - void *userData) +bool initialise_render(BeagleRTContext *context, void *userData) { // Nothing to do here... @@ -35,25 +31,24 @@ // ADCs and DACs (if available). If only audio is available, numMatrixFrames // will be 0. -void render(int numMatrixFrames, int numAudioFrames, float *audioIn, float *audioOut, - uint16_t *matrixIn, uint16_t *matrixOut) +void render(BeagleRTContext *context, void *userData) { // Simplest possible case: pass inputs through to outputs - for(int n = 0; n < numAudioFrames; n++) { - for(int ch = 0; ch < gNumAudioChannels; ch++) - audioOut[n * gNumAudioChannels + ch] = audioIn[n * gNumAudioChannels + ch]; + for(unsigned int n = 0; n < context->audioFrames; n++) { + for(unsigned int ch = 0; ch < context->audioChannels; ch++) + context->audioOut[n * context->audioChannels + ch] = context->audioIn[n * context->audioChannels + ch]; } // Same with matrix, only if matrix is enabled - if(numMatrixFrames != 0) { - for(int n = 0; n < numMatrixFrames; n++) { - for(int ch = 0; ch < gNumMatrixChannels; ch++) { + if(context->analogFrames != 0) { + for(unsigned int n = 0; n < context->analogFrames; n++) { + for(unsigned int ch = 0; ch < context->analogChannels; ch++) { // Two equivalent ways to write this code // The long way, using the buffers directly: - // matrixOut[n * gNumMatrixChannels + ch] = matrixIn[n * gNumMatrixChannels + ch]; + // context->analogOut[n * context->analogChannels + ch] = context->analogIn[n * context->analogChannels + ch]; // Or using the macros: - analogWrite(ch, n, analogRead(ch, n)); + analogWriteFrame(context, n, ch, analogReadFrame(context, n, ch)); } } } @@ -62,7 +57,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) { }
--- a/projects/basic_sensor/main.cpp Sat May 30 13:25:51 2015 -0500 +++ b/projects/basic_sensor/main.cpp Sun May 31 02:13:39 2015 -0500 @@ -10,7 +10,7 @@ #include <libgen.h> #include <signal.h> #include <getopt.h> -#include "../../include/RTAudio.h" +#include "../../include/BeagleRT.h" using namespace std; @@ -37,7 +37,7 @@ int main(int argc, char *argv[]) { - RTAudioSettings settings; // Standard audio settings + BeagleRTInitSettings settings; // Standard audio settings struct option customOptions[] = {
--- a/projects/basic_sensor/render.cpp Sat May 30 13:25:51 2015 -0500 +++ b/projects/basic_sensor/render.cpp Sun May 31 02:13:39 2015 -0500 @@ -6,14 +6,14 @@ */ -#include "../../include/render.h" +#include "../../include/BeagleRT.h" #include "../../include/Utilities.h" #include <rtdk.h> #include <cmath> float gPhase; float gInverseSampleRate; -int gMatrixFramesPerAudioFrame; +int gAudioFramesPerAnalogFrame; // These settings are carried over from main.cpp // Setting global variables is an alternative approach @@ -31,19 +31,15 @@ // // Return true on success; returning false halts the program. -bool initialise_render(int numMatrixChannels, int numAudioChannels, - int numMatrixFramesPerPeriod, - int numAudioFramesPerPeriod, - float matrixSampleRate, float audioSampleRate, - void *userData) +bool initialise_render(BeagleRTContext *context, void *userData) { - if(numMatrixFramesPerPeriod == 0 || numMatrixFramesPerPeriod > numAudioFramesPerPeriod) { - rt_printf("Error: this example needs the matrix enabled, with 4 or 8 channels\n"); + if(context->analogFrames == 0 || context->analogFrames > context->audioFrames) { + rt_printf("Error: this example needs analog enabled, with 4 or 8 channels\n"); return false; } - gMatrixFramesPerAudioFrame = numAudioFramesPerPeriod / numMatrixFramesPerPeriod; - gInverseSampleRate = 1.0 / audioSampleRate; + gAudioFramesPerAnalogFrame = context->audioFrames / context->analogFrames; + gInverseSampleRate = 1.0 / context->audioSampleRate; gPhase = 0.0; return true; @@ -54,26 +50,25 @@ // ADCs and DACs (if available). If only audio is available, numMatrixFrames // will be 0. -void render(int numMatrixFrames, int numAudioFrames, float *audioIn, float *audioOut, - uint16_t *matrixIn, uint16_t *matrixOut) +void render(BeagleRTContext *context, void *userData) { - float frequency = 0; - float amplitude = 0; + float frequency = 440.0; + float amplitude = 0.8; // There are twice as many audio frames as matrix frames since audio sample rate // is twice as high - for(int n = 0; n < numAudioFrames; n++) { - if(!(n % gMatrixFramesPerAudioFrame)) { + for(unsigned int n = 0; n < context->audioFrames; n++) { + if(!(n % gAudioFramesPerAnalogFrame)) { // Even audio samples: update frequency and amplitude from the matrix - frequency = map(analogRead(gSensorInputFrequency, n/gMatrixFramesPerAudioFrame), 0, MATRIX_MAX, 100, 1000); - amplitude = (float)analogRead(gSensorInputAmplitude, n/gMatrixFramesPerAudioFrame) / MATRIX_MAX; + frequency = map(analogReadFrame(context, n/gAudioFramesPerAnalogFrame, gSensorInputFrequency), 0, 1, 100, 1000); + amplitude = analogReadFrame(context, n/gAudioFramesPerAnalogFrame, gSensorInputAmplitude); } float out = amplitude * sinf(gPhase); - for(int channel = 0; channel < gNumAudioChannels; channel++) - audioOut[n * gNumAudioChannels + channel] = out; + for(unsigned int channel = 0; channel < context->audioChannels; channel++) + context->audioOut[n * context->audioChannels + channel] = out; gPhase += 2.0 * M_PI * frequency * gInverseSampleRate; if(gPhase > 2.0 * M_PI) @@ -84,7 +79,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) { }
--- a/projects/filter_FIR/main.cpp Sat May 30 13:25:51 2015 -0500 +++ b/projects/filter_FIR/main.cpp Sun May 31 02:13:39 2015 -0500 @@ -12,7 +12,7 @@ #include <string> #include <getopt.h> #include <sndfile.h> // to load audio files -#include "../../include/RTAudio.h" +#include "../../include/BeagleRT.h" #include "SampleData.h" using namespace std; @@ -90,7 +90,7 @@ int main(int argc, char *argv[]) { - RTAudioSettings settings; // Standard audio settings + BeagleRTInitSettings settings; // Standard audio settings string fileName; // Name of the sample to load SampleData sampleData; // User define structure to pass data retrieved from file to render function
--- a/projects/filter_FIR/render.cpp Sat May 30 13:25:51 2015 -0500 +++ b/projects/filter_FIR/render.cpp Sun May 31 02:13:39 2015 -0500 @@ -6,8 +6,7 @@ */ -#include "../../include/render.h" -#include "../../include/RTAudio.h" // to schedule lower prio parallel process +#include "../../include/BeagleRT.h" // to schedule lower prio parallel process #include <rtdk.h> #include <cmath> #include <stdio.h> @@ -25,7 +24,7 @@ ne10_uint32_t blockSize; ne10_float32_t *gFIRfilterState; -void initialise_filter(); +void initialise_filter(BeagleRTContext *context); // Task for handling the update of the frequencies using the matrix @@ -34,9 +33,6 @@ bool initialise_trigger(); void trigger_samples(); -int gPeriodSize; // Period size in sensor frames - - // initialise_render() is called once before the audio rendering starts. // Use it to perform any initialisation and allocation which is dependent // on the period size or sample rate. @@ -46,20 +42,15 @@ // // Return true on success; returning false halts the program. -bool initialise_render(int numMatrixChannels, int numAudioChannels, - int numMatrixFramesPerPeriod, - int numAudioFramesPerPeriod, - float matrixSampleRate, float audioSampleRate, - void *userData) +bool initialise_render(BeagleRTContext *context, void *userData) { // Retrieve a parameter passed in from the initAudio() call gSampleData = *(SampleData *)userData; gReadPtr = -1; - gPeriodSize = numMatrixFramesPerPeriod; - initialise_filter(); + initialise_filter(context); // Initialise auxiliary tasks if(!initialise_trigger()) @@ -73,10 +64,9 @@ // ADCs and DACs (if available). If only audio is available, numMatrixFrames // will be 0. -void render(int numMatrixFrames, int numAudioFrames, float *audioIn, float *audioOut, - uint16_t *matrixIn, uint16_t *matrixOut) +void render(BeagleRTContext *context, void *userData) { - for(int n = 0; n < numAudioFrames; n++) { + for(unsigned int n = 0; n < context->audioFrames; n++) { float in = 0; // If triggered... @@ -91,21 +81,21 @@ ne10_fir_float_neon(&gFIRfilter, gFIRfilterIn, gFIRfilterOut, blockSize); - for(int n = 0; n < numAudioFrames; n++) { - for(int channel = 0; channel < gNumAudioChannels; channel++) - audioOut[n * gNumAudioChannels + channel] = gFIRfilterOut[n]; // ...and put it in both left and right channel + for(unsigned int n = 0; n < context->audioFrames; n++) { + for(unsigned int channel = 0; channel < context->audioChannels; channel++) + context->audioOut[n * context->audioChannels + channel] = gFIRfilterOut[n]; // ...and put it in both left and right channel } // Request that the lower-priority task run at next opportunity - scheduleAuxiliaryTask(gTriggerSamplesTask); + BeagleRT_scheduleAuxiliaryTask(gTriggerSamplesTask); } // Initialise NE10 data structures to define FIR filter -void initialise_filter() +void initialise_filter(BeagleRTContext *context) { - blockSize = 2*gPeriodSize; + blockSize = context->audioFrames; gFIRfilterState = (ne10_float32_t *) NE10_MALLOC ((FILTER_TAP_NUM+blockSize-1) * sizeof (ne10_float32_t)); gFIRfilterIn = (ne10_float32_t *) NE10_MALLOC (blockSize * sizeof (ne10_float32_t)); gFIRfilterOut = (ne10_float32_t *) NE10_MALLOC (blockSize * sizeof (ne10_float32_t)); @@ -118,7 +108,7 @@ bool initialise_trigger() { - if((gTriggerSamplesTask = createAuxiliaryTaskLoop(&trigger_samples, 50, "beaglert-trigger-samples")) == 0) + if((gTriggerSamplesTask = BeagleRT_createAuxiliaryTask(&trigger_samples, 50, "beaglert-trigger-samples")) == 0) return false; rt_printf("Press 'a' to trigger sample, 's' to stop\n"); @@ -164,7 +154,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) { delete[] gSampleData.samples;
--- a/projects/filter_IIR/main.cpp Sat May 30 13:25:51 2015 -0500 +++ b/projects/filter_IIR/main.cpp Sun May 31 02:13:39 2015 -0500 @@ -12,7 +12,7 @@ #include <string> #include <getopt.h> #include <sndfile.h> // to load audio files -#include "../../include/RTAudio.h" +#include "../../include/BeagleRT.h" #include "SampleData.h" using namespace std; @@ -92,7 +92,7 @@ int main(int argc, char *argv[]) { - RTAudioSettings settings; // Standard audio settings + BeagleRTInitSettings settings; // Standard audio settings string fileName; // Name of the sample to load SampleData sampleData; // User define structure to pass data retrieved from file to render function
--- a/projects/filter_IIR/render.cpp Sat May 30 13:25:51 2015 -0500 +++ b/projects/filter_IIR/render.cpp Sun May 31 02:13:39 2015 -0500 @@ -6,8 +6,7 @@ */ -#include "../../include/render.h" -#include "../../include/RTAudio.h" // to schedule lower prio parallel process +#include "../../include/BeagleRT.h" // to schedule lower prio parallel process #include <rtdk.h> #include <cmath> #include <stdio.h> @@ -54,11 +53,7 @@ // // Return true on success; returning false halts the program. -bool initialise_render(int numMatrixChannels, int numAudioChannels, - int numMatrixFramesPerPeriod, - int numAudioFramesPerPeriod, - float matrixSampleRate, float audioSampleRate, - void *userData) +bool initialise_render(BeagleRTContext *context, void *userData) { // Retrieve a parameter passed in from the initAudio() call @@ -80,10 +75,9 @@ // ADCs and DACs (if available). If only audio is available, numMatrixFrames // will be 0. -void render(int numMatrixFrames, int numAudioFrames, float *audioIn, float *audioOut, - uint16_t *matrixIn, uint16_t *matrixOut) +void render(BeagleRTContext *context, void *userData) { - for(int n = 0; n < numAudioFrames; n++) { + for(unsigned int n = 0; n < context->audioFrames; n++) { float sample = 0; float out = 0; @@ -101,14 +95,14 @@ gLastY[1] = gLastY[0]; gLastY[0] = out; - for(int channel = 0; channel < gNumAudioChannels; channel++) - audioOut[n * gNumAudioChannels + channel] = out; // ...and put it in both left and right channel + for(unsigned int channel = 0; channel < context->audioChannels; channel++) + context->audioOut[n * context->audioChannels + channel] = out; // ...and put it in both left and right channel } // Request that the lower-priority tasks run at next opportunity - scheduleAuxiliaryTask(gChangeCoeffTask); - scheduleAuxiliaryTask(gInputTask); + BeagleRT_scheduleAuxiliaryTask(gChangeCoeffTask); + BeagleRT_scheduleAuxiliaryTask(gInputTask); } // First calculation of coefficients @@ -145,10 +139,10 @@ bool initialise_aux_tasks() { - if((gChangeCoeffTask = createAuxiliaryTaskLoop(&check_coeff, 90, "beaglert-check-coeff")) == 0) + if((gChangeCoeffTask = BeagleRT_createAuxiliaryTask(&check_coeff, 90, "beaglert-check-coeff")) == 0) return false; - if((gInputTask = createAuxiliaryTaskLoop(&read_input, 50, "beaglert-read-input")) == 0) + if((gInputTask = BeagleRT_createAuxiliaryTask(&read_input, 50, "beaglert-read-input")) == 0) return false; rt_printf("Press 'a' to trigger sample, 's' to stop\n"); @@ -221,7 +215,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) { delete[] gSampleData.samples; }
--- a/projects/oscillator_bank/main.cpp Sat May 30 13:25:51 2015 -0500 +++ b/projects/oscillator_bank/main.cpp Sun May 31 02:13:39 2015 -0500 @@ -10,7 +10,7 @@ #include <libgen.h> #include <signal.h> #include <getopt.h> -#include "../../include/RTAudio.h" +#include "../../include/BeagleRT.h" using namespace std; @@ -37,7 +37,7 @@ int main(int argc, char *argv[]) { - RTAudioSettings settings; // Standard audio settings + BeagleRTInitSettings settings; // Standard audio settings struct option customOptions[] = {
--- 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);
--- a/projects/samples/main.cpp Sat May 30 13:25:51 2015 -0500 +++ b/projects/samples/main.cpp Sun May 31 02:13:39 2015 -0500 @@ -12,7 +12,7 @@ #include <string> #include <getopt.h> #include <sndfile.h> // to load audio files -#include "../../include/RTAudio.h" +#include "../../include/BeagleRT.h" #include "SampleData.h" using namespace std; @@ -90,7 +90,7 @@ int main(int argc, char *argv[]) { - RTAudioSettings settings; // Standard audio settings + BeagleRTInitSettings settings; // Standard audio settings string fileName; // Name of the sample to load SampleData sampleData; // User define structure to pass data retrieved from file to render function
--- a/projects/samples/render.cpp Sat May 30 13:25:51 2015 -0500 +++ b/projects/samples/render.cpp Sun May 31 02:13:39 2015 -0500 @@ -6,8 +6,7 @@ */ -#include "../../include/render.h" -#include "../../include/RTAudio.h" // to schedule lower prio parallel process +#include "../../include/BeagleRT.h" // to schedule lower prio parallel process #include <rtdk.h> #include <cmath> #include <stdio.h> @@ -31,11 +30,7 @@ // // Return true on success; returning false halts the program. -bool initialise_render(int numMatrixChannels, int numAudioChannels, - int numMatrixFramesPerPeriod, - int numAudioFramesPerPeriod, - float matrixSampleRate, float audioSampleRate, - void *userData) +bool initialise_render(BeagleRTContext *context, void *userData) { // Retrieve a parameter passed in from the initAudio() call @@ -55,10 +50,9 @@ // ADCs and DACs (if available). If only audio is available, numMatrixFrames // will be 0. -void render(int numMatrixFrames, int numAudioFrames, float *audioIn, float *audioOut, - uint16_t *matrixIn, uint16_t *matrixOut) +void render(BeagleRTContext *context, void *userData) { - for(int n = 0; n < numAudioFrames; n++) { + for(int n = 0; n < context->audioFrames; n++) { float out = 0; // If triggered... @@ -68,12 +62,12 @@ if(gReadPtr >= gSampleData.sampleLen) gReadPtr = -1; - for(int channel = 0; channel < gNumAudioChannels; channel++) - audioOut[n * gNumAudioChannels + channel] = out; // ...and put it in both left and right channel + for(int channel = 0; channel < context->audioChannels; channel++) + context->audioOut[n * context->audioChannels + channel] = out; // ...and put it in both left and right channel } // Request that the lower-priority task run at next opportunity - scheduleAuxiliaryTask(gTriggerSamplesTask); + BeagleRT_scheduleAuxiliaryTask(gTriggerSamplesTask); } // Initialise the auxiliary task @@ -81,7 +75,7 @@ bool initialise_trigger() { - if((gTriggerSamplesTask = createAuxiliaryTaskLoop(&trigger_samples, 50, "beaglert-trigger-samples")) == 0) + if((gTriggerSamplesTask = BeagleRT_createAuxiliaryTask(&trigger_samples, 50, "beaglert-trigger-samples")) == 0) return false; rt_printf("Press 'a' to trigger sample, 's' to stop\n"); @@ -127,7 +121,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) { delete[] gSampleData.samples; }