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: MyAcousticEffector_MIC/WaveformDisplay.hpp
- Revision:
- 10:56f2f01df983
- Parent:
- 5:7de034938856
--- a/MyAcousticEffector_MIC/WaveformDisplay.hpp Fri Mar 17 01:26:25 2017 +0000 +++ b/MyAcousticEffector_MIC/WaveformDisplay.hpp Mon Apr 10 13:44:13 2017 +0000 @@ -1,13 +1,13 @@ //----------------------------------------------------------- // Class for waveform display // -// 2015/12/15, Copyright (c) 2015 MIKAMI, Naoki +// 2017/04/06, Copyright (c) 2016 MIKAMI, Naoki //----------------------------------------------------------- #ifndef F746_WAVEFORM_DISPLAY_HPP #define F746_WAVEFORM_DISPLAY_HPP -#include "mbed.h" +#include "Array.hpp" namespace Mikami { @@ -16,72 +16,55 @@ public: WaveformDisplay(LCD_DISCO_F746NG &lcd, uint16_t x0, uint16_t y0, int nData, - uint16_t rShift, - uint32_t axisColor, uint32_t lineColor, - uint32_t backColor) - : X0_(x0), Y0_(y0), N_DATA_(nData), R_SHIFT_(rShift), - AXIS_COLOR_(axisColor), LINE_COLOR_(lineColor), - BACK_COLOR_(backColor), lcd_(lcd) { Axis(); } - - void Execute(const int16_t xn[]) + uint16_t rShift) + : X0_(x0), Y0_(y0), R_SHIFT_(rShift), + H1_(Y0_+LIMIT_+1), H2_(Y0_-LIMIT_-1), + lcd_(lcd) { Axis(nData); } + + void Execute(const Array<int16_t> &xn) { - static const uint16_t LIMIT1 = Y0_ + LIMIT2_; - static const uint16_t LIMIT2 = Y0_ - LIMIT2_; - Axis(); + lcd_.SetTextColor(GuiBase::ENUM_BACK); + lcd_.FillRect(X0_, Y0_-LIMIT_-1, + xn.Length(), (LIMIT_+1)*2+1); + Axis(xn.Length()); lcd_.SetTextColor(LINE_COLOR_); uint16_t x1 = X0_; uint16_t y1 = Clip(xn[0]); - for (int n=1; n<N_DATA_; n++) + for (int n=1; n<xn.Length(); n++) { uint16_t x2 = X0_ + n; uint16_t y2 = Clip(xn[n]); - if ( ((y2 == LIMIT1) && (y1 == LIMIT1)) || - ((y2 == LIMIT2) && (y1 == LIMIT2)) ) - { // Out of displaying boundaries - lcd_.SetTextColor(LCD_COLOR_RED); - lcd_.DrawHLine(x1, y1, 1); - lcd_.SetTextColor(LINE_COLOR_); - } - else - lcd_.DrawLine(x1, y1, x2, y2); - if ((y1 == LIMIT1) || (y1 == LIMIT2)) + lcd_.DrawLine(x1, y1, x2, y2); + if ((y1 == H1_) || (y1 == H2_)) lcd_.DrawPixel(x1, y1, LCD_COLOR_RED); x1 = x2; y1 = y2; } - lcd_.SetTextColor(BACK_COLOR_); } - + private: - const uint16_t X0_; - const uint16_t Y0_; - const int N_DATA_; + static const uint16_t LIMIT_ = 32; + static const uint32_t LINE_COLOR_ = LCD_COLOR_CYAN; + const uint16_t X0_, Y0_; const uint16_t R_SHIFT_; - const uint32_t AXIS_COLOR_; - const uint32_t LINE_COLOR_; - const uint32_t BACK_COLOR_; - static const int LIMIT_ = 32; - static const int LIMIT2_ = LIMIT_ + 1; - + const uint16_t H1_, H2_; + LCD_DISCO_F746NG& lcd_; - + // Clipping uint16_t Clip(int16_t xn) { int16_t x = xn >> R_SHIFT_; - if (x > LIMIT_ ) x = LIMIT2_; - if (x < -LIMIT_ ) x = -LIMIT2_ ; + if (x > LIMIT_ ) x = LIMIT_ + 1; + if (x < -LIMIT_ ) x = -(LIMIT_ + 1) ; return Y0_ - x; } - - void Axis() + + void Axis(int nData) { - lcd_.SetTextColor(BACK_COLOR_); - lcd_.FillRect(X0_, Y0_-LIMIT2_, N_DATA_, LIMIT2_*2+1); - - lcd_.SetTextColor(AXIS_COLOR_); - lcd_.DrawLine(X0_-5, Y0_, X0_+N_DATA_+5, Y0_); - } + lcd_.SetTextColor(LCD_COLOR_WHITE); + lcd_.DrawLine(X0_-5, Y0_, X0_+nData+5, Y0_); + } // disallow copy constructor and assignment operator WaveformDisplay(const WaveformDisplay& );