Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cellAudioPortOpen/Timestamp fix #10763

Merged
merged 2 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions rpcs3/Emu/Cell/Modules/cellAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<u64>(play_timestamp, update_timestamp) : 0);

const u64 delta_samples_tmp = play_delta * static_cast<u64>(cfg.audio_sampling_rate * frequency_ratio) + last_remainder;
last_remainder = delta_samples_tmp % 1'000'000;
Expand Down Expand Up @@ -1237,7 +1237,7 @@ error_code cellAudioPortOpen(vm::ptr<CellAudioPortParam> audioParam, vm::ptr<u32
port->cur_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)
{
Expand Down Expand Up @@ -1419,7 +1419,7 @@ error_code cellAudioGetPortTimestamp(u32 portNum, u64 tag, vm::ptr<u64> 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;
}
Expand Down
10 changes: 7 additions & 3 deletions rpcs3/Emu/Cell/lv2/sys_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

#include "util/asm.hpp"

u64 timebase_offset;
static u64 timebase_offset;
static u64 systemtime_offset;

#ifdef _WIN32

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/timers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);