![](/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
MyClasses_Functions/MyFunctions.cpp@1:a5837720e14a, 2016-04-27 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Wed Apr 27 14:24:45 2016 +0000
- Revision:
- 1:a5837720e14a
- Parent:
- 0:e953eb392151
- Child:
- 2:2a5c93bf729a
2
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 | // |
MikamiUitOpen | 0:e953eb392151 | 4 | // 2016/04/27, Copyright (c) 2016 MIKAMI, Naoki |
MikamiUitOpen | 0:e953eb392151 | 5 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:e953eb392151 | 6 | |
MikamiUitOpen | 0:e953eb392151 | 7 | #include "MyFunctions.hpp" |
MikamiUitOpen | 0:e953eb392151 | 8 | |
MikamiUitOpen | 0:e953eb392151 | 9 | // 1フレーム分の信号処理 (イコライザ) の実行 |
MikamiUitOpen | 0:e953eb392151 | 10 | void ProcessSignal(SD_WavReader &sdReader, SaiIO_O &mySai, |
MikamiUitOpen | 0:e953eb392151 | 11 | int16_t sn[], BiquadGrEq hn[], int stages) |
MikamiUitOpen | 0:e953eb392151 | 12 | { |
MikamiUitOpen | 0:e953eb392151 | 13 | // 1フレーム分のデータを SD から読み込む |
MikamiUitOpen | 0:e953eb392151 | 14 | sdReader.ReadAndToMono(sn, mySai.GetLength()); |
MikamiUitOpen | 0:e953eb392151 | 15 | |
MikamiUitOpen | 1:a5837720e14a | 16 | while (!mySai.IsXferred()) {} // データの転送が終わるまで待つ |
MikamiUitOpen | 0:e953eb392151 | 17 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:e953eb392151 | 18 | // 1フレーム分のイコライザ処理を行い,その結果を出力する |
MikamiUitOpen | 0:e953eb392151 | 19 | for (int n=0; n<mySai.GetLength(); n++) |
MikamiUitOpen | 0:e953eb392151 | 20 | { |
MikamiUitOpen | 0:e953eb392151 | 21 | // 縦続形の IIR フィルタ実行 |
MikamiUitOpen | 1:a5837720e14a | 22 | float yn = 0.3f*sn[n]; // 0.3 の乗算はブースとしてもクリップされないようにするため |
MikamiUitOpen | 0:e953eb392151 | 23 | for (int k=0; k<stages; k++) yn = hn[k].Execute(yn); |
MikamiUitOpen | 0:e953eb392151 | 24 | int16_t value = (int16_t)yn; |
MikamiUitOpen | 1:a5837720e14a | 25 | mySai.Output(value, value); // 音響信号の出力 |
MikamiUitOpen | 0:e953eb392151 | 26 | } |
MikamiUitOpen | 0:e953eb392151 | 27 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:e953eb392151 | 28 | mySai.ResetXferred(); // 次のデータ転送に備える |
MikamiUitOpen | 0:e953eb392151 | 29 | } |
MikamiUitOpen | 0:e953eb392151 | 30 | |
MikamiUitOpen | 0:e953eb392151 | 31 | // SD カードのファイルのオープン |
MikamiUitOpen | 0:e953eb392151 | 32 | int32_t SD_Open(SD_WavReader &sdReader, |
MikamiUitOpen | 0:e953eb392151 | 33 | string fileName, int32_t frameSize) |
MikamiUitOpen | 0:e953eb392151 | 34 | { |
MikamiUitOpen | 0:e953eb392151 | 35 | sdReader.Open(fileName); |
MikamiUitOpen | 0:e953eb392151 | 36 | sdReader.IsWavFile(); |
MikamiUitOpen | 0:e953eb392151 | 37 | return sdReader.GetSize()/frameSize; |
MikamiUitOpen | 0:e953eb392151 | 38 | } |
MikamiUitOpen | 0:e953eb392151 | 39 | |
MikamiUitOpen | 0:e953eb392151 | 40 | // ファイルの選択 |
MikamiUitOpen | 0:e953eb392151 | 41 | // selectedName: 選択されたファイル名 |
MikamiUitOpen | 0:e953eb392151 | 42 | void SelectFile(ButtonGroup &menu, FileSelector &selector, |
MikamiUitOpen | 0:e953eb392151 | 43 | Label &msg, string &selectedName) |
MikamiUitOpen | 0:e953eb392151 | 44 | { |
MikamiUitOpen | 0:e953eb392151 | 45 | msg.Draw("Select file"); |
MikamiUitOpen | 0:e953eb392151 | 46 | selector.DisplayFileList(); |
MikamiUitOpen | 0:e953eb392151 | 47 | do |
MikamiUitOpen | 0:e953eb392151 | 48 | { |
MikamiUitOpen | 0:e953eb392151 | 49 | if (selector.Select(selectedName)) |
MikamiUitOpen | 0:e953eb392151 | 50 | menu.Activate(1); // PLAY 有効 |
MikamiUitOpen | 0:e953eb392151 | 51 | wait_ms(200); |
MikamiUitOpen | 0:e953eb392151 | 52 | } while (!menu.Touched(1)); // PLAY がタッチされるまで繰り返す |
MikamiUitOpen | 0:e953eb392151 | 53 | } |
MikamiUitOpen | 0:e953eb392151 | 54 | |
MikamiUitOpen | 0:e953eb392151 | 55 | // フィルタの周波数特性の変更 |
MikamiUitOpen | 0:e953eb392151 | 56 | void ModifyFilter(DesignerDrawer &drawerObj, |
MikamiUitOpen | 0:e953eb392151 | 57 | SeekbarGroup &myBars, BiquadGrEq hn[], |
MikamiUitOpen | 0:e953eb392151 | 58 | Button &reset) |
MikamiUitOpen | 0:e953eb392151 | 59 | { |
MikamiUitOpen | 0:e953eb392151 | 60 | if (reset.Touched()) |
MikamiUitOpen | 0:e953eb392151 | 61 | { |
MikamiUitOpen | 0:e953eb392151 | 62 | drawerObj.DesignAndRedraw(); |
MikamiUitOpen | 0:e953eb392151 | 63 | for (int n=0; n<drawerObj.GetStages(); n++) |
MikamiUitOpen | 0:e953eb392151 | 64 | hn[n] = BiquadGrEq(drawerObj.GetCoefficient(n)); |
MikamiUitOpen | 0:e953eb392151 | 65 | myBars.DrawAll(0); // ツマミの位置を 0 dB に設定する |
MikamiUitOpen | 0:e953eb392151 | 66 | reset.Draw(); |
MikamiUitOpen | 0:e953eb392151 | 67 | return; |
MikamiUitOpen | 0:e953eb392151 | 68 | } |
MikamiUitOpen | 0:e953eb392151 | 69 | static int num = 0; |
MikamiUitOpen | 0:e953eb392151 | 70 | if (!myBars.GetSlidedNumber(num)) return; |
MikamiUitOpen | 0:e953eb392151 | 71 | drawerObj.DesignAndRedraw(myBars.GetValue(num), num); |
MikamiUitOpen | 0:e953eb392151 | 72 | hn[num] = BiquadGrEq(drawerObj.GetCoefficient(num)); |
MikamiUitOpen | 0:e953eb392151 | 73 | } |
MikamiUitOpen | 0:e953eb392151 | 74 | |
MikamiUitOpen | 0:e953eb392151 | 75 |