From ebae50c2e6114bdc1d6344a355ce29cfeab0f6e6 Mon Sep 17 00:00:00 2001 From: Christopher Herb Date: Fri, 7 Jul 2023 17:38:31 +0200 Subject: [PATCH] stereo operation --- synth/midi_synth.h | 7 ++++--- synth/voice_allocator.h | 10 +++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/synth/midi_synth.h b/synth/midi_synth.h index 9329e65..533c5e6 100644 --- a/synth/midi_synth.h +++ b/synth/midi_synth.h @@ -25,7 +25,7 @@ public: voice_allocator::set_samplerate(_samplerate); } - void process_block(double* _output, int _n_frames) + void process_block(double** _outputs, int _n_frames) { // sample accurate event handling based on the iPlug2 synth by Oli Larkin if (m_voices_active || !m_event_queue.empty()) { @@ -53,7 +53,7 @@ public: m_event_queue.erase(m_event_queue.begin()); } - voice_allocator::process_samples(_output, start_index, block_size); + voice_allocator::process_samples(_outputs, start_index, block_size); samples_remaining -= block_size; start_index += block_size; @@ -64,7 +64,8 @@ public: flush_event_queue(_n_frames); } else { for (int s = 0; s < _n_frames; s++) { - _output[s] = 0.; + _outputs[0][s] = 0.; + _outputs[1][s] = 0.; } } } diff --git a/synth/voice_allocator.h b/synth/voice_allocator.h index 24203eb..9440d6b 100644 --- a/synth/voice_allocator.h +++ b/synth/voice_allocator.h @@ -47,16 +47,20 @@ public: std::for_each(voices.begin(), voices.end(), f); } - void process_samples(double* _output, int _start_index, int _block_size) + void process_samples(double** _outputs, int _start_index, int _block_size) { for (int s = _start_index; s < _start_index + _block_size; s++) { process_events(s); float voices_signal = 0.; - std::for_each(voices.begin(), voices.end(), [&voices_signal](t_voice& voice) { voices_signal += (voice.process_sample() / 3.); }); - _output[s] = voices_signal; + std::for_each(voices.begin(), voices.end(), [&voices_signal](t_voice& voice) { + voices_signal += (voice.process_sample() / 3.); + }); + + _outputs[0][s] = voices_signal; + _outputs[1][s] = voices_signal; } }