summaryrefslogtreecommitdiff
path: root/psg.c
diff options
context:
space:
mode:
authorMike Pavone <pavone@retrodev.com>2013-06-03 21:43:38 -0700
committerMike Pavone <pavone@retrodev.com>2013-06-03 21:43:38 -0700
commit8bd4d9e1e46a0e4277e61a7c999de9423df8ef92 (patch)
treeef5cb2916d075c81df0f9e211aa369ae6e3d5d4f /psg.c
parent46b12a3e87fbe5608da7e4766114b9ccbc3c2f1c (diff)
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.
Diffstat (limited to 'psg.c')
-rw-r--r--psg.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/psg.c b/psg.c
index 1052436..815784a 100644
--- a/psg.c
+++ b/psg.c
@@ -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 @@ void psg_run(psg_context * context, uint32_t cycles)
render_wait_psg(context);
}
}
- context->cycles++;
+ context->cycles += context->clock_inc;
}
}