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
Diff: main.cpp
- Revision:
- 4:0beea5d9a205
- Parent:
- 3:68f16dc80b68
- Child:
- 5:d12a1fcf5ad1
--- a/main.cpp Wed Jun 15 12:54:02 2016 +0000 +++ b/main.cpp Sat Jul 23 06:14:23 2016 +0000 @@ -1,20 +1,11 @@ -//---------------------------------------------------------------------- -// CODEC を使い,MEMS マイクまたはライン (CN11) から入力した信号をそのまま +//--------------------------------------------------- +// CODEC を使い,MEMS マイクから入力した信号をそのまま // リアルタイムでヘッドフォン出力 (CN10) へ出力する -// ディジタルフィルタなどの雛形として使える // -// "stm32746g_discovery_audio.c" の BSP_AUDIO_IN_OUT_Init() 関数は -// INPUT_LINE_1 からの入力を禁止しているため,これを禁止しない関数として, -// BSP_AUDIO_IN_OUT_Init() の一部を修正し,MyBSP_AUDIO_IN_OUT_Init() -// という関数を定義した. -// この MyBSP_AUDIO_IN_OUT_Init() は "MyBSP_AUDIO_IN_OUT_Init.hpp" で -// 定義されている. -// -// 2016/06/15, Copyright (c) 2016 MIKAMI, Naoki -//---------------------------------------------------------------------- +// 2016/07/23, Copyright (c) 2016 MIKAMI, Naoki +//--------------------------------------------------- -#include "ButtonGroup.hpp" -#include "Label.hpp" +#include "F746_GUI.hpp" #include "WaveformDisplay.hpp" #include "SAI_InOut.hpp" @@ -27,47 +18,43 @@ const uint32_t LINE_COLOR = LCD_COLOR_CYAN; const uint32_t N_DATA = 400; - SaiIO mySai(SaiIO::BOTH, N_DATA, I2S_AUDIOFREQ_16K, INPUT_DEVICE_INPUT_LINE_1); + SaiIO mySai(SaiIO::BOTH, N_DATA, I2S_AUDIOFREQ_16K, + INPUT_DEVICE_DIGITAL_MICROPHONE_2); + LCD_DISCO_F746NG *lcd = GuiBase::GetLcdPtr(); lcd->Clear(BACK_COLOR); - Label labelTitle(240, 10, "Demo of Audio I/O", Label::CENTER, Font16); + Label labelTitle(240, 10, "Demo of Audio I/O 18:48", Label::CENTER, Font16); const uint16_t BG_LEFT = 370; const uint16_t BG_WIDTH = 110; const uint16_t BG_HEIGHT = 40; - const string INPUT[2] = {"MIC", "LINE"}; - ButtonGroup inSw(BG_LEFT, 180, BG_WIDTH/2, BG_HEIGHT, - 2, INPUT, 0, 0, 2, 1); - - const string RUN_STOP[2] = {"RUN", "STOP"}; ButtonGroup runStop(BG_LEFT, 230, BG_WIDTH/2, BG_HEIGHT, - 2, RUN_STOP, 0, 0, 2, 0); + 2, (string[]){"RUN", "STOP"}, 0, 0, 2, 0); lcd->SetTextColor(LCD_COLOR_WHITE); lcd->SetFont(&Font16); const int X_WAV = 30; // Origin for x axis of waveform - const int Y_WAV = 60; // Origin for y axis of waveform + const int Y_WAV = 80; // Origin for y axis of waveform WaveformDisplay waveDispL(lcd, X_WAV, Y_WAV, N_DATA, 7, AXIS_COLOR, LINE_COLOR, BACK_COLOR); - WaveformDisplay waveDispR(lcd, X_WAV, Y_WAV+60, N_DATA, 7, + WaveformDisplay waveDispR(lcd, X_WAV, Y_WAV+80, N_DATA, 7, AXIS_COLOR, LINE_COLOR, BACK_COLOR); Label labelL(445, Y_WAV- 8, "L", Label::LEFT, Font16); - Label labelR(445, Y_WAV+52, "R", Label::LEFT, Font16); + Label labelR(445, Y_WAV+72, "R", Label::LEFT, Font16); int16_t snL[N_DATA]; int16_t snR[N_DATA]; bool on = true; - int inSelect = 1; // input: line mySai.RecordIn(); mySai.PlayOut(); bool run = true; // run - while(1) + while (true) { int sw = 0; if (runStop.GetTouchedNumber(sw)) @@ -78,13 +65,6 @@ run = on; } - int swNow; - if (inSw.GetTouchedNumber(swNow) && (swNow != inSelect)) - { - mySai.SwitchInputDevice(swNow); - inSelect = swNow; - } - if (mySai.IsCompleted()) { for (int n=0; n<mySai.GetLength(); n++)