changeset 2255:74112041b2c7

Proper calculation of sample rate for YM2612/PSG oscilloscope view
author Michael Pavone <pavone@retrodev.com>
date Mon, 12 Dec 2022 22:26:56 -0800
parents 8b88d57d1218
children cbe1ba70c247
files genesis.c psg.c psg.h ym2612.c ym2612.h
diffstat 5 files changed, 8 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/genesis.c	Mon Dec 12 21:49:51 2022 -0800
+++ b/genesis.c	Mon Dec 12 22:26:56 2022 -0800
@@ -1733,8 +1733,8 @@
 			scope_close(scope);
 		} else {
 			oscilloscope *scope = create_oscilloscope();
-			ym_enable_scope(gen->ym, scope);
-			psg_enable_scope(gen->psg, scope);
+			ym_enable_scope(gen->ym, scope, gen->normal_clock);
+			psg_enable_scope(gen->psg, scope, gen->normal_clock);
 			if (gen->expansion) {
 				segacd_context *cd = gen->expansion;
 				rf5c164_enable_scope(&cd->pcm, scope);
--- a/psg.c	Mon Dec 12 21:49:51 2022 -0800
+++ b/psg.c	Mon Dec 12 22:26:56 2022 -0800
@@ -21,7 +21,7 @@
 	context->pan = 0xFF;
 }
 
-void psg_enable_scope(psg_context *context, oscilloscope *scope)
+void psg_enable_scope(psg_context *context, oscilloscope *scope, uint32_t master_clock)
 {
 	context->scope = scope;
 	static const char *names[] = {
@@ -32,7 +32,7 @@
 	};
 	for (int i = 0; i < 4; i++)
 	{
-		context->scope_channel[i] = scope_add_channel(scope, names[i], 53693175 / context->clock_inc);
+		context->scope_channel[i] = scope_add_channel(scope, names[i], master_clock / context->clock_inc);
 	}
 }
 
--- a/psg.h	Mon Dec 12 21:49:51 2022 -0800
+++ b/psg.h	Mon Dec 12 22:26:56 2022 -0800
@@ -33,7 +33,7 @@
 
 
 void psg_init(psg_context * context, uint32_t master_clock, uint32_t clock_div);
-void psg_enable_scope(psg_context *context, oscilloscope *scope);
+void psg_enable_scope(psg_context *context, oscilloscope *scope, uint32_t master_clock);
 void psg_free(psg_context *context);
 void psg_adjust_master_clock(psg_context * context, uint32_t master_clock);
 void psg_write(psg_context * context, uint8_t value);
--- a/ym2612.c	Mon Dec 12 21:49:51 2022 -0800
+++ b/ym2612.c	Mon Dec 12 22:26:56 2022 -0800
@@ -1397,7 +1397,7 @@
 	}
 }
 
-void ym_enable_scope(ym2612_context *context, oscilloscope *scope)
+void ym_enable_scope(ym2612_context *context, oscilloscope *scope, uint32_t master_clock)
 {
 	static const char *names[] = {
 		"YM2612 #1",
@@ -1410,7 +1410,6 @@
 	context->scope = scope;
 	for (int i = 0; i < NUM_CHANNELS; i++)
 	{
-		//TODO: calculate actual sample rate based on current clock settings
-		context->channels[i].scope_channel = scope_add_channel(scope, names[i], 53267);
+		context->channels[i].scope_channel = scope_add_channel(scope, names[i], master_clock / (context->clock_inc * NUM_OPERATORS));
 	}
 }
--- a/ym2612.h	Mon Dec 12 21:49:51 2022 -0800
+++ b/ym2612.h	Mon Dec 12 22:26:56 2022 -0800
@@ -159,7 +159,7 @@
 void ym_print_timer_info(ym2612_context *context);
 void ym_serialize(ym2612_context *context, serialize_buffer *buf);
 void ym_deserialize(deserialize_buffer *buf, void *vcontext);
-void ym_enable_scope(ym2612_context *context, oscilloscope *scope);
+void ym_enable_scope(ym2612_context *context, oscilloscope *scope, uint32_t master_clock);
 
 #endif //YM2612_H_