fix: ADSR logic

This commit is contained in:
2023-09-04 23:25:54 +04:00
parent d883bbbf12
commit ef40eaf7ef
4 changed files with 14 additions and 14 deletions

View File

@@ -102,7 +102,7 @@ void Application::update_on_note_input() {
//m_sound_played_count = 0;
write_log("Note played: %s\n", m_current_note->name.c_str());
}
else if (is_note_up()) {
else if (is_note_up() && m_synth.GetIsNoteTriggered()) {
m_synth.StopSound();
}
// will produce 0 signal if ADSR is in off state
@@ -112,18 +112,17 @@ void Application::update_on_note_input() {
// Play ring-buffered audio
void Application::play_buffered_audio() {
if (IsAudioStreamProcessed(m_synth_stream)) {
const float audio_frame_start_time = GetTime();
//const float audio_frame_start_time = GetTime();
update_on_note_input();
UpdateAudioStream(m_synth_stream, m_synth.GetOutSignal().data(), STREAM_BUFFER_SIZE);
const float audio_freme_duration = GetTime() - audio_frame_start_time;
//const float audio_freme_duration = GetTime() - audio_frame_start_time;
//write_log("Frame time: %.3f%% \n", 100.0f / ((1.0f / audio_freme_duration) / ((float)SAMPLE_RATE/STREAM_BUFFER_SIZE)));
}
}
void Application::Run() {
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
while (!WindowShouldClose()) {
play_buffered_audio();
m_renderer.Draw(m_synth, m_synth_gui_state);
}