![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Reverb system using single comb filter for ST Nucleo F401RE.
main.cpp@0:e2e604ed785d, 2014-10-31 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Fri Oct 31 07:56:04 2014 +0000
- Revision:
- 0:e2e604ed785d
- Child:
- 2:501cd3d93dd7
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:e2e604ed785d | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:e2e604ed785d | 2 | // Reverb system using comb filter |
MikamiUitOpen | 0:e2e604ed785d | 3 | // 2014/10/31, Copyright (c) 2014 MIKAMI, Naoki |
MikamiUitOpen | 0:e2e604ed785d | 4 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:e2e604ed785d | 5 | |
MikamiUitOpen | 0:e2e604ed785d | 6 | #include "mbed.h" |
MikamiUitOpen | 0:e2e604ed785d | 7 | |
MikamiUitOpen | 0:e2e604ed785d | 8 | #include "ADC_Base.hpp" // for ADC not using interrupt |
MikamiUitOpen | 0:e2e604ed785d | 9 | #include "DAC_MCP4922.hpp" // for DAC MCP4922 |
MikamiUitOpen | 0:e2e604ed785d | 10 | #include "ScfClockTim3.hpp" // for clock supplied to SCF |
MikamiUitOpen | 0:e2e604ed785d | 11 | |
MikamiUitOpen | 0:e2e604ed785d | 12 | using namespace Mikami; |
MikamiUitOpen | 0:e2e604ed785d | 13 | |
MikamiUitOpen | 0:e2e604ed785d | 14 | const int FS_ = 12000; // Sampling frequency: 12 kHz |
MikamiUitOpen | 0:e2e604ed785d | 15 | ADC_Base adc_(A0, FS_); // for AD |
MikamiUitOpen | 0:e2e604ed785d | 16 | DAC_MCP4922 myDac_; // for DA |
MikamiUitOpen | 0:e2e604ed785d | 17 | |
MikamiUitOpen | 0:e2e604ed785d | 18 | const float G_C_ = 0.8f; |
MikamiUitOpen | 0:e2e604ed785d | 19 | const float G0_ = 2.0f*(1.0f - G_C_); |
MikamiUitOpen | 0:e2e604ed785d | 20 | const int M1 = 1153; |
MikamiUitOpen | 0:e2e604ed785d | 21 | float ynD[M1]; |
MikamiUitOpen | 0:e2e604ed785d | 22 | |
MikamiUitOpen | 0:e2e604ed785d | 23 | DigitalIn sw_(D2, PullDown); |
MikamiUitOpen | 0:e2e604ed785d | 24 | |
MikamiUitOpen | 0:e2e604ed785d | 25 | int main() |
MikamiUitOpen | 0:e2e604ed785d | 26 | { |
MikamiUitOpen | 0:e2e604ed785d | 27 | ScfClockTim3(500000); // cutoff frequency: 5 kHz |
MikamiUitOpen | 0:e2e604ed785d | 28 | |
MikamiUitOpen | 0:e2e604ed785d | 29 | for (int n=0; n<M1; n++) ynD[n] = 0.0f; |
MikamiUitOpen | 0:e2e604ed785d | 30 | int nD = 0; |
MikamiUitOpen | 0:e2e604ed785d | 31 | |
MikamiUitOpen | 0:e2e604ed785d | 32 | while (true) |
MikamiUitOpen | 0:e2e604ed785d | 33 | { |
MikamiUitOpen | 0:e2e604ed785d | 34 | float xn = adc_.Read(); // Read from A0 |
MikamiUitOpen | 0:e2e604ed785d | 35 | //----------------------------------------------- |
MikamiUitOpen | 0:e2e604ed785d | 36 | |
MikamiUitOpen | 0:e2e604ed785d | 37 | float yn; |
MikamiUitOpen | 0:e2e604ed785d | 38 | if (sw_.read() == 1) |
MikamiUitOpen | 0:e2e604ed785d | 39 | { |
MikamiUitOpen | 0:e2e604ed785d | 40 | yn = ynD[nD]; |
MikamiUitOpen | 0:e2e604ed785d | 41 | ynD[nD++] = G0_*xn + G_C_*yn; |
MikamiUitOpen | 0:e2e604ed785d | 42 | if (nD >= M1) nD = 0; |
MikamiUitOpen | 0:e2e604ed785d | 43 | } |
MikamiUitOpen | 0:e2e604ed785d | 44 | else |
MikamiUitOpen | 0:e2e604ed785d | 45 | yn = xn; |
MikamiUitOpen | 0:e2e604ed785d | 46 | |
MikamiUitOpen | 0:e2e604ed785d | 47 | //----------------------------------------------- |
MikamiUitOpen | 0:e2e604ed785d | 48 | myDac_.Write(yn); // Write to DAC |
MikamiUitOpen | 0:e2e604ed785d | 49 | } |
MikamiUitOpen | 0:e2e604ed785d | 50 | } |