Mercurial > hg > beaglert
comparison examples/analogDigitalDemo/render.cpp @ 311:493a07f6ec09 prerelease
Renamed BelaContext->audioSampleCount to BelaContext->audioFramesElapsed for consistency of terminology
author | andrewm |
---|---|
date | Fri, 27 May 2016 18:37:51 +0100 |
parents | 02c4ca0e3718 |
children | db2fe4e1b88e |
comparison
equal
deleted
inserted
replaced
310:02c4ca0e3718 | 311:493a07f6ec09 |
---|---|
34 * */ | 34 * */ |
35 { | 35 { |
36 /* | 36 /* |
37 * TODO: as an exercise, you will need to set the pin mode before writing or reading the digital pins. | 37 * TODO: as an exercise, you will need to set the pin mode before writing or reading the digital pins. |
38 */ | 38 */ |
39 if((context->audioSampleCount&31)==0){ //every 32 frames... | 39 if((context->audioFramesElapsed&31)==0){ //every 32 frames... |
40 //ANALOG channels | 40 //ANALOG channels |
41 analogWrite(context, 0, 0, analogRead(context, 0,0)); | 41 analogWrite(context, 0, 0, analogRead(context, 0,0)); |
42 // read the input0 at frame0 and write it to output0 frame0. Using analogWrite will fill the rest of the buffer with the same value | 42 // read the input0 at frame0 and write it to output0 frame0. Using analogWrite will fill the rest of the buffer with the same value |
43 // The value at the last frame will persist through the successive buffers until is set again. | 43 // The value at the last frame will persist through the successive buffers until is set again. |
44 // This effectively is a pass-through with downsampling by 32 times | 44 // This effectively is a pass-through with downsampling by 32 times |
65 context->audioOut[n*context->audioChannels + c]=context->audioIn[n*context->audioChannels + c]; | 65 context->audioOut[n*context->audioChannels + c]=context->audioIn[n*context->audioChannels + c]; |
66 } | 66 } |
67 //use digital channels 2-8 to create a 7 bit binary counter | 67 //use digital channels 2-8 to create a 7 bit binary counter |
68 context->digital[n]=context->digital[n] & (~0b111111100); // set to zero (GPIO_OUTPUT) the bits in the lower word | 68 context->digital[n]=context->digital[n] & (~0b111111100); // set to zero (GPIO_OUTPUT) the bits in the lower word |
69 context->digital[n]=context->digital[n] & ((~0b111111100<<16) | 0xffff ); //initialize to zero the bits in the higher word (output value) | 69 context->digital[n]=context->digital[n] & ((~0b111111100<<16) | 0xffff ); //initialize to zero the bits in the higher word (output value) |
70 context->digital[n]=context->digital[n] | ( ((context->audioSampleCount&0b1111111)<<(16+2)) ) ; // set the bits in the higher word to the desired output value, keeping the lower word unchanged | 70 context->digital[n]=context->digital[n] | ( ((context->audioFramesElapsed&0b1111111)<<(16+2)) ) ; // set the bits in the higher word to the desired output value, keeping the lower word unchanged |
71 digitalWrite(context, n, P8_29, digitalRead(context, n, P8_30)); // echo the input from from channel 15 to channel 14 | 71 digitalWrite(context, n, P8_29, digitalRead(context, n, P8_30)); // echo the input from from channel 15 to channel 14 |
72 digitalWrite(context, n, P8_28, digitalRead(context, n, P9_16)); // echo the input from from channel 10 to channel 13 | 72 digitalWrite(context, n, P8_28, digitalRead(context, n, P9_16)); // echo the input from from channel 10 to channel 13 |
73 pinMode(context, 0, P8_30, 0); //set channel 15 to input | 73 pinMode(context, 0, P8_30, 0); //set channel 15 to input |
74 } | 74 } |
75 | 75 |
76 for(unsigned int n=0; n<context->analogFrames; n++){ | 76 for(unsigned int n=0; n<context->analogFrames; n++){ |
77 analogWrite(context, n, 1, (context->audioSampleCount&8191)/8192.0); // writes a single frame. channel 1 is a ramp that follows gCountFrames | 77 analogWrite(context, n, 1, (context->audioFramesElapsed&8191)/8192.0); // writes a single frame. channel 1 is a ramp that follows gCountFrames |
78 analogWrite(context, n, 2, analogRead(context, n, 2)); // writes a single frame. channel2 is just a passthrough | 78 analogWrite(context, n, 2, analogRead(context, n, 2)); // writes a single frame. channel2 is just a passthrough |
79 // rt_printf("Analog out frame %d :",n); | 79 // rt_printf("Analog out frame %d :",n); |
80 // for(int c=0; c<gNumAnalogChannels; c++) | 80 // for(int c=0; c<gNumAnalogChannels; c++) |
81 // rt_printf("%.1f ",analogOut[n*gNumAnalogChannels + c]); | 81 // rt_printf("%.1f ",analogOut[n*gNumAnalogChannels + c]); |
82 // rt_printf("\n"); | 82 // rt_printf("\n"); |