Mercurial > repos > blastem
changeset 521:7565ec2ac652
Fix overflow handling on FM channel output
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 11 Feb 2014 12:45:43 -0800 |
parents | 6e9d1a8c1b08 |
children | 6a14c5a95648 |
files | ym2612.c |
diffstat | 1 files changed, 10 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/ym2612.c Tue Feb 11 12:45:15 2014 -0800 +++ b/ym2612.c Tue Feb 11 12:45:43 2014 -0800 @@ -470,9 +470,16 @@ context->audio_buffer[context->buffer_pos] = 0; context->audio_buffer[context->buffer_pos + 1] = 0; for (int i = 0; i < NUM_CHANNELS; i++) { - int16_t value = context->channels[i].output & 0x3FE0; - if (value & 0x2000) { - value |= 0xC000; + int16_t value = context->channels[i].output; + if (value > 0x1FE0) { + value = 0x1FE0; + } else if (value < -0x1FF0) { + value = -0x1FF0; + } else { + value &= 0x3FE0; + if (value & 0x2000) { + value |= 0xC000; + } } if (context->channels[i].logfile) { fwrite(&value, sizeof(value), 1, context->channels[i].logfile);