stereo operation

This commit is contained in:
Christopher Herb
2023-07-07 17:38:31 +02:00
parent 810be3b0b7
commit ebae50c2e6
2 changed files with 11 additions and 6 deletions

View File

@@ -25,7 +25,7 @@ public:
voice_allocator::set_samplerate(_samplerate); 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 // sample accurate event handling based on the iPlug2 synth by Oli Larkin
if (m_voices_active || !m_event_queue.empty()) { if (m_voices_active || !m_event_queue.empty()) {
@@ -53,7 +53,7 @@ public:
m_event_queue.erase(m_event_queue.begin()); 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; samples_remaining -= block_size;
start_index += block_size; start_index += block_size;
@@ -64,7 +64,8 @@ public:
flush_event_queue(_n_frames); flush_event_queue(_n_frames);
} else { } else {
for (int s = 0; s < _n_frames; s++) { for (int s = 0; s < _n_frames; s++) {
_output[s] = 0.; _outputs[0][s] = 0.;
_outputs[1][s] = 0.;
} }
} }
} }

View File

@@ -47,16 +47,20 @@ public:
std::for_each(voices.begin(), voices.end(), f); 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++) { for (int s = _start_index; s < _start_index + _block_size; s++) {
process_events(s); process_events(s);
float voices_signal = 0.; 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;
} }
} }