comparison projects/basic_analog_output/render.cpp @ 13:6adb088196a7

Fixed ADC bug; added a simple passthrough test
author andrewm
date Fri, 23 Jan 2015 15:17:09 +0000
parents a6beeba3a648
children a6d223473ea2
comparison
equal deleted inserted replaced
12:a6beeba3a648 13:6adb088196a7
16 const float kAmplitudeRange = MATRIX_MAX - kMinimumAmplitude; 16 const float kAmplitudeRange = MATRIX_MAX - kMinimumAmplitude;
17 17
18 float gFrequency; 18 float gFrequency;
19 float gPhase; 19 float gPhase;
20 float gInverseSampleRate; 20 float gInverseSampleRate;
21
22 int gMatrixChannels;
23 21
24 // initialise_render() is called once before the audio rendering starts. 22 // initialise_render() is called once before the audio rendering starts.
25 // Use it to perform any initialisation and allocation which is dependent 23 // Use it to perform any initialisation and allocation which is dependent
26 // on the period size or sample rate. 24 // on the period size or sample rate.
27 // 25 //
42 if(numMatrixFramesPerPeriod == 0) { 40 if(numMatrixFramesPerPeriod == 0) {
43 rt_printf("Error: this example needs the matrix enabled\n"); 41 rt_printf("Error: this example needs the matrix enabled\n");
44 return false; 42 return false;
45 } 43 }
46 44
47 gMatrixChannels = numMatrixChannels;
48 gInverseSampleRate = 1.0 / matrixSampleRate; 45 gInverseSampleRate = 1.0 / matrixSampleRate;
49 gPhase = 0.0; 46 gPhase = 0.0;
50 47
51 return true; 48 return true;
52 } 49 }
60 uint16_t *matrixIn, uint16_t *matrixOut) 57 uint16_t *matrixIn, uint16_t *matrixOut)
61 { 58 {
62 for(int n = 0; n < numMatrixFrames; n++) { 59 for(int n = 0; n < numMatrixFrames; n++) {
63 // Set LED to different phase for each matrix channel 60 // Set LED to different phase for each matrix channel
64 float relativePhase = 0.0; 61 float relativePhase = 0.0;
65 for(int channel = 0; channel < gMatrixChannels; channel++) { 62 for(int channel = 0; channel < gNumMatrixChannels; channel++) {
66 float out = kMinimumAmplitude + kAmplitudeRange * 0.5f * (1.0f + sinf(gPhase + relativePhase)); 63 float out = kMinimumAmplitude + kAmplitudeRange * 0.5f * (1.0f + sinf(gPhase + relativePhase));
67 if(out > MATRIX_MAX) 64 if(out > MATRIX_MAX)
68 out = MATRIX_MAX; 65 out = MATRIX_MAX;
69 66
70 matrixOut[n * gMatrixChannels + channel] = (uint16_t)out; 67 analogWrite(channel, n, out);
71 //analogWrite(channel, n, out);
72 68
73 // Advance by pi/4 (1/8 of a full rotation) for each channel 69 // Advance by pi/4 (1/8 of a full rotation) for each channel
74 relativePhase += M_PI * 0.25; 70 relativePhase += M_PI * 0.25;
75 } 71 }
76 72