Mercurial > hg > beaglert
comparison projects/analogDigitalDemo/render.cpp @ 19:c98863e63174 matrix_gpio
Renamed matrixGpio to digital and matrix to analog
| author | Giulio Moro <giuliomoro@yahoo.it> |
|---|---|
| date | Thu, 30 Apr 2015 16:58:41 +0100 |
| parents | |
| children | 58eb99dac921 |
comparison
equal
deleted
inserted
replaced
| 18:31503d9de101 | 19:c98863e63174 |
|---|---|
| 1 /* | |
| 2 * | |
| 3 * First assignment for ECS732 RTDSP, to implement a 2-way audio crossover | |
| 4 * using the BeagleBone Black. | |
| 5 * | |
| 6 * Andrew McPherson and Victor Zappi | |
| 7 * Queen Mary, University of London | |
| 8 */ | |
| 9 | |
| 10 #include "../include/render.h" | |
| 11 #include <cmath> | |
| 12 #include <rtdk.h> | |
| 13 | |
| 14 /* TASK: declare any global variables you need here */ | |
| 15 | |
| 16 // initialise_render() is called once before the audio rendering starts. | |
| 17 // Use it to perform any initialisation and allocation which is dependent | |
| 18 // on the period size or sample rate. | |
| 19 // | |
| 20 // userData holds an opaque pointer to a data structure that was passed | |
| 21 // in from the call to initAudio(). | |
| 22 // | |
| 23 // Return true on success; returning false halts the program. | |
| 24 int gNumMatrixGpioFrames=0; | |
| 25 bool initialise_render(int numMatrixChannels, int numMatrixGpioChannels, int numAudioChannels, | |
| 26 int numMatrixFramesPerPeriod, | |
| 27 int numAudioFramesPerPeriod, | |
| 28 float matrixSampleRate, float audioSampleRate, | |
| 29 void *userData) | |
| 30 { | |
| 31 gNumMatrixChannels=numMatrixChannels; | |
| 32 return true; | |
| 33 } | |
| 34 | |
| 35 // render() is called regularly at the highest priority by the audio engine. | |
| 36 // Input and output are given from the audio hardware and the other | |
| 37 // ADCs and DACs (if available). If only audio is available, numMatrixFrames | |
| 38 // will be 0. | |
| 39 | |
| 40 long int gCountFrames=0; | |
| 41 void render(int numMatrixFrames, int numMatrixGpioFrames, int numAudioFrames, float *audioIn, float *audioOut, | |
| 42 float *matrixIn, float *matrixOut, uint32_t *matrixGpio) | |
| 43 /* | |
| 44 * Hey, expect buffer underruns to happen here, as we are doing lots of printfs | |
| 45 * */ | |
| 46 { | |
| 47 gNumMatrixGpioFrames=numMatrixGpioFrames; | |
| 48 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 | |
| 49 // that is, P8_29 will pulse at the beginning of each buffer | |
| 50 } | |
| 51 for(int i=1; i<gNumMatrixGpioFrames; i++) | |
| 52 digitalWriteAll(i, GPIO_LOW); //write all channels on the given frame. Initialize them to zero | |
| 53 digitalWrite(0, 4, GPIO_HIGH); // set pin 0 HIGH from the current frame to the end of the buffer | |
| 54 for(int n=0; n<numMatrixFrames; n++) { | |
| 55 for(int c=0; c<gNumMatrixChannels; c++) | |
| 56 analogWriteFrame(c,n,0); //set channel c on frame n to 0, equivalent to matrixOut[n*numMatrixChannels+c]=0; | |
| 57 } | |
| 58 analogWrite(0,3,0.2); //set channel 0 to 0.2 from frame 3 onwards ... | |
| 59 analogWrite(1,3,0.7); //set channel 1 to 0.7 from frame 3 onwards ... | |
| 60 analogWrite(2,6,0.5); //set channel 2 to 0.5 from frame 6 onwards ... | |
| 61 for(int n=0; n<numAudioFrames; n++){ | |
| 62 printf("Digital frame %d: 0x%08x;\n",n,matrixGpio[n]); | |
| 63 } | |
| 64 for(int n=0; n<numMatrixFrames; n++){ | |
| 65 printf("Analog out frame %d :",n); | |
| 66 for(int c=0; c<gNumMatrixChannels; c++) | |
| 67 printf("%.1f ",matrixOut[n*gNumMatrixChannels + c]); | |
| 68 printf("\n"); | |
| 69 } | |
| 70 } | |
| 71 // cleanup_render() is called once at the end, after the audio has stopped. | |
| 72 // Release any resources that were allocated in initialise_render(). | |
| 73 | |
| 74 void cleanup_render() | |
| 75 { | |
| 76 /* TASK: | |
| 77 * If you allocate any memory, be sure to release it here. | |
| 78 * You may or may not need anything in this function, depending | |
| 79 * on your implementation. | |
| 80 */ | |
| 81 } |
