fix: retriggering phase problem
This commit is contained in:
@@ -9,22 +9,25 @@
|
||||
|
||||
class Synth {
|
||||
private:
|
||||
bool is_note_triggered;
|
||||
std::vector<Oscillator*> m_oscillators;
|
||||
Adder m_adder;
|
||||
std::vector<Effect*> m_effects;
|
||||
// OscillatorUI* ui_oscillators;
|
||||
// Note m_current_note;
|
||||
std::vector<float> m_out_signal;
|
||||
void get_note(int semitone, float beats);
|
||||
void get_note();
|
||||
void apply_effects();
|
||||
|
||||
public:
|
||||
Synth(/* args */);
|
||||
~Synth();
|
||||
void ProduceNoteSound(Note input);
|
||||
void StopNoteSound();
|
||||
void TriggerNote(Note input);
|
||||
void ProduceSound();
|
||||
void StopSound();
|
||||
void AddOscillator();
|
||||
void AddEffect(Effect* fx);
|
||||
const std::vector<float>& GetOutSignal() { return m_out_signal; }
|
||||
const std::vector<Oscillator*>& GetOscillators() { return m_oscillators; }
|
||||
const bool& GetIsNoteTriggered() { return is_note_triggered; }
|
||||
};
|
||||
@@ -93,13 +93,16 @@ bool Application::detect_note_pressed(Note* note) {
|
||||
void Application::update_on_note_input() {
|
||||
if (detect_note_pressed(m_current_note)) {
|
||||
// if (detect_note_pressed(m_current_note)) {
|
||||
m_synth.ProduceNoteSound((*m_current_note));
|
||||
if (!m_synth.GetIsNoteTriggered()){
|
||||
m_synth.TriggerNote((*m_current_note));
|
||||
}
|
||||
m_synth.ProduceSound();
|
||||
//m_sound_played_count = 0;
|
||||
write_log("Note played: %s\n", m_current_note->name.c_str());
|
||||
//}
|
||||
}
|
||||
else {
|
||||
m_synth.StopNoteSound();
|
||||
m_synth.StopSound();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,19 +19,12 @@ Synth::~Synth() {
|
||||
m_out_signal.clear();
|
||||
}
|
||||
|
||||
void Synth::get_note(int semitone, float beats) {
|
||||
void Synth::get_note() {
|
||||
for (size_t i = 0; i < STREAM_BUFFER_SIZE; i++) {
|
||||
float sample = 0.0f;
|
||||
m_out_signal[i] = sample;
|
||||
}
|
||||
|
||||
float hz = KeyBoard::GetHzBySemitone(semitone);
|
||||
|
||||
// will change after oscillator starts to be more autonomous
|
||||
for (Oscillator* osc : m_oscillators) {
|
||||
osc->SetFreq(hz);
|
||||
}
|
||||
|
||||
// todo: add other pipeline steps (e.g ADSR, Filters, FX);
|
||||
Adder::SumOscillators(m_oscillators, m_out_signal);
|
||||
}
|
||||
@@ -44,18 +37,29 @@ void Synth::apply_effects() {
|
||||
}
|
||||
}
|
||||
|
||||
void Synth::ProduceNoteSound(Note input) {
|
||||
void Synth::TriggerNote(Note input) {
|
||||
float length = 1.f / input.length;
|
||||
int semitone_shift = KeyBoard::GetSemitoneShift(input.name);
|
||||
get_note(semitone_shift, length);
|
||||
float hz = KeyBoard::GetHzBySemitone(semitone_shift);
|
||||
|
||||
// will change after oscillator starts to be more autonomous
|
||||
for (Oscillator* osc : m_oscillators) {
|
||||
osc->SetFreq(hz);
|
||||
}
|
||||
is_note_triggered = true;
|
||||
}
|
||||
|
||||
void Synth::ProduceSound() {
|
||||
get_note();
|
||||
apply_effects();
|
||||
}
|
||||
|
||||
void Synth::StopNoteSound() {
|
||||
void Synth::StopSound() {
|
||||
for (size_t i = 0; i < STREAM_BUFFER_SIZE; i++) {
|
||||
float sample = 0.0f;
|
||||
m_out_signal[i] = sample;
|
||||
}
|
||||
is_note_triggered = false;
|
||||
}
|
||||
|
||||
void Synth::AddOscillator() {
|
||||
|
||||
Reference in New Issue
Block a user