Funcional

Dependencies:   FastAnalogIn HSI2RGBW_PWM NVIC_set_all_priorities mbed-dsp mbed TextLCD

Fork of Seniales-Tacometro by Grissell Esquivel

Revision:
2:035d551759a5
Parent:
1:736b34e0f484
Child:
3:6c9dabbb7261
--- a/main.cpp	Sat Mar 08 18:56:14 2014 +0000
+++ b/main.cpp	Sat Mar 08 19:30:20 2014 +0000
@@ -6,6 +6,7 @@
 #include "NVIC_set_all_priorities.h"
 #include <ctype.h>
 #include "arm_math.h"
+#include "arm_const_structs.h"
 #include "hsi2rgbw_pwm.h"
 #include "FastAnalogIn.h"
 
@@ -35,21 +36,18 @@
 // These values can be changed to alter the behavior of the spectrum display.
 // KL25Z limitations
 // -----------------
-// - When used without the Spectrogram python script :
-//   When SAMPLE_RATE_HZ = 10000...40000, max allowed FFT_SIZE is 16.
-//   When SAMPLE_RATE_HZ < 9000, FFT can go up to 256 
 // - When used with the Spectrogram python script :
 //   There is a substantial time lag between the music and the screen output.
-//   Max allowed SAMPLE_RATE_HZ is 8000
-//   Max allowed FFT_SIZE is 16
+//   Max allowed SAMPLE_RATE_HZ is 40000
+//   Max allowed FFT_SIZE is 64
 ////////////////////////////////////////////////////////////////////////////////
 
-int SLOWDOWN = 3;                       // Create an optical delay in spectrumLoop - useful when only one RGB led is used.
+int SLOWDOWN = 4;                       // Create an optical delay in spectrumLoop - useful when only one RGB led is used.
                                         // Only active when nonzero.
                                         // A value >= 1000 and <= 1000 + PIXEL_COUNT fixes the output to a single frequency
                                         // window = a single color.
 int SAMPLE_RATE_HZ = 40000;             // Sample rate of the audio in hertz.
-float SPECTRUM_MIN_DB = 40.0;           // Audio intensity (in decibels) that maps to low LED brightness.
+float SPECTRUM_MIN_DB = 30.0;           // Audio intensity (in decibels) that maps to low LED brightness.
 float SPECTRUM_MAX_DB = 80.0;           // Audio intensity (in decibels) that maps to high LED brightness.
 int LEDS_ENABLED = 1;                   // Control if the LED's should display the spectrum or not.  1 is true, 0 is false.
                                         // Useful for turning the LED display on and off with commands from the serial port.
@@ -62,6 +60,7 @@
 // INTERNAL STATE
 // These shouldn't be modified unless you know what you're doing.
 ////////////////////////////////////////////////////////////////////////////////
+const static arm_cfft_instance_f32 *S;
 Ticker samplingTimer;
 float samples[FFT_SIZE*2];
 float magnitudes[FFT_SIZE];
@@ -316,13 +315,44 @@
     // Begin sampling audio
     samplingBegin();
 
+    // Init arm_ccft_32
+    switch (FFT_SIZE)
+    {
+    case 16:
+        S = & arm_cfft_sR_f32_len16;
+        break;
+    case 32:
+        S = & arm_cfft_sR_f32_len32;
+        break;
+    case 64:
+        S = & arm_cfft_sR_f32_len64;
+        break;
+    case 128:
+        S = & arm_cfft_sR_f32_len128;
+        break;
+    case 256:
+        S = & arm_cfft_sR_f32_len256;
+        break;
+    case 512:
+        S = & arm_cfft_sR_f32_len512;
+        break;
+    case 1024:
+        S = & arm_cfft_sR_f32_len1024;
+        break;
+    case 2048:
+        S = & arm_cfft_sR_f32_len2048;
+        break;
+    case 4096:
+        S = & arm_cfft_sR_f32_len4096;
+        break;
+    }
+
     while(1) {
         // Calculate FFT if a full sample is available.
         if (samplingIsDone()) {
             // Run FFT on sample data.
-            arm_cfft_radix4_instance_f32 fft_inst;
-            arm_cfft_radix4_init_f32(&fft_inst, FFT_SIZE, 0, 1);
-            arm_cfft_radix4_f32(&fft_inst, samples);
+            // Run FFT on sample data.
+            arm_cfft_f32(S, samples, 0, 1);
             // Calculate magnitude of complex numbers output by the FFT.
             arm_cmplx_mag_f32(samples, magnitudes, FFT_SIZE);