Mercurial > hg > beaglert
diff projects/matrix_gpio_demo/render.cpp @ 18:31503d9de101 matrix_gpio
- digitalWrite and analogWrite macros are now persistent: they write a value on the given channel from the current frame to the end of the buffer. When
this is not needed you can use digitalWriteFrame and analogWriteFrame instead.
- included the matrix_gpio_demo code
- the Eclipe project is somehow broken
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Thu, 30 Apr 2015 16:02:47 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/projects/matrix_gpio_demo/render.cpp Thu Apr 30 16:02:47 2015 +0100 @@ -0,0 +1,81 @@ +/* + * + * 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 <cmath> +#include <rtdk.h> + +/* TASK: declare any global variables you need here */ + +// 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. +// +// userData holds an opaque pointer to a data structure that was passed +// in from the call to initAudio(). +// +// Return true on success; returning false halts the program. +int gNumMatrixGpioFrames=0; +bool initialise_render(int numMatrixChannels, int numMatrixGpioChannels, int numAudioChannels, + int numMatrixFramesPerPeriod, + int numAudioFramesPerPeriod, + float matrixSampleRate, float audioSampleRate, + void *userData) +{ + gNumMatrixChannels=numMatrixChannels; + return true; +} + +// render() is called regularly at the highest priority by the audio engine. +// Input and output are given from the audio hardware and the other +// ADCs and DACs (if available). If only audio is available, numMatrixFrames +// will be 0. + +long int gCountFrames=0; +void render(int numMatrixFrames, int numMatrixGpioFrames, int numAudioFrames, float *audioIn, float *audioOut, + float *matrixIn, float *matrixOut, uint32_t *matrixGpio) +/* + * Hey, expect buffer underruns to happen here, as we are doing lots of printfs + * */ +{ + gNumMatrixGpioFrames=numMatrixGpioFrames; + if(gCountFrames==0){ //this will be executed only on the first call to render(), but the bits will go through this cycle for every subsequent buffer + // that is, P8_29 will pulse at the beginning of each buffer + } + for(int i=1; i<gNumMatrixGpioFrames; i++) + digitalWriteAll(i, GPIO_LOW); //write all channels on the given frame. Initialize them to zero + digitalWrite(0, 4, GPIO_HIGH); // set pin 0 HIGH from the current frame to the end of the buffer + for(int n=0; n<numMatrixFrames; n++) { + for(int c=0; c<gNumMatrixChannels; c++) + analogWriteFrame(c,n,0); //set channel c on frame n to 0, equivalent to matrixOut[n*numMatrixChannels+c]=0; + } + analogWrite(0,3,0.2); //set channel 0 to 0.2 from frame 3 onwards ... + analogWrite(1,3,0.7); //set channel 1 to 0.7 from frame 3 onwards ... + analogWrite(2,6,0.5); //set channel 2 to 0.5 from frame 6 onwards ... + for(int n=0; n<numAudioFrames; n++){ + printf("Digital frame %d: 0x%08x;\n",n,matrixGpio[n]); + } + for(int n=0; n<numMatrixFrames; n++){ + printf("Analog out frame %d :",n); + for(int c=0; c<gNumMatrixChannels; c++) + printf("%.1f ",matrixOut[n*gNumMatrixChannels + c]); + printf("\n"); + } +} +// 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() +{ + /* TASK: + * If you allocate any memory, be sure to release it here. + * You may or may not need anything in this function, depending + * on your implementation. + */ +}