annotate projects/analogDigitalDemo/render.cpp @ 20:58eb99dac921 matrix_gpio

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