diff options
author | Michael Pavone <pavone@retrodev.com> | 2015-10-29 01:06:48 -0700 |
---|---|---|
committer | Michael Pavone <pavone@retrodev.com> | 2015-10-29 01:06:48 -0700 |
commit | 3a8f89cb47c0715d091dde6e317cebf9a4796778 (patch) | |
tree | 7cfc6815bf7af3cc8578d24c152babd28d00a9bc | |
parent | 0a372b26313bf60fe7afedfcfeea20149f2b4399 (diff) |
Somewhat better handling of high frequency PSG tones. Needs work to fully handle case where frequency > half our output sample rate
-rw-r--r-- | psg.c | 29 | ||||
-rw-r--r-- | psg.h | 2 |
2 files changed, 21 insertions, 10 deletions
@@ -8,6 +8,9 @@ #include "blastem.h" #include <string.h> #include <stdlib.h> +#include <stdio.h> + +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 @@ void psg_init(psg_context * context, uint32_t sample_rate, uint32_t master_clock 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 @@ void psg_run(psg_context * context, uint32_t cycles) } } } + + 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); } @@ -21,6 +21,8 @@ typedef struct { 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; |