Audio singal input and output example for DISCO-F746. Input: MEMS mic, Output: CN10 OUT, Acoustic effect: echo and frequency shift. DISCO-F746 によるオーディオ信号入出力.入力:MEMS マイク,出力:CN10 OUT,音響効果:エコー,周波数変換.
Dependencies: F746_GUI F746_SAI_IO
Diff: main.cpp
- Revision:
- 9:1221ba81a1bb
- Parent:
- 8:9378fea59845
- Child:
- 10:56f2f01df983
diff -r 9378fea59845 -r 1221ba81a1bb main.cpp --- a/main.cpp Thu Nov 10 12:53:05 2016 +0000 +++ b/main.cpp Fri Mar 17 01:26:25 2017 +0000 @@ -2,7 +2,7 @@ // MEMS マイクの入力に対して音響効果を与える // 音響効果:エコー生成,周波数シフト // -// 2016/11/10, Copyright (c) 2016 MIKAMI, Naoki +// 2017/03/17, Copyright (c) 2017 MIKAMI, Naoki //-------------------------------------------------------------- #include "EffectorInitializeGUI.hpp" @@ -15,7 +15,7 @@ int main() { - const int FS = I2S_AUDIOFREQ_16K; // 標本化周波数: 16 kHz + const int FS = AUDIO_FREQUENCY_16K; // 標本化周波数: 16 kHz SaiIO mySai(SaiIO::BOTH, 256, FS, INPUT_DEVICE_DIGITAL_MICROPHONE_2); ButtonGroup *onOff; // "ON", "OFF" @@ -23,7 +23,7 @@ SeekBar *barEcho, *barFqCh; NumericLabel<int> *frqLabel; WaveformDisplay *displayIn, *displayOut; - + EffectorInitializeGUI(onOff, menu, barEcho, barFqCh, frqLabel, displayIn, displayOut); @@ -32,10 +32,10 @@ FrqShifter shifter(FS); // 2: 周波数シフト ProcessingBase *func[3] = { &through, &echo, &shifter }; shifter.SetFrequensy(100); // 周波数シフタの初期値:100 Hz - + int runStop = 1; - int menuNum = 0; - + int menuNum = 0; + // 入出力の波形表示で使用 Array<int16_t> snIn(mySai.GetLength()); Array<int16_t> snOut(mySai.GetLength()); @@ -48,26 +48,24 @@ { // On/OFF の設定 int num; - if (onOff->GetTouchedNumber(num)) - if (runStop != num) - { - if (num == 0) mySai.ResumeOut(); - else mySai.PauseOut(); - runStop = num; - } + + if ( (onOff->GetTouchedNumber(num)) && (runStop != num) ) + { + if (num == 0) mySai.ResumeOut(); + else mySai.PauseOut(); + runStop = num; + } // エコーの長さを設定 - if (menuNum == 1) - if (barEcho->Slide()) - echo.SetDelay(6000 - barEcho->GetIntValue()); - + if ( (menuNum == 1) && (barEcho->Slide()) ) + echo.SetDelay(6000 - barEcho->GetIntValue()); + // 周波数シフトの値の設定 - if (menuNum == 2) - if (barFqCh->Slide()) - { - frqLabel->Draw(barFqCh->GetIntValue()); - shifter.SetFrequensy(barFqCh->GetIntValue()); - } + if ( (menuNum == 2) && (barFqCh->Slide()) ) + { + frqLabel->Draw(barFqCh->GetIntValue()); + shifter.SetFrequensy(barFqCh->GetIntValue()); + } // 信号処理の種類の切り替え if (menu->GetTouchedNumber(menuNum)) @@ -75,15 +73,15 @@ { case 0: barEcho->Inactivate(); // Through barFqCh->Inactivate(); - frqLabel->Redraw(GuiBase::ENUM_INACTIVE_TEXT); + frqLabel->Redraw(GuiBase::ENUM_INACTIVE_TEXT); break; case 1: barEcho->Activate(); // Echo barFqCh->Inactivate(); - frqLabel->Redraw(GuiBase::ENUM_INACTIVE_TEXT); + frqLabel->Redraw(GuiBase::ENUM_INACTIVE_TEXT); break; case 2: barEcho->Inactivate(); // Frequency shifter barFqCh->Activate(); - frqLabel->Redraw(GuiBase::ENUM_TEXT); + frqLabel->Redraw(GuiBase::ENUM_TEXT); break; } @@ -102,15 +100,14 @@ // 信号処理実行 int16_t yn = (int16_t)func[menuNum]->Execute((float)xn); //------------------------------------------------------- - + mySai.Output(yn, yn); // 左右チャンネルに同じ信号を出力 snOut[n] = yn; // 表示用 } - mySai.Reset(); - + displayIn->Execute(snIn); // 入力波形の表示 displayOut->Execute(snOut); // 出力波形の表示 - } + } // 1フレーム分の信号処理はここまで //--------------------------------------------- }