comparison 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
comparison
equal deleted inserted replaced
19:c98863e63174 20:58eb99dac921
19 // 19 //
20 // userData holds an opaque pointer to a data structure that was passed 20 // userData holds an opaque pointer to a data structure that was passed
21 // in from the call to initAudio(). 21 // in from the call to initAudio().
22 // 22 //
23 // Return true on success; returning false halts the program. 23 // Return true on success; returning false halts the program.
24 int gNumMatrixGpioFrames=0; 24 int gNumDigitalFrames=0;
25 bool initialise_render(int numMatrixChannels, int numMatrixGpioChannels, int numAudioChannels, 25 bool initialise_render(int numAnalogChannels, int numDigitalChannels, int numAudioChannels,
26 int numMatrixFramesPerPeriod, 26 int numAnalogFramesPerPeriod,
27 int numAudioFramesPerPeriod, 27 int numAudioFramesPerPeriod,
28 float matrixSampleRate, float audioSampleRate, 28 float analogSampleRate, float audioSampleRate,
29 void *userData) 29 void *userData)
30 { 30 {
31 gNumMatrixChannels=numMatrixChannels; 31 gNumAnalogChannels=numAnalogChannels;
32 return true; 32 return true;
33 } 33 }
34 34
35 // render() is called regularly at the highest priority by the audio engine. 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 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 37 // ADCs and DACs (if available). If only audio is available, numAnalogFrames
38 // will be 0. 38 // will be 0.
39 39
40 long int gCountFrames=0; 40 long int gCountFrames=0;
41 void render(int numMatrixFrames, int numMatrixGpioFrames, int numAudioFrames, float *audioIn, float *audioOut, 41 void render(int numAnalogFrames, int numDigitalFrames, int numAudioFrames, float *audioIn, float *audioOut,
42 float *matrixIn, float *matrixOut, uint32_t *matrixGpio) 42 float *analogIn, float *analogOut, uint32_t *digital)
43 /* 43 /*
44 * Hey, expect buffer underruns to happen here, as we are doing lots of printfs 44 * Hey, expect buffer underruns to happen here, as we are doing lots of printfs
45 * */ 45 * */
46 { 46 {
47 gNumMatrixGpioFrames=numMatrixGpioFrames; 47 gNumDigitalFrames=numDigitalFrames;
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 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 49 // that is, P8_29 will pulse at the beginning of each buffer
50 } 50 }
51 for(int i=1; i<gNumMatrixGpioFrames; i++) 51 for(int i=1; i<gNumDigitalFrames; i++)
52 digitalWriteAll(i, GPIO_LOW); //write all channels on the given frame. Initialize them to zero 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 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++) { 54 for(int n=0; n<numAnalogFrames; n++) {
55 for(int c=0; c<gNumMatrixChannels; c++) 55 for(int c=0; c<gNumAnalogChannels; c++)
56 analogWriteFrame(c,n,0); //set channel c on frame n to 0, equivalent to matrixOut[n*numMatrixChannels+c]=0; 56 AnalogWriteFrame(c,n,0); //set channel c on frame n to 0, equivalent to analogOut[n*numAnalogChannels+c]=0;
57 } 57 }
58 analogWrite(0,3,0.2); //set channel 0 to 0.2 from frame 3 onwards ... 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 ... 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 ... 60 AnalogWrite(2,6,0.5); //set channel 2 to 0.5 from frame 6 onwards ...
61 for(int n=0; n<numAudioFrames; n++){ 61 for(int n=0; n<numAudioFrames; n++){
62 printf("Digital frame %d: 0x%08x;\n",n,matrixGpio[n]); 62 printf("Digital frame %d: 0x%08x;\n",n,digital[n]);
63 } 63 }
64 for(int n=0; n<numMatrixFrames; n++){ 64 for(int n=0; n<numAnalogFrames; n++){
65 printf("Analog out frame %d :",n); 65 printf("Analog out frame %d :",n);
66 for(int c=0; c<gNumMatrixChannels; c++) 66 for(int c=0; c<gNumAnalogChannels; c++)
67 printf("%.1f ",matrixOut[n*gNumMatrixChannels + c]); 67 printf("%.1f ",analogOut[n*gNumAnalogChannels + c]);
68 printf("\n"); 68 printf("\n");
69 } 69 }
70 } 70 }
71 // cleanup_render() is called once at the end, after the audio has stopped. 71 // cleanup_render() is called once at the end, after the audio has stopped.
72 // Release any resources that were allocated in initialise_render(). 72 // Release any resources that were allocated in initialise_render().