From 8f69b4fcf8489fa8e95af3cce0ff422247f601c8 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 16 May 2025 13:44:15 +0200 Subject: [PATCH] add optional modulators to synth/voices --- synth/ivoice.h | 3 ++- synth/midi_synth.h | 4 ++-- synth/tx_voice.h | 3 ++- synth/voice_allocator.h | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/synth/ivoice.h b/synth/ivoice.h index 890db6b..e4f6ed2 100644 --- a/synth/ivoice.h +++ b/synth/ivoice.h @@ -1,10 +1,11 @@ #pragma once +#include namespace trnr { template struct ivoice { virtual ~ivoice() = default; - virtual void process_samples(t_sample** _outputs, int _start_index, int _block_size) = 0; + virtual void process_samples(t_sample** _outputs, int _start_index, int _block_size, std::span> _modulators = {}) = 0; virtual bool is_busy() = 0; virtual void set_samplerate(double samplerate) = 0; virtual void note_on(int _note, float _velocity) = 0; diff --git a/synth/midi_synth.h b/synth/midi_synth.h index caecdfa..3e0470f 100644 --- a/synth/midi_synth.h +++ b/synth/midi_synth.h @@ -25,7 +25,7 @@ public: voice_allocator::set_samplerate(_samplerate); } - void process_block(t_sample** _outputs, int _n_frames) + void process_block(t_sample** _outputs, int _n_frames, std::span> _modulators = {}) { // clear outputs for (auto i = 0; i < 2; i++) { memset(_outputs[i], 0, _n_frames * sizeof(t_sample)); } @@ -55,7 +55,7 @@ public: m_event_queue.erase(m_event_queue.begin()); } - voice_allocator::process_samples(_outputs, start_index, block_size); + voice_allocator::process_samples(_outputs, start_index, block_size, _modulators); samples_remaining -= block_size; start_index += block_size; diff --git a/synth/tx_voice.h b/synth/tx_voice.h index 94a1b8e..204c3b0 100644 --- a/synth/tx_voice.h +++ b/synth/tx_voice.h @@ -5,6 +5,7 @@ #include "tx_operator.h" #include "tx_sineosc.h" #include "tx_parameter_mapping.h" +#include namespace trnr { @@ -48,7 +49,7 @@ public: // modulates the pitch in semitones void modulate_pitch(float _pitch) override { this->pitch_mod = _pitch; } - void process_samples(t_sample** _outputs, int _start_index, int _block_size) override + void process_samples(t_sample** _outputs, int _start_index, int _block_size, std::span> _modulators = {}) override { float frequency = midi_to_frequency(midi_note + pitch_mod + additional_pitch_mod); diff --git a/synth/voice_allocator.h b/synth/voice_allocator.h index 63d64ad..a985c51 100644 --- a/synth/voice_allocator.h +++ b/synth/voice_allocator.h @@ -61,14 +61,14 @@ public: }); } - void process_samples(t_sample** _outputs, int _start_index, int _block_size) + void process_samples(t_sample** _outputs, int _start_index, int _block_size, std::span> _modulators = {}) { for (int b = _start_index; b < _start_index + _block_size; b += internal_block_size) { // process all events in the block (introduces potential inaccuracy of up to 16 samples) process_events(b, internal_block_size); - for (const auto& v : voicePtrs) { v->process_samples(_outputs, b, internal_block_size); } + for (const auto& v : voicePtrs) { v->process_samples(_outputs, b, internal_block_size, _modulators); } } }