![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Demo program of SAI_IO class for audio signal input and output. DISCO-F746 搭載の CODEC (WM8994) を使ってオーディオ信号の入出力を行うための SAI_IO クラスの使用例.
Dependencies: BSP_DISCO_F746NG F746_GUI F746_SAI_IO LCD_DISCO_F746NG TS_DISCO_F746NG mbed
main.cpp@5:d12a1fcf5ad1, 2016-08-15 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Mon Aug 15 06:45:21 2016 +0000
- Revision:
- 5:d12a1fcf5ad1
- Parent:
- 4:0beea5d9a205
- Child:
- 7:770d50e8dbb1
6
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 4:0beea5d9a205 | 1 | //--------------------------------------------------- |
MikamiUitOpen | 4:0beea5d9a205 | 2 | // CODEC を使い,MEMS マイクから入力した信号をそのまま |
MikamiUitOpen | 0:089c5e022aa8 | 3 | // リアルタイムでヘッドフォン出力 (CN10) へ出力する |
MikamiUitOpen | 0:089c5e022aa8 | 4 | // |
MikamiUitOpen | 5:d12a1fcf5ad1 | 5 | // 2016/08/15, Copyright (c) 2016 MIKAMI, Naoki |
MikamiUitOpen | 4:0beea5d9a205 | 6 | //--------------------------------------------------- |
MikamiUitOpen | 0:089c5e022aa8 | 7 | |
MikamiUitOpen | 4:0beea5d9a205 | 8 | #include "F746_GUI.hpp" |
MikamiUitOpen | 0:089c5e022aa8 | 9 | #include "WaveformDisplay.hpp" |
MikamiUitOpen | 0:089c5e022aa8 | 10 | |
MikamiUitOpen | 0:089c5e022aa8 | 11 | #include "SAI_InOut.hpp" |
MikamiUitOpen | 0:089c5e022aa8 | 12 | using namespace Mikami; |
MikamiUitOpen | 0:089c5e022aa8 | 13 | |
MikamiUitOpen | 0:089c5e022aa8 | 14 | int main() |
MikamiUitOpen | 0:089c5e022aa8 | 15 | { |
MikamiUitOpen | 0:089c5e022aa8 | 16 | const uint32_t BACK_COLOR = GuiBase::ENUM_BACK; |
MikamiUitOpen | 0:089c5e022aa8 | 17 | const uint32_t AXIS_COLOR = 0xFFCCFFFF; |
MikamiUitOpen | 0:089c5e022aa8 | 18 | const uint32_t LINE_COLOR = LCD_COLOR_CYAN; |
MikamiUitOpen | 0:089c5e022aa8 | 19 | |
MikamiUitOpen | 0:089c5e022aa8 | 20 | const uint32_t N_DATA = 400; |
MikamiUitOpen | 4:0beea5d9a205 | 21 | SaiIO mySai(SaiIO::BOTH, N_DATA, I2S_AUDIOFREQ_16K, |
MikamiUitOpen | 4:0beea5d9a205 | 22 | INPUT_DEVICE_DIGITAL_MICROPHONE_2); |
MikamiUitOpen | 4:0beea5d9a205 | 23 | |
MikamiUitOpen | 0:089c5e022aa8 | 24 | |
MikamiUitOpen | 0:089c5e022aa8 | 25 | LCD_DISCO_F746NG *lcd = GuiBase::GetLcdPtr(); |
MikamiUitOpen | 0:089c5e022aa8 | 26 | lcd->Clear(BACK_COLOR); |
MikamiUitOpen | 0:089c5e022aa8 | 27 | |
MikamiUitOpen | 5:d12a1fcf5ad1 | 28 | Label labelTitle(240, 10, "Demo of Audio I/O", Label::CENTER, Font16); |
MikamiUitOpen | 3:68f16dc80b68 | 29 | |
MikamiUitOpen | 2:034168531ce0 | 30 | const uint16_t BG_LEFT = 370; |
MikamiUitOpen | 2:034168531ce0 | 31 | const uint16_t BG_WIDTH = 110; |
MikamiUitOpen | 0:089c5e022aa8 | 32 | const uint16_t BG_HEIGHT = 40; |
MikamiUitOpen | 0:089c5e022aa8 | 33 | |
MikamiUitOpen | 3:68f16dc80b68 | 34 | ButtonGroup runStop(BG_LEFT, 230, BG_WIDTH/2, BG_HEIGHT, |
MikamiUitOpen | 4:0beea5d9a205 | 35 | 2, (string[]){"RUN", "STOP"}, 0, 0, 2, 0); |
MikamiUitOpen | 0:089c5e022aa8 | 36 | |
MikamiUitOpen | 0:089c5e022aa8 | 37 | lcd->SetTextColor(LCD_COLOR_WHITE); |
MikamiUitOpen | 0:089c5e022aa8 | 38 | lcd->SetFont(&Font16); |
MikamiUitOpen | 0:089c5e022aa8 | 39 | |
MikamiUitOpen | 0:089c5e022aa8 | 40 | const int X_WAV = 30; // Origin for x axis of waveform |
MikamiUitOpen | 4:0beea5d9a205 | 41 | const int Y_WAV = 80; // Origin for y axis of waveform |
MikamiUitOpen | 0:089c5e022aa8 | 42 | WaveformDisplay waveDispL(lcd, X_WAV, Y_WAV, N_DATA, 7, |
MikamiUitOpen | 0:089c5e022aa8 | 43 | AXIS_COLOR, LINE_COLOR, BACK_COLOR); |
MikamiUitOpen | 4:0beea5d9a205 | 44 | WaveformDisplay waveDispR(lcd, X_WAV, Y_WAV+80, N_DATA, 7, |
MikamiUitOpen | 0:089c5e022aa8 | 45 | AXIS_COLOR, LINE_COLOR, BACK_COLOR); |
MikamiUitOpen | 0:089c5e022aa8 | 46 | Label labelL(445, Y_WAV- 8, "L", Label::LEFT, Font16); |
MikamiUitOpen | 4:0beea5d9a205 | 47 | Label labelR(445, Y_WAV+72, "R", Label::LEFT, Font16); |
MikamiUitOpen | 0:089c5e022aa8 | 48 | |
MikamiUitOpen | 0:089c5e022aa8 | 49 | int16_t snL[N_DATA]; |
MikamiUitOpen | 0:089c5e022aa8 | 50 | int16_t snR[N_DATA]; |
MikamiUitOpen | 0:089c5e022aa8 | 51 | bool on = true; |
MikamiUitOpen | 0:089c5e022aa8 | 52 | |
MikamiUitOpen | 1:7400dd732dbc | 53 | mySai.RecordIn(); |
MikamiUitOpen | 1:7400dd732dbc | 54 | mySai.PlayOut(); |
MikamiUitOpen | 3:68f16dc80b68 | 55 | bool run = true; // run |
MikamiUitOpen | 1:7400dd732dbc | 56 | |
MikamiUitOpen | 4:0beea5d9a205 | 57 | while (true) |
MikamiUitOpen | 0:089c5e022aa8 | 58 | { |
MikamiUitOpen | 0:089c5e022aa8 | 59 | int sw = 0; |
MikamiUitOpen | 3:68f16dc80b68 | 60 | if (runStop.GetTouchedNumber(sw)) |
MikamiUitOpen | 3:68f16dc80b68 | 61 | { |
MikamiUitOpen | 0:089c5e022aa8 | 62 | on = (sw == 0) ? true : false; |
MikamiUitOpen | 3:68f16dc80b68 | 63 | if (on && !run) mySai.ResumeOut(); |
MikamiUitOpen | 3:68f16dc80b68 | 64 | if (!on && run) mySai.PauseOut(); |
MikamiUitOpen | 3:68f16dc80b68 | 65 | run = on; |
MikamiUitOpen | 3:68f16dc80b68 | 66 | } |
MikamiUitOpen | 0:089c5e022aa8 | 67 | |
MikamiUitOpen | 0:089c5e022aa8 | 68 | if (mySai.IsCompleted()) |
MikamiUitOpen | 0:089c5e022aa8 | 69 | { |
MikamiUitOpen | 0:089c5e022aa8 | 70 | for (int n=0; n<mySai.GetLength(); n++) |
MikamiUitOpen | 0:089c5e022aa8 | 71 | { |
MikamiUitOpen | 0:089c5e022aa8 | 72 | int16_t xL; |
MikamiUitOpen | 0:089c5e022aa8 | 73 | int16_t xR; |
MikamiUitOpen | 0:089c5e022aa8 | 74 | mySai.Input(xL, xR); |
MikamiUitOpen | 0:089c5e022aa8 | 75 | snL[n] = xL; // 入力波形のモニタのため |
MikamiUitOpen | 0:089c5e022aa8 | 76 | snR[n] = xR; // 入力波形のモニタのため |
MikamiUitOpen | 0:089c5e022aa8 | 77 | |
MikamiUitOpen | 0:089c5e022aa8 | 78 | //---------------------------------------- |
MikamiUitOpen | 0:089c5e022aa8 | 79 | // ここにディジタルフィルタなどの処理を書く |
MikamiUitOpen | 0:089c5e022aa8 | 80 | int16_t yL = xL; // through の場合 |
MikamiUitOpen | 0:089c5e022aa8 | 81 | int16_t yR = xR; // through の場合 |
MikamiUitOpen | 0:089c5e022aa8 | 82 | //---------------------------------------- |
MikamiUitOpen | 0:089c5e022aa8 | 83 | |
MikamiUitOpen | 0:089c5e022aa8 | 84 | mySai.Output(yL, yR); |
MikamiUitOpen | 0:089c5e022aa8 | 85 | } |
MikamiUitOpen | 0:089c5e022aa8 | 86 | if (on) |
MikamiUitOpen | 0:089c5e022aa8 | 87 | { |
MikamiUitOpen | 0:089c5e022aa8 | 88 | waveDispL.Execute(snL); |
MikamiUitOpen | 0:089c5e022aa8 | 89 | waveDispR.Execute(snR); |
MikamiUitOpen | 0:089c5e022aa8 | 90 | } |
MikamiUitOpen | 0:089c5e022aa8 | 91 | mySai.Reset(); |
MikamiUitOpen | 0:089c5e022aa8 | 92 | } |
MikamiUitOpen | 0:089c5e022aa8 | 93 | } |
MikamiUitOpen | 0:089c5e022aa8 | 94 | } |