Mercurial > hg > beaglert
comparison projects/level_meter/render.cpp @ 268:8d80eda512cd prerelease
Added new overlay for using PRU0 or PRU1, a script to halt board on button press, and several example projects
author | andrewm |
---|---|
date | Tue, 17 May 2016 14:46:26 +0100 |
parents | 3a5823f7a11f |
children |
comparison
equal
deleted
inserted
replaced
267:247a182adb6d | 268:8d80eda512cd |
---|---|
19 // Decay rates for detecting levels | 19 // Decay rates for detecting levels |
20 float gLocalDecayRate = 0.99, gPeakDecayRate = 0.999; | 20 float gLocalDecayRate = 0.99, gPeakDecayRate = 0.999; |
21 | 21 |
22 // Thresholds for LEDs: set in setup() | 22 // Thresholds for LEDs: set in setup() |
23 float gThresholds[NUMBER_OF_SEGMENTS + 1]; | 23 float gThresholds[NUMBER_OF_SEGMENTS + 1]; |
24 int gSamplesToLight[NUMBER_OF_SEGMENTS]; | |
24 | 25 |
25 // High-pass filter on the input | 26 // High-pass filter on the input |
26 float gLastX[2] = {0}; | 27 float gLastX[2] = {0}; |
27 float gLastY[2] = {0}; | 28 float gLastY[2] = {0}; |
28 | 29 |
55 // Level = 10^(dB/20) | 56 // Level = 10^(dB/20) |
56 for(int i = 0; i < NUMBER_OF_SEGMENTS + 1; i++) { | 57 for(int i = 0; i < NUMBER_OF_SEGMENTS + 1; i++) { |
57 gThresholds[i] = powf(10.0f, (-1.0 * (NUMBER_OF_SEGMENTS - i)) * .05); | 58 gThresholds[i] = powf(10.0f, (-1.0 * (NUMBER_OF_SEGMENTS - i)) * .05); |
58 } | 59 } |
59 | 60 |
60 for(int i = 0; i < NUMBER_OF_SEGMENTS; i++) | 61 for(int i = 0; i < NUMBER_OF_SEGMENTS; i++) { |
62 gSamplesToLight[i] = 0; | |
61 pinModeFrame(context, 0, i, OUTPUT); | 63 pinModeFrame(context, 0, i, OUTPUT); |
64 } | |
62 | 65 |
63 return true; | 66 return true; |
64 } | 67 } |
65 | 68 |
66 // render() is called regularly at the highest priority by the audio engine. | 69 // render() is called regularly at the highest priority by the audio engine. |
109 for(int led = 0; led < NUMBER_OF_SEGMENTS; led++) { | 112 for(int led = 0; led < NUMBER_OF_SEGMENTS; led++) { |
110 // All LEDs up to the local level light up. The LED | 113 // All LEDs up to the local level light up. The LED |
111 // for the peak level also remains lit. | 114 // for the peak level also remains lit. |
112 int state = LOW; | 115 int state = LOW; |
113 | 116 |
114 if(gAudioLocalLevel > gThresholds[led]) | 117 if(gAudioLocalLevel > gThresholds[led]) { |
115 state = HIGH; | 118 state = HIGH; |
116 else if(gAudioPeakLevel > gThresholds[led] && gAudioPeakLevel <= gThresholds[led + 1]) | 119 gSamplesToLight[led] = 1000; |
120 } | |
121 /*else if(gAudioPeakLevel > gThresholds[led] && gAudioPeakLevel <= gThresholds[led + 1]) { | |
122 state = HIGH; | |
123 gSamplesToLight[led] = 1000; | |
124 }*/ | |
125 else if(--gSamplesToLight[led] > 0) | |
117 state = HIGH; | 126 state = HIGH; |
118 | 127 |
119 // Write LED | 128 // Write LED |
120 digitalWriteFrameOnce(context, n, led, state); | 129 digitalWriteFrameOnce(context, n, led, state); |
121 } | 130 } |