Transient Designer: image and text for manual, small change to the UI
[calf.git] / src / organ.cpp
blobb6e15a0c22f71e59d58e88fea65221945220931c
1 /* Calf DSP Library
2 * Example audio modules - organ
4 * Copyright (C) 2001-2007 Krzysztof Foltman
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301 USA
21 #include <config.h>
23 #include <calf/giface.h>
24 #include <calf/organ.h>
25 #include <iostream>
27 using namespace std;
28 using namespace dsp;
29 using namespace calf_plugins;
31 //////////////////////////////////////////////////////////////////////////////////////////////////////////
33 organ_audio_module::organ_audio_module()
34 : drawbar_organ(&par_values)
36 var_map_curve = "2\n0 1\n1 1\n"; // XXXKF hacky bugfix
39 void organ_audio_module::activate()
41 setup(srate);
42 panic_flag = false;
45 void organ_audio_module::post_instantiate(uint32_t)
47 dsp::organ_voice_base::precalculate_waves(progress_report);
51 uint32_t organ_audio_module::process(uint32_t offset, uint32_t nsamples, uint32_t inputs_mask, uint32_t outputs_mask)
53 float *o[2] = { outs[0] + offset, outs[1] + offset };
54 if (panic_flag)
56 control_change(120, 0); // stop all sounds
57 control_change(121, 0); // reset all controllers
58 panic_flag = false;
60 render_separate(o, nsamples);
61 return 3;
64 void organ_audio_module::params_changed() {
65 for (int i = 0; i < param_count; i++)
66 ((float *)&par_values)[i] = *params[i];
68 unsigned int old_poly = polyphony_limit;
69 polyphony_limit = dsp::clip(dsp::fastf2i_drm(*params[par_polyphony]), 1, 32);
70 if (polyphony_limit < old_poly)
71 trim_voices();
72 redraw = true;
73 update_params();
75 bool organ_audio_module::get_layers(int index, int generation, unsigned int &layers) const
77 layers = LG_REALTIME_GRAPH;
78 return true;
80 bool organ_audio_module::get_graph(int index, int subindex, int phase, float *data, int points, cairo_iface *context, int *mode) const
82 if (index != par_master or subindex or !phase)
83 return false;
85 organ_voice_base::precalculate_waves(progress_report);
86 float *waveforms[9];
87 int S[9], S2[9];
88 enum { small_waves = organ_voice_base::wave_count_small};
89 for (int i = 0; i < 9; i++)
91 int wave = dsp::clip((int)(parameters->waveforms[i]), 0, (int)organ_voice_base::wave_count - 1);
92 if (wave >= small_waves)
94 waveforms[i] = organ_voice_base::get_big_wave(wave - small_waves).original;
95 S[i] = ORGAN_BIG_WAVE_SIZE;
96 S2[i] = ORGAN_WAVE_SIZE / 64;
98 else
100 waveforms[i] = organ_voice_base::get_wave(wave).original;
101 S[i] = S2[i] = ORGAN_WAVE_SIZE;
104 for (int i = 0; i < points; i++)
106 float sum = 0.f;
107 for (int j = 0; j < 9; j++)
109 float shift = parameters->phase[j] * S[j] / 360.0;
110 sum += parameters->drawbars[j] * waveforms[j][int(parameters->harmonics[j] * i * S2[j] / points + shift) & (S[j] - 1)];
112 data[i] = sum * 2 / (9 * 8);
114 return true;
118 uint32_t organ_audio_module::message_run(const void *valid_inputs, void *output_ports)
120 // silence a default printf (which is kind of a warning about unhandled message_run)
121 return 0;
125 ////////////////////////////////////////////////////////////////////////////
127 organ_voice_base::small_wave_family (*organ_voice_base::waves)[organ_voice_base::wave_count_small];
128 organ_voice_base::big_wave_family (*organ_voice_base::big_waves)[organ_voice_base::wave_count_big];
130 static void smoothen(bandlimiter<ORGAN_WAVE_BITS> &bl, float tmp[ORGAN_WAVE_SIZE])
132 bl.compute_spectrum(tmp);
133 for (int i = 1; i <= ORGAN_WAVE_SIZE / 2; i++) {
134 bl.spectrum[i] *= 1.0 / sqrt(i);
135 bl.spectrum[ORGAN_WAVE_SIZE - i] *= 1.0 / sqrt(i);
137 bl.compute_waveform(tmp);
138 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
141 static void phaseshift(bandlimiter<ORGAN_WAVE_BITS> &bl, float tmp[ORGAN_WAVE_SIZE])
143 bl.compute_spectrum(tmp);
144 for (int i = 1; i <= ORGAN_WAVE_SIZE / 2; i++) {
145 float frac = i * 2.0 / ORGAN_WAVE_SIZE;
146 float phase = M_PI / sqrt(frac) ;
147 complex<float> shift = complex<float>(cos(phase), sin(phase));
148 bl.spectrum[i] *= shift;
149 bl.spectrum[ORGAN_WAVE_SIZE - i] *= conj(shift);
151 bl.compute_waveform(tmp);
152 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
155 static void padsynth(bandlimiter<ORGAN_WAVE_BITS> blSrc, bandlimiter<ORGAN_BIG_WAVE_BITS> &blDest, organ_voice_base::big_wave_family &result, int bwscale = 20, float bell_factor = 0, bool foldover = false)
157 // kept in a vector to avoid putting large arrays on stack
158 vector<complex<float> >orig_spectrum;
159 orig_spectrum.resize(ORGAN_WAVE_SIZE / 2);
160 for (int i = 0; i < ORGAN_WAVE_SIZE / 2; i++)
162 orig_spectrum[i] = blSrc.spectrum[i];
163 // printf("@%d = %f\n", i, abs(orig_spectrum[i]));
166 int periods = (1 << ORGAN_BIG_WAVE_SHIFT) * ORGAN_BIG_WAVE_SIZE / ORGAN_WAVE_SIZE;
167 for (int i = 0; i <= ORGAN_BIG_WAVE_SIZE / 2; i++) {
168 blDest.spectrum[i] = 0;
170 int MAXHARM = (ORGAN_WAVE_SIZE >> (1 + ORGAN_BIG_WAVE_SHIFT));
171 for (int i = 1; i <= MAXHARM; i++) {
172 //float esc = 0.25 * (1 + 0.5 * log(i));
173 float esc = 0.5;
174 float amp = abs(blSrc.spectrum[i]);
175 // fade out starting from half
176 if (i >= MAXHARM / 2) {
177 float pos = (i - MAXHARM/2) * 1.0 / (MAXHARM / 2);
178 amp *= 1.0 - pos;
179 amp *= 1.0 - pos;
181 int bw = 1 + 20 * i;
182 float sum = 1;
183 int delta = 1;
184 if (bw > 20) delta = bw / 20;
185 for (int j = delta; j <= bw; j+=delta)
187 float p = j * 1.0 / bw;
188 sum += 2 * exp(-p * p * esc);
190 if (sum < 0.0001)
191 continue;
192 amp *= (ORGAN_BIG_WAVE_SIZE / ORGAN_WAVE_SIZE);
193 amp /= sum;
194 int orig = i * periods + bell_factor * cos(i);
195 if (orig > 0 && orig < ORGAN_BIG_WAVE_SIZE / 2)
196 blDest.spectrum[orig] += amp;
197 for (int j = delta; j <= bw; j += delta)
199 float p = j * 1.0 / bw;
200 float val = amp * exp(-p * p * esc);
201 int dist = j * bwscale / 40;
202 int pos = orig + dist;
203 if (pos < 1 || pos >= ORGAN_BIG_WAVE_SIZE / 2)
204 continue;
205 int pos2 = orig - dist;
206 if (pos2 < 1 || pos2 >= ORGAN_BIG_WAVE_SIZE / 2)
207 continue;
208 blDest.spectrum[pos] += val;
209 if (j)
210 blDest.spectrum[pos2] += val;
213 for (int i = 1; i <= ORGAN_BIG_WAVE_SIZE / 2; i++) {
214 float phase = M_PI * 2 * (rand() & 255) / 256;
215 complex<float> shift = complex<float>(cos(phase), sin(phase));
216 blDest.spectrum[i] *= shift;
217 // printf("@%d = %f\n", i, abs(blDest.spectrum[i]));
219 blDest.spectrum[ORGAN_BIG_WAVE_SIZE - i] = conj(blDest.spectrum[i]);
221 // same as above - put large array on heap to avoid stack overflow in ingen
222 vector<float> tmp;
223 tmp.resize(ORGAN_BIG_WAVE_SIZE);
224 float *ptmp = &tmp.front();
225 blDest.compute_waveform(ptmp);
226 normalize_waveform(ptmp, ORGAN_BIG_WAVE_SIZE);
227 blDest.compute_spectrum(ptmp);
229 // limit is 1/2 of the number of harmonics of the original wave
230 result.make_from_spectrum(blDest, foldover, ORGAN_WAVE_SIZE >> (1 + ORGAN_BIG_WAVE_SHIFT));
231 memcpy(result.original, result.begin()->second, sizeof(result.original));
232 #if 0
233 blDest.compute_waveform(result);
234 normalize_waveform(result, ORGAN_BIG_WAVE_SIZE);
235 result[ORGAN_BIG_WAVE_SIZE] = result[0];
236 for (int i =0 ; i<ORGAN_BIG_WAVE_SIZE + 1; i++)
237 printf("%f\n", result[i]);
238 #endif
241 #define LARGE_WAVEFORM_PROGRESS() do { if (reporter) { progress += 100; reporter->report_progress(floor(progress / totalwaves), "Precalculating large waveforms"); } } while(0)
243 void organ_voice_base::update_pitch()
245 float phase = dsp::midi_note_to_phase(note, 100 * parameters->global_transpose + parameters->global_detune, sample_rate_ref);
246 dpphase.set((long int) (phase * parameters->percussion_harmonic * parameters->pitch_bend));
247 moddphase.set((long int) (phase * parameters->percussion_fm_harmonic * parameters->pitch_bend));
250 void organ_voice_base::precalculate_waves(progress_report_iface *reporter)
252 static bool inited = false;
253 if (!inited)
255 static organ_voice_base::small_wave_family waves[organ_voice_base::wave_count_small];
256 static organ_voice_base::big_wave_family big_waves[organ_voice_base::wave_count_big];
257 organ_voice_base::waves = &waves;
258 organ_voice_base::big_waves = &big_waves;
260 float progress = 0.0;
261 int totalwaves = 1 + wave_count_big;
262 if (reporter)
263 reporter->report_progress(0, "Precalculating small waveforms");
264 float tmp[ORGAN_WAVE_SIZE];
265 static bandlimiter<ORGAN_WAVE_BITS> bl;
266 static bandlimiter<ORGAN_BIG_WAVE_BITS> blBig;
267 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
268 tmp[i] = sin(i * 2 * M_PI / ORGAN_WAVE_SIZE);
269 waves[wave_sine].make(bl, tmp);
270 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
271 tmp[i] = (i < (ORGAN_WAVE_SIZE / 16)) ? 1 : 0;
272 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
273 waves[wave_pulse].make(bl, tmp);
274 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
275 tmp[i] = i < (ORGAN_WAVE_SIZE / 2) ? sin(i * 2 * 2 * M_PI / ORGAN_WAVE_SIZE) : 0;
276 waves[wave_sinepl1].make(bl, tmp);
277 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
278 tmp[i] = i < (ORGAN_WAVE_SIZE / 3) ? sin(i * 3 * 2 * M_PI / ORGAN_WAVE_SIZE) : 0;
279 waves[wave_sinepl2].make(bl, tmp);
280 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
281 tmp[i] = i < (ORGAN_WAVE_SIZE / 4) ? sin(i * 4 * 2 * M_PI / ORGAN_WAVE_SIZE) : 0;
282 waves[wave_sinepl3].make(bl, tmp);
283 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
284 tmp[i] = (i < (ORGAN_WAVE_SIZE / 2)) ? 1 : -1;
285 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
286 waves[wave_sqr].make(bl, tmp);
287 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
288 tmp[i] = -1 + (i * 2.0 / ORGAN_WAVE_SIZE);
289 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
290 waves[wave_saw].make(bl, tmp);
292 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
293 tmp[i] = (i < (ORGAN_WAVE_SIZE / 2)) ? 1 : -1;
294 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
295 smoothen(bl, tmp);
296 waves[wave_ssqr].make(bl, tmp);
298 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
299 tmp[i] = -1 + (i * 2.0 / ORGAN_WAVE_SIZE);
300 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
301 smoothen(bl, tmp);
302 waves[wave_ssaw].make(bl, tmp);
304 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
305 tmp[i] = (i < (ORGAN_WAVE_SIZE / 16)) ? 1 : 0;
306 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
307 smoothen(bl, tmp);
308 waves[wave_spls].make(bl, tmp);
309 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
310 tmp[i] = i < (ORGAN_WAVE_SIZE / 1.5) ? sin(i * 1.5 * 2 * M_PI / ORGAN_WAVE_SIZE) : 0;
311 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
312 waves[wave_sinepl05].make(bl, tmp);
313 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
314 tmp[i] = i < (ORGAN_WAVE_SIZE / 1.5) ? (i < ORGAN_WAVE_SIZE / 3 ? -1 : +1) : 0;
315 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
316 waves[wave_sqr05].make(bl, tmp);
317 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
318 tmp[i] = sin(i * M_PI / ORGAN_WAVE_SIZE);
319 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
320 waves[wave_halfsin].make(bl, tmp);
321 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
322 tmp[i] = sin(i * 3 * M_PI / ORGAN_WAVE_SIZE);
323 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
324 waves[wave_clvg].make(bl, tmp);
325 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
327 float ph = i * 2 * M_PI / ORGAN_WAVE_SIZE;
328 float fm = 0.3 * sin(6*ph) + 0.2 * sin(11*ph) + 0.2 * cos(17*ph) - 0.2 * cos(19*ph);
329 tmp[i] = sin(5*ph + fm) + 0.7 * cos(7*ph - fm);
331 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
332 waves[wave_bell].make(bl, tmp, true);
333 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
335 float ph = i * 2 * M_PI / ORGAN_WAVE_SIZE;
336 float fm = 0.3 * sin(3*ph) + 0.3 * sin(11*ph) + 0.3 * cos(17*ph) - 0.3 * cos(19*ph) + 0.3 * cos(25*ph) - 0.3 * cos(31*ph) + 0.3 * cos(37*ph);
337 tmp[i] = sin(3*ph + fm) + cos(7*ph - fm);
339 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
340 waves[wave_bell2].make(bl, tmp, true);
341 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
343 float ph = i * 2 * M_PI / ORGAN_WAVE_SIZE;
344 float fm = 0.5 * sin(3*ph) + 0.3 * sin(5*ph) + 0.3 * cos(6*ph) - 0.3 * cos(9*ph);
345 tmp[i] = sin(4*ph + fm) + cos(ph - fm);
347 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
348 waves[wave_w1].make(bl, tmp);
349 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
351 float ph = i * 2 * M_PI / ORGAN_WAVE_SIZE;
352 tmp[i] = sin(ph) * sin(2 * ph) * sin(4 * ph) * sin(8 * ph);
354 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
355 waves[wave_w2].make(bl, tmp);
356 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
358 float ph = i * 2 * M_PI / ORGAN_WAVE_SIZE;
359 tmp[i] = sin(ph) * sin(3 * ph) * sin(5 * ph) * sin(7 * ph) * sin(9 * ph);
361 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
362 waves[wave_w3].make(bl, tmp);
363 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
365 float ph = i * 2 * M_PI / ORGAN_WAVE_SIZE;
366 tmp[i] = sin(ph + 2 * sin(ph + 2 * sin(ph)));
368 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
369 waves[wave_w4].make(bl, tmp);
370 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
372 float ph = i * 2 * M_PI / ORGAN_WAVE_SIZE;
373 tmp[i] = ph * sin(ph);
375 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
376 waves[wave_w5].make(bl, tmp);
377 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
379 float ph = i * 2 * M_PI / ORGAN_WAVE_SIZE;
380 tmp[i] = ph * sin(ph) + (2 * M_PI - ph) * sin(2 * ph);
382 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
383 waves[wave_w6].make(bl, tmp);
384 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
386 float ph = i * 1.0 / ORGAN_WAVE_SIZE;
387 tmp[i] = exp(-ph * ph);
389 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
390 waves[wave_w7].make(bl, tmp);
391 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
393 float ph = i * 1.0 / ORGAN_WAVE_SIZE;
394 tmp[i] = exp(-ph * sin(2 * M_PI * ph));
396 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
397 waves[wave_w8].make(bl, tmp);
398 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
400 float ph = i * 1.0 / ORGAN_WAVE_SIZE;
401 tmp[i] = sin(2 * M_PI * ph * ph);
403 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
404 waves[wave_w9].make(bl, tmp);
406 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
407 tmp[i] = -1 + (i * 2.0 / ORGAN_WAVE_SIZE);
408 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
409 phaseshift(bl, tmp);
410 waves[wave_dsaw].make(bl, tmp);
412 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
413 tmp[i] = (i < (ORGAN_WAVE_SIZE / 2)) ? 1 : -1;
414 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
415 phaseshift(bl, tmp);
416 waves[wave_dsqr].make(bl, tmp);
418 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
419 tmp[i] = (i < (ORGAN_WAVE_SIZE / 16)) ? 1 : 0;
420 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
421 phaseshift(bl, tmp);
422 waves[wave_dpls].make(bl, tmp);
424 LARGE_WAVEFORM_PROGRESS();
425 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
426 tmp[i] = -1 + (i * 2.0 / ORGAN_WAVE_SIZE);
427 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
428 bl.compute_spectrum(tmp);
429 padsynth(bl, blBig, big_waves[wave_strings - wave_count_small], 15);
431 LARGE_WAVEFORM_PROGRESS();
432 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
433 tmp[i] = -1 + (i * 2.0 / ORGAN_WAVE_SIZE);
434 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
435 bl.compute_spectrum(tmp);
436 padsynth(bl, blBig, big_waves[wave_strings2 - wave_count_small], 40);
438 LARGE_WAVEFORM_PROGRESS();
439 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
440 tmp[i] = sin(i * 2 * M_PI / ORGAN_WAVE_SIZE);
441 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
442 bl.compute_spectrum(tmp);
443 padsynth(bl, blBig, big_waves[wave_sinepad - wave_count_small], 20);
445 LARGE_WAVEFORM_PROGRESS();
446 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
448 float ph = i * 2 * M_PI / ORGAN_WAVE_SIZE;
449 float fm = 0.3 * sin(6*ph) + 0.2 * sin(11*ph) + 0.2 * cos(17*ph) - 0.2 * cos(19*ph);
450 tmp[i] = sin(5*ph + fm) + 0.7 * cos(7*ph - fm);
452 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
453 bl.compute_spectrum(tmp);
454 padsynth(bl, blBig, big_waves[wave_bellpad - wave_count_small], 30, 30, true);
456 LARGE_WAVEFORM_PROGRESS();
457 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
459 float ph = i * 2 * M_PI / ORGAN_WAVE_SIZE;
460 float fm = 0.3 * sin(3*ph) + 0.2 * sin(4*ph) + 0.2 * cos(5*ph) - 0.2 * cos(6*ph);
461 tmp[i] = sin(2*ph + fm) + 0.7 * cos(3*ph - fm);
463 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
464 bl.compute_spectrum(tmp);
465 padsynth(bl, blBig, big_waves[wave_space - wave_count_small], 30, 30);
467 LARGE_WAVEFORM_PROGRESS();
468 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
470 float ph = i * 2 * M_PI / ORGAN_WAVE_SIZE;
471 float fm = 0.5 * sin(ph) + 0.5 * sin(2*ph) + 0.5 * sin(3*ph);
472 tmp[i] = sin(ph + fm) + 0.5 * cos(7*ph - 2 * fm) + 0.25 * cos(13*ph - 4 * fm);
474 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
475 bl.compute_spectrum(tmp);
476 padsynth(bl, blBig, big_waves[wave_choir - wave_count_small], 50, 10);
478 LARGE_WAVEFORM_PROGRESS();
479 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
481 float ph = i * 2 * M_PI / ORGAN_WAVE_SIZE;
482 float fm = sin(ph) ;
483 tmp[i] = sin(ph + fm) + 0.25 * cos(11*ph - 2 * fm) + 0.125 * cos(23*ph - 2 * fm) + 0.0625 * cos(49*ph - 2 * fm);
485 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
486 bl.compute_spectrum(tmp);
487 padsynth(bl, blBig, big_waves[wave_choir2 - wave_count_small], 50, 10);
489 LARGE_WAVEFORM_PROGRESS();
490 for (int i = 0; i < ORGAN_WAVE_SIZE; i++)
492 float ph = i * 2 * M_PI / ORGAN_WAVE_SIZE;
493 float fm = sin(ph) ;
494 tmp[i] = sin(ph + 4 * fm) + 0.5 * sin(2 * ph + 4 * ph);
496 normalize_waveform(tmp, ORGAN_WAVE_SIZE);
497 bl.compute_spectrum(tmp);
498 padsynth(bl, blBig, big_waves[wave_choir3 - wave_count_small], 50, 10);
499 LARGE_WAVEFORM_PROGRESS();
501 inited = true;
505 organ_voice_base::organ_voice_base(organ_parameters *_parameters, int &_sample_rate_ref, bool &_released_ref)
506 : parameters(_parameters)
507 , sample_rate_ref(_sample_rate_ref)
508 , released_ref(_released_ref)
510 note = -1;
513 void organ_voice_base::render_percussion_to(float (*buf)[2], int nsamples)
515 if (note == -1)
516 return;
518 if (!pamp.get_active())
519 return;
520 if (parameters->percussion_level < small_value<float>())
521 return;
522 float level = parameters->percussion_level * 9;
523 static float zeros[ORGAN_WAVE_SIZE];
524 // XXXKF the decay needs work!
525 double age_const = parameters->perc_decay_const;
526 double fm_age_const = parameters->perc_fm_decay_const;
527 int timbre = parameters->get_percussion_wave();
528 if (timbre < 0 || timbre >= wave_count_small)
529 return;
530 int timbre2 = parameters->get_percussion_fm_wave();
531 if (timbre2 < 0 || timbre2 >= wave_count_small)
532 timbre2 = wave_sine;
533 float *fmdata = (*waves)[timbre2].get_level(moddphase.get());
534 if (!fmdata)
535 fmdata = zeros;
536 float *data = (*waves)[timbre].get_level(dpphase.get());
537 if (!data) {
538 pamp.deactivate();
539 return;
541 float s = parameters->percussion_stereo * ORGAN_WAVE_SIZE * (0.5 / 360.0);
542 for (int i = 0; i < nsamples; i++) {
543 float fm = wave(fmdata, modphase);
544 fm *= ORGAN_WAVE_SIZE * parameters->percussion_fm_depth * fm_amp.get();
545 modphase += moddphase;
546 fm_amp.age_exp(fm_age_const, 1.0 / 32768.0);
548 float lamp = level * pamp.get();
549 buf[i][0] += lamp * wave(data, pphase + dsp::fixed_point<int64_t, 52>(fm - s));
550 buf[i][1] += lamp * wave(data, pphase + dsp::fixed_point<int64_t, 52>(fm + s));
551 if (released_ref)
552 pamp.age_lin(rel_age_const,0.0);
553 else
554 pamp.age_exp(age_const, 1.0 / 32768.0);
555 pphase += dpphase;
559 void organ_voice_base::perc_reset()
561 pphase = 0;
562 modphase = 0;
563 dpphase = 0;
564 moddphase = 0;
565 note = -1;
568 //////////////////////////////////////////////////////////////////////////////////////////////////////
570 void organ_vibrato::reset()
572 for (int i = 0; i < VibratoSize; i++)
573 vibrato_x1[i][0] = vibrato_y1[i][0] = vibrato_x1[i][1] = vibrato_y1[i][1] = 0.f;
574 vibrato[0].a0 = vibrato[1].a0 = 0;
575 lfo_phase = 0.f;
578 void organ_vibrato::process(organ_parameters *parameters, float (*data)[2], unsigned int len, float sample_rate)
580 float lfo1 = lfo_phase < 0.5 ? 2 * lfo_phase : 2 - 2 * lfo_phase;
581 float lfo_phase2 = lfo_phase + parameters->lfo_phase * (1.0 / 360.0);
582 if (lfo_phase2 >= 1.0)
583 lfo_phase2 -= 1.0;
584 float lfo2 = lfo_phase2 < 0.5 ? 2 * lfo_phase2 : 2 - 2 * lfo_phase2;
585 lfo_phase += parameters->lfo_rate * len / sample_rate;
586 if (lfo_phase >= 1.0)
587 lfo_phase -= 1.0;
588 if (!len)
589 return;
590 float olda0[2] = {vibrato[0].a0, vibrato[1].a0};
591 vibrato[0].set_ap(3000 + 7000 * parameters->lfo_amt * lfo1 * lfo1, sample_rate);
592 vibrato[1].set_ap(3000 + 7000 * parameters->lfo_amt * lfo2 * lfo2, sample_rate);
593 float ilen = 1.0 / len;
594 float deltaa0[2] = {(vibrato[0].a0 - olda0[0])*ilen, (vibrato[1].a0 - olda0[1])*ilen};
596 float vib_wet = parameters->lfo_wet;
597 for (int c = 0; c < 2; c++)
599 for (unsigned int i = 0; i < len; i++)
601 float v = data[i][c];
602 float v0 = v;
603 float coeff = olda0[c] + deltaa0[c] * i;
604 for (int t = 0; t < VibratoSize; t++)
605 v = vibrato[c].process_ap(v, vibrato_x1[t][c], vibrato_y1[t][c], coeff);
607 data[i][c] += (v - v0) * vib_wet;
609 for (int t = 0; t < VibratoSize; t++)
611 sanitize(vibrato_x1[t][c]);
612 sanitize(vibrato_y1[t][c]);
617 void scanner_vibrato::reset()
619 legacy.reset();
620 for (int i = 0; i < ScannerSize; i++)
621 scanner[i].reset();
622 lfo_phase = 0.f;
625 void scanner_vibrato::process(organ_parameters *parameters, float (*data)[2], unsigned int len, float sample_rate)
627 if (!len)
628 return;
630 int vtype = (int)parameters->lfo_type;
631 if (!vtype || vtype > organ_enums::lfotype_cvfull)
633 legacy.process(parameters, data, len, sample_rate);
634 return;
637 // I bet the original components of the line box had some tolerance,
638 // hence two different values of cutoff frequency
639 scanner[0].set_lp_rbj(4000, 0.707, sample_rate);
640 scanner[1].set_lp_rbj(4200, 0.707, sample_rate);
641 for (int t = 2; t < ScannerSize; t ++)
643 scanner[t].copy_coeffs(scanner[t & 1]);
646 float lfo_phase2 = lfo_phase + parameters->lfo_phase * (1.0 / 360.0);
647 if (lfo_phase2 >= 1.0)
648 lfo_phase2 -= 1.0;
649 float vib_wet = parameters->lfo_wet;
650 float dphase = parameters->lfo_rate / sample_rate;
651 static const int v1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8 };
652 static const int v2[] = { 0, 1, 2, 4, 6, 8, 9, 10, 12 };
653 static const int v3[] = { 0, 1, 3, 6, 11, 12, 15, 17, 18, 18, 18 };
654 static const int vfull[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 18 };
655 static const int *vtypes[] = { NULL, v1, v2, v3, vfull };
656 const int *vib = vtypes[vtype];
658 float vibamt = 8 * parameters->lfo_amt;
659 if (vtype == organ_enums::lfotype_cvfull)
660 vibamt = 17 * parameters->lfo_amt;
661 for (unsigned int i = 0; i < len; i++)
663 float line[ScannerSize + 1];
664 float v0 = (data[i][0] + data[i][1]) * 0.5;
666 line[0] = v0;
667 for (int t = 0; t < ScannerSize; t++)
668 line[t + 1] = scanner[t].process(line[t]) * 1.03;
670 float lfo1 = lfo_phase < 0.5 ? 2 * lfo_phase : 2 - 2 * lfo_phase;
671 float lfo2 = lfo_phase2 < 0.5 ? 2 * lfo_phase2 : 2 - 2 * lfo_phase2;
673 float pos = vibamt * lfo1;
674 int ipos = (int)pos;
675 float vl = lerp(line[vib[ipos]], line[vib[ipos + 1]], pos - ipos);
677 pos = vibamt * lfo2;
678 ipos = (int)pos;
679 float vr = lerp(line[vib[ipos]], line[vib[ipos + 1]], pos - ipos);
681 lfo_phase += dphase;
682 if (lfo_phase >= 1.0)
683 lfo_phase -= 1.0;
684 lfo_phase2 += dphase;
685 if (lfo_phase2 >= 1.0)
686 lfo_phase2 -= 1.0;
688 data[i][0] += (vl - v0) * vib_wet;
689 data[i][1] += (vr - v0) * vib_wet;
691 for (int t = 0; t < ScannerSize; t++)
693 scanner[t].sanitize();
696 //////////////////////////////////////////////////////////////////////////////////////////////////////
698 void organ_voice::update_pitch()
700 organ_voice_base::update_pitch();
701 dphase.set(dsp::midi_note_to_phase(note, 100 * parameters->global_transpose + parameters->global_detune, sample_rate) * inertia_pitchbend.get_last());
704 void organ_voice::render_block(int snapshot) {
705 if (note == -1)
706 return;
708 dsp::zero(&output_buffer[0][0], Channels * BlockSize);
709 dsp::zero(&aux_buffers[1][0][0], 2 * Channels * BlockSize);
710 if (!amp.get_active())
712 if (use_percussion())
713 render_percussion_to(output_buffer, BlockSize);
714 return;
717 inertia_pitchbend.set_inertia(parameters->pitch_bend);
718 inertia_pitchbend.step();
719 update_pitch();
720 dsp::fixed_point<int, 20> tphase, tdphase;
721 unsigned int foldvalue = parameters->foldvalue * inertia_pitchbend.get_last();
722 int vibrato_mode = fastf2i_drm(parameters->lfo_mode);
723 for (int h = 0; h < 9; h++)
725 float amp = parameters->drawbars[h];
726 if (amp < small_value<float>())
727 continue;
728 float *data;
729 dsp::fixed_point<int, 24> hm = dsp::fixed_point<int, 24>(parameters->multiplier[h]);
730 int waveid = (int)parameters->waveforms[h];
731 if (waveid < 0 || waveid >= wave_count)
732 waveid = 0;
734 uint32_t rate = (dphase * hm).get();
735 if (waveid >= wave_count_small)
737 data = (*big_waves)[waveid - wave_count_small].get_level(rate >> (ORGAN_BIG_WAVE_BITS - ORGAN_WAVE_BITS + ORGAN_BIG_WAVE_SHIFT));
738 if (!data)
739 continue;
740 hm.set(hm.get() >> ORGAN_BIG_WAVE_SHIFT);
741 dsp::fixed_point<int64_t, 20> tphase, tdphase;
742 tphase.set(((phase * hm).get()) + parameters->phaseshift[h]);
743 tdphase.set(rate >> ORGAN_BIG_WAVE_SHIFT);
744 float ampl = amp * 0.5f * (1 - parameters->pan[h]);
745 float ampr = amp * 0.5f * (1 + parameters->pan[h]);
746 float (*out)[Channels] = aux_buffers[dsp::fastf2i_drm(parameters->routing[h])];
748 for (int i=0; i < (int)BlockSize; i++) {
749 float wv = big_wave(data, tphase);
750 out[i][0] += wv * ampl;
751 out[i][1] += wv * ampr;
752 tphase += tdphase;
755 else
757 unsigned int foldback = 0;
758 while (rate > foldvalue)
760 rate >>= 1;
761 foldback++;
763 hm.set(hm.get() >> foldback);
764 data = (*waves)[waveid].get_level(rate);
765 if (!data)
766 continue;
767 tphase.set((uint32_t)((phase * hm).get()) + parameters->phaseshift[h]);
768 tdphase.set((uint32_t)rate);
769 float ampl = amp * 0.5f * (1 - parameters->pan[h]);
770 float ampr = amp * 0.5f * (1 + parameters->pan[h]);
771 float (*out)[Channels] = aux_buffers[dsp::fastf2i_drm(parameters->routing[h])];
773 for (int i=0; i < (int)BlockSize; i++) {
774 float wv = wave(data, tphase);
775 out[i][0] += wv * ampl;
776 out[i][1] += wv * ampr;
777 tphase += tdphase;
782 bool is_quad = parameters->quad_env >= 0.5f;
784 expression.set_inertia(parameters->cutoff);
785 phase += dphase * BlockSize;
786 float escl[EnvCount], eval[EnvCount];
787 for (int i = 0; i < EnvCount; i++)
788 escl[i] = (1.f + parameters->envs[i].velscale * (velocity - 1.f));
790 if (is_quad)
792 for (int i = 0; i < EnvCount; i++)
793 eval[i] = envs[i].value * envs[i].value * escl[i];
795 else
797 for (int i = 0; i < EnvCount; i++)
798 eval[i] = envs[i].value * escl[i];
800 for (int i = 0; i < FilterCount; i++)
802 float mod = parameters->filters[i].envmod[0] * eval[0] ;
803 mod += parameters->filters[i].keyf * 100 * (note - 60);
804 for (int j = 1; j < EnvCount; j++)
806 mod += parameters->filters[i].envmod[j] * eval[j];
808 if (i) mod += expression.get() * 1200 * 4;
809 float fc = parameters->filters[i].cutoff * pow(2.0f, mod * (1.f / 1200.f));
810 if (i == 0 && parameters->filter1_type >= 0.5f)
811 filterL[i].set_hp_rbj(dsp::clip<float>(fc, 10, 18000), parameters->filters[i].resonance, sample_rate);
812 else
813 filterL[i].set_lp_rbj(dsp::clip<float>(fc, 10, 18000), parameters->filters[i].resonance, sample_rate);
814 filterR[i].copy_coeffs(filterL[i]);
816 float amp_pre[ampctl_count - 1], amp_post[ampctl_count - 1];
817 for (int i = 0; i < ampctl_count - 1; i++)
819 amp_pre[i] = 1.f;
820 amp_post[i] = 1.f;
822 bool any_running = false;
823 for (int i = 0; i < EnvCount; i++)
825 float pre = eval[i];
826 envs[i].advance();
827 int mode = fastf2i_drm(parameters->envs[i].ampctl);
828 if (!envs[i].stopped())
829 any_running = true;
830 if (mode == ampctl_none)
831 continue;
832 float post = (is_quad ? envs[i].value : 1) * envs[i].value * escl[i];
833 amp_pre[mode - 1] *= pre;
834 amp_post[mode - 1] *= post;
836 if (vibrato_mode >= lfomode_direct && vibrato_mode <= lfomode_filter2)
837 vibrato.process(parameters, aux_buffers[vibrato_mode - lfomode_direct], BlockSize, sample_rate);
838 if (!any_running)
839 finishing = true;
840 // calculate delta from pre and post
841 for (int i = 0; i < ampctl_count - 1; i++)
842 amp_post[i] = (amp_post[i] - amp_pre[i]) * (1.0 / BlockSize);
843 float a0 = amp_pre[0], a1 = amp_pre[1], a2 = amp_pre[2], a3 = amp_pre[3];
844 float d0 = amp_post[0], d1 = amp_post[1], d2 = amp_post[2], d3 = amp_post[3];
845 if (parameters->filter_chain >= 0.5f)
847 for (int i=0; i < (int) BlockSize; i++) {
848 output_buffer[i][0] = a3 * (a0 * output_buffer[i][0] + a2 * filterL[1].process(a1 * filterL[0].process(aux_buffers[1][i][0]) + aux_buffers[2][i][0]));
849 output_buffer[i][1] = a3 * (a0 * output_buffer[i][1] + a2 * filterR[1].process(a1 * filterR[0].process(aux_buffers[1][i][1]) + aux_buffers[2][i][1]));
850 a0 += d0, a1 += d1, a2 += d2, a3 += d3;
853 else
855 for (int i=0; i < (int) BlockSize; i++) {
856 output_buffer[i][0] = a3 * (a0 * output_buffer[i][0] + a1 * filterL[0].process(aux_buffers[1][i][0]) + a2 * filterL[1].process(aux_buffers[2][i][0]));
857 output_buffer[i][1] = a3 * (a0 * output_buffer[i][1] + a1 * filterR[0].process(aux_buffers[1][i][1]) + a2 * filterR[1].process(aux_buffers[2][i][1]));
858 a0 += d0, a1 += d1, a2 += d2, a3 += d3;
861 filterL[0].sanitize();
862 filterR[0].sanitize();
863 filterL[1].sanitize();
864 filterR[1].sanitize();
865 if (vibrato_mode == lfomode_voice)
866 vibrato.process(parameters, output_buffer, BlockSize, sample_rate);
868 if (finishing)
870 for (int i = 0; i < (int) BlockSize; i++) {
871 output_buffer[i][0] *= amp.get();
872 output_buffer[i][1] *= amp.get();
873 amp.age_lin((1.0/44100.0)/0.03,0.0);
877 if (use_percussion())
878 render_percussion_to(output_buffer, BlockSize);
882 void organ_voice::note_on(int note, int vel)
884 stolen = false;
885 finishing = false;
886 perc_released = false;
887 released = false;
888 reset();
889 this->note = note;
890 const float sf = 0.001f;
891 for (int i = 0; i < EnvCount; i++)
893 organ_parameters::organ_env_parameters &p = parameters->envs[i];
894 envs[i].set(sf * p.attack, sf * p.decay, p.sustain, sf * p.release, sample_rate / BlockSize);
895 envs[i].note_on();
897 update_pitch();
898 velocity = vel * 1.0 / 127.0;
899 amp.set(1.0f);
900 perc_note_on(note, vel);
903 void organ_voice::note_off(int /* vel */)
905 // reset age to 0 (because decay will turn from exponential to linear, necessary because of error cumulation prevention)
906 perc_released = true;
907 if (pamp.get_active())
909 pamp.reinit();
911 rel_age_const = pamp.get() * ((1.0/44100.0)/0.03);
912 for (int i = 0; i < EnvCount; i++)
913 envs[i].note_off();
916 void organ_voice::steal()
918 perc_released = true;
919 finishing = true;
920 stolen = true;
923 void organ_voice::reset()
925 inertia_pitchbend.ramp.set_length(sample_rate / (BlockSize * 30)); // 1/30s
926 vibrato.reset();
927 phase = 0;
928 for (int i = 0; i < FilterCount; i++)
930 filterL[i].reset();
931 filterR[i].reset();
935 ///////////////////////////////////////////////////////////////////////////////////////////////////
937 void drawbar_organ::update_params()
939 parameters->perc_decay_const = dsp::decay::calc_exp_constant(1.0 / 1024.0, 0.001 * parameters->percussion_time * sample_rate);
940 parameters->perc_fm_decay_const = dsp::decay::calc_exp_constant(1.0 / 1024.0, 0.001 * parameters->percussion_fm_time * sample_rate);
941 for (int i = 0; i < 9; i++)
943 parameters->multiplier[i] = parameters->harmonics[i] * pow(2.0, parameters->detune[i] * (1.0 / 1200.0));
944 parameters->phaseshift[i] = int(parameters->phase[i] * 65536 / 360) << 16;
946 double dphase = dsp::midi_note_to_phase((int)parameters->foldover, 0, sample_rate);
947 parameters->foldvalue = (int)(dphase);
950 dsp::voice *drawbar_organ::alloc_voice()
952 block_voice<organ_voice> *v = new block_voice<organ_voice>();
953 v->parameters = parameters;
954 return v;
957 void drawbar_organ::percussion_note_on(int note, int vel)
959 percussion.perc_note_on(note, vel);
962 void drawbar_organ::setup(int sr)
964 basic_synth::setup(sr);
965 percussion.setup(sr);
966 parameters->cutoff = 0;
967 params_changed();
968 global_vibrato.reset();
971 bool drawbar_organ::check_percussion() {
972 switch(dsp::fastf2i_drm(parameters->percussion_trigger))
974 case organ_voice_base::perctrig_first:
975 return active_voices.empty();
976 case organ_voice_base::perctrig_each:
977 default:
978 return true;
979 case organ_voice_base::perctrig_eachplus:
980 return !percussion.get_noticable();
981 case organ_voice_base::perctrig_polyphonic:
982 return false;
986 void drawbar_organ::pitch_bend(int amt)
988 parameters->pitch_bend = pow(2.0, (amt * parameters->pitch_bend_range) / (1200.0 * 8192.0));
989 for (voice_array::iterator i = active_voices.begin(); i != active_voices.end(); ++i)
991 organ_voice *v = dynamic_cast<organ_voice *>(*i);
992 v->update_pitch();
994 percussion.update_pitch();
997 void organ_audio_module::execute(int cmd_no)
999 switch(cmd_no)
1001 case 0:
1002 panic_flag = true;
1003 break;
1007 void organ_voice_base::perc_note_on(int note, int vel)
1009 perc_reset();
1010 released_ref = false;
1011 this->note = note;
1012 if (parameters->percussion_level > 0)
1013 pamp.set(1.0f + (vel - 127) * parameters->percussion_vel2amp / 127.0);
1014 update_pitch();
1015 float (*kt)[2] = parameters->percussion_keytrack;
1016 // assume last point (will be put there by padding)
1017 fm_keytrack = kt[ORGAN_KEYTRACK_POINTS - 1][1];
1018 // yes binary search would be nice if we had more than those crappy 4 points
1019 for (int i = 0; i < ORGAN_KEYTRACK_POINTS - 1; i++)
1021 float &lower = kt[i][0], upper = kt[i + 1][0];
1022 if (note >= lower && note < upper)
1024 fm_keytrack = kt[i][1] + (note - lower) * (kt[i + 1][1] - kt[i][1]) / (upper - lower);
1025 break;
1028 fm_amp.set(fm_keytrack * (1.0f + (vel - 127) * parameters->percussion_vel2fm / 127.0));
1031 char *organ_audio_module::configure(const char *key, const char *value)
1033 if (!strcmp(key, "map_curve"))
1035 if (!value)
1036 value = "2\n0 1\n1 1\n";
1037 var_map_curve = value;
1038 stringstream ss(value);
1039 int i = 0;
1040 float x = 0, y = 1;
1041 if (*value)
1043 int points;
1044 ss >> points;
1045 for (i = 0; i < points; i++)
1047 static const int whites[] = { 0, 2, 4, 5, 7, 9, 11 };
1048 ss >> x >> y;
1049 int wkey = (int)(x * 71);
1050 x = whites[wkey % 7] + 12 * (wkey / 7);
1051 parameters->percussion_keytrack[i][0] = x;
1052 parameters->percussion_keytrack[i][1] = y;
1053 // cout << "(" << x << ", " << y << ")" << endl;
1056 // pad with constant Y
1057 for (; i < ORGAN_KEYTRACK_POINTS; i++) {
1058 parameters->percussion_keytrack[i][0] = x;
1059 parameters->percussion_keytrack[i][1] = y;
1061 return NULL;
1063 cout << "Set unknown configure value " << key << " to " << value << endl;
1064 return NULL;
1067 void organ_audio_module::send_configures(send_configure_iface *sci)
1069 sci->send_configure("map_curve", var_map_curve.c_str());
1072 void organ_audio_module::deactivate()
1077 void drawbar_organ::render_separate(float *output[], int nsamples)
1079 float buf[MAX_SAMPLE_RUN][2];
1080 dsp::zero(&buf[0][0], 2 * nsamples);
1081 basic_synth::render_to(buf, nsamples);
1082 if (dsp::fastf2i_drm(parameters->lfo_mode) == organ_voice_base::lfomode_global)
1084 for (int i = 0; i < nsamples; i += 64)
1085 global_vibrato.process(parameters, buf + i, std::min(64, nsamples - i), sample_rate);
1087 if (percussion.get_active())
1088 percussion.render_percussion_to(buf, nsamples);
1089 float gain = parameters->master * (1.0 / 8);
1090 eq_l.set(parameters->bass_freq, parameters->bass_gain, parameters->treble_freq, parameters->treble_gain, sample_rate);
1091 eq_r.copy_coeffs(eq_l);
1092 for (int i=0; i<nsamples; i++) {
1093 output[0][i] = gain*eq_l.process(buf[i][0]);
1094 output[1][i] = gain*eq_r.process(buf[i][1]);
1096 eq_l.sanitize();
1097 eq_r.sanitize();