comparison ym2612.c @ 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 24ebabd89162
children 6a14c5a95648
comparison
equal deleted inserted replaced
520:6e9d1a8c1b08 521:7565ec2ac652
468 if (context->buffer_fraction > BUFFER_INC_RES) { 468 if (context->buffer_fraction > BUFFER_INC_RES) {
469 context->buffer_fraction -= BUFFER_INC_RES; 469 context->buffer_fraction -= BUFFER_INC_RES;
470 context->audio_buffer[context->buffer_pos] = 0; 470 context->audio_buffer[context->buffer_pos] = 0;
471 context->audio_buffer[context->buffer_pos + 1] = 0; 471 context->audio_buffer[context->buffer_pos + 1] = 0;
472 for (int i = 0; i < NUM_CHANNELS; i++) { 472 for (int i = 0; i < NUM_CHANNELS; i++) {
473 int16_t value = context->channels[i].output & 0x3FE0; 473 int16_t value = context->channels[i].output;
474 if (value & 0x2000) { 474 if (value > 0x1FE0) {
475 value |= 0xC000; 475 value = 0x1FE0;
476 } else if (value < -0x1FF0) {
477 value = -0x1FF0;
478 } else {
479 value &= 0x3FE0;
480 if (value & 0x2000) {
481 value |= 0xC000;
482 }
476 } 483 }
477 if (context->channels[i].logfile) { 484 if (context->channels[i].logfile) {
478 fwrite(&value, sizeof(value), 1, context->channels[i].logfile); 485 fwrite(&value, sizeof(value), 1, context->channels[i].logfile);
479 } 486 }
480 if (context->channels[i].lr & 0x80) { 487 if (context->channels[i].lr & 0x80) {