Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: F746_GUI F746_SAI_IO SD_PlayerSkeleton FrequencyResponseDrawer
GrEqParamsCalculator.hpp
00001 //------------------------------------------------------------------------------ 00002 // Parameters calculator class of buquad unit for graphic equalizer 00003 // グラフィックイコライザで使う biquad フィルタの係数を計算するクラス 00004 // 00005 // 2017/03/28, Copyright (c) 2017 MIKAMI, Naoki 00006 //------------------------------------------------------------------------------ 00007 00008 #ifndef GRAPHIC_EQALIZER_PARAMETER_CALCULATOR_HPP 00009 #define GRAPHIC_EQALIZER_PARAMETER_CALCULATOR_HPP 00010 00011 #include "mbed.h" 00012 #include "BiquadGrEq.hpp" 00013 00014 namespace Mikami 00015 { 00016 class GrEqParams 00017 { 00018 public: 00019 // Constructor 00020 GrEqParams(int bands, float fs) : BANDS_(bands), FS_(fs) {} 00021 00022 // 係数を計算する 00023 // gDb : 利得(dB単位) 00024 BiquadGrEq::Coefs Execute(int band, float f0, float gDb, float qVal) 00025 { 00026 const float PI = 3.1415926536f; 00027 BiquadGrEq::Coefs coefs; 00028 00029 float gSqrt = sqrtf(powf(10, gDb/20.0f)); 00030 float w0 = 2.0f*PI*f0/FS_; 00031 00032 if ( (band != 0) && (band != BANDS_-1) ) // ピーキングフィルタ 00033 { 00034 float alpha = sinf(w0)/(2.0f*qVal); 00035 float beta = 1.0f + alpha/gSqrt; 00036 coefs.a1 = 2.0f*cosf(w0)/beta; 00037 coefs.a2 = -(1.0f - alpha/gSqrt)/beta; 00038 coefs.b0 = (1.0f + alpha*gSqrt)/beta; 00039 coefs.b1 = -coefs.a1; 00040 coefs.b2 = (1.0f - alpha*gSqrt)/beta; 00041 } 00042 else // シェルビングフィルタ 00043 { // Q は固定 00044 w0 = (band == 0) ? w0*1.414f : w0/1.414f; 00045 float alpha = sinf(w0)/sqrtf(2.0f); // Q = 1/sqrt(2) 00046 float g_a = sqrtf(gSqrt); 00047 float cosW0 = cosf(w0); 00048 float gSqrtP1 = gSqrt+1.0f; 00049 float gSqrtM1 = gSqrt-1.0f; 00050 if (band == 0) // ローシェルビング 00051 { 00052 float beta = gSqrtP1 + gSqrtM1*cosW0 00053 + 2.0f*g_a*alpha; 00054 coefs.a1 = 2.0f*(gSqrtM1 + gSqrtP1*cosW0)/beta; 00055 coefs.a2 = -(gSqrtP1 + gSqrtM1*cosW0 00056 - 2.0f*g_a*alpha)/beta; 00057 coefs.b0 = gSqrt*(gSqrtP1 - gSqrtM1*cosW0 00058 + 2.0f*g_a*alpha)/beta; 00059 coefs.b1 = 2.0f*gSqrt*(gSqrtM1 00060 - gSqrtP1*cosW0)/beta; 00061 coefs.b2 = gSqrt*(gSqrtP1 - gSqrtM1*cosW0 00062 - 2.0f*g_a*alpha)/beta; 00063 } 00064 else // ハイシェルビング 00065 { 00066 float beta = gSqrtP1 - gSqrtM1*cosW0 00067 + 2.0f*g_a*alpha; 00068 coefs.a1 = -2.0f*(gSqrtM1 - gSqrtP1*cosW0)/beta; 00069 coefs.a2 = -(gSqrtP1 - gSqrtM1*cosW0 00070 - 2.0f*g_a*alpha)/beta; 00071 coefs.b0 = gSqrt*(gSqrtP1 + gSqrtM1*cosW0 00072 + 2.0f*g_a*alpha)/beta; 00073 coefs.b1 = -2.0f*gSqrt*(gSqrtM1 + gSqrtP1*cosW0)/beta; 00074 coefs.b2 = gSqrt*(gSqrtP1 + gSqrtM1*cosW0 00075 - 2.0f*g_a*alpha)/beta; 00076 } 00077 } 00078 00079 return coefs; 00080 } 00081 00082 private: 00083 const int BANDS_; 00084 const float FS_; 00085 }; 00086 } 00087 #endif // GRAPHIC_EQALIZER_PARAMETER_CALCULATOR_HPP
Generated on Tue Jul 12 2022 22:59:37 by
