Skip to content

Commit

Permalink
cellAudio fix
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 committed Sep 10, 2021
1 parent f98595b commit 15ffdba
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
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
8 changes: 5 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,9 @@ 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;
return (time != umax ? time : get_system_time()) * g_cfg.core.clocks_scale / 100 - 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);

0 comments on commit 15ffdba

Please sign in to comment.