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