![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Reverb system using parallel structure of comb filters and cascade structure of allpass filters for ST Nucleo F401RE.
Dependencies: UITDSP_ADDA mbed
main.cpp@5:3568300a78d8, 2015-07-25 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Sat Jul 25 07:22:14 2015 +0000
- Revision:
- 5:3568300a78d8
- Parent:
- 3:c0d8eec43a4e
6
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:72e321f29769 | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 1:51c85e0a6e1e | 2 | // Reverb system using comb filter and allpass filter |
MikamiUitOpen | 5:3568300a78d8 | 3 | // sw number = even : No reverb |
MikamiUitOpen | 5:3568300a78d8 | 4 | // sw number = odd : Reverb |
MikamiUitOpen | 5:3568300a78d8 | 5 | // 2015/07/25, Copyright (c) 2015 MIKAMI, Naoki |
MikamiUitOpen | 0:72e321f29769 | 6 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:72e321f29769 | 7 | |
MikamiUitOpen | 5:3568300a78d8 | 8 | #include "ADC_BuiltIn.hpp" // for ADC not using interrupt |
MikamiUitOpen | 5:3568300a78d8 | 9 | #include "DAC_MCP4921.hpp" // for DAC MCP4921, MCP4922 |
MikamiUitOpen | 0:72e321f29769 | 10 | #include "reverb_unit.hpp" |
MikamiUitOpen | 0:72e321f29769 | 11 | |
MikamiUitOpen | 0:72e321f29769 | 12 | using namespace Mikami; |
MikamiUitOpen | 0:72e321f29769 | 13 | |
MikamiUitOpen | 5:3568300a78d8 | 14 | const int FS_ = 12000; // Sampling frequency: 12 kHz |
MikamiUitOpen | 5:3568300a78d8 | 15 | ADC_BuiltIn adc_(A0, FS_); // for AD |
MikamiUitOpen | 5:3568300a78d8 | 16 | DAC_MCP4921 myDac_; // for DA |
MikamiUitOpen | 0:72e321f29769 | 17 | |
MikamiUitOpen | 0:72e321f29769 | 18 | const float G_C_ = 0.8f; |
MikamiUitOpen | 0:72e321f29769 | 19 | const float G_A_ = 0.6f; |
MikamiUitOpen | 0:72e321f29769 | 20 | const float G0_ = 1.0f - G_C_; |
MikamiUitOpen | 0:72e321f29769 | 21 | CombFilter<887> cm1(G_C_); |
MikamiUitOpen | 0:72e321f29769 | 22 | CombFilter<1153> cm2(G_C_); |
MikamiUitOpen | 0:72e321f29769 | 23 | CombFilter<1499> cm3(G_C_); |
MikamiUitOpen | 0:72e321f29769 | 24 | AllpassFilter<97> ap1(G_A_); |
MikamiUitOpen | 0:72e321f29769 | 25 | AllpassFilter<131> ap2(G_A_); |
MikamiUitOpen | 0:72e321f29769 | 26 | |
MikamiUitOpen | 0:72e321f29769 | 27 | DigitalIn sw_(D2, PullDown); |
MikamiUitOpen | 0:72e321f29769 | 28 | |
MikamiUitOpen | 0:72e321f29769 | 29 | int main() |
MikamiUitOpen | 0:72e321f29769 | 30 | { |
MikamiUitOpen | 3:c0d8eec43a4e | 31 | myDac_.ScfClockTim3(500000); // cutoff frequency: 5 kHz |
MikamiUitOpen | 0:72e321f29769 | 32 | |
MikamiUitOpen | 0:72e321f29769 | 33 | while (true) |
MikamiUitOpen | 0:72e321f29769 | 34 | { |
MikamiUitOpen | 0:72e321f29769 | 35 | float xn = adc_.Read(); // Read from A0 |
MikamiUitOpen | 0:72e321f29769 | 36 | //----------------------------------------------- |
MikamiUitOpen | 0:72e321f29769 | 37 | |
MikamiUitOpen | 0:72e321f29769 | 38 | xn = G0_*xn; |
MikamiUitOpen | 0:72e321f29769 | 39 | // parallel part using comb filters |
MikamiUitOpen | 0:72e321f29769 | 40 | float yn = cm1.Execute(xn) + cm2.Execute(xn) |
MikamiUitOpen | 0:72e321f29769 | 41 | + cm3.Execute(xn); |
MikamiUitOpen | 0:72e321f29769 | 42 | // cascade part using allpass filters |
MikamiUitOpen | 0:72e321f29769 | 43 | yn = ap2.Execute(ap1.Execute(yn)); |
MikamiUitOpen | 0:72e321f29769 | 44 | // add direct input signal |
MikamiUitOpen | 0:72e321f29769 | 45 | yn = yn + xn; |
MikamiUitOpen | 0:72e321f29769 | 46 | |
MikamiUitOpen | 0:72e321f29769 | 47 | if (sw_.read() == 0) yn = xn; // no reverb |
MikamiUitOpen | 0:72e321f29769 | 48 | |
MikamiUitOpen | 0:72e321f29769 | 49 | //----------------------------------------------- |
MikamiUitOpen | 0:72e321f29769 | 50 | myDac_.Write(yn); // Write to DAC |
MikamiUitOpen | 0:72e321f29769 | 51 | } |
MikamiUitOpen | 0:72e321f29769 | 52 | } |