From 8bd4d9e1e46a0e4277e61a7c999de9423df8ef92 Mon Sep 17 00:00:00 2001 From: Mike Pavone Date: Mon, 3 Jun 2013 21:43:38 -0700 Subject: Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run. --- psg.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'psg.c') diff --git a/psg.c b/psg.c index 1052436..815784a 100644 --- a/psg.c +++ b/psg.c @@ -3,12 +3,14 @@ #include #include -void psg_init(psg_context * context, uint32_t sample_rate, uint32_t clock_rate, uint32_t samples_frame) +void psg_init(psg_context * context, uint32_t sample_rate, uint32_t master_clock, uint32_t clock_div, uint32_t samples_frame) { memset(context, 0, sizeof(*context)); context->audio_buffer = malloc(sizeof(*context->audio_buffer) * samples_frame); context->back_buffer = malloc(sizeof(*context->audio_buffer) * samples_frame); - context->buffer_inc = (double)sample_rate / (double)clock_rate; + double clock_rate = (double)master_clock / (double)clock_div; + context->buffer_inc = ((double)sample_rate / (double)master_clock) * clock_div; + context->clock_inc = clock_div; context->samples_frame = samples_frame; for (int i = 0; i < 4; i++) { context->volume[i] = 0xF; @@ -106,7 +108,7 @@ void psg_run(psg_context * context, uint32_t cycles) render_wait_psg(context); } } - context->cycles++; + context->cycles += context->clock_inc; } } -- cgit v1.2.3