Final version.
Dependencies: F746_GUI F746_SAI_IO UIT_FFT_Real
Fork of F746_Spectrogram by
Diff: main.cpp
- Revision:
- 7:23b60827582d
- Parent:
- 6:b3885567877c
- Child:
- 8:99d57d6e0ea1
--- a/main.cpp Mon Apr 10 13:43:07 2017 +0000 +++ b/main.cpp Wed Aug 16 10:06:28 2017 +0000 @@ -1,9 +1,9 @@ -//------------------------------------------------ -// リアルタイム・スペクトログラム -// 入力: MEMS マイク -// -// 2017/04/10, Copyright (c) 2017 MIKAMI, Naoki -//------------------------------------------------ +/******************************************************** + * Real time spectrogram + * Input: MEMS microphone + * + * Mladen Adamovic, 3326/2016 + ********************************************************/ #include "SAI_InOut.hpp" #include "F746_GUI.hpp" @@ -12,16 +12,16 @@ int main() { - const int FS = AUDIO_FREQUENCY_16K; // 標本化周波数:16 kHz - const int N_FFT = 512; // FFT の点数 - SaiIO mySai(SaiIO::INPUT, N_FFT+1, FS, // 入力用 - INPUT_DEVICE_DIGITAL_MICROPHONE_2); // 入力デバイス:MEMS マイク + const int FS = AUDIO_FREQUENCY_16K; // Sampling frequency: 16 kHz + const int N_FFT = 512; // FFT score + SaiIO mySai(SaiIO::INPUT, N_FFT+1, FS, // Use with force + INPUT_DEVICE_DIGITAL_MICROPHONE_2); // Input device: MEMS microphone - LCD_DISCO_F746NG &lcd = GuiBase::GetLcd(); // LCD 表示器のオブジェクトの参照を取得 + LCD_DISCO_F746NG &lcd = GuiBase::GetLcd(); // Obtain reference of object of LCD display lcd.Clear(GuiBase::ENUM_BACK); Label myLabel1(240, 2, "Real-time spectrogram", Label::CENTER, Font16); - // ButtonGroup の設定 + // Set ButtonGroup const uint16_t B_W = 50; const uint16_t B_Y = 242; const uint16_t B_H = 30; @@ -31,32 +31,32 @@ Button clearButton(430, B_Y, B_W, B_H, "CLEAR"); clearButton.Inactivate(); - // 座標軸 - const uint16_t X0 = 40; // 表示領域の x 座標の原点 - const uint16_t Y0 = 200; // 表示領域の y 座標の原点 - const uint16_t PX_1KHZ = 32; // 1 kHz に対応するピクセル数 - const uint16_t H0 = PX_1KHZ*5; // 周波数軸の長さ(5 kHz に対応)に対応するピクセル数 - const uint16_t W0 = 360; // 横方向の全体の表示の幅(単位:ピクセル) - const float FRAME = (N_FFT/(float)FS)*1000.0f; // 1 フレームに対応する時間(単位:ms) - const uint16_t H_BAR = 2; // 表示する際の 1 フレームに対応する横方向のピクセル数 - const uint16_t MS100 = 100*H_BAR/FRAME; // 100 ms に対応するピクセル数 + // Coordinate axis + const uint16_t X0 = 40; // The origin of the x coordinate of the display area + const uint16_t Y0 = 200; // The origin of the y coordinate of the display area + const uint16_t PX_1KHZ = 32; // Number of pixels corresponding to 1 kHz + const uint16_t H0 = PX_1KHZ*5; // Number of pixels corresponding to the length of the frequency axis (corresponding to 5 kHz) + const uint16_t W0 = 360; // Width in the horizontal direction (unit: pixels) + const float FRAME = (N_FFT/(float)FS)*1000.0f; // Time corresponding to one frame (unit: ms) + const uint16_t H_BAR = 2; // The number of pixels in the horizontal direction corresponding to one frame when displaying + const uint16_t MS100 = 100*H_BAR/FRAME; // Number of pixels corresponding to 100 ms const uint32_t AXIS_COLOR = LCD_COLOR_WHITE; DrawAxis(X0, Y0, W0, H0, AXIS_COLOR, MS100, PX_1KHZ, lcd); - // 色と dB の関係の表示 + // Display of relationship between color and dB ColorDb(Y0, AXIS_COLOR, lcd); - Array<float> sn(N_FFT+1); // スペクトル解析する信号を格納するバッファ - Array<float> db(N_FFT/2+1); // 計算された対数スペクトルを格納するバッファ - // スペクトルの大きさに対応する色データを格納する2次元配列 + Array<float> sn(N_FFT+1); // Buffer for storing signals for spectrum analysis + Array<float> db(N_FFT/2+1); // A buffer storing the calculated log spectrum + // Two-dimensional array that stores color data corresponding to the size of spectrum Matrix<uint32_t> spectra(W0/H_BAR, H0+1, GuiBase::ENUM_BACK); FftAnalyzer fftAnalyzer(N_FFT+1, N_FFT); - // ループ内で使う変数の初期化 + // Initialization of variable used in loop int stop = 0; // 0: run, 1: stop - while(!runStop.Touched(0)) {} // "RUN" をタッチするまで待つ - // データ読み込み開始 + while(!runStop.Touched(0)) {} // Wait till you touch "RUN" + // Start reading data mySai.RecordIn(); while(!mySai.IsCaptured()) {} @@ -68,7 +68,7 @@ clearButton.Inactivate(); if (mySai.IsCaptured()) { - // 1フレーム分の信号の入力 + // Input of signal for one frame for (int n=0; n<mySai.GetLength(); n++) { int16_t xL, xR; @@ -76,9 +76,9 @@ sn[n] = (float)xL; } - // スペクトルの更新 + // Spectrum update SpectrumUpdate(spectra, fftAnalyzer, sn, db); - // スペクトルの表示 + // Display spectrum DisplaySpectrum(spectra, X0, Y0, H_BAR, lcd); } } @@ -87,8 +87,8 @@ clearButton.Activate(); if (clearButton.Touched()) { - spectra.Fill(GuiBase::ENUM_BACK); // スペクトルの表示をクリアするための処理 - DisplaySpectrum(spectra, X0, Y0, H_BAR, lcd); // スペクトルの表示をクリア + spectra.Fill(GuiBase::ENUM_BACK); // Process for clearing the spectrum display + DisplaySpectrum(spectra, X0, Y0, H_BAR, lcd); // Clear spectrum display clearButton.Draw(); } }