diff --git a/src/emu/sound/ymz280b.c b/src/emu/sound/ymz280b.c index c4a1587735f..597f9f5b64f 100644 --- a/src/emu/sound/ymz280b.c +++ b/src/emu/sound/ymz280b.c @@ -222,9 +222,7 @@ int ymz280b_device::generate_adpcm(struct YMZ280BVoice *voice, INT16 *buffer, in position++; if (position >= voice->stop) { - if (!samples) - samples |= 0x10000; - + voice->ended = true; break; } } @@ -276,9 +274,7 @@ int ymz280b_device::generate_adpcm(struct YMZ280BVoice *voice, INT16 *buffer, in } if (position >= voice->stop) { - if (!samples) - samples |= 0x10000; - + voice->ended = true; break; } } @@ -322,9 +318,7 @@ int ymz280b_device::generate_pcm8(struct YMZ280BVoice *voice, INT16 *buffer, int position += 2; if (position >= voice->stop) { - if (!samples) - samples |= 0x10000; - + voice->ended = true; break; } } @@ -352,9 +346,7 @@ int ymz280b_device::generate_pcm8(struct YMZ280BVoice *voice, INT16 *buffer, int } if (position >= voice->stop) { - if (!samples) - samples |= 0x10000; - + voice->ended = true; break; } } @@ -396,9 +388,7 @@ int ymz280b_device::generate_pcm16(struct YMZ280BVoice *voice, INT16 *buffer, in position += 4; if (position >= voice->stop) { - if (!samples) - samples |= 0x10000; - + voice->ended = true; break; } } @@ -426,9 +416,7 @@ int ymz280b_device::generate_pcm16(struct YMZ280BVoice *voice, INT16 *buffer, in } if (position >= voice->stop) { - if (!samples) - samples |= 0x10000; - + voice->ended = true; break; } } @@ -514,13 +502,14 @@ void ymz280b_device::sound_stream_update(sound_stream &stream, stream_sample_t * default: samples_left = 0; memset(m_scratch, 0, new_samples * sizeof(m_scratch[0])); break; } - /* if there are leftovers, ramp back to 0 */ - if (samples_left) + if (samples_left || voice->ended) { - /* NOTE: samples_left bit 16 is set if the voice was finished at the same time the function ended */ - int base = new_samples - (samples_left & 0xffff); + voice->ended = false; + + /* if there are leftovers, ramp back to 0 */ + int base = new_samples - samples_left; int i, t = (base == 0) ? curr : m_scratch[base - 1]; - for (i = 0; i < (samples_left & 0xffff); i++) + for (i = 0; i < samples_left; i++) { if (t < 0) t = -((-t * 15) >> 4); else if (t > 0) t = (t * 15) >> 4; @@ -623,6 +612,7 @@ void ymz280b_device::device_start() for (int j = 0; j < 8; j++) { save_item(NAME(m_voice[j].playing), j); + save_item(NAME(m_voice[j].ended), j); save_item(NAME(m_voice[j].keyon), j); save_item(NAME(m_voice[j].looping), j); save_item(NAME(m_voice[j].mode), j); diff --git a/src/emu/sound/ymz280b.h b/src/emu/sound/ymz280b.h index d67895e25a2..6bfa8a4f81e 100644 --- a/src/emu/sound/ymz280b.h +++ b/src/emu/sound/ymz280b.h @@ -55,6 +55,7 @@ private: struct YMZ280BVoice { UINT8 playing; /* 1 if we are actively playing */ + bool ended; /* indicate voice has ended in case samples_left is 0 */ UINT8 keyon; /* 1 if the key is on */ UINT8 looping; /* 1 if looping is enabled */