bugfixes to make tx_voice work with base synth
This commit is contained in:
@@ -11,7 +11,8 @@ template <typename t_voice>
|
|||||||
class midi_synth : public voice_allocator<t_voice> {
|
class midi_synth : public voice_allocator<t_voice> {
|
||||||
public:
|
public:
|
||||||
midi_synth(int _n_voices, double _samplerate, int _block_size)
|
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_block_size { _block_size }
|
||||||
, m_voices_active { false }
|
, m_voices_active { false }
|
||||||
{
|
{
|
||||||
@@ -58,13 +59,12 @@ public:
|
|||||||
start_index += block_size;
|
start_index += block_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
voices_active = voice_allocator::voices_active();
|
m_voices_active = voice_allocator::voices_active();
|
||||||
|
|
||||||
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++) {
|
||||||
outputs[0][s] = 0.;
|
_output[s] = 0.;
|
||||||
outputs[1][s] = 0.;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ enum env_state {
|
|||||||
|
|
||||||
class tx_envelope {
|
class tx_envelope {
|
||||||
public:
|
public:
|
||||||
|
env_state state;
|
||||||
float attack1_rate;
|
float attack1_rate;
|
||||||
float attack1_level;
|
float attack1_level;
|
||||||
float attack2_rate;
|
float attack2_rate;
|
||||||
@@ -259,7 +260,6 @@ private:
|
|||||||
double samplerate;
|
double samplerate;
|
||||||
int phase;
|
int phase;
|
||||||
float level;
|
float level;
|
||||||
env_state state;
|
|
||||||
float start_level;
|
float start_level;
|
||||||
float h1;
|
float h1;
|
||||||
float h2;
|
float h2;
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
#include "tx_sineosc.h"
|
#include "tx_sineosc.h"
|
||||||
#include "tx_envelope.h"
|
#include "tx_envelope.h"
|
||||||
#include "tx_operator.h"
|
#include "tx_operator.h"
|
||||||
|
#include "../util/audio_math.h"
|
||||||
|
|
||||||
|
using namespace trnr::lib::util;
|
||||||
|
|
||||||
namespace trnr::lib::synth {
|
namespace trnr::lib::synth {
|
||||||
|
|
||||||
@@ -22,7 +25,7 @@ public:
|
|||||||
|
|
||||||
bool gate = false;
|
bool gate = false;
|
||||||
bool trigger = false;
|
bool trigger = false;
|
||||||
float frequency = 100.f;
|
int midi_note = 0;
|
||||||
float velocity = 1.f;
|
float velocity = 1.f;
|
||||||
|
|
||||||
int algorithm;
|
int algorithm;
|
||||||
@@ -35,9 +38,20 @@ public:
|
|||||||
tx_operator op2;
|
tx_operator op2;
|
||||||
tx_operator op3;
|
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 process_sample() {
|
||||||
float pitch_env_signal = pitch_env.process_sample(gate, trigger) * pitch_env_amt;
|
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;
|
float output = 0.f;
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public:
|
|||||||
void note_off(const note_event& event)
|
void note_off(const note_event& event)
|
||||||
{
|
{
|
||||||
for (auto it = voices.begin(); it != voices.end(); it++) {
|
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();
|
(*it).note_off();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,4 +8,8 @@ namespace trnr::lib::util {
|
|||||||
static inline double db_2_lin(double db) {
|
static inline double db_2_lin(double db) {
|
||||||
return pow(10, db/20);
|
return pow(10, db/20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline float midi_to_frequency(int midi_note) {
|
||||||
|
return 440.0 * powf(2.0, ((float)midi_note - 69.0) / 12.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user