[hatari-devel] [PATCH] Tidy YM2149 clock conversion |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/hatari-devel Archives
]
- To: hatari-devel@xxxxxxxxxxxxxxxxxxx
- Subject: [hatari-devel] [PATCH] Tidy YM2149 clock conversion
- From: Ian Ray <ianjray@xxxxxx>
- Date: Sat, 17 Sep 2022 12:44:02 +0300
- Cc: Ian Ray <ianjray@xxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1663407854; bh=qZ+LqWOB/6XvMfKINmt4Bbxm/KCwtNUU85FPPV7D4e0=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=fWpdd5Jwp1oK6ZzyXR7sg/fE3DV/vv6IgWPB/fJEuO+MlMShnZBLHlzqqOYCZjhw+ yjt81q+BxTPpN1UK8Y9/hNPvJsIqlcpn5nud2kTs5Kb+41ujxguANmNuzL4Avcvcnv 4VNVKjIJdTfBfVabtvGJ14pXAsvzyLw3VMS2DgEM8QE3QYKYISqVQVxXzn3QKZyeqi br1xt1ThqzDBN9DXnEH8+rvdczJPgb/sqlksYSS2kZ3JB7L3blO+RNuFnG6dRc4SnR Tp/kr+v9RyMC0qM+EKIB4KWR7oQmkwCRqIzI6okf0xQa7KQg78XsqM0NZBNEcqZ5U8 sqBJM38A6eqTQ==
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)