![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Reverb system using single comb filter for ST Nucleo F401RE.
main.cpp@2:501cd3d93dd7, 2014-11-12 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Wed Nov 12 09:45:26 2014 +0000
- Revision:
- 2:501cd3d93dd7
- Parent:
- 0:e2e604ed785d
3
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 | 2:501cd3d93dd7 | 3 | // 2014/11/12, 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 | |
MikamiUitOpen | 0:e2e604ed785d | 11 | using namespace Mikami; |
MikamiUitOpen | 0:e2e604ed785d | 12 | |
MikamiUitOpen | 0:e2e604ed785d | 13 | const int FS_ = 12000; // Sampling frequency: 12 kHz |
MikamiUitOpen | 0:e2e604ed785d | 14 | ADC_Base adc_(A0, FS_); // for AD |
MikamiUitOpen | 0:e2e604ed785d | 15 | DAC_MCP4922 myDac_; // for DA |
MikamiUitOpen | 0:e2e604ed785d | 16 | |
MikamiUitOpen | 0:e2e604ed785d | 17 | const float G_C_ = 0.8f; |
MikamiUitOpen | 0:e2e604ed785d | 18 | const float G0_ = 2.0f*(1.0f - G_C_); |
MikamiUitOpen | 0:e2e604ed785d | 19 | const int M1 = 1153; |
MikamiUitOpen | 0:e2e604ed785d | 20 | float ynD[M1]; |
MikamiUitOpen | 0:e2e604ed785d | 21 | |
MikamiUitOpen | 0:e2e604ed785d | 22 | DigitalIn sw_(D2, PullDown); |
MikamiUitOpen | 0:e2e604ed785d | 23 | |
MikamiUitOpen | 0:e2e604ed785d | 24 | int main() |
MikamiUitOpen | 0:e2e604ed785d | 25 | { |
MikamiUitOpen | 2:501cd3d93dd7 | 26 | myDac_.ScfClockTim3(500000); // cutoff frequency: 5 kHz |
MikamiUitOpen | 0:e2e604ed785d | 27 | |
MikamiUitOpen | 0:e2e604ed785d | 28 | for (int n=0; n<M1; n++) ynD[n] = 0.0f; |
MikamiUitOpen | 0:e2e604ed785d | 29 | int nD = 0; |
MikamiUitOpen | 0:e2e604ed785d | 30 | |
MikamiUitOpen | 0:e2e604ed785d | 31 | while (true) |
MikamiUitOpen | 0:e2e604ed785d | 32 | { |
MikamiUitOpen | 0:e2e604ed785d | 33 | float xn = adc_.Read(); // Read from A0 |
MikamiUitOpen | 0:e2e604ed785d | 34 | //----------------------------------------------- |
MikamiUitOpen | 0:e2e604ed785d | 35 | |
MikamiUitOpen | 0:e2e604ed785d | 36 | float yn; |
MikamiUitOpen | 0:e2e604ed785d | 37 | if (sw_.read() == 1) |
MikamiUitOpen | 0:e2e604ed785d | 38 | { |
MikamiUitOpen | 0:e2e604ed785d | 39 | yn = ynD[nD]; |
MikamiUitOpen | 0:e2e604ed785d | 40 | ynD[nD++] = G0_*xn + G_C_*yn; |
MikamiUitOpen | 0:e2e604ed785d | 41 | if (nD >= M1) nD = 0; |
MikamiUitOpen | 0:e2e604ed785d | 42 | } |
MikamiUitOpen | 0:e2e604ed785d | 43 | else |
MikamiUitOpen | 0:e2e604ed785d | 44 | yn = xn; |
MikamiUitOpen | 0:e2e604ed785d | 45 | |
MikamiUitOpen | 0:e2e604ed785d | 46 | //----------------------------------------------- |
MikamiUitOpen | 0:e2e604ed785d | 47 | myDac_.Write(yn); // Write to DAC |
MikamiUitOpen | 0:e2e604ed785d | 48 | } |
MikamiUitOpen | 0:e2e604ed785d | 49 | } |