[hatari-devel] [PATCH] Tidy YM2149 clock conversion

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


All machines use the integer code path, so remove commented out code,
and coalesce YM2149_UpdateClock_250_int_new into YM2149_UpdateClock_250.

Change ClocksTimings_ConvertCycles signature to take Uint64, since the
caller uses Uint64.

Signed-off-by: Ian Ray <ianjray@xxxxxx>
---
 src/clocks_timings.c          |  2 +-
 src/includes/clocks_timings.h |  2 +-
 src/sound.c                   | 85 +----------------------------------
 3 files changed, 3 insertions(+), 86 deletions(-)

diff --git a/src/clocks_timings.c b/src/clocks_timings.c
index ad80829b..d6bd1f8e 100644
--- a/src/clocks_timings.c
+++ b/src/clocks_timings.c
@@ -555,7 +555,7 @@ Sint64	ClocksTimings_GetSamplesPerVBL ( MACHINETYPE MachineType , int ScreenRefr
  * precise results than using floating point, because there's no roundings that accumulate
  * after a while.
  */
-void	ClocksTimings_ConvertCycles ( Uint32 CyclesIn , Uint64 ClockFreqIn , CLOCKS_CYCLES_STRUCT *CyclesStructOut , Uint64 ClockFreqOut )
+void	ClocksTimings_ConvertCycles ( Uint64 CyclesIn , Uint64 ClockFreqIn , CLOCKS_CYCLES_STRUCT *CyclesStructOut , Uint64 ClockFreqOut )
 {
 	Uint64	CyclesTotal;
 	Uint64	CyclesOut;
diff --git a/src/includes/clocks_timings.h b/src/includes/clocks_timings.h
index 87aea865..98f59c97 100644
--- a/src/includes/clocks_timings.h
+++ b/src/includes/clocks_timings.h
@@ -78,7 +78,7 @@ Uint32	ClocksTimings_GetVBLPerSec ( MACHINETYPE MachineType , int ScreenRefreshR
 Uint32	ClocksTimings_GetVBLDuration_micro ( MACHINETYPE MachineType , int ScreenRefreshRate );
 Sint64	ClocksTimings_GetSamplesPerVBL ( MACHINETYPE MachineType , int ScreenRefreshRate , int AudioFreq );
 
-void	ClocksTimings_ConvertCycles ( Uint32 CyclesIn , Uint64 ClockFreqIn , CLOCKS_CYCLES_STRUCT *CyclesStructOut , Uint64 ClockFreqOut );
+void	ClocksTimings_ConvertCycles ( Uint64 CyclesIn , Uint64 ClockFreqIn , CLOCKS_CYCLES_STRUCT *CyclesStructOut , Uint64 ClockFreqOut );
 
 
 
diff --git a/src/sound.c b/src/sound.c
index 42840ae4..624bb543 100644
--- a/src/sound.c
+++ b/src/sound.c
@@ -797,64 +797,7 @@ static void	Ym2149_BuildVolumeTable(void)
  * After each call the remainder will be saved to be used on the next call
  */
 
-#if 0
-/* integer version : use it when YM2149's clock is the same as CPU's clock (eg STF) */
-
-static void	YM2149_UpdateClock_250_int ( Uint64 CpuClock )
-{
-	Uint64		CpuClockDiff;
-	Uint64		YM_Div;
-	Uint64		YM_Inc;
-
-	/* We divide CpuClockDiff by YM_Div to get a 250 Hz YM clock increment (YM_Div=32 for an STF with a 8 MHz CPU) */
-	YM_Div = 32 << nCpuFreqShift;
-
-//fprintf ( stderr , "ym_div %lu %f\n" , YM_Div , ((double)MachineClocks.CPU_Freq_Emul) / YM_ATARI_CLOCK_COUNTER );
-	/* We update YM2149_Clock_250 only if enough CpuClock units elapsed (at least YM_Div) */
-	CpuClockDiff = CpuClock - YM2149_Clock_250_CpuClock;
-	if ( CpuClockDiff >= YM_Div )
-	{
-		YM_Inc = CpuClockDiff / YM_Div;			/* truncate to lower integer */
-//fprintf ( stderr , "update_250  in div=%lu clock_cpu=%lu cpu_diff=%lu inc=%lu clock_250_in=%lu\n" , YM_Div, CpuClock, CpuClockDiff, YM_Inc, YM2149_Clock_250 );
-		YM2149_Clock_250 += YM_Inc;
-		YM2149_Clock_250_CpuClock = CpuClock - CpuClockDiff % YM_Div;
-//fprintf ( stderr , "update_250 out div=%lu clock_cpu=%lu cpu_diff=%lu inc=%lu clock_250_in=%lu\n" , YM_Div, CpuClock, CpuClockDiff, YM_Inc, YM2149_Clock_250 );
-	}
-
-//fprintf ( stderr , "update_250 clock_cpu=%ld -> ym_inc=%ld clock_250=%ld clock_250_cpu_clock=%ld\n" , CpuClock , YM_Inc , YM2149_Clock_250 , YM2149_Clock_250_CpuClock );
-}
-
-
-
-/* floating point version : use it when YM2149's clock is different from CPU's clock (eg STE) */
-
-static void	YM2149_UpdateClock_250_float ( Uint64 CpuClock )
-{
-	Uint64		CpuClockDiff;
-	double		YM_Div;
-	Uint64		YM_Inc;
-
-	/* We divide CpuClockDiff by YM_Div to get a 250 Hz YM clock increment (YM_Div=32.0425 for an STE with a 8 MHz CPU) */
-	YM_Div = ((double)MachineClocks.CPU_Freq_Emul) / YM_ATARI_CLOCK_COUNTER;
-
-//fprintf ( stderr , "ym_div %f\n" , YM_Div );
-	/* We update YM2149_Clock_250 only if enough CpuClock units elapsed (at least YM_Div) */
-	CpuClockDiff = CpuClock - YM2149_Clock_250_CpuClock;
-	if ( CpuClockDiff >= YM_Div )
-	{
-		YM_Inc = CpuClockDiff / YM_Div;			/* will truncate to lower integer when casting to Uint64 */
-//fprintf ( stderr , "update_250  in div=%f clock_cpu=%lu cpu_diff=%lu inc=%lu clock_250_in=%lu\n" , YM_Div, CpuClock, CpuClockDiff, YM_Inc, YM2149_Clock_250 );
-		YM2149_Clock_250 += YM_Inc;
-		YM2149_Clock_250_CpuClock = CpuClock - round ( fmod ( CpuClockDiff , YM_Div ) );
-//fprintf ( stderr , "update_250 out div=%f clock_cpu=%lu cpu_diff=%lu inc=%lu clock_250_in=%lu\n" , YM_Div, CpuClock, CpuClockDiff, YM_Inc, YM2149_Clock_250 );
-	}
-
-//fprintf ( stderr , "update_250 clock_cpu=%ld -> ym_inc=%ld clock_250=%ld clock_250_cpu_clock=%ld\n" , CpuClock , YM_Inc , YM2149_Clock_250 , YM2149_Clock_250_CpuClock );
-}
-#endif
-
-
-static void	YM2149_UpdateClock_250_int_new ( Uint64 CpuClock )
+static void	YM2149_UpdateClock_250 ( Uint64 CpuClock )
 {
 	Uint64		CpuClockDiff;
 
@@ -864,32 +807,6 @@ static void	YM2149_UpdateClock_250_int_new ( Uint64 CpuClock )
 
 	YM2149_Clock_250 += YM2149_ConvertCycles_250.Cycles;
 	YM2149_Clock_250_CpuClock = CpuClock;
-//fprintf ( stderr , "update_250_new out clock_cpu=%lu cpu_diff=%lu inc=%lu rem=%lu clock_250_in=%lu\n" , CpuClock, CpuClockDiff, YM2149_ConvertCycles_250.Cycles, YM2149_ConvertCycles_250.Remainder , YM2149_Clock_250 );
-
-
-//fprintf ( stderr , "update_250 clock_cpu=%ld -> ym_inc=%ld clock_250=%ld clock_250_cpu_clock=%ld\n" , CpuClock , YM2149_ConvertCycles_250.Cycles , YM2149_Clock_250 , YM2149_Clock_250_CpuClock );
-}
-
-
-/*
- * In case of STF/MegaST, we use the 'integer' version that should give less rounding
- * than the 'floating point' version. It should slightly faster too.
- * For other machines, we use the 'floating point' version because CPU and YM/DMA Audio don't
- * share the same clock.
- *
- * In the end, 'integer' and 'floating point' versions will sound the same because
- * floating point precision should be good enough to avoid rounding errors.
- */
-static void	YM2149_UpdateClock_250 ( Uint64 CpuClock )
-{
-	if ( ConfigureParams.System.nMachineType == MACHINE_ST || ConfigureParams.System.nMachineType == MACHINE_MEGA_ST )
-{
-//		YM2149_UpdateClock_250_int ( CpuClock );
-		YM2149_UpdateClock_250_int_new ( CpuClock );
-}
-	else
-//		YM2149_UpdateClock_250_float ( CpuClock );
-		YM2149_UpdateClock_250_int_new ( CpuClock );
 }
 
 
-- 
2.37.0 (Apple Git-136)




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/