revised version of F746_SD_GraphicEqualizer

Dependencies:   BSP_DISCO_F746NG F746_GUI F746_SAI_IO FrequencyResponseDrawer LCD_DISCO_F746NG SDFileSystem_Warning_Fixed TS_DISCO_F746NG mbed

Fork of F746_SD_GraphicEqualizer by 不韋 呂

Files at this revision

API Documentation at this revision

Comitter:
MikamiUitOpen
Date:
Sun May 01 02:44:30 2016 +0000
Parent:
1:a5837720e14a
Child:
3:c3976d34cde9
Commit message:
3

Changed in this revision

F746_GUI.lib Show annotated file Show diff for this revision Revisions of this file
MyClasses_Functions/DesignerDrawer.cpp Show annotated file Show diff for this revision Revisions of this file
MyClasses_Functions/DesignerDrawer.hpp Show annotated file Show diff for this revision Revisions of this file
MyClasses_Functions/FileSelectorWav.hpp Show annotated file Show diff for this revision Revisions of this file
MyClasses_Functions/FrquencyResponseDrawer.cpp Show annotated file Show diff for this revision Revisions of this file
MyClasses_Functions/FrquencyResponseDrawer.hpp Show annotated file Show diff for this revision Revisions of this file
MyClasses_Functions/MyFunctions.cpp Show annotated file Show diff for this revision Revisions of this file
MyClasses_Functions/MyFunctions.hpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/F746_GUI.lib	Wed Apr 27 14:24:45 2016 +0000
+++ b/F746_GUI.lib	Sun May 01 02:44:30 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/MikamiUitOpen/code/F746_GUI/#7debdaa7b503
+http://mbed.org/users/MikamiUitOpen/code/F746_GUI/#687ec6183385
--- a/MyClasses_Functions/DesignerDrawer.cpp	Wed Apr 27 14:24:45 2016 +0000
+++ b/MyClasses_Functions/DesignerDrawer.cpp	Sun May 01 02:44:30 2016 +0000
@@ -1,7 +1,7 @@
 //------------------------------------------------------------------------------
 //  イコライザ用フィルタのパラメータを設定し,その周波数特性を描画するためのクラス
 //  
-//  2016/04/27, Copyright (c) 2016 MIKAMI, Naoki
+//  2016/05/01, Copyright (c) 2016 MIKAMI, Naoki
 //------------------------------------------------------------------------------
 
 #include "DesignerDrawer.hpp"
@@ -10,12 +10,12 @@
 {
     // Constructor
     DesignerDrawer::DesignerDrawer(uint16_t x0, uint16_t y0,
-                                   int stages, float f0, int fs, uint16_t db1)
+                                   int stages, float f0, int fs, float db1)
         : lcd_(GuiBase::GetLcdPtr()), ts_(GuiBase::GetTsPtr()),
-          X0_(x0), Y0_(y0), STAGES_(stages), DB1_(db1), Q_VAL_(1.5f)
+          X0_(x0), Y0_(y0), STAGES_(stages), Q_VAL_(1.0f)
     {
         drawerObj_ = new FrqRespDrawer(x0, 50.0f, 20000.0f, 142,
-                                       y0, -12, 12, db1, 3, fs);
+                                       y0, -18, 18, db1, 6, fs);
 
         calculator_ = new GrEqParamsCalculator(fs);
         f0_ = new float[STAGES_];
@@ -23,7 +23,8 @@
             f0_[n] = f0*powf(2, n);
 
         ck_ = new BiquadGrEq::Coefs[STAGES_];
-        Flatten();
+        for (int n=0; n<STAGES_; n++)
+            ck_[n] = calculator_->Execute(f0_[n], 0, Q_VAL_);
         frqResp_ = new GrEqualizerFrqResp(STAGES_);
         frqResp_->SetParams(ck_);
 
@@ -60,22 +61,4 @@
         drawerObj_->DrawAxis();             // 目盛線の描画
         drawerObj_->DrawGraph(frqResp_);    // 周波数特性のグラフのカーブを描画する
     }
-
-    // 周波数特性をフラットにし,その周波数特性を再描画
-    void DesignerDrawer::DesignAndRedraw()
-    {
-        Flatten();
-        frqResp_->SetParams(ck_);
-        drawerObj_->Erase();
-        drawerObj_->DrawAxis();             // 目盛線の描画
-        drawerObj_->DrawGraph(frqResp_);    // 周波数特性のグラフのカーブを描画する
-    }
-
-    // イコライザ用フィルタの周波数特性をフラットにする
-    void DesignerDrawer::Flatten()
-    {
-        for (int n=0; n<STAGES_; n++)
-            ck_[n] = calculator_->Execute(f0_[n], 0, Q_VAL_);
-    }
 }
-
--- a/MyClasses_Functions/DesignerDrawer.hpp	Wed Apr 27 14:24:45 2016 +0000
+++ b/MyClasses_Functions/DesignerDrawer.hpp	Sun May 01 02:44:30 2016 +0000
@@ -1,7 +1,7 @@
 //------------------------------------------------------------------------------
 //  イコライザ用フィルタのパラメータを設定し,その周波数特性を描画するためのクラス -- Header
 //  
-//  2016/04/27, Copyright (c) 2016 MIKAMI, Naoki
+//  2016/05/01, Copyright (c) 2016 MIKAMI, Naoki
 //------------------------------------------------------------------------------
 
 #ifndef F746_DISIGNER_AND_DRAWER_HPP
@@ -19,7 +19,7 @@
     public:
         // Constructor
         DesignerDrawer(uint16_t x0, uint16_t y0,
-                       int stages, float f0, int fs, uint16_t db1);
+                       int stages, float f0, int fs, float db1);
 
         ~DesignerDrawer();
 
@@ -28,12 +28,6 @@
 
         // 特定のバンドのイコライザ用フィルタのパラメータの設定と周波数特性の再描画
         void DesignAndRedraw(float gainDb, int n);
-        
-        // 周波数特性をフラットにし,その周波数特性を再描画
-        void DesignAndRedraw();
-
-        // イコライザ用フィルタの周波数特性をフラットにする
-        void Flatten();
 
         void GetCoefficients(BiquadGrEq::Coefs ck[])
         {   for (int n=0; n<STAGES_; n++) ck[n] = ck_[n]; }
@@ -55,10 +49,9 @@
 
         const uint16_t X0_, Y0_;
         const int STAGES_;
-        const uint16_t DB1_;
         const float Q_VAL_;
 
-        float *f0_;
+        float *f0_;         // 中心周波数を格納する配列のポインタ
         GrEqParamsCalculator *calculator_;
         GrEqualizerFrqResp *frqResp_;   // フィルタの周波数応答に対応するオブジェクト
         BiquadGrEq::Coefs *ck_;         // フィルタの係数        
--- a/MyClasses_Functions/FileSelectorWav.hpp	Wed Apr 27 14:24:45 2016 +0000
+++ b/MyClasses_Functions/FileSelectorWav.hpp	Sun May 01 02:44:30 2016 +0000
@@ -120,17 +120,17 @@
             if (sort)
                 std::sort(sortedFileNames_, sortedFileNames_+fileCount_); 
             
-            Erase(MAX_NAME_LENGTH_*((sFONT *)(&Font16))->Width, 288);
+            Erase(X_, 0, MAX_NAME_LENGTH_*((sFONT *)(&Font16))->Width, 288);
             rect_->DrawAll();
             for (int n=0; n<fileCount_; n++)
                 fileNameLabels_[n]->Draw(GetFileNameNoExt(n));
         }
 
-        void Erase(uint16_t width, uint16_t height,
+        void Erase(uint16_t x, uint16_t y, uint16_t width, uint16_t height,
                    uint32_t color = GuiBase::ENUM_BACK)
         {
             lcd_->SetTextColor(color);
-            lcd_->FillRect(0, 0, width, height);
+            lcd_->FillRect(x, y, width, height);
         }
 
     private:
--- a/MyClasses_Functions/FrquencyResponseDrawer.cpp	Wed Apr 27 14:24:45 2016 +0000
+++ b/MyClasses_Functions/FrquencyResponseDrawer.cpp	Sun May 01 02:44:30 2016 +0000
@@ -2,7 +2,7 @@
 //  周波数が対数スケールの周波数特性を描画するクラス
 //  FrqRespDrawer class
 //
-//  2016/04/25, Copyright (c) 2016 MIKAMI, Naoki
+//  2016/05/01, Copyright (c) 2016 MIKAMI, Naoki
 //-----------------------------------------------------------
 
 #include "FrquencyResponseDrawer.hpp"
@@ -36,9 +36,9 @@
         lcd_->DrawVLine(X(MAX_), y0, height);   // 最大値に対応する線
         
         uint16_t width = X(MAX_) - X(MIN_);
-        int count =Round((MAX_DB_ - MIN_DB_)/(Y_SPACE_/DB1_));
+        int count = Round((MAX_DB_ - MIN_DB_)/(Y_SPACE_/DB1_));
         for (int n=0; n<= count; n++)
-            lcd_->DrawHLine(X(MIN_), ORGY_-Y_SPACE_*n, width);
+            lcd_->DrawHLine(X(MIN_), Round(ORGY_-Y_SPACE_*n), width);
     }
 
     // 横軸の目盛値の表示
@@ -90,7 +90,7 @@
             y1 = y2;
         }
         lcd_->SetTextColor(AXIS_COLOR_);
-        lcd_->DrawHLine(X(MIN_), ORGY_, width);
+        lcd_->DrawHLine(X(MIN_), ORGY_, width+1);
     }
 
     // 消去
--- a/MyClasses_Functions/FrquencyResponseDrawer.hpp	Wed Apr 27 14:24:45 2016 +0000
+++ b/MyClasses_Functions/FrquencyResponseDrawer.hpp	Sun May 01 02:44:30 2016 +0000
@@ -2,7 +2,7 @@
 //  周波数が対数スケールの周波数特性を描画するクラス
 //  FrqRespDrawer class Header
 //
-//  2016/04/25, Copyright (c) 2016 MIKAMI, Naoki
+//  2016/05/01, Copyright (c) 2016 MIKAMI, Naoki
 //-----------------------------------------------------------
 
 #ifndef F746_FRQ_RESP_DRAWER_HPP
--- a/MyClasses_Functions/MyFunctions.cpp	Wed Apr 27 14:24:45 2016 +0000
+++ b/MyClasses_Functions/MyFunctions.cpp	Sun May 01 02:44:30 2016 +0000
@@ -1,14 +1,15 @@
 //--------------------------------------------------------------
 //  グラフィックイコライザ付き SD オーディオプレーヤーで使う大域関数
 //
-//  2016/04/27, Copyright (c) 2016 MIKAMI, Naoki
+//  2016/05/01, Copyright (c) 2016 MIKAMI, Naoki
 //--------------------------------------------------------------
 
 #include "MyFunctions.hpp"
 
 // 1フレーム分の信号処理 (イコライザ) の実行
 void ProcessSignal(SD_WavReader &sdReader, SaiIO_O &mySai,
-                   int16_t sn[], BiquadGrEq hn[], int stages)
+                   int16_t sn[], BiquadGrEq hn[],
+                   int stages, bool on)
 {
     // 1フレーム分のデータを SD から読み込む
     sdReader.ReadAndToMono(sn, mySai.GetLength());
@@ -19,9 +20,10 @@
     for (int n=0; n<mySai.GetLength(); n++)
     {
         // 縦続形の IIR フィルタ実行
-        float yn = 0.3f*sn[n];      // 0.3 の乗算はブースとしてもクリップされないようにするため
+        float xn = 0.125f*sn[n];    // 0.125 の乗算はブースとしてもクリップされないようにするため
+        float yn = xn;
         for (int k=0; k<stages; k++) yn = hn[k].Execute(yn);
-        int16_t value = (int16_t)yn;
+        int16_t value = on ? (int16_t)yn : xn;
         mySai.Output(value, value); // 音響信号の出力
     }
     //--------------------------------------------------------------
@@ -42,8 +44,8 @@
 void SelectFile(ButtonGroup &menu, FileSelector &selector,
                 Label &msg, string &selectedName)
 {
+    selector.DisplayFileList();   
     msg.Draw("Select file");
-    selector.DisplayFileList();   
     do
     {
         if (selector.Select(selectedName))
@@ -55,9 +57,12 @@
 // フィルタの周波数特性の変更
 void ModifyFilter(DesignerDrawer &drawerObj,
                   SeekbarGroup &myBars, BiquadGrEq hn[],
-                  Button &reset)
+                  ButtonGroup &onOff, bool &on)
 {
-    if (reset.Touched())
+    int sw = 0;
+    if (onOff.GetTouchedNumber(sw))
+        on = (sw == 0) ? true : false;
+/*
     {
         drawerObj.DesignAndRedraw();
         for (int n=0; n<drawerObj.GetStages(); n++)
@@ -66,6 +71,7 @@
         reset.Draw();
         return;
     }
+*/
     static int num = 0;
     if (!myBars.GetSlidedNumber(num)) return;
     drawerObj.DesignAndRedraw(myBars.GetValue(num), num);
--- a/MyClasses_Functions/MyFunctions.hpp	Wed Apr 27 14:24:45 2016 +0000
+++ b/MyClasses_Functions/MyFunctions.hpp	Sun May 01 02:44:30 2016 +0000
@@ -19,7 +19,8 @@
 
 // 1フレーム分の信号処理 (イコライザ) の実行
 void ProcessSignal(SD_WavReader &sdReader, SaiIO_O &mySai,
-                   int16_t sn[], BiquadGrEq hn[], int stages);
+                   int16_t sn[], BiquadGrEq hn[],
+                   int stages, bool on);
 
 // SD カードのファイルのオープン
 int32_t SD_Open(SD_WavReader &sdReader,
@@ -32,6 +33,6 @@
 // フィルタの変更
 void ModifyFilter(DesignerDrawer &drawerObj,
                   SeekbarGroup &myBars, BiquadGrEq hn[],
-                  Button &reset);
+                  ButtonGroup &onOff, bool &on);
 
 #endif  // F746_MY_FUNCTIONS_HPP
--- a/main.cpp	Wed Apr 27 14:24:45 2016 +0000
+++ b/main.cpp	Sun May 01 02:44:30 2016 +0000
@@ -5,7 +5,7 @@
 //                   上記以外の形式は扱わない
 //      出力:モノラル
 //
-//  2016/04/27, Copyright (c) 2016 MIKAMI, Naoki
+//  2016/05/01, Copyright (c) 2016 MIKAMI, Naoki
 //--------------------------------------------------------------
 
 #include "MyFunctions.hpp"
@@ -15,20 +15,21 @@
 
 int main()
 {
-    Label myLabel(80, 4, "SD Card Audio Player", Label::LEFT, Font16);
+    Label myLabel1(212, 2, "SD Card Audio Player", Label::CENTER, Font16);
+    Label myLabel2(212, 16, "---- Graphic equalizer ----", Label::CENTER, Font12);
 
     const int FS = AUDIO_FREQUENCY_44K;         // 標本化周波数: 44.1 kHz
     SaiIO_O mySai(2048, FS);
 
     SD_WavReader sdReader(mySai.GetLength());   // SD カード読み込み用オブジェクト
     const int MAX_FILES = 7;
-    FileSelector selector(4, 28, MAX_FILES, 38, sdReader);
+    FileSelector selector(4, 26, MAX_FILES, 37, sdReader);
     if (!selector.CreateTable())
         BlinkLabel errLabel(240, 100, "SD CARD ERROR", Label::CENTER);
 
     // ボタン用の定数
-    const uint16_t BG_LEFT = 420;
-    const uint16_t BG_WIDTH = 60;
+    const uint16_t BG_LEFT = 414;
+    const uint16_t BG_WIDTH = 66;
     const uint16_t BG_HEIGHT = 40;
 
     // ButtonGroup: "OPEN", "PLAY", "PAUSE", "RESUME", "STOP"
@@ -39,21 +40,23 @@
     menu.Activate(0);
     for (int n=1; n<5; n++) menu.Inactivate(n);
 
-    Button flatButton(BG_LEFT, 230, BG_WIDTH, BG_HEIGHT, "FLAT");
+    const string ON_OFF[2] = {"ON", "OFF"};
+    ButtonGroup onOff(BG_LEFT, 230, BG_WIDTH/2, BG_HEIGHT,
+                      2, ON_OFF, 0, 0, 2, 0);
 
     // フィルタの設計と周波数特性描画用
     const int STAGES = 9;       // バンド数
     DesignerDrawer drawerObj(
-                     30,        // グラフの左端の位置
+                     28,        // グラフの左端の位置
                      130,       // グラフの下端の位置
                      STAGES,    // バンド数
                      62.5f,     // 最低域バンドの中心周波数
                      FS,        // 標本化周波数
-                     4);        // 1 dB 当たりのピクセル数
+                     2.5f);     // 1 dB 当たりのピクセル数
 
     // 周波数特性変更用スライダ
-    SeekbarGroup myBars(drawerObj.GetX0(), 186, 66, STAGES,
-                        drawerObj.GetSpaceX(), -8, 8, 0,
+    SeekbarGroup myBars(drawerObj.GetX0(), 178, 82, STAGES,
+                        drawerObj.GetSpaceX(), -9.6f, 9.6f, 0,
                         SeekBar::Vertical);
 
     // フィルタの準備
@@ -65,6 +68,7 @@
     int32_t frameSize = mySai.GetLength();
     int16_t *sn = new int16_t[frameSize+1]; // フレームバッファ
     bool playOk = false;
+    bool on = true;
     bool whileFirst = true;
     string fileName;
     int32_t loopCount;
@@ -77,28 +81,28 @@
             {
                 whileFirst = false;
                 while (!menu.Touched(0))    // OPEN がタッチされるまで待つ
-                    ModifyFilter(drawerObj, myBars, hn, flatButton);
-                SelectFile(menu, selector, myLabel, fileName);
+                    ModifyFilter(drawerObj, myBars, hn, onOff, on);
+                SelectFile(menu, selector, myLabel1, fileName);
             }
             else
             {
                 menu.Activate(1);       // PLAY 有効
                 int touch10;
                 while (!menu.GetTouchedNumber(touch10))
-                    ModifyFilter(drawerObj, myBars, hn, flatButton);
+                    ModifyFilter(drawerObj, myBars, hn, onOff, on);
                 if (touch10 == 0)
-                    SelectFile(menu, selector, myLabel, fileName);
+                    SelectFile(menu, selector, myLabel1, fileName);
             }
 
             loopCount = SD_Open(sdReader, fileName, frameSize);
             while (!menu.Touched(1))   // PLAY がタッチされるまで待つ
-                ModifyFilter(drawerObj, myBars, hn, flatButton);
+                ModifyFilter(drawerObj, myBars, hn, onOff, on);
         }
         else
             loopCount = SD_Open(sdReader, fileName, frameSize);
 
-        selector.Erase(BG_LEFT-4, 288);
-        myLabel.Draw("9-band Graphic Equalizer");
+        selector.Erase(0, 0, BG_LEFT-4, 288);
+        myLabel1.Draw("9-band Graphic Equalizer");
         myBars.RedrawAll();
         drawerObj.DrawResponse();
         menu.Inactivate(0); // OPEN 無効
@@ -126,7 +130,7 @@
                 // PLAY か RESUME か STOP がタッチされるまで待つ
                 int touch134 = -1;
                 while (!menu.GetTouchedNumber(touch134))
-                    ModifyFilter(drawerObj, myBars, hn, flatButton);
+                    ModifyFilter(drawerObj, myBars, hn, onOff, on);
                 switch (touch134)
                 {
                     case 1: playOk = true;  // 最初から PLAY
@@ -142,9 +146,9 @@
             }
             if (playOk || stopOk) break;
 
-            ModifyFilter(drawerObj, myBars, hn, flatButton);
+            ModifyFilter(drawerObj, myBars, hn, onOff, on);
             // 1フレーム分の信号処理 (イコライザ) の実行
-            ProcessSignal(sdReader, mySai, sn, hn, STAGES);
+            ProcessSignal(sdReader, mySai, sn, hn, STAGES, on);
         }
         mySai.Stop();
         menu.Activate(0);               // OPEN 有効
@@ -154,4 +158,3 @@
         sdReader.Close();   // SD のファイルのクローズ
     }
 }
-