# HG changeset patch # User Michael Pavone # Date 1446106008 25200 # Node ID 9a5dc22297f2b78184c843e912294c5b030a39e0 # Parent f2cd380adebe3ea4f8c01e965f48a171dce4221d Somewhat better handling of high frequency PSG tones. Needs work to fully handle case where frequency > half our output sample rate diff -r f2cd380adebe -r 9a5dc22297f2 psg.c --- a/psg.c Wed Oct 28 19:45:24 2015 -0700 +++ b/psg.c Thu Oct 29 01:06:48 2015 -0700 @@ -8,6 +8,9 @@ #include "blastem.h" #include #include +#include + +FILE *blah; void psg_init(psg_context * context, uint32_t sample_rate, uint32_t master_clock, uint32_t clock_div, uint32_t samples_frame) { @@ -21,6 +24,7 @@ for (int i = 0; i < 4; i++) { context->volume[i] = 0xF; } + blah = fopen("psg.raw", "wb"); } #define BUFFER_INC_RES 1000000000UL @@ -105,20 +109,25 @@ } } } + + for (int i = 0; i < 3; i++) { + if (context->output_state[i]) { + context->accum += volume_table[context->volume[i]]; + } + } + if (context->noise_out) { + context->accum += volume_table[context->volume[3]]; + } + context->sample_count++; + context->buffer_fraction += context->buffer_inc; if (context->buffer_fraction >= BUFFER_INC_RES) { context->buffer_fraction -= BUFFER_INC_RES; - int16_t acc = 0; - for (int i = 0; i < 3; i++) { - if (context->output_state[i]) { - acc += volume_table[context->volume[i]]; - } - } - if (context->noise_out) { - acc += volume_table[context->volume[3]]; - } - context->audio_buffer[context->buffer_pos++] = acc; + + context->audio_buffer[context->buffer_pos++] = context->accum / context->sample_count; + context->accum = context->sample_count = 0; if (context->buffer_pos == context->samples_frame) { + fwrite(context->audio_buffer, 1, context->buffer_pos, blah); if (!headless) { render_wait_psg(context); } diff -r f2cd380adebe -r 9a5dc22297f2 psg.h --- a/psg.h Wed Oct 28 19:45:24 2015 -0700 +++ b/psg.h Thu Oct 29 01:06:48 2015 -0700 @@ -21,6 +21,8 @@ uint16_t lsfr; uint16_t counter_load[4]; uint16_t counters[4]; + int16_t accum; + int16_t sample_count; uint8_t volume[4]; uint8_t output_state[4]; uint8_t noise_out;