Mercurial > hg > beaglert
comparison projects/analogDigitalDemo/render.cpp @ 33:83baffda5786 matrix_gpio
Fixed bug in Digital macros and in example project
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Mon, 11 May 2015 18:58:47 +0100 |
parents | 182ae9367104 |
children | a6d223473ea2 |
comparison
equal
deleted
inserted
replaced
31:06fd2ffee605 | 33:83baffda5786 |
---|---|
24 int gNumDigitalFrames=0; | 24 int gNumDigitalFrames=0; |
25 bool initialise_render(int numAnalogChannels, int numDigitalChannels, int numAudioChannels, | 25 bool initialise_render(int numAnalogChannels, int numDigitalChannels, int numAudioChannels, |
26 int numAnalogFramesPerPeriod, | 26 int numAnalogFramesPerPeriod, |
27 int numAudioFramesPerPeriod, | 27 int numAudioFramesPerPeriod, |
28 float analogSampleRate, float audioSampleRate, | 28 float analogSampleRate, float audioSampleRate, |
29 void *userData) | 29 void *userData, RTAudioSettings* settings) |
30 { | 30 { |
31 gNumAnalogChannels=numAnalogChannels; | 31 gNumAnalogChannels=numAnalogChannels; |
32 gNumDigitalChannels=numDigitalChannels; | 32 gNumDigitalChannels=numDigitalChannels; |
33 return true; | 33 return true; |
34 } | 34 } |
43 float *analogIn, float *analogOut, uint32_t *digital) | 43 float *analogIn, float *analogOut, uint32_t *digital) |
44 /* | 44 /* |
45 we assume that gNumAnalogChannels=8, numAnalogFrames==8 and numDigitalFrames==numAudioFrames | 45 we assume that gNumAnalogChannels=8, numAnalogFrames==8 and numDigitalFrames==numAudioFrames |
46 * */ | 46 * */ |
47 { | 47 { |
48 gNumDigitalFrames=numDigitalFrames; | |
49 | |
50 if((gCountFrames&31)==0){ //every 32 frames... | 48 if((gCountFrames&31)==0){ //every 32 frames... |
51 //ANALOG channels | 49 //ANALOG channels |
52 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 | 50 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 |
53 // The value at the last frame will persist through the successive buffers until is set again. | 51 // The value at the last frame will persist through the successive buffers until is set again. |
54 // This effectively is a pass-through with downsampling by 32 times | 52 // This effectively is a pass-through with downsampling by 32 times |
64 // in the next buffer each frame of channel 0 will be initialized to 1 (the last value of this buffer) | 62 // in the next buffer each frame of channel 0 will be initialized to 1 (the last value of this buffer) |
65 digitalWrite(P8_08,0,GPIO_HIGH); | 63 digitalWrite(P8_08,0,GPIO_HIGH); |
66 digitalWrite(P8_08,2,GPIO_LOW); | 64 digitalWrite(P8_08,2,GPIO_LOW); |
67 digitalWrite(P8_08,4,GPIO_HIGH); | 65 digitalWrite(P8_08,4,GPIO_HIGH); |
68 digitalWrite(P8_08,5,GPIO_LOW); | 66 digitalWrite(P8_08,5,GPIO_LOW); |
67 setDigitalDirection(P9_16,0,GPIO_INPUT); // set channel 10 to input | |
69 // in this buffer the frames of channel 1 will look like this: 1 1 0 0 1 0 0 0 .... 0 | 68 // in this buffer the frames of channel 1 will look like this: 1 1 0 0 1 0 0 0 .... 0 |
70 // in the next buffer each frame of channel 1 will be initialized to 0 (the last value of this buffer) | 69 // in the next buffer each frame of channel 1 will be initialized to 0 (the last value of this buffer) |
71 } | 70 } |
72 for(int n=0; n<numAudioFrames; n++){ | 71 for(int n=0; n<numAudioFrames; n++){ |
73 for(int c=0; c<gNumAudioChannels; c++){ | 72 for(int c=0; c<gNumAudioChannels; c++){ |
74 audioOut[n*gNumAudioChannels + c]=audioIn[n*gNumAudioChannels + c]; | 73 audioOut[n*gNumAudioChannels + c]=audioIn[n*gNumAudioChannels + c]; |
75 } | 74 } |
76 //use digital channels 2-5 to create a 4 bit binary counter | 75 //use digital channels 2-8 to create a 7 bit binary counter |
77 digital[n]=digital[n] & (~0b111100); // set to zero (GPIO_OUTPUT) the bits in the lower word | 76 digital[n]=digital[n] & (~0b111111100); // set to zero (GPIO_OUTPUT) the bits in the lower word |
78 digital[n]=digital[n] & (~0b111100<<16); //initialize to zero the bits in the higher word (output value) | 77 digital[n]=digital[n] & ((~0b111111100<<16) | 0xffff ); //initialize to zero the bits in the higher word (output value) |
79 digital[n]=digital[n] | (n<<(16+2)); // set the bits in the higher word to the desired output value | 78 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 |
79 digitalWriteFrame(P8_29,n,digitalRead(P8_30,n)); // echo the input from from channel 15 to channel 14 | |
80 digitalWriteFrame(P8_28,n,digitalRead(P9_16,n)); // echo the input from from channel 10 to channel 13 | |
81 setDigitalDirection(P8_30,0,GPIO_INPUT); //set channel 15 to input | |
82 gCountFrames++; | |
80 } | 83 } |
81 | 84 |
82 for(int n=0; n<numAnalogFrames; n++){ | 85 for(int n=0; n<numAnalogFrames; n++){ |
83 analogWriteFrame(1,n,(gCountFrames&8191)/8192.0); // writes a single frame. channel 1 is a ramp that follows gCountFrames | 86 analogWriteFrame(1,n,(gCountFrames&8191)/8192.0); // writes a single frame. channel 1 is a ramp that follows gCountFrames |
84 analogWriteFrame(2,n,analogRead(2,n)); // writes a single frame. channel2 is just a passthrough | 87 analogWriteFrame(2,n,analogRead(2,n)); // writes a single frame. channel2 is just a passthrough |
85 // rt_printf("Analog out frame %d :",n); | 88 // rt_printf("Analog out frame %d :",n); |
86 // for(int c=0; c<gNumAnalogChannels; c++) | 89 // for(int c=0; c<gNumAnalogChannels; c++) |
87 // rt_printf("%.1f ",analogOut[n*gNumAnalogChannels + c]); | 90 // rt_printf("%.1f ",analogOut[n*gNumAnalogChannels + c]); |
88 // rt_printf("\n"); | 91 // rt_printf("\n"); |
89 gCountFrames++; | |
90 } | 92 } |
91 return; | 93 return; |
92 | 94 |
93 } | 95 } |
94 // cleanup_render() is called once at the end, after the audio has stopped. | 96 // cleanup_render() is called once at the end, after the audio has stopped. |