From b6387c85475c5e83ceecb69cbebe97e49685eb97 Mon Sep 17 00:00:00 2001 From: cam900 Date: Tue, 17 May 2022 11:14:22 +0900 Subject: [PATCH] Fix AY8910 envelope hangs --- src/engine/platform/sound/ay8910.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/engine/platform/sound/ay8910.cpp b/src/engine/platform/sound/ay8910.cpp index 7b38ad319..867b5d214 100644 --- a/src/engine/platform/sound/ay8910.cpp +++ b/src/engine/platform/sound/ay8910.cpp @@ -1061,9 +1061,8 @@ void ay8910_device::sound_stream_update(short** outputs, int outLen) for (int chan = 0; chan < NUM_CHANNELS; chan++) { tone = &m_tone[chan]; - const int period = tone->period * (m_step_mul << 1); + const int period = std::max(1, tone->period) * (m_step_mul << 1); tone->count += is_expanded_mode() ? 32 : ((m_feature & PSG_HAS_EXPANDED_MODE) ? 1 : 2); - if (period==0) continue; while (tone->count >= period) { tone->duty_cycle = (tone->duty_cycle - 1) & 0x1f; @@ -1116,7 +1115,7 @@ void ay8910_device::sound_stream_update(short** outputs, int outLen) envelope = &m_envelope[chan]; if (envelope->holding == 0) { - const int period = envelope->period * m_env_step_mul; + const int period = std::max(1, envelope->period) * m_env_step_mul; if ((++envelope->count) >= period) { envelope->count = 0;