Mercurial > repos > blastem
diff psg.c @ 380:1c8d74f2ab0b
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.
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 03 Jun 2013 21:43:38 -0700 |
parents | 62177cc39049 |
children | 41c079dbee73 |
line wrap: on
line diff
--- a/psg.c Sun Jun 02 22:37:48 2013 -0700 +++ b/psg.c Mon Jun 03 21:43:38 2013 -0700 @@ -3,12 +3,14 @@ #include <string.h> #include <stdlib.h> -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 @@ render_wait_psg(context); } } - context->cycles++; + context->cycles += context->clock_inc; } }