From 38d5f688b3428da3433dc43db838821b866c367f Mon Sep 17 00:00:00 2001 From: Eladash Date: Wed, 25 Aug 2021 15:26:41 +0300 Subject: [PATCH] cellAudio fix --- rpcs3/Emu/Cell/Modules/cellAudio.cpp | 8 ++++---- rpcs3/Emu/Cell/lv2/sys_time.cpp | 10 +++++++--- rpcs3/Emu/Cell/timers.hpp | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellAudio.cpp b/rpcs3/Emu/Cell/Modules/cellAudio.cpp index 670d40f41c..ab6bd02d3a 100644 --- a/rpcs3/Emu/Cell/Modules/cellAudio.cpp +++ b/rpcs3/Emu/Cell/Modules/cellAudio.cpp @@ -161,7 +161,7 @@ f32 audio_ringbuffer::set_frequency_ratio(f32 new_ratio) u64 audio_ringbuffer::get_timestamp() { - return get_system_time() - Emu.GetPauseTime(); + return get_system_time(); } void audio_ringbuffer::enqueue(const float* in_buffer) @@ -296,7 +296,7 @@ u64 audio_ringbuffer::update() } else { - const u64 play_delta = timestamp - (play_timestamp > update_timestamp ? play_timestamp : update_timestamp); + const u64 play_delta = (update_timestamp ? timestamp - std::max(play_timestamp, update_timestamp) : 0); const u64 delta_samples_tmp = play_delta * static_cast(cfg.audio_sampling_rate * frequency_ratio) + last_remainder; last_remainder = delta_samples_tmp % 1'000'000; @@ -1237,7 +1237,7 @@ error_code cellAudioPortOpen(vm::ptr audioParam, vm::ptrcur_pos = 0; port->global_counter = g_audio.m_counter; port->active_counter = 0; - port->timestamp = g_audio.m_last_period_end; + port->timestamp = get_guest_system_time(g_audio.m_last_period_end); if (attr & CELL_AUDIO_PORTATTR_INITLEVEL) { @@ -1419,7 +1419,7 @@ error_code cellAudioGetPortTimestamp(u32 portNum, u64 tag, vm::ptr stamp) const u64 delta_tag_stamp = delta_tag * g_audio.cfg.audio_block_period; // Apparently no error is returned if stamp is null - *stamp = port.timestamp - delta_tag_stamp; + *stamp = get_guest_system_time(port.timestamp - delta_tag_stamp); return CELL_OK; } diff --git a/rpcs3/Emu/Cell/lv2/sys_time.cpp b/rpcs3/Emu/Cell/lv2/sys_time.cpp index 178aaa429a..f2f4eea393 100644 --- a/rpcs3/Emu/Cell/lv2/sys_time.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_time.cpp @@ -6,7 +6,8 @@ #include "util/asm.hpp" -u64 timebase_offset; +static u64 timebase_offset; +static u64 systemtime_offset; #ifdef _WIN32 @@ -157,6 +158,7 @@ void initalize_timebased_time() { timebase_offset = 0; timebase_offset = get_timebased_time(); + systemtime_offset = timebase_offset / (g_timebase_freq / 1000000); } // Returns some relative time in microseconds, don't change this fact @@ -184,9 +186,11 @@ u64 get_system_time() } // As get_system_time but obeys Clocks scaling setting -u64 get_guest_system_time() +u64 get_guest_system_time(u64 time) { - return get_system_time() * g_cfg.core.clocks_scale / 100; + const u64 result = (time != umax ? time : get_system_time()) * g_cfg.core.clocks_scale / 100; + ensure(result >= systemtime_offset); + return result - systemtime_offset; } // Functions diff --git a/rpcs3/Emu/Cell/timers.hpp b/rpcs3/Emu/Cell/timers.hpp index ee9b58bb69..ec6c2d04eb 100644 --- a/rpcs3/Emu/Cell/timers.hpp +++ b/rpcs3/Emu/Cell/timers.hpp @@ -5,4 +5,4 @@ u64 get_timebased_time(); void initalize_timebased_time(); u64 get_system_time(); -u64 get_guest_system_time(); +u64 get_guest_system_time(u64 time = umax);