add optional modulators to synth/voices
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
#pragma once
|
||||
#include <span>
|
||||
|
||||
namespace trnr {
|
||||
template <typename t_sample>
|
||||
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<std::span<t_sample>> _modulators = {}) = 0;
|
||||
virtual bool is_busy() = 0;
|
||||
virtual void set_samplerate(double samplerate) = 0;
|
||||
virtual void note_on(int _note, float _velocity) = 0;
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
voice_allocator<t_voice, t_sample>::set_samplerate(_samplerate);
|
||||
}
|
||||
|
||||
void process_block(t_sample** _outputs, int _n_frames)
|
||||
void process_block(t_sample** _outputs, int _n_frames, std::span<std::span<t_sample>> _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<t_voice, t_sample>::process_samples(_outputs, start_index, block_size);
|
||||
voice_allocator<t_voice, t_sample>::process_samples(_outputs, start_index, block_size, _modulators);
|
||||
|
||||
samples_remaining -= block_size;
|
||||
start_index += block_size;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "tx_operator.h"
|
||||
#include "tx_sineosc.h"
|
||||
#include "tx_parameter_mapping.h"
|
||||
#include <span>
|
||||
|
||||
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<std::span<t_sample>> _modulators = {}) override
|
||||
{
|
||||
float frequency = midi_to_frequency(midi_note + pitch_mod + additional_pitch_mod);
|
||||
|
||||
|
||||
@@ -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<std::span<t_sample>> _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); }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user