# HG changeset patch # User Michael Pavone # Date 1392184335 28800 # Node ID 450c7745379ac1e4d23aff8bc8c58890f0221f7e # Parent 6a14c5a95648ea85d4dbb33df4678eae6bb1bf59# Parent 0b21a1a73fb7d193522606a28eea1981344d88c3 Merge diff -r 0b21a1a73fb7 -r 450c7745379a psg.c --- a/psg.c Sun Feb 09 17:16:55 2014 -0800 +++ b/psg.c Tue Feb 11 21:52:15 2014 -0800 @@ -74,7 +74,7 @@ } } -#define PSG_VOL_DIV 6 +#define PSG_VOL_DIV 14 //table shamelessly swiped from PSG doc from smspower.org int16_t volume_table[16] = { diff -r 0b21a1a73fb7 -r 450c7745379a wave.c --- a/wave.c Sun Feb 09 17:16:55 2014 -0800 +++ b/wave.c Tue Feb 11 21:52:15 2014 -0800 @@ -1,6 +1,6 @@ /* Copyright 2013 Michael Pavone - This file is part of BlastEm. + This file is part of BlastEm. BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. */ #include "wave.h" @@ -31,13 +31,13 @@ uint32_t size = ftell(f); fseek(f, offsetof(wave_header, chunk.size), SEEK_SET); size -= 8; - if (fwrite(&size, sizeof(size), 1, f) != sizeof(size)) { + if (fwrite(&size, sizeof(size), 1, f) != 1) { fclose(f); return 0; } fseek(f, offsetof(wave_header, data_header.size), SEEK_SET); size -= 36; - if (fwrite(&size, sizeof(size), 1, f)) { + if (fwrite(&size, sizeof(size), 1, f) != 1) { fclose(f); return 0; } diff -r 0b21a1a73fb7 -r 450c7745379a ym2612.c --- a/ym2612.c Sun Feb 09 17:16:55 2014 -0800 +++ b/ym2612.c Tue Feb 11 21:52:15 2014 -0800 @@ -232,7 +232,8 @@ } } -#define YM_VOLUME_DIVIDER 2 +#define YM_VOLUME_MULTIPLIER 2 +#define YM_VOLUME_DIVIDER 3 #define YM_MOD_SHIFT 1 #define TIMER_A_MAX 1023 @@ -455,7 +456,7 @@ if (value & 0x2000) { value |= 0xC000; } - dfprintf(debug_file, "channel %d output: %d\n", channel, value / YM_VOLUME_DIVIDER); + dfprintf(debug_file, "channel %d output: %d\n", channel, (value * YM_VOLUME_MULTIPLIER) / YM_VOLUME_DIVIDER); } } //puts("operator update done"); @@ -470,18 +471,25 @@ 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); } if (context->channels[i].lr & 0x80) { - context->audio_buffer[context->buffer_pos] += value / YM_VOLUME_DIVIDER; + context->audio_buffer[context->buffer_pos] += (value * YM_VOLUME_MULTIPLIER) / YM_VOLUME_DIVIDER; } if (context->channels[i].lr & 0x40) { - context->audio_buffer[context->buffer_pos+1] += value / YM_VOLUME_DIVIDER; + context->audio_buffer[context->buffer_pos+1] += (value * YM_VOLUME_MULTIPLIER) / YM_VOLUME_DIVIDER; } } context->buffer_pos += 2;