2
Copyright (C) 2003 Fons Adriaensen <fons.adriaensen@skynet.be>
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
void Delelm::init (int size, float fb)
29
_line = new float [size];
30
memset (_line, 0, size * sizeof (float));
38
void Delelm::fini (void)
44
void Delelm::set_t60mf (float tmf)
46
_gmf = powf (0.001f, _size / tmf);
50
void Delelm::set_t60lo (float tlo, float wlo)
52
_glo = powf (0.001f, _size / tlo) / _gmf - 1.0f;
57
void Delelm::set_t60hi (float thi, float chi)
61
g = powf (0.001f, _size / thi) / _gmf;
62
t = (1 - g * g) / (2 * g * g * chi);
63
_whi = (sqrt (1 + 4 * t) - 1) / (2 * t);
67
float Delelm::process (float x)
71
t = _line [_i] * _gmf;
72
_slo += _wlo * (t - _slo);
74
_shi += _whi * (t - _shi);
75
t = x - _fb * _shi + 1e-10;
77
if (++_i == _size) _i = 0;
78
return _shi + _fb * t;
82
void Delelm::print (void)
84
printf ("%5d %6.3lf %5.3lf %5.3lf %6.4lf %6.4lf\n",
85
_size, _fb, _glo, _gmf, _wlo, _whi);
89
int Reverb::_sizes [16] =
102
float Reverb::_feedb [16] =
115
void Reverb::init (float rate)
120
_size = (int)(0.15f * rate);
121
_line = new float [_size];
122
memset (_line, 0, _size * sizeof (float));
124
m = (rate < 64e3) ? 1 : 2;
125
for (int i = 0; i < 16; i++) _delm [i].init (m * _sizes [i], _feedb [i]);
126
_x0 = _x1 = _x2 = _x3 = _x4 = _x5 = _x6 = _x7 = _z = 0;
129
set_t60lo (5.0f, 250.0f);
130
set_t60hi (2.0f, 4e3f);
134
void Reverb::fini (void)
137
for (int i = 0; i < 16; i++) _delm [i].fini ();
141
void Reverb::set_delay (float del)
143
if (del < 0.01f) del = 0.01f;
144
_idel = (int)(_rate * del);
145
if (_idel > _size) _idel = _size;
149
void Reverb::set_t60mf (float tmf)
155
for (int i = 0; i < 16; i++) _delm [i].set_t60mf (t);
156
_gain = 1.0f / sqrtf (tmf);
160
void Reverb::set_t60lo (float tlo, float flo)
167
w = 2 * M_PI * flo / _rate;
168
for (int i = 0; i < 16; i++) _delm [i].set_t60lo (t, w);
172
void Reverb::set_t60hi (float thi, float fhi)
179
c = 1 - cosf (2 * M_PI * fhi / _rate);
180
for (int i = 0; i < 16; i++) _delm [i].set_t60hi (t, c);
184
void Reverb::print (void)
186
for (int i = 0; i < 16; i++) _delm [i].print ();
190
void Reverb::process (int n, float gain, float *R, float *W, float *X, float *Y, float *Z)
202
if (j < 0) j += _size;
204
_z += 0.6f * (*R++ - _z) + 1e-10f;
206
if (++i == _size) i = 0;
208
_x0 = _delm [0].process (g * _x0 + x);
209
_x1 = _delm [2].process (g * _x1 + x);
210
_x2 = _delm [4].process (g * _x2 + x);
211
_x3 = _delm [6].process (g * _x3 + x);
212
_x4 = _delm [8].process (g * _x4 + x);
213
_x5 = _delm [10].process (g * _x5 + x);
214
_x6 = _delm [12].process (g * _x6 + x);
215
_x7 = _delm [14].process (g * _x7 + x);
217
t = _x0 - _x1; _x0 += _x1; _x1 = t;
218
t = _x2 - _x3; _x2 += _x3; _x3 = t;
219
t = _x4 - _x5; _x4 += _x5; _x5 = t;
220
t = _x6 - _x7; _x6 += _x7; _x7 = t;
222
t = _x0 - _x2; _x0 += _x2; _x2 = t;
223
t = _x1 - _x3; _x1 += _x3; _x3 = t;
224
t = _x4 - _x6; _x4 += _x6; _x6 = t;
225
t = _x5 - _x7; _x5 += _x7; _x7 = t;
227
t = _x0 - _x4; _x0 += _x4; _x4 = t;
228
t = _x1 - _x5; _x1 += _x5; _x5 = t;
229
t = _x2 - _x6; _x2 += _x6; _x6 = t;
230
t = _x3 - _x7; _x3 += _x7; _x7 = t;
232
*W++ += 1.25f * gain * _x0;
233
*X++ += gain * (_x1 - 0.05f * _x2);
237
_x0 = _delm [1].process (_x0);
238
_x1 = _delm [3].process (_x1);
239
_x2 = _delm [5].process (_x2);
240
_x3 = _delm [7].process (_x3);
241
_x4 = _delm [9].process (_x4);
242
_x5 = _delm [11].process (_x5);
243
_x6 = _delm [13].process (_x6);
244
_x7 = _delm [15].process (_x7);