Fix AY8910 envelope hangs

This commit is contained in:
cam900 2022-05-17 11:14:22 +09:00 committed by GitHub
parent 34d0925569
commit b6387c8547
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1061,9 +1061,8 @@ void ay8910_device::sound_stream_update(short** outputs, int outLen)
for (int chan = 0; chan < NUM_CHANNELS; chan++) for (int chan = 0; chan < NUM_CHANNELS; chan++)
{ {
tone = &m_tone[chan]; tone = &m_tone[chan];
const int period = tone->period * (m_step_mul << 1); const int period = std::max<int>(1, tone->period) * (m_step_mul << 1);
tone->count += is_expanded_mode() ? 32 : ((m_feature & PSG_HAS_EXPANDED_MODE) ? 1 : 2); tone->count += is_expanded_mode() ? 32 : ((m_feature & PSG_HAS_EXPANDED_MODE) ? 1 : 2);
if (period==0) continue;
while (tone->count >= period) while (tone->count >= period)
{ {
tone->duty_cycle = (tone->duty_cycle - 1) & 0x1f; 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]; envelope = &m_envelope[chan];
if (envelope->holding == 0) if (envelope->holding == 0)
{ {
const int period = envelope->period * m_env_step_mul; const int period = std::max<int>(1, envelope->period) * m_env_step_mul;
if ((++envelope->count) >= period) if ((++envelope->count) >= period)
{ {
envelope->count = 0; envelope->count = 0;