![](/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@10:fc6367c2ffcf, 2016-06-22 (annotated)
- Committer:
- edamame22
- Date:
- Wed Jun 22 03:50:38 2016 +0000
- Revision:
- 10:fc6367c2ffcf
- Parent:
- 8:12aa05f3cc24
- Child:
- 12:87f6955b5a80
auto play is enabled
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 8:12aa05f3cc24 | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 8:12aa05f3cc24 | 2 | // グラフィックイコライザ付き SD オーディオプレーヤーで使う大域関数 |
MikamiUitOpen | 8:12aa05f3cc24 | 3 | // |
MikamiUitOpen | 8:12aa05f3cc24 | 4 | // 2016/05/09, Copyright (c) 2016 MIKAMI, Naoki |
MikamiUitOpen | 8:12aa05f3cc24 | 5 | //-------------------------------------------------------------- |
MikamiUitOpen | 8:12aa05f3cc24 | 6 | |
MikamiUitOpen | 8:12aa05f3cc24 | 7 | #include "MyFunctions.hpp" |
MikamiUitOpen | 8:12aa05f3cc24 | 8 | |
MikamiUitOpen | 8:12aa05f3cc24 | 9 | // 1フレーム分の信号処理 (イコライザ) の実行 |
MikamiUitOpen | 8:12aa05f3cc24 | 10 | void SignalProcessing(SD_WavReader &sdReader, SaiIO &mySai, |
MikamiUitOpen | 8:12aa05f3cc24 | 11 | int16_t sn[], BiquadGrEq hn[], |
MikamiUitOpen | 8:12aa05f3cc24 | 12 | int stages, bool on) |
MikamiUitOpen | 8:12aa05f3cc24 | 13 | { |
MikamiUitOpen | 8:12aa05f3cc24 | 14 | // 1フレーム分のデータを SD から読み込む |
MikamiUitOpen | 8:12aa05f3cc24 | 15 | sdReader.ReadAndToMono(sn, mySai.GetLength()); |
MikamiUitOpen | 8:12aa05f3cc24 | 16 | |
MikamiUitOpen | 8:12aa05f3cc24 | 17 | while (!mySai.IsXferred()) {} // データの転送が終わるまで待つ |
MikamiUitOpen | 8:12aa05f3cc24 | 18 | //-------------------------------------------------------------- |
MikamiUitOpen | 8:12aa05f3cc24 | 19 | // 1フレーム分のイコライザ処理を行い,その結果を出力する |
MikamiUitOpen | 8:12aa05f3cc24 | 20 | for (int n=0; n<mySai.GetLength(); n++) |
MikamiUitOpen | 8:12aa05f3cc24 | 21 | { |
MikamiUitOpen | 8:12aa05f3cc24 | 22 | // 縦続形の IIR フィルタ実行 |
MikamiUitOpen | 8:12aa05f3cc24 | 23 | float xn = 0.125f*sn[n]; // 0.125 の乗算はブースとしてもクリップ |
MikamiUitOpen | 8:12aa05f3cc24 | 24 | // されないようにするため |
MikamiUitOpen | 8:12aa05f3cc24 | 25 | float yn = xn; |
MikamiUitOpen | 8:12aa05f3cc24 | 26 | for (int k=0; k<stages; k++) yn = hn[k].Execute(yn); |
MikamiUitOpen | 8:12aa05f3cc24 | 27 | int16_t value = on ? (int16_t)yn : xn; |
MikamiUitOpen | 8:12aa05f3cc24 | 28 | mySai.Output(value, value); // 音響信号の出力 |
MikamiUitOpen | 8:12aa05f3cc24 | 29 | } |
MikamiUitOpen | 8:12aa05f3cc24 | 30 | //-------------------------------------------------------------- |
MikamiUitOpen | 8:12aa05f3cc24 | 31 | mySai.ResetXferred(); // 次のデータ転送に備える |
MikamiUitOpen | 8:12aa05f3cc24 | 32 | } |
MikamiUitOpen | 8:12aa05f3cc24 | 33 | |
MikamiUitOpen | 8:12aa05f3cc24 | 34 | // SD カードのファイルのオープン |
MikamiUitOpen | 8:12aa05f3cc24 | 35 | int32_t SD_Open(SD_WavReader &sdReader, |
MikamiUitOpen | 8:12aa05f3cc24 | 36 | string fileName, int32_t frameSize) |
MikamiUitOpen | 8:12aa05f3cc24 | 37 | { |
MikamiUitOpen | 8:12aa05f3cc24 | 38 | sdReader.Open(fileName); |
MikamiUitOpen | 8:12aa05f3cc24 | 39 | sdReader.IsWavFile(); |
MikamiUitOpen | 8:12aa05f3cc24 | 40 | return sdReader.GetSize()/frameSize; |
MikamiUitOpen | 8:12aa05f3cc24 | 41 | } |
MikamiUitOpen | 8:12aa05f3cc24 | 42 | |
MikamiUitOpen | 8:12aa05f3cc24 | 43 | // ファイルの選択 |
MikamiUitOpen | 8:12aa05f3cc24 | 44 | // selectedName: 選択されたファイル名 |
MikamiUitOpen | 8:12aa05f3cc24 | 45 | void SelectFile(ButtonGroup &menu, FileSelector &selector, |
edamame22 | 10:fc6367c2ffcf | 46 | Label &msg, string fileList[], int *selected) |
MikamiUitOpen | 8:12aa05f3cc24 | 47 | { |
MikamiUitOpen | 8:12aa05f3cc24 | 48 | selector.DisplayFileList(); |
MikamiUitOpen | 8:12aa05f3cc24 | 49 | msg.Draw("Select file"); |
MikamiUitOpen | 8:12aa05f3cc24 | 50 | do |
MikamiUitOpen | 8:12aa05f3cc24 | 51 | { |
edamame22 | 10:fc6367c2ffcf | 52 | if (selector.Select(fileList, selected)) |
MikamiUitOpen | 8:12aa05f3cc24 | 53 | menu.Activate(1); // PLAY 有効 |
edamame22 | 10:fc6367c2ffcf | 54 | // ren: change wait timer 200 to 60 |
edamame22 | 10:fc6367c2ffcf | 55 | wait_ms(60); |
MikamiUitOpen | 8:12aa05f3cc24 | 56 | } while (!menu.Touched(1)); // PLAY がタッチされるまで繰り返す |
MikamiUitOpen | 8:12aa05f3cc24 | 57 | } |
MikamiUitOpen | 8:12aa05f3cc24 | 58 | |
MikamiUitOpen | 8:12aa05f3cc24 | 59 | // フィルタの周波数特性の変更 |
MikamiUitOpen | 8:12aa05f3cc24 | 60 | void ModifyFilter(DesignerDrawer &drawerObj, |
MikamiUitOpen | 8:12aa05f3cc24 | 61 | SeekbarGroup &myBars, BiquadGrEq hn[], |
MikamiUitOpen | 8:12aa05f3cc24 | 62 | Button &flat, ButtonGroup &onOff, bool &on) |
MikamiUitOpen | 8:12aa05f3cc24 | 63 | { |
MikamiUitOpen | 8:12aa05f3cc24 | 64 | |
MikamiUitOpen | 8:12aa05f3cc24 | 65 | // 周波数特性を平坦化 |
MikamiUitOpen | 8:12aa05f3cc24 | 66 | if (flat.Touched()) |
MikamiUitOpen | 8:12aa05f3cc24 | 67 | { |
MikamiUitOpen | 8:12aa05f3cc24 | 68 | drawerObj.DrawFlat(); |
MikamiUitOpen | 8:12aa05f3cc24 | 69 | for (int n=0; n<drawerObj.GetStages(); n++) |
MikamiUitOpen | 8:12aa05f3cc24 | 70 | hn[n] = BiquadGrEq(drawerObj.GetCoefficient(n)); |
MikamiUitOpen | 8:12aa05f3cc24 | 71 | myBars.DrawAll(0); // ツマミの位置を 0 dB に設定する |
MikamiUitOpen | 8:12aa05f3cc24 | 72 | flat.Draw(); |
MikamiUitOpen | 8:12aa05f3cc24 | 73 | return; |
MikamiUitOpen | 8:12aa05f3cc24 | 74 | } |
MikamiUitOpen | 8:12aa05f3cc24 | 75 | |
MikamiUitOpen | 8:12aa05f3cc24 | 76 | int sw = 0; |
MikamiUitOpen | 8:12aa05f3cc24 | 77 | if (onOff.GetTouchedNumber(sw)) |
MikamiUitOpen | 8:12aa05f3cc24 | 78 | on = (sw == 0) ? true : false; |
MikamiUitOpen | 8:12aa05f3cc24 | 79 | |
MikamiUitOpen | 8:12aa05f3cc24 | 80 | static int num = 0; |
MikamiUitOpen | 8:12aa05f3cc24 | 81 | if (!myBars.GetSlidedNumber(num)) return; |
MikamiUitOpen | 8:12aa05f3cc24 | 82 | drawerObj.DesignAndRedraw(myBars.GetValue(num), num); |
MikamiUitOpen | 8:12aa05f3cc24 | 83 | hn[num] = BiquadGrEq(drawerObj.GetCoefficient(num)); |
MikamiUitOpen | 8:12aa05f3cc24 | 84 | } |