From 51cef18bfffd91008c87d7ae1cbb03030ed059c2 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Thu, 12 Jan 2023 16:05:03 -0500 Subject: [PATCH] AY: optimize --- src/engine/platform/sound/ay8910.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/engine/platform/sound/ay8910.cpp b/src/engine/platform/sound/ay8910.cpp index c7be503e..530b03d0 100644 --- a/src/engine/platform/sound/ay8910.cpp +++ b/src/engine/platform/sound/ay8910.cpp @@ -1064,12 +1064,11 @@ void ay8910_device::sound_stream_update(short** outputs, int outLen) tone = &m_tone[chan]; 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); - while (tone->count >= period) - { - tone->duty_cycle = (tone->duty_cycle - 1) & 0x1f; - tone->output = is_expanded_mode() ? BIT(duty_cycle[tone_duty(tone)], tone->duty_cycle) : BIT(tone->duty_cycle, 0); - tone->count -= period; - } + if (tone->count>=period) { + tone->duty_cycle = (tone->duty_cycle - (tone->count/period)) & 0x1f; + tone->output = is_expanded_mode() ? BIT(duty_cycle[tone_duty(tone)], tone->duty_cycle) : BIT(tone->duty_cycle, 0); + tone->count = tone->count % period; + } } const int period_noise = (int)(noise_period()) * m_step_mul;