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:
10:351d70a4efde
Parent:
9:99c55850cb41
Child:
11:a8420871920e
Child:
12:e5367ab82460
--- a/main.cpp	Tue Dec 29 14:09:10 2015 +0000
+++ b/main.cpp	Thu Dec 31 09:17:58 2015 +0000
@@ -2,7 +2,7 @@
 //  Realtime spectrum analyzer
 //      Input: A0 (CN5)
 //
-//  2015/12/29, Copyright (c) 2015 MIKAMI, Naoki
+//  2015/12/31, Copyright (c) 2015 MIKAMI, Naoki
 //------------------------------------------------
 
 #include "button_group.hpp"
@@ -67,34 +67,28 @@
     SpectrumDisplay disp(lcd, N_FFT, X0, Y0, DB1, BIN, W_DB, FS,
                          AXIS_COLOR, LINE_COLOR, BACK_COLOR);
     // Linear prediction:   order = 14
-    // Cepstral smoothing:  lifter length = 50
+    // Cepstral smoothing:  highest quefrency = 50
     Selector analyzer(disp, N_DATA, N_FFT, 14, 50);
 
     // Wait for "RUN" button touched
-    while (!runStop.Touched(0)) {}
-    method.DrawAll(ORIGINAL_COLOR);
+    while (!runStop.Touched(0, TOUCHED_COLOR)) {}
 
     // Start of spectrum analyzing
+    method.DrawAll(ORIGINAL_COLOR);
     int inv = 0;    // 0: "NORM", 1: "INV"
     int select = -1;
+    int stop = 0;
+    input.Start(inv == 1);
+    
     while (true)
     {
-        if (runStop.GetCurrentColor(0) != TOUCHED_COLOR)
-        {
-            if (runStop.Touched(0, TOUCHED_COLOR))
-            {
-                input.Start(inv == 1);
-                normInv.Draw(inv, TOUCHED_COLOR);
-                normInv.Redraw(1-inv);
-            }
-            if (method.GetTouchedNumber(select, TOUCHED_COLOR))
-                analyzer.Execute(sn, select);
-        }
-
-        if (runStop.GetCurrentColor(0) == TOUCHED_COLOR)
+        runStop.GetTouchedNumber(stop, TOUCHED_COLOR);
+        
+        if (stop == 0)
         {
             normInv.GetTouchedNumber(inv, TOUCHED_COLOR);
-
+            normInv.Draw(inv, TOUCHED_COLOR);
+            normInv.Redraw(1-inv);
             if (input.Filled())
             {
                 // Restart
@@ -108,10 +102,14 @@
             else
                 if (method.GetTouchedNumber(select, TOUCHED_COLOR))
                     analyzer.Execute(sn, select);
-
+        }            
+        else
+        {
             // Check "STOP" button touched
-            if (runStop.Touched(1, TOUCHED_COLOR))
+            if (runStop.GetTouchedNumber(stop))
                 normInv.DrawAll(INACTIVE_COLOR, INACTIVE_TEXT_COLOR);
+            if (method.GetTouchedNumber(select, TOUCHED_COLOR))
+                analyzer.Execute(sn, select);
         }
     }
 }