diff options
author | Michael Pavone <pavone@retrodev.com> | 2014-02-11 12:45:43 -0800 |
---|---|---|
committer | Michael Pavone <pavone@retrodev.com> | 2014-02-11 12:45:43 -0800 |
commit | 94a138521f2ac37d238ca75ee0a052587fcfad87 (patch) | |
tree | 5ed56adcdd1909f4754282053851e8bef4e26e6a /ym2612.c | |
parent | 8a2df056c2612b1ce4748b46a194c3e07722986c (diff) |
Fix overflow handling on FM channel output
Diffstat (limited to 'ym2612.c')
-rw-r--r-- | ym2612.c | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -470,9 +470,16 @@ void ym_run(ym2612_context * context, uint32_t to_cycle) 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); |