Realtime spectrum analyzer. Using FFT, linear prediction, or cepstrum smoothing. Version using MEMS microphone and CODEC, named "F746_RealtimeSpectrumAnalyzer_MEMS_Mic" is registered. リアルタイム スペクトル解析器.解析の手法:FFT,線形予測法,ケプストラムによる平滑化の3種類.このプログラムの説明は,CQ出版社のインターフェース誌,2016年4月号に掲載.外付けのマイクまたは他の信号源等を A0 に接続する.線形予測法,ケプストラムは,スペクトル解析の対象を音声信号に想定してパラメータを設定している.MEMS マイクと CODEC を使ったバージョンを "F746_RealtimeSpectrumAnalyzer_MEMS_Mic" として登録.

Dependencies:   BSP_DISCO_F746NG BUTTON_GROUP LCD_DISCO_F746NG TS_DISCO_F746NG UIT_FFT_Real mbed

Revision:
1:1656f55c2d5c
Parent:
0:5c237fdcba23
Child:
2:095b360e0f54
--- a/main.cpp	Wed Dec 09 05:05:00 2015 +0000
+++ b/main.cpp	Thu Dec 10 04:56:04 2015 +0000
@@ -2,12 +2,12 @@
 //  Realtime spectrum analyzer
 //      Input: A0 (CN5)
 //
-//  2015/12/09, Copyright (c) 2015 MIKAMI, Naoki
+//  2015/12/10, Copyright (c) 2015 MIKAMI, Naoki
 //-----------------------------------------------------------
 
 #include "button_group.hpp"
-#include "sampler.hpp"
-#include "waveform_display.hpp"
+#include "Sampler.hpp"
+#include "WaveformDisplay.hpp"
 #include "AnalysisSelector.hpp"
 
 using namespace Mikami;
@@ -18,7 +18,7 @@
 Sampler input_(A0, timer_, N_DATA_);
 
 // Interrupt service routine for timer
-void TimerIsr()
+void Isr()
 {
     input_.Execute();
 }
@@ -92,7 +92,7 @@
             if (runStop.Touched(0, TOUCHED_COLOR))
             {
                 input_.ClearCount();
-                timer_.attach_us(&TimerIsr, TS);   // Enable timer interrupt
+                timer_.attach_us(&Isr, TS); // Enable timer interrupt
                 runSelected = true;
                 for (int n=0; n<3; n++)
                     if (n != touchedNum) method.Redraw(n);
@@ -115,14 +115,8 @@
                     normInv.Draw(1, TOUCHED_COLOR);                
             }
 
-            int button;
-            if (normInv.GetTouchedNumber(button, TOUCHED_COLOR))
-            {
-                if (button == 0)    
-                    inv = input_.InvertEnable(false);
-                else
-                    inv = input_.InvertEnable(true);
-            }
+            int invButton;     // 0: "NORM", 1: "INV"
+            normInv.GetTouchedNumber(invButton, TOUCHED_COLOR);
 
             // If input buffer filled, start analysis
             if (input_.Filled())
@@ -130,19 +124,22 @@
                 sn = input_.Get();
                 waveDisp.Execute(sn);
   
-                selector.Execute(sn, touchedNum);   // spectrum analysis and display
+                // spectrum analysis and display
+                selector.Execute(sn, touchedNum);   
 
                 // Check "STOP" button touched
                 if (runStop.Touched(1, TOUCHED_COLOR))
                 {
-                    timer_.detach();                // Disable timer interrupt
+                    timer_.detach();        // Disable timer interrupt
                     runSelected = false;
                     normInv.DrawAll(INACTIVE_COLOR, INACTIVE_TEXT_COLOR);
                 }
 
                 // Restart sampling
+                inv = (invButton == 0) ? input_.InvertEnable(false)
+                                       : input_.InvertEnable(true);
                 input_.Restart();
-                timer_.attach_us(&TimerIsr, TS);    // Enable timer interrupt
+                timer_.attach_us(&Isr, TS); // Enable timer interrupt
             }
         }
     }