bugfixes to make tx_voice work with base synth

This commit is contained in:
Christopher Herb
2023-07-07 16:57:30 +02:00
parent 1bc737ad66
commit 810be3b0b7
5 changed files with 26 additions and 8 deletions

View File

@@ -11,7 +11,8 @@ template <typename t_voice>
class midi_synth : public voice_allocator<t_voice> {
public:
midi_synth(int _n_voices, double _samplerate, int _block_size)
: m_samplerate { _samplerate }
: voice_allocator<t_voice> { _samplerate }
, m_samplerate { _samplerate }
, m_block_size { _block_size }
, m_voices_active { false }
{
@@ -58,13 +59,12 @@ public:
start_index += block_size;
}
voices_active = voice_allocator::voices_active();
m_voices_active = voice_allocator::voices_active();
flush_event_queue(_n_frames);
} else {
for (int s = 0; s < _n_frames; s++) {
outputs[0][s] = 0.;
outputs[1][s] = 0.;
_output[s] = 0.;
}
}
}

View File

@@ -17,6 +17,7 @@ enum env_state {
class tx_envelope {
public:
env_state state;
float attack1_rate;
float attack1_level;
float attack2_rate;
@@ -259,7 +260,6 @@ private:
double samplerate;
int phase;
float level;
env_state state;
float start_level;
float h1;
float h2;

View File

@@ -2,6 +2,9 @@
#include "tx_sineosc.h"
#include "tx_envelope.h"
#include "tx_operator.h"
#include "../util/audio_math.h"
using namespace trnr::lib::util;
namespace trnr::lib::synth {
@@ -22,7 +25,7 @@ public:
bool gate = false;
bool trigger = false;
float frequency = 100.f;
int midi_note = 0;
float velocity = 1.f;
int algorithm;
@@ -35,9 +38,20 @@ public:
tx_operator op2;
tx_operator op3;
void note_on(int _note, float _velocity) {
this->gate = true;
this->trigger = true;
midi_note = _note;
velocity = _velocity;
}
void note_off() {
this->gate = false;
}
float process_sample() {
float pitch_env_signal = pitch_env.process_sample(gate, trigger) * pitch_env_amt;
float pitched_freq = frequency + pitch_env_signal;
float pitched_freq = midi_to_frequency(midi_note) + pitch_env_signal;
float output = 0.f;

View File

@@ -36,7 +36,7 @@ public:
void note_off(const note_event& event)
{
for (auto it = voices.begin(); it != voices.end(); it++) {
if ((*it).MidiNote == event.midi_note) {
if ((*it).midi_note == event.midi_note) {
(*it).note_off();
}
}