1 /*
2     Echo.h - Echo Effect
3 
4     Original ZynAddSubFX author Nasca Octavian Paul
5     Copyright (C) 2002-2005 Nasca Octavian Paul
6     Copyright 2009-2011, Alan Calvert
7     Copyright 2018-2019, Will Godfrey
8 
9     This file is part of yoshimi, which is free software: you can redistribute
10     it and/or modify it under the terms of the GNU Library General Public
11     License as published by the Free Software Foundation; either version 2 of
12     the License, or (at your option) any later version.
13 
14     yoshimi is distributed in the hope that it will be useful, but WITHOUT ANY
15     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16     FOR A PARTICULAR PURPOSE.   See the GNU General Public License (version 2 or
17     later) for more details.
18 
19     You should have received a copy of the GNU General Public License along with
20     yoshimi; if not, write to the Free Software Foundation, Inc., 51 Franklin
21     Street, Fifth Floor, Boston, MA  02110-1301, USA.
22 
23     This file is derivative of ZynAddSubFX original code.
24 
25     Modified March 2019
26 */
27 
28 #ifndef ECHO_H
29 #define ECHO_H
30 
31 #include "Effects/Effect.h"
32 
33 // The ratio which, when exceeded, causes the echo effect to update its internal
34 // delay. If not exceeded, the delay remains constant even if the BPM
35 // changes. This is to combat fluctuations in inaccurate BPM sources, such as
36 // ALSA. Must be a number above 1.0f.
37 #define ECHO_INACCURATE_BPM_THRESHOLD 1.02f
38 
39 class SynthEngine;
40 
41 class Echo : public Effect
42 {
43     public:
44         Echo(bool insertion_, float *efxoutl_, float *efxoutr_, SynthEngine *_synth);
45         ~Echo();
46 
47         void out(float *smpsl, float *smpr);
48         void setpreset(unsigned char npreset);
49         void changepar(int npar, unsigned char value);
50         unsigned char getpar(int npar);
51         int getnumparams(void);
52         void cleanup(void);
53         void setdryonly(void);
54 
55     private:
56         // Parameters
57         bool Pchanged;
58         unsigned char Pvolume;  // 1 Volume or Dry/Wetness
59         unsigned char Pdelay;   // 3 Delay of the Echo
60         unsigned char Plrdelay; // 4 L/R delay difference
61         unsigned char Pfb;      // 6 Feedback
62         unsigned char Phidamp;  // 7 Dampening of the Echo
63         bool Pbpm;
64 
65         void setvolume(unsigned char Pvolume_);
66         void setdelay(unsigned char Pdelay_);
67         void setlrdelay(unsigned char Plrdelay_);
68         void setfb(unsigned char Pfb_);
69         void sethidamp(unsigned char Phidamp_);
70 
71         // Real Parameters
72         synth::InterpolatedValue<float> fb, hidamp;
73         int dl, dr, delay, lrdelay;
74 
75         void initdelays(void);
76         float *ldelay;
77         float *rdelay;
78         int maxdelay;
79         float  oldl, oldr; // pt. lpf
80 
81         float prevBeat; // Used to calculate BPM.
82 
83         int realposl, realposr;
84         synth::InterpolatedValue<int> lxfade, rxfade;
85 };
86 
87 class Echolimit
88 {
89     public:
90         float getlimits(CommandBlock *getData);
91 };
92 
93 
94 #endif
95 
96