From 35a29b9c2fc6cfc6c34716d40b5367909bb95b54 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 18 Jul 2023 20:25:39 +0200 Subject: [PATCH] templated sample data type --- filter/ybandpass.h | 3 ++- filter/yhighpass.h | 3 ++- filter/ylowpass.h | 11 ++++++----- filter/ynotch.h | 3 ++- filter/ysvf.h | 3 ++- synth/midi_synth.h | 14 +++++++------- synth/voice_allocator.h | 4 ++-- 7 files changed, 23 insertions(+), 18 deletions(-) diff --git a/filter/ybandpass.h b/filter/ybandpass.h index 6d8bfbe..9cb048f 100644 --- a/filter/ybandpass.h +++ b/filter/ybandpass.h @@ -5,6 +5,7 @@ #include namespace trnr { +template // Bandpass filter based on YBandpass by Chris Johnson class ybandpass { public: @@ -70,7 +71,7 @@ public: { F = value; } - void processblock(double** inputs, double** outputs, int blockSize) + void processblock(t_sample** inputs, t_sample** outputs, int blockSize) { double* in1 = inputs[0]; double* in2 = inputs[1]; diff --git a/filter/yhighpass.h b/filter/yhighpass.h index 997b136..1abb1e6 100644 --- a/filter/yhighpass.h +++ b/filter/yhighpass.h @@ -5,6 +5,7 @@ #include namespace trnr { +template // Highpass filter based on YHighpass by Chris Johnson class yhighpass { public: @@ -70,7 +71,7 @@ public: { F = value; } - void processblock(double** inputs, double** outputs, int blockSize) + void processblock(t_sample** inputs, t_sample** outputs, int blockSize) { double* in1 = inputs[0]; double* in2 = inputs[1]; diff --git a/filter/ylowpass.h b/filter/ylowpass.h index aa80785..6e2cdb2 100644 --- a/filter/ylowpass.h +++ b/filter/ylowpass.h @@ -5,6 +5,7 @@ #include namespace trnr { +template // Lowpass filter based on YLowpass by Chris Johnson class ylowpass { public: @@ -70,12 +71,12 @@ public: { F = value; } - void processblock(double** inputs, double** outputs, int blockSize) + void processblock(t_sample** inputs, t_sample** outputs, int blockSize) { - double* in1 = inputs[0]; - double* in2 = inputs[1]; - double* out1 = outputs[0]; - double* out2 = outputs[1]; + t_sample* in1 = inputs[0]; + t_sample* in2 = inputs[1]; + t_sample* out1 = outputs[0]; + t_sample* out2 = outputs[1]; int inFramesToProcess = blockSize; double overallscale = 1.0; diff --git a/filter/ynotch.h b/filter/ynotch.h index fefe59a..1af0475 100644 --- a/filter/ynotch.h +++ b/filter/ynotch.h @@ -4,6 +4,7 @@ #include #include +template namespace trnr { // Notch filter based on YNotch by Chris Johnson class ynotch { @@ -70,7 +71,7 @@ public: { F = value; } - void processblock(double** inputs, double** outputs, int blockSize) + void processblock(t_sample** inputs, t_sample** outputs, int blockSize) { double* in1 = inputs[0]; double* in2 = inputs[1]; diff --git a/filter/ysvf.h b/filter/ysvf.h index a2e38cf..717e8f8 100644 --- a/filter/ysvf.h +++ b/filter/ysvf.h @@ -5,6 +5,7 @@ #include "ynotch.h" namespace trnr { +template enum filter_types { lowpass = 0, @@ -75,7 +76,7 @@ public: notch.set_mix(value); } - void process_block(double** inputs, double** outputs, int block_size) { + void process_block(t_sample** inputs, t_sample** outputs, int block_size) { switch (filter_type) { case filter_types::lowpass: diff --git a/synth/midi_synth.h b/synth/midi_synth.h index e62534c..2e7aeb0 100644 --- a/synth/midi_synth.h +++ b/synth/midi_synth.h @@ -9,8 +9,8 @@ namespace trnr { // a generic midi synth base class with sample accurate event handling. // the templated type t_voice must derive from ivoice -template -class midi_synth : public voice_allocator { +template +class midi_synth : public voice_allocator { public: midi_synth(int _n_voices) : m_voices_active { false } @@ -22,10 +22,10 @@ public: void set_samplerate_blocksize(double _samplerate, int _block_size) { m_block_size = _block_size; - voice_allocator::set_samplerate(_samplerate); + voice_allocator::set_samplerate(_samplerate); } - void process_block(double** _outputs, int _n_frames) + void process_block(t_sample** _outputs, int _n_frames) { // sample accurate event handling based on the iPlug2 synth by Oli Larkin if (m_voices_active || !m_event_queue.empty()) { @@ -48,18 +48,18 @@ public: // send performance messages to the voice allocator // message offset is relative to the start of this process_samples() block event.offset -= start_index; - voice_allocator::add_event(event); + voice_allocator::add_event(event); 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); samples_remaining -= block_size; start_index += block_size; } - m_voices_active = voice_allocator::voices_active(); + m_voices_active = voice_allocator::voices_active(); flush_event_queue(_n_frames); } else { diff --git a/synth/voice_allocator.h b/synth/voice_allocator.h index 12b2a80..0f85716 100644 --- a/synth/voice_allocator.h +++ b/synth/voice_allocator.h @@ -5,7 +5,7 @@ namespace trnr { -template +template class voice_allocator { public: std::vector voices; @@ -49,7 +49,7 @@ public: std::for_each(voices.begin(), voices.end(), f); } - void process_samples(double** _outputs, int _start_index, int _block_size) + void process_samples(t_sample** _outputs, int _start_index, int _block_size) { for (int s = _start_index; s < _start_index + _block_size; s++) {