File tree Expand file tree Collapse file tree 1 file changed +6
-0
lines changed
Arduino_package/hardware/libraries/AudioCodec/examples/InputFFT Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change 12
12
13
13
#define SAMPLERATE 16000
14
14
#define SAMPLECOUNT 128
15
+ #define GAIN_FACTOR 1.0 // Gain factor (can be adjusted), Cannot be 0 as it will mute the signal
15
16
16
17
int16_t audio_buffer[SAMPLECOUNT] = {0 };
17
18
float fft_buffer[SAMPLECOUNT/2 ] = {0 };
18
19
uint16_t freq_bins[SAMPLECOUNT/2 ] = {0 };
19
20
int i = 0 ;
21
+ int audioBufferMaxValue = INT16_MAX; // 16-bit signed audio data (Refer to int16_t audio_buffer[SAMPLECOUNT])
20
22
21
23
FFT fft;
22
24
@@ -38,6 +40,10 @@ void setup() {
38
40
void loop () {
39
41
if (Codec.readAvaliable ()) {
40
42
Codec.readDataPage (audio_buffer, SAMPLECOUNT); // read latest received data from buffer
43
+ for (int i = 0 ; i < SAMPLECOUNT; i++) {
44
+ audio_buffer[i] *= constrain (audio_buffer[i] * GAIN_FACTOR, -audioBufferMaxValue, audioBufferMaxValue); // Clamping to avoid overflow and amplify each sample
45
+ }
46
+
41
47
fft.calculate (audio_buffer, fft_buffer, SAMPLECOUNT);
42
48
for (i = 0 ; i < (SAMPLECOUNT/2 ); i++) {
43
49
if (fft_buffer[i] > 0.01 ) {
You can’t perform that action at this time.
0 commit comments