Avoid sin/cos and cent->frequency in filter code by using a lookup table (risky).
[calfbox.git] / sampler_voice.c
blobf4c2844d8cf8038f512c60b29d84887f10f8f744
1 /*
2 Calf Box, an open source musical instrument.
3 Copyright (C) 2010-2013 Krzysztof Foltman
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "config.h"
20 #include "config-api.h"
21 #include "dspmath.h"
22 #include "errors.h"
23 #include "midi.h"
24 #include "module.h"
25 #include "rt.h"
26 #include "sampler.h"
27 #include "sampler_impl.h"
28 #include "sfzloader.h"
29 #include "stm.h"
30 #include <assert.h>
31 #include <errno.h>
32 #include <glib.h>
33 #include <math.h>
34 #include <memory.h>
35 #include <sndfile.h>
36 #include <stdio.h>
37 #include <stdlib.h>
40 static void lfo_init(struct sampler_lfo *lfo, struct sampler_lfo_params *lfop, int srate, double srate_inv)
42 lfo->phase = 0;
43 lfo->age = 0;
44 lfo->delta = (uint32_t)(lfop->freq * 65536.0 * 65536.0 * CBOX_BLOCK_SIZE * srate_inv);
45 lfo->delay = (uint32_t)(lfop->delay * srate);
46 lfo->fade = (uint32_t)(lfop->fade * srate);
49 static inline float lfo_run(struct sampler_lfo *lfo)
51 if (lfo->age < lfo->delay)
53 lfo->age += CBOX_BLOCK_SIZE;
54 return 0.f;
57 const int FRAC_BITS = 32 - 11;
58 lfo->phase += lfo->delta;
59 uint32_t iphase = lfo->phase >> FRAC_BITS;
60 float frac = (lfo->phase & ((1 << FRAC_BITS) - 1)) * (1.0 / (1 << FRAC_BITS));
62 float v = sampler_sine_wave[iphase] + (sampler_sine_wave[iphase + 1] - sampler_sine_wave[iphase]) * frac;
63 if (lfo->fade && lfo->age < lfo->delay + lfo->fade)
65 v *= (lfo->age - lfo->delay) * 1.0 / lfo->fade;
66 lfo->age += CBOX_BLOCK_SIZE;
69 return v;
72 static gboolean is_tail_finished(struct sampler_voice *v)
74 if (v->layer->cutoff == -1)
75 return TRUE;
76 double eps = 1.0 / 65536.0;
77 if (cbox_biquadf_is_audible(&v->filter_left, eps))
78 return FALSE;
79 if (cbox_biquadf_is_audible(&v->filter_right, eps))
80 return FALSE;
81 if (sampler_layer_data_is_4pole(v->layer))
83 if (cbox_biquadf_is_audible(&v->filter_left2, eps))
84 return FALSE;
85 if (cbox_biquadf_is_audible(&v->filter_right2, eps))
86 return FALSE;
89 return TRUE;
92 #if USE_NEON
94 #include <arm_neon.h>
96 static inline void mix_block_into_with_gain(cbox_sample_t **outputs, int oofs, float *src_left, float *src_right, float gain)
98 float *dst_left = outputs[oofs];
99 float *dst_right = outputs[oofs + 1];
100 float32x2_t gain2 = {gain, gain};
101 for (size_t i = 0; i < CBOX_BLOCK_SIZE; i += 4)
103 float32x2_t l1 = vld1_f32(&src_left[i]);
104 float32x2_t l2 = vld1_f32(&src_left[i + 2]);
105 float32x2_t r1 = vld1_f32(&src_right[i]);
106 float32x2_t r2 = vld1_f32(&src_right[i + 2]);
107 float32x2_t dl1 = vld1_f32(&dst_left[i]);
108 float32x2_t dl2 = vld1_f32(&dst_left[i + 2]);
109 float32x2_t dr1 = vld1_f32(&dst_right[i]);
110 float32x2_t dr2 = vld1_f32(&dst_right[i + 2]);
112 l1 = vmla_f32(dl1, l1, gain2);
113 l2 = vmla_f32(dl2, l2, gain2);
114 vst1_f32(&dst_left[i], l1);
115 vst1_f32(&dst_left[i + 2], l2);
116 r1 = vmla_f32(dr1, r1, gain2);
117 r2 = vmla_f32(dr2, r2, gain2);
118 vst1_f32(&dst_right[i], r1);
119 vst1_f32(&dst_right[i + 2], r2);
123 #else
125 static inline void mix_block_into_with_gain(cbox_sample_t **outputs, int oofs, float *src_left, float *src_right, float gain)
127 cbox_sample_t *dst_left = outputs[oofs];
128 cbox_sample_t *dst_right = outputs[oofs + 1];
129 for (size_t i = 0; i < CBOX_BLOCK_SIZE; i++)
131 dst_left[i] += gain * src_left[i];
132 dst_right[i] += gain * src_right[i];
136 #endif
138 ////////////////////////////////////////////////////////////////////////////////
140 void sampler_voice_activate(struct sampler_voice *v, enum sampler_player_type mode)
142 assert(v->gen.mode == spt_inactive);
143 sampler_voice_unlink(&v->program->module->voices_free, v);
144 assert(mode != spt_inactive);
145 assert(v->channel);
146 v->gen.mode = mode;
147 sampler_voice_link(&v->channel->voices_running, v);
150 void sampler_voice_start(struct sampler_voice *v, struct sampler_channel *c, struct sampler_layer_data *l, int note, int vel, int *exgroups, int *pexgroupcount)
152 struct sampler_module *m = c->module;
153 sampler_gen_reset(&v->gen);
155 v->age = 0;
156 if (l->trigger == stm_release)
158 // time since last 'note on' for that note
159 v->age = m->current_time - c->prev_note_start_time[note];
160 double age = v->age * m->module.srate_inv;
161 // if attenuation is more than 84dB, ignore the release trigger
162 if (age * l->rt_decay > 84)
163 return;
165 uint32_t end = l->eff_waveform->info.frames;
166 if (l->end != 0)
167 end = (l->end == -1) ? 0 : l->end;
168 v->last_waveform = l->eff_waveform;
169 v->gen.cur_sample_end = end;
170 if (end > l->eff_waveform->info.frames)
171 end = l->eff_waveform->info.frames;
173 assert(!v->current_pipe);
174 if (end > l->eff_waveform->preloaded_frames)
176 if (l->loop_mode == slm_loop_continuous && l->loop_end < l->eff_waveform->preloaded_frames)
178 // Everything fits in prefetch, because loop ends in prefetch and post-loop part is not being played
180 else
182 uint32_t loop_start = -1, loop_end = end;
183 // If in loop mode, set the loop over the looped part... unless we're doing sustain-only loop on prefetch area only. Then
184 // streaming will only cover the release part, and it shouldn't be looped.
185 if (l->loop_mode == slm_loop_continuous || (l->loop_mode == slm_loop_sustain && l->loop_end >= l->eff_waveform->preloaded_frames))
187 loop_start = l->loop_start;
188 loop_end = l->loop_end;
190 // Those are initial values only, they will be adjusted in process function
191 v->current_pipe = cbox_prefetch_stack_pop(m->pipe_stack, l->eff_waveform, loop_start, loop_end, l->count);
192 if (!v->current_pipe)
193 g_warning("Prefetch pipe pool exhausted, no streaming playback will be possible");
197 v->output_pair_no = l->output % m->output_pairs;
198 v->serial_no = m->serial_no;
200 uint32_t pos = l->offset;
201 pos = l->offset;
202 if (l->offset_random)
203 pos += ((uint32_t)(rand() + (rand() << 16))) % l->offset_random;
204 if (pos >= end)
205 pos = end;
206 v->gen.bigpos = ((uint64_t)pos) << 32;
208 float delay = l->delay;
209 if (l->delay_random)
210 delay += rand() * (1.0 / RAND_MAX) * l->delay_random;
211 if (delay > 0)
212 v->delay = (int)(delay * m->module.srate);
213 else
214 v->delay = 0;
215 v->gen.loop_overlap = l->loop_overlap;
216 v->gen.loop_overlap_step = l->loop_overlap > 0 ? 1.0 / l->loop_overlap : 0;
217 v->gain_fromvel = 1.0 + (l->eff_velcurve[vel] - 1.0) * l->amp_veltrack * 0.01;
218 v->gain_shift = 0.0;
219 v->note = note;
220 v->vel = vel;
221 v->pitch_shift = 0;
222 v->released = 0;
223 v->released_with_sustain = 0;
224 v->released_with_sostenuto = 0;
225 v->captured_sostenuto = 0;
226 v->channel = c;
227 v->layer = l;
228 v->program = c->program;
229 v->amp_env.shape = &l->amp_env_shape;
230 v->filter_env.shape = &l->filter_env_shape;
231 v->pitch_env.shape = &l->pitch_env_shape;
233 v->cutoff_shift = vel * l->fil_veltrack / 127.0 + (note - l->fil_keycenter) * l->fil_keytrack;
234 v->loop_mode = l->loop_mode;
235 v->off_by = l->off_by;
236 int auxes = (m->module.outputs - m->module.aux_offset) / 2;
237 if (l->effect1bus >= 1 && l->effect1bus < 1 + auxes)
238 v->send1bus = l->effect1bus;
239 else
240 v->send1bus = 0;
241 if (l->effect2bus >= 1 && l->effect2bus < 1 + auxes)
242 v->send2bus = l->effect2bus;
243 else
244 v->send2bus = 0;
245 v->send1gain = l->effect1 * 0.01;
246 v->send2gain = l->effect2 * 0.01;
247 if (l->group >= 1 && *pexgroupcount < MAX_RELEASED_GROUPS)
249 gboolean found = FALSE;
250 for (int j = 0; j < *pexgroupcount; j++)
252 if (exgroups[j] == l->group)
254 found = TRUE;
255 break;
258 if (!found)
260 exgroups[(*pexgroupcount)++] = l->group;
263 lfo_init(&v->amp_lfo, &l->amp_lfo, m->module.srate, m->module.srate_inv);
264 lfo_init(&v->filter_lfo, &l->filter_lfo, m->module.srate, m->module.srate_inv);
265 lfo_init(&v->pitch_lfo, &l->pitch_lfo, m->module.srate, m->module.srate_inv);
267 cbox_biquadf_reset(&v->filter_left);
268 cbox_biquadf_reset(&v->filter_right);
269 cbox_biquadf_reset(&v->filter_left2);
270 cbox_biquadf_reset(&v->filter_right2);
272 GSList *nif = v->layer->nifs;
273 while(nif)
275 struct sampler_noteinitfunc *p = nif->data;
276 p->notefunc(p, v);
277 nif = nif->next;
280 cbox_envelope_reset(&v->amp_env);
281 cbox_envelope_reset(&v->filter_env);
282 cbox_envelope_reset(&v->pitch_env);
284 sampler_voice_activate(v, l->eff_waveform->info.channels == 2 ? spt_stereo16 : spt_mono16);
286 if (v->current_pipe && v->gen.bigpos)
287 cbox_prefetch_pipe_consumed(v->current_pipe, v->gen.bigpos >> 32);
290 void sampler_voice_link(struct sampler_voice **pv, struct sampler_voice *v)
292 v->prev = NULL;
293 v->next = *pv;
294 if (*pv)
295 (*pv)->prev = v;
296 *pv = v;
299 void sampler_voice_unlink(struct sampler_voice **pv, struct sampler_voice *v)
301 if (*pv == v)
302 *pv = v->next;
303 if (v->prev)
304 v->prev->next = v->next;
305 if (v->next)
306 v->next->prev = v->prev;
307 v->prev = NULL;
308 v->next = NULL;
311 void sampler_voice_inactivate(struct sampler_voice *v, gboolean expect_active)
313 assert((v->gen.mode != spt_inactive) == expect_active);
314 sampler_voice_unlink(&v->channel->voices_running, v);
315 v->gen.mode = spt_inactive;
316 if (v->current_pipe)
318 cbox_prefetch_stack_push(v->program->module->pipe_stack, v->current_pipe);
319 v->current_pipe = NULL;
321 v->channel = NULL;
322 sampler_voice_link(&v->program->module->voices_free, v);
325 void sampler_voice_release(struct sampler_voice *v, gboolean is_polyaft)
327 if ((v->loop_mode == slm_one_shot_chokeable) != is_polyaft)
328 return;
329 if (v->delay >= v->age + CBOX_BLOCK_SIZE)
331 v->released = 1;
332 sampler_voice_inactivate(v, TRUE);
334 else
336 if (v->loop_mode != slm_one_shot && !v->layer->count)
338 v->released = 1;
339 if (v->loop_mode == slm_loop_sustain && v->current_pipe)
341 // Break the loop
342 v->current_pipe->file_loop_end = v->gen.cur_sample_end;
343 v->current_pipe->file_loop_start = -1;
349 void sampler_voice_process(struct sampler_voice *v, struct sampler_module *m, cbox_sample_t **outputs)
351 struct sampler_layer_data *l = v->layer;
352 assert(v->gen.mode != spt_inactive);
354 // if it's a DAHD envelope without sustain, consider the note finished
355 if (v->amp_env.cur_stage == 4 && v->amp_env.shape->stages[3].end_value <= 0.f)
356 cbox_envelope_go_to(&v->amp_env, 15);
358 struct sampler_channel *c = v->channel;
359 v->age += CBOX_BLOCK_SIZE;
361 if (v->age < v->delay)
362 return;
364 if (v->last_waveform != v->layer->eff_waveform)
366 v->last_waveform = v->layer->eff_waveform;
367 if (v->layer->eff_waveform)
369 v->gen.mode = v->layer->eff_waveform->info.channels == 2 ? spt_stereo16 : spt_mono16;
370 v->gen.cur_sample_end = v->layer->eff_waveform->info.frames;
372 else
374 sampler_voice_inactivate(v, TRUE);
375 return;
378 // XXXKF I'm sacrificing sample accuracy for delays for now
379 v->delay = 0;
381 float pitch = (v->note - l->pitch_keycenter) * l->pitch_keytrack + l->tune + l->transpose * 100 + v->pitch_shift;
382 float modsrcs[smsrc_pernote_count];
383 modsrcs[smsrc_vel - smsrc_pernote_offset] = v->vel * (1.f / 127.f);
384 modsrcs[smsrc_pitch - smsrc_pernote_offset] = pitch * (1.f / 100.f);
385 modsrcs[smsrc_polyaft - smsrc_pernote_offset] = 0.f; // XXXKF not supported yet
386 modsrcs[smsrc_pitchenv - smsrc_pernote_offset] = cbox_envelope_get_next(&v->pitch_env, v->released) * 0.01f;
387 modsrcs[smsrc_filenv - smsrc_pernote_offset] = cbox_envelope_get_next(&v->filter_env, v->released) * 0.01f;
388 modsrcs[smsrc_ampenv - smsrc_pernote_offset] = cbox_envelope_get_next(&v->amp_env, v->released) * 0.01f;
390 modsrcs[smsrc_amplfo - smsrc_pernote_offset] = lfo_run(&v->amp_lfo);
391 modsrcs[smsrc_fillfo - smsrc_pernote_offset] = lfo_run(&v->filter_lfo);
392 modsrcs[smsrc_pitchlfo - smsrc_pernote_offset] = lfo_run(&v->pitch_lfo);
394 if (v->amp_env.cur_stage < 0)
396 if (is_tail_finished(v))
398 sampler_voice_inactivate(v, TRUE);
399 return;
403 float moddests[smdestcount];
404 moddests[smdest_gain] = 0;
405 moddests[smdest_pitch] = pitch;
406 moddests[smdest_cutoff] = v->cutoff_shift;
407 moddests[smdest_resonance] = 0;
408 GSList *mod = l->modulations;
409 if (l->trigger == stm_release)
410 moddests[smdest_gain] -= v->age * l->rt_decay * m->module.srate_inv;
412 if (c->pitchwheel)
413 moddests[smdest_pitch] += c->pitchwheel * (c->pitchwheel > 0 ? l->bend_up : l->bend_down) >> 13;
415 static const int modoffset[4] = {0, -1, -1, 1 };
416 static const int modscale[4] = {1, 1, 2, -2 };
417 while(mod)
419 struct sampler_modulation *sm = mod->data;
420 float value = 0.f, value2 = 1.f;
421 if (sm->src < smsrc_pernote_offset)
422 value = c->cc[sm->src] * (1.f / 127.f);
423 else
424 value = modsrcs[sm->src - smsrc_pernote_offset];
425 value = modoffset[sm->flags & 3] + value * modscale[sm->flags & 3];
427 if (sm->src2 != smsrc_none)
429 if (sm->src2 < smsrc_pernote_offset)
430 value2 = c->cc[sm->src2] * (1.f / 127.f);
431 else
432 value2 = modsrcs[sm->src2 - smsrc_pernote_offset];
434 value2 = modoffset[(sm->flags & 12) >> 2] + value2 * modscale[(sm->flags & 12) >> 2];
435 value *= value2;
437 moddests[sm->dest] += value * sm->amount;
439 mod = g_slist_next(mod);
442 double maxv = 127 << 7;
443 double freq = l->eff_freq * cent2factor(moddests[smdest_pitch]) ;
444 uint64_t freq64 = (uint64_t)(freq * 65536.0 * 65536.0 * m->module.srate_inv);
446 gboolean playing_sustain_loop = !v->released && v->loop_mode == slm_loop_sustain;
447 uint32_t loop_start, loop_end;
448 gboolean bandlimited = FALSE;
450 if (!v->current_pipe)
452 v->gen.sample_data = v->last_waveform->data;
453 if (v->last_waveform->levels)
455 // XXXKF: optimise later by caching last lookup value
456 // XXXKF: optimise later by using binary search
457 for (int i = 0; i < v->last_waveform->level_count; i++)
459 if (freq64 <= v->last_waveform->levels[i].max_rate)
461 v->gen.sample_data = v->last_waveform->levels[i].data;
462 bandlimited = TRUE;
464 break;
470 gboolean play_loop = v->layer->loop_end && (v->loop_mode == slm_loop_continuous || playing_sustain_loop) && v->layer->on_cc_number == -1;
471 loop_start = play_loop ? v->layer->loop_start : (v->layer->count ? 0 : (uint32_t)-1);
472 loop_end = play_loop ? v->layer->loop_end : v->gen.cur_sample_end;
474 if (v->current_pipe)
476 v->gen.sample_data = v->gen.loop_count ? v->current_pipe->data : v->last_waveform->data;
477 v->gen.streaming_buffer = v->current_pipe->data;
479 v->gen.prefetch_only_loop = (loop_end < v->last_waveform->preloaded_frames);
480 v->gen.loop_overlap = 0;
481 if (v->gen.prefetch_only_loop)
483 assert(!v->gen.in_streaming_buffer); // XXXKF this won't hold true when loops are edited while sound is being played (but that's not supported yet anyway)
484 v->gen.loop_start = loop_start;
485 v->gen.loop_end = loop_end;
486 v->gen.streaming_buffer_frames = 0;
488 else
490 v->gen.loop_start = 0;
491 v->gen.loop_end = v->last_waveform->preloaded_frames;
492 v->gen.streaming_buffer_frames = v->current_pipe->buffer_loop_end;
495 else
497 v->gen.loop_count = v->layer->count;
498 v->gen.loop_start = loop_start;
499 v->gen.loop_end = loop_end;
501 if (!bandlimited)
503 // Use pre-calculated join
504 v->gen.scratch = loop_start == (uint32_t)-1 ? v->layer->scratch_end : v->layer->scratch_loop;
506 else
508 // The standard waveforms have extra MAX_INTERPOLATION_ORDER of samples from the loop start added past loop_end,
509 // to avoid wasting time generating the joins in all the practical cases. The slow path covers custom loops
510 // (i.e. partial loop or no loop) over bandlimited versions of the standard waveforms, and those are probably
511 // not very useful anyway, as changing the loop removes the guarantee of the waveform being bandlimited and
512 // may cause looping artifacts or introduce DC offset (e.g. if only a positive part of a sine wave is looped).
513 if (loop_start == 0 && loop_end == l->eff_waveform->info.frames)
514 v->gen.scratch = v->gen.sample_data + l->eff_waveform->info.frames - MAX_INTERPOLATION_ORDER;
515 else
517 // Generate the join for the current wave level
518 // XXXKF this could be optimised further, by checking if waveform and loops are the same as the last
519 // time. However, this code is
520 int shift = l->eff_waveform->info.channels == 2 ? 1 : 0;
521 uint32_t halfscratch = MAX_INTERPOLATION_ORDER << shift;
523 v->gen.scratch = v->gen.scratch_bandlimited;
524 memcpy(&v->gen.scratch_bandlimited[0], &v->gen.sample_data[(loop_end - MAX_INTERPOLATION_ORDER) << shift], halfscratch * sizeof(int16_t) );
525 if (loop_start != (uint32_t)-1)
526 memcpy(v->gen.scratch_bandlimited + halfscratch, &v->gen.sample_data[loop_start << shift], halfscratch * sizeof(int16_t));
527 else
528 memset(v->gen.scratch_bandlimited + halfscratch, 0, halfscratch * sizeof(int16_t));
534 v->gen.bigdelta = freq64;
535 float gain = modsrcs[smsrc_ampenv - smsrc_pernote_offset] * l->volume_linearized * v->gain_fromvel * sampler_channel_addcc(c, 7) * sampler_channel_addcc(c, 11) / (maxv * maxv);
536 if (moddests[smdest_gain] != 0.f)
537 gain *= dB2gain(moddests[smdest_gain]);
538 // http://drealm.info/sfz/plj-sfz.xhtml#amp "The overall gain must remain in the range -144 to 6 decibels."
539 if (gain > 2.f)
540 gain = 2.f;
541 float pan = (l->pan + 100.f) * (1.f / 200.f) + (sampler_channel_addcc(c, 10) * 1.f / maxv - 0.5f) * 2.f;
542 if (pan < 0.f)
543 pan = 0.f;
544 if (pan > 1.f)
545 pan = 1.f;
546 v->gen.lgain = gain * (1.f - pan) / 32768.f;
547 v->gen.rgain = gain * pan / 32768.f;
548 gboolean is4p = sampler_layer_data_is_4pole(v->layer);
549 if (l->cutoff != -1.f)
551 float logcutoff = l->logcutoff + moddests[smdest_cutoff];
552 if (logcutoff < 0)
553 logcutoff = 0;
554 if (logcutoff > 12798)
555 logcutoff = 12798;
556 //float resonance = v->resonance*pow(32.0,c->cc[71]/maxv);
557 float resonance = l->resonance_linearized * dB2gain((is4p ? 0.5 : 1) * moddests[smdest_resonance]);
558 if (resonance < 0.7f)
559 resonance = 0.7f;
560 if (resonance > 32.f)
561 resonance = 32.f;
562 switch(l->fil_type)
564 case sft_lp12:
565 case sft_lp24:
567 cbox_biquadf_set_lp_rbj_lookup(&v->filter_coeffs, &m->sincos[(int)logcutoff], resonance);
568 break;
570 case sft_hp12:
571 case sft_hp24:
572 cbox_biquadf_set_hp_rbj_lookup(&v->filter_coeffs, &m->sincos[(int)logcutoff], resonance);
573 break;
574 case sft_bp6:
575 case sft_bp12:
576 cbox_biquadf_set_bp_rbj_lookup(&v->filter_coeffs, &m->sincos[(int)logcutoff], resonance);
577 break;
578 case sft_lp6:
579 cbox_biquadf_set_1plp_lookup(&v->filter_coeffs, &m->sincos[(int)logcutoff]);
580 break;
581 case sft_hp6:
582 cbox_biquadf_set_1php_lookup(&v->filter_coeffs, &m->sincos[(int)logcutoff]);
583 break;
584 default:
585 assert(0);
589 float left[CBOX_BLOCK_SIZE], right[CBOX_BLOCK_SIZE];
591 uint32_t samples = 0;
594 if (v->current_pipe)
596 uint32_t limit = cbox_prefetch_pipe_get_remaining(v->current_pipe) - 4;
597 if (!limit)
598 v->gen.mode = spt_inactive;
599 else
601 samples = sampler_gen_sample_playback(&v->gen, left, right, limit);
602 cbox_prefetch_pipe_consumed(v->current_pipe, v->gen.consumed);
603 v->gen.consumed = 0;
606 else
608 samples = sampler_gen_sample_playback(&v->gen, left, right, (uint32_t)-1);
611 for (int i = samples; i < CBOX_BLOCK_SIZE; i++)
612 left[i] = right[i] = 0.f;
613 if (l->cutoff != -1)
615 cbox_biquadf_process(&v->filter_left, &v->filter_coeffs, left);
616 if (is4p)
617 cbox_biquadf_process(&v->filter_left2, &v->filter_coeffs, left);
618 cbox_biquadf_process(&v->filter_right, &v->filter_coeffs, right);
619 if (is4p)
620 cbox_biquadf_process(&v->filter_right2, &v->filter_coeffs, right);
622 mix_block_into_with_gain(outputs, v->output_pair_no * 2, left, right, 1.f);
623 if ((v->send1bus > 0 && v->send1gain != 0) || (v->send2bus > 0 && v->send2gain != 0))
625 if (v->send1bus > 0 && v->send1gain != 0)
627 int oofs = m->module.aux_offset + (v->send1bus - 1) * 2;
628 mix_block_into_with_gain(outputs, oofs, left, right, v->send1gain);
630 if (v->send2bus > 0 && v->send2gain != 0)
632 int oofs = m->module.aux_offset + (v->send2bus - 1) * 2;
633 mix_block_into_with_gain(outputs, oofs, left, right, v->send2gain);
636 if (v->gen.mode == spt_inactive)
637 sampler_voice_inactivate(v, FALSE);