![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Version using MEMS microphone and CODEC for the program "F746_RealtimeSpectrumAnalyzer". "F746_RealtimeSpectrumAnalyzer" の入力を MEMS のマイクと CODEC に変更.このプログラムは Tomona Nanase さんが作成し DISCO-F746NG_Oscilloscope の名前で登録しているプログラムで, CODEC を使って入力する部分を参考にして作成.このプログラムの説明は,CQ出版社のインターフェース誌,2016年4月号に掲載.
Dependencies: BSP_DISCO_F746NG BUTTON_GROUP LCD_DISCO_F746NG TS_DISCO_F746NG UIT_FFT_Real mbed
Diff: main.cpp
- Revision:
- 3:a6df3a2de219
- Parent:
- 1:ac0a67a0deec
- Child:
- 5:3465b7b7acb8
--- a/main.cpp Thu Jan 07 09:48:29 2016 +0000 +++ b/main.cpp Fri Jan 08 13:03:24 2016 +0000 @@ -2,7 +2,7 @@ // Realtime spectrum analyzer // Input: MEMS microphone or CN11 // -// 2016/01/06, Copyright (c) 2016 MIKAMI, Naoki +// 2016/01/08, Copyright (c) 2016 MIKAMI, Naoki //------------------------------------------------ #include "main.h" @@ -14,6 +14,14 @@ __IO int32_t audio_in_buffer_offset = 0; __IO int32_t audio_in_buffer_length = 0; +// Switching input device +void SwitchInputDevice(int sw) +{ + uint16_t dev = (sw == 0) ? INPUT_DEVICE_DIGITAL_MICROPHONE_2 + : INPUT_DEVICE_INPUT_LINE_1; + InitRunAudioIn(dev, I2S_AUDIOFREQ_16K); +} + int main() { const int FS = 8000; // Sampling frequency: 8 kHz @@ -65,7 +73,7 @@ WaveformDisplay waveDisp(lcd, X_WAV, Y_WAV, N_DATA, 9, AXIS_COLOR, LINE_COLOR, BACK_COLOR); - SpectrumDisplay disp(lcd, N_FFT, X0, Y0, -40, DB1, BIN, W_DB, FS, + SpectrumDisplay disp(lcd, N_FFT, X0, Y0, -45, DB1, BIN, W_DB, FS, AXIS_COLOR, LINE_COLOR, BACK_COLOR); // Linear prediction: order = 10 // Cepstral smoothing: highest quefrency = 40 @@ -73,8 +81,8 @@ // Initialize the infinite loop procedure int select = -1; - uint16_t inputDevice; - int mic = 0; +// int mic = 0; + int sw = 0; // 0: mic, 1: line int stop = 0; int16_t sn[N_DATA]; @@ -88,23 +96,16 @@ { if (runStop.Touched(0, TOUCHED_COLOR)) { - inputDevice = (mic == 0) ? INPUT_DEVICE_DIGITAL_MICROPHONE_2 - : INPUT_DEVICE_INPUT_LINE_1; - InitRunAudioIn(inputDevice, I2S_AUDIOFREQ_16K); - micLine.Draw(mic, TOUCHED_COLOR); - micLine.Redraw(1-mic); + SwitchInputDevice(sw); + micLine.Draw(sw, TOUCHED_COLOR); + micLine.Redraw(1-sw); } runStop.GetTouchedNumber(stop, TOUCHED_COLOR); if (stop == 0) { - if (micLine.GetTouchedNumber(mic, TOUCHED_COLOR)) - { - StopAudioIn(); // Stop sampling - inputDevice = (mic == 0) ? INPUT_DEVICE_DIGITAL_MICROPHONE_2 - : INPUT_DEVICE_INPUT_LINE_1; - InitRunAudioIn(inputDevice, I2S_AUDIOFREQ_16K); - } + if (micLine.GetTouchedNumber(sw, TOUCHED_COLOR)) + SwitchInputDevice(sw); if (audio_in_buffer_captured) {