summaryrefslogtreecommitdiff
path: root/psg.c
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2016-04-19 00:38:44 -0700
committerMichael Pavone <pavone@retrodev.com>2016-04-19 00:38:44 -0700
commit38a8d12e41a45a75618f13944124f37dd30f47c3 (patch)
tree238fdb0afc02f9096eeb1211df3acbd99c5790e0 /psg.c
parent112c7326f0a2ba30625e1fb38952d638edfea161 (diff)
Not so successful attempt at improved PSG resampling
Diffstat (limited to 'psg.c')
-rw-r--r--psg.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/psg.c b/psg.c
index a33aa7c..8d43190 100644
--- a/psg.c
+++ b/psg.c
@@ -33,7 +33,7 @@ void psg_free(psg_context *context)
free(context);
}
-#define BUFFER_INC_RES 1000000000UL
+#define BUFFER_INC_RES 0x40000000UL
void psg_adjust_master_clock(psg_context * context, uint32_t master_clock)
{
@@ -116,6 +116,9 @@ void psg_run(psg_context * context, uint32_t cycles)
}
}
+ context->last_sample = context->accum;
+ context->accum = 0;
+
for (int i = 0; i < 3; i++) {
if (context->output_state[i]) {
context->accum += volume_table[context->volume[i]];
@@ -129,9 +132,13 @@ void psg_run(psg_context * context, uint32_t cycles)
context->buffer_fraction += context->buffer_inc;
if (context->buffer_fraction >= BUFFER_INC_RES) {
context->buffer_fraction -= BUFFER_INC_RES;
+ uint32_t tmp = context->last_sample * (0x10000 - ((context->buffer_fraction << 16) / context->buffer_inc));
+ tmp += context->accum * ((context->buffer_fraction << 16) / context->buffer_inc);
+ printf("Last: %d, Cur: %d, Fraction: %d, Inc: %d, Result: %d, Samples: %d, Float: %f, Fixed: %X\n",
+ context->last_sample, context->accum, (int)context->buffer_fraction, (int)context->buffer_inc, tmp >> 16, context->sample_count, (float)context->buffer_fraction/(float)context->buffer_inc, (int)((context->buffer_fraction << 16) / context->buffer_inc));
- context->audio_buffer[context->buffer_pos++] = context->accum / context->sample_count;
- context->accum = context->sample_count = 0;
+ context->audio_buffer[context->buffer_pos++] = tmp >> 16;
+ context->sample_count = 0;
if (context->buffer_pos == context->samples_frame) {
if (!headless) {
render_wait_psg(context);