Demo program of digital signal processing: Variable LPF/HPF, Vocal canceller, Pitch shifter, Reverbrator. ディジタル信号処理のデモプログラム. 遮断周波数可変 LPF/HPF,ボーカルキャンセラ,ピッチシフタ,残響生成器.

Dependencies:   Array_Matrix F446_AD_DA UIT_AQM1602 mbed

Committer:
MikamiUitOpen
Date:
Tue Jan 31 12:52:35 2017 +0000
Revision:
5:503bd366fd73
Parent:
0:fa74b1130cc3
6

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MikamiUitOpen 0:fa74b1130cc3 1 //--------------------------------------------------------------
MikamiUitOpen 0:fa74b1130cc3 2 // Weaver 変調器
MikamiUitOpen 0:fa74b1130cc3 3 // 入力信号の帯域: 0.1 kHz ---- 9.9 kHz
MikamiUitOpen 0:fa74b1130cc3 4 // 帯域中央の周波数: 5.0 kHz
MikamiUitOpen 0:fa74b1130cc3 5 // 低域通過フィルタの遮断周波数: 4.9 kHz
MikamiUitOpen 0:fa74b1130cc3 6
MikamiUitOpen 5:503bd366fd73 7 // 2017/01/31, Copyright (c) 2017 MIKAMI, Naoki
MikamiUitOpen 0:fa74b1130cc3 8 //--------------------------------------------------------------
MikamiUitOpen 0:fa74b1130cc3 9
MikamiUitOpen 0:fa74b1130cc3 10 #ifndef WEAVER_MODULATOR_HPP
MikamiUitOpen 0:fa74b1130cc3 11 #define WEAVER_MODULATOR_HPP
MikamiUitOpen 0:fa74b1130cc3 12
MikamiUitOpen 0:fa74b1130cc3 13 #include "IIR_Cascade.hpp"
MikamiUitOpen 0:fa74b1130cc3 14 #include "Coefficients.hpp" // Coeffisients of LPF and DC-cut filter
MikamiUitOpen 0:fa74b1130cc3 15 #include "Array.hpp"
MikamiUitOpen 0:fa74b1130cc3 16 using namespace Mikami;
MikamiUitOpen 0:fa74b1130cc3 17
MikamiUitOpen 0:fa74b1130cc3 18 class FrqShifter : public SignalProcessing
MikamiUitOpen 0:fa74b1130cc3 19 {
MikamiUitOpen 0:fa74b1130cc3 20 public:
MikamiUitOpen 0:fa74b1130cc3 21 FrqShifter(float fS)
MikamiUitOpen 0:fa74b1130cc3 22 : lpfC_(WEAVER_ORDER_, weaver_g0Lpf_, weaver_ck_),
MikamiUitOpen 0:fa74b1130cc3 23 lpfS_(WEAVER_ORDER_, weaver_g0Lpf_, weaver_ck_),
MikamiUitOpen 0:fa74b1130cc3 24 dcCut_(weaver_c1_),
MikamiUitOpen 5:503bd366fd73 25 FS_(fS), F_B_(5000)
MikamiUitOpen 0:fa74b1130cc3 26 {
MikamiUitOpen 0:fa74b1130cc3 27 lpfC_.Clear();
MikamiUitOpen 0:fa74b1130cc3 28 lpfS_.Clear();
MikamiUitOpen 0:fa74b1130cc3 29
MikamiUitOpen 0:fa74b1130cc3 30 dPhi1_ = F_B_*PI2_/FS_;
MikamiUitOpen 0:fa74b1130cc3 31 dPhi2_ = dPhi1_;
MikamiUitOpen 0:fa74b1130cc3 32 phi1_ = 0;
MikamiUitOpen 0:fa74b1130cc3 33 phi2_ = 0;
MikamiUitOpen 0:fa74b1130cc3 34 }
MikamiUitOpen 5:503bd366fd73 35
MikamiUitOpen 0:fa74b1130cc3 36 virtual float Execute(float xn1, float xn2)
MikamiUitOpen 0:fa74b1130cc3 37 {
MikamiUitOpen 0:fa74b1130cc3 38 float xn = (xn1 + xn2)*0.5f;
MikamiUitOpen 0:fa74b1130cc3 39 xn = dcCut_.Execute(weaver_g0_*xn); // DC 成分除去
MikamiUitOpen 5:503bd366fd73 40
MikamiUitOpen 0:fa74b1130cc3 41 float mpyC = xn*cosf(phi1_);
MikamiUitOpen 0:fa74b1130cc3 42 float mpyS = xn*sinf(phi1_);
MikamiUitOpen 5:503bd366fd73 43
MikamiUitOpen 0:fa74b1130cc3 44 // LPF
MikamiUitOpen 0:fa74b1130cc3 45 float mpyC_Lpf = lpfC_.Execute(mpyC);
MikamiUitOpen 0:fa74b1130cc3 46 float mpyS_Lpf = lpfS_.Execute(mpyS);
MikamiUitOpen 5:503bd366fd73 47
MikamiUitOpen 0:fa74b1130cc3 48 float mpyC_C = mpyC_Lpf*cosf(phi2_);
MikamiUitOpen 0:fa74b1130cc3 49 float mpyS_S = mpyS_Lpf*sinf(phi2_);
MikamiUitOpen 5:503bd366fd73 50
MikamiUitOpen 0:fa74b1130cc3 51 float yn = 2.0f*(mpyC_C + mpyS_S);
MikamiUitOpen 0:fa74b1130cc3 52
MikamiUitOpen 0:fa74b1130cc3 53 phi1_ = phi1_ + dPhi1_;
MikamiUitOpen 0:fa74b1130cc3 54 if (phi1_ > PI2_) phi1_ = phi1_ - PI2_;
MikamiUitOpen 0:fa74b1130cc3 55 phi2_ = phi2_ + dPhi2_;
MikamiUitOpen 0:fa74b1130cc3 56 if (phi2_ > PI2_) phi2_ = phi2_ - PI2_;
MikamiUitOpen 0:fa74b1130cc3 57
MikamiUitOpen 5:503bd366fd73 58 return yn;
MikamiUitOpen 0:fa74b1130cc3 59 }
MikamiUitOpen 5:503bd366fd73 60
MikamiUitOpen 0:fa74b1130cc3 61 // 周波数のシフト量を設定
MikamiUitOpen 0:fa74b1130cc3 62 void SetFrequensy(float fShift)
MikamiUitOpen 0:fa74b1130cc3 63 { dPhi2_ = (fShift + F_B_)*PI2_/FS_; }
MikamiUitOpen 0:fa74b1130cc3 64
MikamiUitOpen 0:fa74b1130cc3 65 private:
MikamiUitOpen 5:503bd366fd73 66 // Weaver 変調器で使う低域通過フィルタ
MikamiUitOpen 0:fa74b1130cc3 67 IirCascade lpfC_;
MikamiUitOpen 0:fa74b1130cc3 68 IirCascade lpfS_;
MikamiUitOpen 0:fa74b1130cc3 69 // 直流分除去フィルタ
MikamiUitOpen 0:fa74b1130cc3 70 Biquad dcCut_;
MikamiUitOpen 5:503bd366fd73 71
MikamiUitOpen 5:503bd366fd73 72 static const float PI2_ = 3.1415926536f*2;
MikamiUitOpen 0:fa74b1130cc3 73 const float FS_;
MikamiUitOpen 0:fa74b1130cc3 74 const float F_B_; // 中心周波数
MikamiUitOpen 5:503bd366fd73 75
MikamiUitOpen 0:fa74b1130cc3 76 float phi1_, dPhi1_;
MikamiUitOpen 0:fa74b1130cc3 77 float phi2_, dPhi2_;
MikamiUitOpen 0:fa74b1130cc3 78 };
MikamiUitOpen 0:fa74b1130cc3 79 #endif // WEAVER_MODULATOR_HPP