summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--psg.c2
-rw-r--r--wave.c6
-rw-r--r--ym2612.c22
3 files changed, 19 insertions, 11 deletions
diff --git a/psg.c b/psg.c
index cb5e8ce..083d7d5 100644
--- a/psg.c
+++ b/psg.c
@@ -74,7 +74,7 @@ void psg_write(psg_context * context, uint8_t value)
}
}
-#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 --git a/wave.c b/wave.c
index af0b8b7..9a9171f 100644
--- a/wave.c
+++ b/wave.c
@@ -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 @@ int wave_finalize(FILE * f)
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 --git a/ym2612.c b/ym2612.c
index 978dc95..4943cee 100644
--- a/ym2612.c
+++ b/ym2612.c
@@ -232,7 +232,8 @@ void ym_init(ym2612_context * context, uint32_t sample_rate, uint32_t master_clo
}
}
-#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 @@ void ym_run(ym2612_context * context, uint32_t to_cycle)
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 @@ 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);
}
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;