不韋 呂 / F746_MySoundMachine

Dependencies:   F746_GUI F746_SAI_IO FrequencyResponseDrawer SD_PlayerSkeleton UIT_FFT_Real

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ReverbFrShifterMain.hpp Source File

ReverbFrShifterMain.hpp

00001 //--------------------------------------------------------------
00002 //  MEMS マイクの入力に対して音響効果を与える
00003 //      音響効果:残響生成,周波数シフト
00004 //
00005 //  2017/04/13, Copyright (c) 2017 MIKAMI, Naoki
00006 //--------------------------------------------------------------
00007 
00008 #ifndef REVERB_FRSHIFTER_HPP
00009 #define REVERB_FRSHIFTER_HPP
00010 
00011 #include "InitializeGUI.hpp"
00012 #include "SAI_InOut.hpp"
00013 #include "Reverberator.hpp"
00014 #include "WeaverModulator.hpp"
00015 #include "GuiChanger.hpp"
00016 using namespace Mikami;
00017 
00018 void ReverbFrShifter()
00019 {
00020     const int FS = AUDIO_FREQUENCY_16K; // 標本化周波数: 16 kHz
00021     SaiIO mySai(SaiIO::BOTH, 256, FS, INPUT_DEVICE_DIGITAL_MICROPHONE_2);
00022 
00023     ButtonGroup *onOff;     // "ON", "OFF"
00024     ButtonGroup *menu;      // "THROUGH", "REVERB", "F_SHIFTER"
00025     SeekBar *barReverb, *barFqCh;
00026     NumericLabel<int> *frqLabel;
00027     WaveformDisplay *displayIn, *displayOut;
00028 
00029     // GUI 部品の初期化
00030     InitializeGUI(onOff, menu, barReverb, barFqCh,
00031                   frqLabel, displayIn, displayOut);
00032     // 処理に応じて GUI 部品の状態を変更する関数の割り当て
00033     void (*fPtr[])(SeekBar*, SeekBar*, NumericLabel<int>*)
00034         = { SetThrough, SetReverb, SetFrqShifter };
00035 
00036     ProcessingBase through;     // 0: 信号処理なしで出力
00037     Reverberator reverb;        // 1: 残響生成
00038     WeaverMod shifter(FS, 100); // 2: 周波数シフト(シフトの初期値:100 Hz)
00039     ProcessingBase *func[3] = { &through, &reverb, &shifter };
00040     ResetButton reset;
00041 
00042     int runStop = 1;
00043     int menuNum = 0;
00044 
00045     // 入出力の波形表示で使用
00046     Array<int16_t> snIn(mySai.GetLength());
00047     Array<int16_t> snOut(mySai.GetLength());
00048 
00049     mySai.RecordIn();
00050     mySai.PlayOut();
00051     mySai.PauseOut();
00052 
00053     while (true)
00054     {
00055         // On/OFF の設定
00056         int num;
00057         if (onOff->GetTouchedNumber(num))
00058             if (runStop != num)
00059             {
00060                 if (num == 0) mySai.ResumeOut();
00061                 else          mySai.PauseOut();
00062                 runStop = num;
00063             }
00064 
00065         // 信号処理の種類の切り替えに対応する GUI 部品の状態の設定
00066         if (menu->GetTouchedNumber(menuNum))
00067             fPtr[menuNum](barReverb, barFqCh, frqLabel);
00068 
00069         // 残響の長さを設定
00070         if ( (menuNum == 1) && (barReverb->Slide()) )
00071             reverb.SetDelay(6000 - barReverb->GetIntValue());
00072 
00073         // 周波数シフトの値の設定
00074         if ( (menuNum == 2) && (barFqCh->Slide()) )
00075         {
00076             frqLabel->Draw("+%d Hz", barFqCh->GetIntValue());
00077             shifter.SetFrequency(barFqCh->GetIntValue());
00078         }
00079 
00080         //---------------------------------------------
00081         // 1ブロック分の信号処理を行い,その結果を出力する
00082         if ( mySai.IsCompleted())
00083         {
00084             for (int n=0; n<mySai.GetLength(); n++)
00085             {
00086                 int16_t xL, xR;
00087                 mySai.Input(xL, xR);
00088                 int16_t xn = xL + xR;
00089                 snIn[n] = xn;   // 表示用
00090 
00091                 //-------------------------------------------------------
00092                 // 信号処理実行
00093                 int16_t yn = (int16_t)func[menuNum]->Execute((float)xn);
00094                 //-------------------------------------------------------
00095 
00096                 mySai.Output(yn, yn);   // 左右チャンネルに同じ信号を出力
00097                 snOut[n] = yn;  // 表示用
00098             }
00099 
00100             displayIn->Execute(snIn);   // 入力波形の表示
00101             displayOut->Execute(snOut); // 出力波形の表示
00102         }
00103         // 1ブロック分の信号処理はここまで
00104         //---------------------------------------------
00105 
00106         reset.DoIfTouched();    // リセットボタンがタッチされればメニューに戻る
00107     }
00108 }
00109 #endif  // REVERB_FRSHIFTER_HPP