![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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
main.cpp@9:0d5bd1539291, 2016-05-09 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Mon May 09 13:48:33 2016 +0000
- Revision:
- 9:0d5bd1539291
- Parent:
- 7:be29ba9c83b2
- Child:
- 10:fc6367c2ffcf
10
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:e953eb392151 | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:e953eb392151 | 2 | // グラフィックイコライザ付き SD オーディオプレーヤー |
MikamiUitOpen | 0:e953eb392151 | 3 | // SD のファイル: *.wav |
MikamiUitOpen | 0:e953eb392151 | 4 | // PCM,16 ビットステレオ,標本化周波数 44.1 kHz |
MikamiUitOpen | 0:e953eb392151 | 5 | // 上記以外の形式は扱わない |
MikamiUitOpen | 0:e953eb392151 | 6 | // 出力:モノラル |
MikamiUitOpen | 0:e953eb392151 | 7 | // |
MikamiUitOpen | 7:be29ba9c83b2 | 8 | // 2016/05/09, Copyright (c) 2016 MIKAMI, Naoki |
MikamiUitOpen | 0:e953eb392151 | 9 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:e953eb392151 | 10 | |
MikamiUitOpen | 0:e953eb392151 | 11 | #include "MyFunctions.hpp" |
MikamiUitOpen | 0:e953eb392151 | 12 | #include "BlinkLabel.hpp" |
MikamiUitOpen | 0:e953eb392151 | 13 | |
MikamiUitOpen | 0:e953eb392151 | 14 | using namespace Mikami; |
MikamiUitOpen | 0:e953eb392151 | 15 | |
MikamiUitOpen | 0:e953eb392151 | 16 | int main() |
MikamiUitOpen | 0:e953eb392151 | 17 | { |
MikamiUitOpen | 2:2a5c93bf729a | 18 | Label myLabel1(212, 2, "SD Card Audio Player", Label::CENTER, Font16); |
MikamiUitOpen | 2:2a5c93bf729a | 19 | Label myLabel2(212, 16, "---- Graphic equalizer ----", Label::CENTER, Font12); |
MikamiUitOpen | 0:e953eb392151 | 20 | |
MikamiUitOpen | 0:e953eb392151 | 21 | const int FS = AUDIO_FREQUENCY_44K; // 標本化周波数: 44.1 kHz |
MikamiUitOpen | 5:a5a4f9d7b26c | 22 | SaiIO mySai(SaiIO::OUTPUT, 2048, FS); |
MikamiUitOpen | 0:e953eb392151 | 23 | |
MikamiUitOpen | 0:e953eb392151 | 24 | SD_WavReader sdReader(mySai.GetLength()); // SD カード読み込み用オブジェクト |
MikamiUitOpen | 0:e953eb392151 | 25 | const int MAX_FILES = 7; |
MikamiUitOpen | 2:2a5c93bf729a | 26 | FileSelector selector(4, 26, MAX_FILES, 37, sdReader); |
MikamiUitOpen | 0:e953eb392151 | 27 | if (!selector.CreateTable()) |
MikamiUitOpen | 0:e953eb392151 | 28 | BlinkLabel errLabel(240, 100, "SD CARD ERROR", Label::CENTER); |
MikamiUitOpen | 0:e953eb392151 | 29 | |
MikamiUitOpen | 0:e953eb392151 | 30 | // ボタン用の定数 |
MikamiUitOpen | 2:2a5c93bf729a | 31 | const uint16_t BG_LEFT = 414; |
MikamiUitOpen | 2:2a5c93bf729a | 32 | const uint16_t BG_WIDTH = 66; |
MikamiUitOpen | 7:be29ba9c83b2 | 33 | const uint16_t BG_HEIGHT = 36; |
MikamiUitOpen | 0:e953eb392151 | 34 | |
MikamiUitOpen | 0:e953eb392151 | 35 | // ButtonGroup: "OPEN", "PLAY", "PAUSE", "RESUME", "STOP" |
MikamiUitOpen | 0:e953eb392151 | 36 | const string MENU[5] = {"OPEN", "PLAY", "PAUSE", "RESUME", "STOP"}; |
MikamiUitOpen | 0:e953eb392151 | 37 | ButtonGroup menu(BG_LEFT, 2, BG_WIDTH, BG_HEIGHT, |
MikamiUitOpen | 0:e953eb392151 | 38 | 5, MENU, 0, 2, 1); |
MikamiUitOpen | 0:e953eb392151 | 39 | // OPEN のみアクティブ |
MikamiUitOpen | 0:e953eb392151 | 40 | menu.Activate(0); |
MikamiUitOpen | 0:e953eb392151 | 41 | for (int n=1; n<5; n++) menu.Inactivate(n); |
MikamiUitOpen | 0:e953eb392151 | 42 | |
MikamiUitOpen | 7:be29ba9c83b2 | 43 | Button flat(BG_LEFT, 197, BG_WIDTH, BG_HEIGHT, "FLAT"); |
MikamiUitOpen | 7:be29ba9c83b2 | 44 | |
MikamiUitOpen | 2:2a5c93bf729a | 45 | const string ON_OFF[2] = {"ON", "OFF"}; |
MikamiUitOpen | 7:be29ba9c83b2 | 46 | ButtonGroup onOff(BG_LEFT, 235, BG_WIDTH/2, BG_HEIGHT, |
MikamiUitOpen | 2:2a5c93bf729a | 47 | 2, ON_OFF, 0, 0, 2, 0); |
MikamiUitOpen | 0:e953eb392151 | 48 | |
MikamiUitOpen | 0:e953eb392151 | 49 | // フィルタの設計と周波数特性描画用 |
MikamiUitOpen | 0:e953eb392151 | 50 | const int STAGES = 9; // バンド数 |
MikamiUitOpen | 0:e953eb392151 | 51 | DesignerDrawer drawerObj( |
MikamiUitOpen | 2:2a5c93bf729a | 52 | 28, // グラフの左端の位置 |
MikamiUitOpen | 0:e953eb392151 | 53 | 130, // グラフの下端の位置 |
MikamiUitOpen | 0:e953eb392151 | 54 | STAGES, // バンド数 |
MikamiUitOpen | 0:e953eb392151 | 55 | 62.5f, // 最低域バンドの中心周波数 |
MikamiUitOpen | 0:e953eb392151 | 56 | FS, // 標本化周波数 |
MikamiUitOpen | 2:2a5c93bf729a | 57 | 2.5f); // 1 dB 当たりのピクセル数 |
MikamiUitOpen | 0:e953eb392151 | 58 | |
MikamiUitOpen | 0:e953eb392151 | 59 | // 周波数特性変更用スライダ |
MikamiUitOpen | 2:2a5c93bf729a | 60 | SeekbarGroup myBars(drawerObj.GetX0(), 178, 82, STAGES, |
MikamiUitOpen | 7:be29ba9c83b2 | 61 | drawerObj.GetSpaceX(), -8.0f, 8.0f, 0, |
MikamiUitOpen | 0:e953eb392151 | 62 | SeekBar::Vertical); |
MikamiUitOpen | 0:e953eb392151 | 63 | |
MikamiUitOpen | 0:e953eb392151 | 64 | // フィルタの準備 |
MikamiUitOpen | 0:e953eb392151 | 65 | BiquadGrEq::Coefs ck[STAGES]; |
MikamiUitOpen | 0:e953eb392151 | 66 | drawerObj.GetCoefficients(ck); |
MikamiUitOpen | 0:e953eb392151 | 67 | BiquadGrEq hn[STAGES]; |
MikamiUitOpen | 0:e953eb392151 | 68 | for (int k=0; k<STAGES; k++) hn[k] = BiquadGrEq(ck[k]); |
MikamiUitOpen | 0:e953eb392151 | 69 | |
MikamiUitOpen | 0:e953eb392151 | 70 | int32_t frameSize = mySai.GetLength(); |
MikamiUitOpen | 0:e953eb392151 | 71 | int16_t *sn = new int16_t[frameSize+1]; // フレームバッファ |
MikamiUitOpen | 0:e953eb392151 | 72 | bool playOk = false; |
MikamiUitOpen | 2:2a5c93bf729a | 73 | bool on = true; |
MikamiUitOpen | 0:e953eb392151 | 74 | bool whileFirst = true; |
MikamiUitOpen | 0:e953eb392151 | 75 | string fileName; |
MikamiUitOpen | 0:e953eb392151 | 76 | int32_t loopCount; |
MikamiUitOpen | 0:e953eb392151 | 77 | |
MikamiUitOpen | 0:e953eb392151 | 78 | while (true) |
MikamiUitOpen | 0:e953eb392151 | 79 | { |
MikamiUitOpen | 0:e953eb392151 | 80 | if (!playOk) |
MikamiUitOpen | 0:e953eb392151 | 81 | { |
MikamiUitOpen | 0:e953eb392151 | 82 | if (whileFirst) |
MikamiUitOpen | 0:e953eb392151 | 83 | { |
MikamiUitOpen | 0:e953eb392151 | 84 | whileFirst = false; |
MikamiUitOpen | 0:e953eb392151 | 85 | while (!menu.Touched(0)) // OPEN がタッチされるまで待つ |
MikamiUitOpen | 7:be29ba9c83b2 | 86 | ModifyFilter(drawerObj, myBars, hn, flat, onOff, on); |
MikamiUitOpen | 2:2a5c93bf729a | 87 | SelectFile(menu, selector, myLabel1, fileName); |
MikamiUitOpen | 0:e953eb392151 | 88 | } |
MikamiUitOpen | 0:e953eb392151 | 89 | else |
MikamiUitOpen | 0:e953eb392151 | 90 | { |
MikamiUitOpen | 0:e953eb392151 | 91 | menu.Activate(1); // PLAY 有効 |
MikamiUitOpen | 0:e953eb392151 | 92 | int touch10; |
MikamiUitOpen | 0:e953eb392151 | 93 | while (!menu.GetTouchedNumber(touch10)) |
MikamiUitOpen | 7:be29ba9c83b2 | 94 | ModifyFilter(drawerObj, myBars, hn, flat, onOff, on); |
MikamiUitOpen | 0:e953eb392151 | 95 | if (touch10 == 0) |
MikamiUitOpen | 2:2a5c93bf729a | 96 | SelectFile(menu, selector, myLabel1, fileName); |
MikamiUitOpen | 0:e953eb392151 | 97 | } |
MikamiUitOpen | 0:e953eb392151 | 98 | |
MikamiUitOpen | 0:e953eb392151 | 99 | loopCount = SD_Open(sdReader, fileName, frameSize); |
MikamiUitOpen | 0:e953eb392151 | 100 | while (!menu.Touched(1)) // PLAY がタッチされるまで待つ |
MikamiUitOpen | 7:be29ba9c83b2 | 101 | ModifyFilter(drawerObj, myBars, hn, flat, onOff, on); |
MikamiUitOpen | 0:e953eb392151 | 102 | } |
MikamiUitOpen | 0:e953eb392151 | 103 | else |
MikamiUitOpen | 0:e953eb392151 | 104 | loopCount = SD_Open(sdReader, fileName, frameSize); |
MikamiUitOpen | 0:e953eb392151 | 105 | |
MikamiUitOpen | 2:2a5c93bf729a | 106 | selector.Erase(0, 0, BG_LEFT-4, 288); |
MikamiUitOpen | 2:2a5c93bf729a | 107 | myLabel1.Draw("9-band Graphic Equalizer"); |
MikamiUitOpen | 0:e953eb392151 | 108 | myBars.RedrawAll(); |
MikamiUitOpen | 0:e953eb392151 | 109 | drawerObj.DrawResponse(); |
MikamiUitOpen | 0:e953eb392151 | 110 | menu.Inactivate(0); // OPEN 無効 |
MikamiUitOpen | 0:e953eb392151 | 111 | menu.Activate(2); // PAUSE 有効 |
MikamiUitOpen | 0:e953eb392151 | 112 | menu.Activate(4); // STOP 有効 |
MikamiUitOpen | 0:e953eb392151 | 113 | |
MikamiUitOpen | 0:e953eb392151 | 114 | playOk = false; |
MikamiUitOpen | 0:e953eb392151 | 115 | bool stopOk = false; |
MikamiUitOpen | 0:e953eb392151 | 116 | |
MikamiUitOpen | 0:e953eb392151 | 117 | // IIR フィルタの内部の遅延器のクリア |
MikamiUitOpen | 0:e953eb392151 | 118 | for (int k=0; k<STAGES; k++) hn[k].Clear(); |
MikamiUitOpen | 7:be29ba9c83b2 | 119 | mySai.PlayOut(); // Play 開始 |
MikamiUitOpen | 0:e953eb392151 | 120 | |
MikamiUitOpen | 0:e953eb392151 | 121 | for (int k=0; k<loopCount; k++) |
MikamiUitOpen | 0:e953eb392151 | 122 | { |
MikamiUitOpen | 0:e953eb392151 | 123 | int touch42 = -1; |
MikamiUitOpen | 0:e953eb392151 | 124 | menu.GetTouchedNumber(touch42); |
MikamiUitOpen | 0:e953eb392151 | 125 | if (touch42 == 4) break; // STOP |
MikamiUitOpen | 0:e953eb392151 | 126 | if (touch42 == 2) // PAUSE |
MikamiUitOpen | 0:e953eb392151 | 127 | { |
MikamiUitOpen | 0:e953eb392151 | 128 | menu.Inactivate(2); // PAUSE 無効 |
MikamiUitOpen | 0:e953eb392151 | 129 | menu.Activate(3); // RESUME 有効 |
MikamiUitOpen | 9:0d5bd1539291 | 130 | mySai.PauseOut(); |
MikamiUitOpen | 0:e953eb392151 | 131 | |
MikamiUitOpen | 0:e953eb392151 | 132 | // PLAY か RESUME か STOP がタッチされるまで待つ |
MikamiUitOpen | 0:e953eb392151 | 133 | int touch134 = -1; |
MikamiUitOpen | 0:e953eb392151 | 134 | while (!menu.GetTouchedNumber(touch134)) |
MikamiUitOpen | 7:be29ba9c83b2 | 135 | ModifyFilter(drawerObj, myBars, hn, flat, onOff, on); |
MikamiUitOpen | 0:e953eb392151 | 136 | switch (touch134) |
MikamiUitOpen | 0:e953eb392151 | 137 | { |
MikamiUitOpen | 9:0d5bd1539291 | 138 | case 1: playOk = true; // 最初から PLAY |
MikamiUitOpen | 0:e953eb392151 | 139 | break; |
MikamiUitOpen | 9:0d5bd1539291 | 140 | case 3: mySai.ResumeOut(); // PAUSE したところから PLAY 再開 |
MikamiUitOpen | 0:e953eb392151 | 141 | menu.Activate(2); |
MikamiUitOpen | 0:e953eb392151 | 142 | menu.Inactivate(3); |
MikamiUitOpen | 0:e953eb392151 | 143 | menu.TouchedColor(1); |
MikamiUitOpen | 0:e953eb392151 | 144 | break; |
MikamiUitOpen | 9:0d5bd1539291 | 145 | case 4: stopOk = true; // STOP |
MikamiUitOpen | 0:e953eb392151 | 146 | break; |
MikamiUitOpen | 0:e953eb392151 | 147 | } |
MikamiUitOpen | 0:e953eb392151 | 148 | } |
MikamiUitOpen | 0:e953eb392151 | 149 | if (playOk || stopOk) break; |
MikamiUitOpen | 0:e953eb392151 | 150 | |
MikamiUitOpen | 7:be29ba9c83b2 | 151 | ModifyFilter(drawerObj, myBars, hn, flat, onOff, on); |
MikamiUitOpen | 0:e953eb392151 | 152 | // 1フレーム分の信号処理 (イコライザ) の実行 |
MikamiUitOpen | 7:be29ba9c83b2 | 153 | SignalProcessing(sdReader, mySai, sn, hn, STAGES, on); |
MikamiUitOpen | 0:e953eb392151 | 154 | } |
MikamiUitOpen | 9:0d5bd1539291 | 155 | mySai.StopOut(); |
MikamiUitOpen | 0:e953eb392151 | 156 | menu.Activate(0); // OPEN 有効 |
MikamiUitOpen | 0:e953eb392151 | 157 | if (!playOk) menu.Activate(1); // PLAY 有効 |
MikamiUitOpen | 0:e953eb392151 | 158 | for (int n=2; n<5; n++) // その他は無効 |
MikamiUitOpen | 0:e953eb392151 | 159 | menu.Inactivate(n); |
MikamiUitOpen | 0:e953eb392151 | 160 | sdReader.Close(); // SD のファイルのクローズ |
MikamiUitOpen | 0:e953eb392151 | 161 | } |
MikamiUitOpen | 0:e953eb392151 | 162 | } |