revised version of F746_SD_GraphicEqualizer

Dependencies:   BSP_DISCO_F746NG F746_GUI F746_SAI_IO FrequencyResponseDrawer LCD_DISCO_F746NG SDFileSystem_Warning_Fixed TS_DISCO_F746NG mbed

Fork of F746_SD_GraphicEqualizer by 不韋 呂

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DesignerDrawer.cpp Source File

DesignerDrawer.cpp

00001 //------------------------------------------------------------------------------
00002 //  イコライザ用フィルタのパラメータを設定し,その周波数特性を描画するためのクラス
00003 //  
00004 //  2016/05/09, Copyright (c) 2016 MIKAMI, Naoki
00005 //------------------------------------------------------------------------------
00006 
00007 #include "DesignerDrawer.hpp"
00008 
00009 namespace Mikami
00010 {
00011     // Constructor
00012     DesignerDrawer::DesignerDrawer(uint16_t x0, uint16_t y0,
00013                                    int bands, float f0, int fs, float db1)
00014         : lcd_(GuiBase::GetLcdPtr()), ts_(GuiBase::GetTsPtr()),
00015           X0_(x0), Y0_(y0), BANDS_(bands), Q_VAL_(1.0f/sqrtf(2.0f))
00016     {
00017         drawerObj_ = new FrqRespDrawer(x0, 50.0f, 20000.0f, 142,
00018                                        y0, -18, 18, db1, 6, fs);
00019 
00020         calculator_ = new GrEqParams(bands, fs);
00021         f0_ = new float[bands];
00022         for (int n=0; n<bands; n++)
00023             f0_[n] = f0*powf(2, n);
00024 
00025         ck_ = new BiquadGrEq::Coefs[bands];
00026         for (int n=0; n<bands; n++)
00027             ck_[n] = calculator_->Execute(n, f0_[n], 0, Q_VAL_);
00028         frqResp_ = new GrEqualizerFrqResp(bands);
00029         frqResp_->SetParams(ck_);
00030 
00031         // 周波数特性の描画
00032         DrawResponse();
00033     }
00034 
00035     DesignerDrawer::~DesignerDrawer()
00036     {
00037         delete[] frqResp_;
00038         delete[] ck_;
00039         delete[] f0_;
00040         delete calculator_;
00041         delete drawerObj_;
00042     }
00043 
00044     // 周波数特性の描画
00045     void DesignerDrawer::DrawResponse()
00046     {
00047         drawerObj_->DrawAxis();             // 目盛線の描画        
00048         FrqRespDrawer::AxisX_Char numX[] =  // 横軸の目盛値を描画する際に使う構造体の配列
00049             {{   50,  "50"}, {  100, "100"}, {  200, "200"}, {  500, "500"}, { 1000, "1k"},
00050              { 2000,  "2k"}, { 5000,  "5k"}, {10000, "10k"}, {20000, "20k"}};
00051         drawerObj_->DrawNumericX(numX, 9, 6, "Frequency [Hz]"); // 横軸の目盛
00052         drawerObj_->DrawNumericY(-24, -6, 6, "%3d");            // 縦軸の目盛値は 6 dB 間隔
00053         drawerObj_->DrawGraph(frqResp_);    // 周波数特性のカーブの描画
00054     }
00055     
00056     // 周波数特性の平坦化と描画
00057     void DesignerDrawer::DrawFlat()
00058     {
00059         for (int n=0; n<BANDS_; n++)
00060             ck_[n] = calculator_->Execute(n, f0_[n], 0, Q_VAL_);
00061         frqResp_->SetParams(ck_);
00062         drawerObj_->Erase();
00063         drawerObj_->DrawAxis();             // 目盛線の描画
00064         drawerObj_->DrawGraph(frqResp_);    // 周波数特性のグラフのカーブを描画する
00065     }
00066 
00067     // 特定のバンドのイコライザ用フィルタのパラメータの設定と周波数特性の再描画
00068     void DesignerDrawer::DesignAndRedraw(float gainDb, int n)
00069     {
00070         ck_[n] = calculator_->Execute(n, f0_[n],  gainDb, Q_VAL_);
00071         frqResp_->SetParam(ck_[n], n);
00072         drawerObj_->Erase();
00073         drawerObj_->DrawAxis();             // 目盛線の描画
00074         drawerObj_->DrawGraph(frqResp_);    // 周波数特性のグラフのカーブを描画する
00075     }
00076 }