![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Chapter006_Zara_F746NG
Dependencies: F746_GUI SRF08 Array_Matrix TS_DISCO_F746NG mbed LCD_DISCO_F746NG BSP_DISCO_F746NG SDFileSystem_Warning_Fixed FrequencyResponseDrawer F746_SAI_IO
MyClasses_Functions/MyFunctions.cpp@0:04b43b777fae, 2016-04-19 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Tue Apr 19 09:46:11 2016 +0000
- Revision:
- 0:04b43b777fae
- Child:
- 5:3e8ca1ed31a1
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:04b43b777fae | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:04b43b777fae | 2 | // フィルタ処理付き SD オーディオプレーヤーで使う大域関数(ヘッダ) |
MikamiUitOpen | 0:04b43b777fae | 3 | // |
MikamiUitOpen | 0:04b43b777fae | 4 | // 2016/04/19, Copyright (c) 2016 MIKAMI, Naoki |
MikamiUitOpen | 0:04b43b777fae | 5 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:04b43b777fae | 6 | |
MikamiUitOpen | 0:04b43b777fae | 7 | #include "MyFunctions.hpp" |
MikamiUitOpen | 0:04b43b777fae | 8 | |
MikamiUitOpen | 0:04b43b777fae | 9 | // 1フレーム分の信号処理 (IIR フィルタ) の実行 |
MikamiUitOpen | 0:04b43b777fae | 10 | void ProcessSignal(SD_WavReader &sdReader, SaiIO_O &mySai, |
MikamiUitOpen | 0:04b43b777fae | 11 | int16_t sn[], float g0, Biquad hn[], |
MikamiUitOpen | 0:04b43b777fae | 12 | int order, bool filterOn) |
MikamiUitOpen | 0:04b43b777fae | 13 | { |
MikamiUitOpen | 0:04b43b777fae | 14 | // 1フレーム分のデータを SD から読み込む |
MikamiUitOpen | 0:04b43b777fae | 15 | sdReader.ReadAndToMono(sn, mySai.GetLength()); |
MikamiUitOpen | 0:04b43b777fae | 16 | |
MikamiUitOpen | 0:04b43b777fae | 17 | while (!mySai.IsXferred()) {} // データの転送が終わるまで待つ |
MikamiUitOpen | 0:04b43b777fae | 18 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:04b43b777fae | 19 | // 1フレーム分の信号処理を行い,その結果を出力する |
MikamiUitOpen | 0:04b43b777fae | 20 | for (int n=0; n<mySai.GetLength(); n++) |
MikamiUitOpen | 0:04b43b777fae | 21 | { |
MikamiUitOpen | 0:04b43b777fae | 22 | int16_t value; |
MikamiUitOpen | 0:04b43b777fae | 23 | if (filterOn) // フィルタ処理実行 |
MikamiUitOpen | 0:04b43b777fae | 24 | { |
MikamiUitOpen | 0:04b43b777fae | 25 | // 縦続形の IIR フィルタ |
MikamiUitOpen | 0:04b43b777fae | 26 | float yn = g0*sn[n]; |
MikamiUitOpen | 0:04b43b777fae | 27 | for (int k=0; k<order/2; k++) yn = hn[k].Execute(yn); |
MikamiUitOpen | 0:04b43b777fae | 28 | value = (int16_t)yn; |
MikamiUitOpen | 0:04b43b777fae | 29 | } |
MikamiUitOpen | 0:04b43b777fae | 30 | else |
MikamiUitOpen | 0:04b43b777fae | 31 | value = sn[n]; // フィルタ処理なし |
MikamiUitOpen | 0:04b43b777fae | 32 | mySai.Output(value, value); // 音響信号の出力 |
MikamiUitOpen | 0:04b43b777fae | 33 | } |
MikamiUitOpen | 0:04b43b777fae | 34 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:04b43b777fae | 35 | mySai.ResetXferred(); // 次のデータ転送に備える |
MikamiUitOpen | 0:04b43b777fae | 36 | } |
MikamiUitOpen | 0:04b43b777fae | 37 | |
MikamiUitOpen | 0:04b43b777fae | 38 | // SD カードのファイルのオープン |
MikamiUitOpen | 0:04b43b777fae | 39 | int32_t SD_Open(SD_WavReader &sdReader, |
MikamiUitOpen | 0:04b43b777fae | 40 | string fileName, int32_t frameSize) |
MikamiUitOpen | 0:04b43b777fae | 41 | { |
MikamiUitOpen | 0:04b43b777fae | 42 | sdReader.Open(fileName); |
MikamiUitOpen | 0:04b43b777fae | 43 | sdReader.IsWavFile(); |
MikamiUitOpen | 0:04b43b777fae | 44 | return sdReader.GetSize()/frameSize; |
MikamiUitOpen | 0:04b43b777fae | 45 | } |
MikamiUitOpen | 0:04b43b777fae | 46 | |
MikamiUitOpen | 0:04b43b777fae | 47 | // ファイルの選択 |
MikamiUitOpen | 0:04b43b777fae | 48 | // selectedName: 選択されたファイル名 |
MikamiUitOpen | 0:04b43b777fae | 49 | void SelectFile(ButtonGroup &menu, FileSelector &selector, |
MikamiUitOpen | 0:04b43b777fae | 50 | Label &msg, string &selectedName) |
MikamiUitOpen | 0:04b43b777fae | 51 | { |
MikamiUitOpen | 0:04b43b777fae | 52 | msg.Draw("Select file"); |
MikamiUitOpen | 0:04b43b777fae | 53 | selector.DisplayFileList(); |
MikamiUitOpen | 0:04b43b777fae | 54 | do |
MikamiUitOpen | 0:04b43b777fae | 55 | { |
MikamiUitOpen | 0:04b43b777fae | 56 | if (selector.Select(selectedName)) |
MikamiUitOpen | 0:04b43b777fae | 57 | menu.Activate(1); // PLAY 有効 |
MikamiUitOpen | 0:04b43b777fae | 58 | wait_ms(200); |
MikamiUitOpen | 0:04b43b777fae | 59 | } while (!menu.Touched(1)); // PLAY がタッチされるまで繰り返す |
MikamiUitOpen | 0:04b43b777fae | 60 | } |
MikamiUitOpen | 0:04b43b777fae | 61 | |
MikamiUitOpen | 0:04b43b777fae | 62 | // フィルタの変更 |
MikamiUitOpen | 0:04b43b777fae | 63 | void ModifyFilter(DesignerDrawer &drawerObj, |
MikamiUitOpen | 0:04b43b777fae | 64 | ButtonGroup &lpHp, ButtonGroup &onOff, |
MikamiUitOpen | 0:04b43b777fae | 65 | Biquad hn[], Biquad::Coefs ck[], |
MikamiUitOpen | 0:04b43b777fae | 66 | float &g0, bool &filterOn) |
MikamiUitOpen | 0:04b43b777fae | 67 | { |
MikamiUitOpen | 0:04b43b777fae | 68 | // フィルタ処理の有効/無効切り替え |
MikamiUitOpen | 0:04b43b777fae | 69 | int sw = 0; |
MikamiUitOpen | 0:04b43b777fae | 70 | if (onOff.GetTouchedNumber(sw)) |
MikamiUitOpen | 0:04b43b777fae | 71 | filterOn = (sw == 0) ? true : false; |
MikamiUitOpen | 0:04b43b777fae | 72 | |
MikamiUitOpen | 0:04b43b777fae | 73 | // フィルタの周波数特性の変更 |
MikamiUitOpen | 0:04b43b777fae | 74 | static int num = 0; |
MikamiUitOpen | 0:04b43b777fae | 75 | lpHp.GetTouchedNumber(num); |
MikamiUitOpen | 0:04b43b777fae | 76 | BilinearDesign::Type typeLH = (BilinearDesign::Type)num; |
MikamiUitOpen | 0:04b43b777fae | 77 | if (drawerObj.ReDesignAndDraw(ck, g0, typeLH)) |
MikamiUitOpen | 0:04b43b777fae | 78 | for (int k=0; k<drawerObj.GetOrder()/2; k++) |
MikamiUitOpen | 0:04b43b777fae | 79 | { |
MikamiUitOpen | 0:04b43b777fae | 80 | hn[k].SetCoefficients(ck[k]); |
MikamiUitOpen | 0:04b43b777fae | 81 | hn[k].Clear(); |
MikamiUitOpen | 0:04b43b777fae | 82 | } |
MikamiUitOpen | 0:04b43b777fae | 83 | } |
MikamiUitOpen | 0:04b43b777fae | 84 |