From d03fcad9bd203e8cf946b5cac5ddc40d6d9c1055 Mon Sep 17 00:00:00 2001 From: Eladash Date: Sun, 8 May 2022 21:09:31 +0300 Subject: [PATCH] cellAudio: Some bugfixes * Reading position storage is 16 bytes aligned according to hw test. * Fix cellAudioGetPortConfig portSize reporting, now matches PS3. * Remove ghost code about unearthly 6 channels cellAudio port mode. --- rpcs3/Emu/Cell/Modules/cellAudio.cpp | 48 +++++++++------------------- rpcs3/Emu/Cell/Modules/cellAudio.h | 5 --- 2 files changed, 15 insertions(+), 38 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellAudio.cpp b/rpcs3/Emu/Cell/Modules/cellAudio.cpp index 3a2d4f7b20..730269227b 100644 --- a/rpcs3/Emu/Cell/Modules/cellAudio.cpp +++ b/rpcs3/Emu/Cell/Modules/cellAudio.cpp @@ -12,7 +12,13 @@ LOG_CHANNEL(cellAudio); vm::gvar g_audio_buffer; -vm::gvar g_audio_indices; +struct alignas(16) aligned_index_t +{ + be_t index; + u8 pad[8]; +}; + +vm::gvar g_audio_indices; template <> void fmt_class_string::format(std::string& out, u64 arg) @@ -335,8 +341,8 @@ void audio_port::tag(s32 offset) // We use -0.0f in case games check if the buffer is empty. -0.0f == 0.0f evaluates to true, but std::signbit can be used to distinguish them const f32 tag = -0.0f; - const u32 tag_first_pos = num_channels == 2 ? PORT_BUFFER_TAG_FIRST_2CH : num_channels == 6 ? PORT_BUFFER_TAG_FIRST_6CH : PORT_BUFFER_TAG_FIRST_8CH; - const u32 tag_delta = num_channels == 2 ? PORT_BUFFER_TAG_DELTA_2CH : num_channels == 6 ? PORT_BUFFER_TAG_DELTA_6CH : PORT_BUFFER_TAG_DELTA_8CH; + const u32 tag_first_pos = num_channels == 2 ? PORT_BUFFER_TAG_FIRST_2CH : PORT_BUFFER_TAG_FIRST_8CH; + const u32 tag_delta = num_channels == 2 ? PORT_BUFFER_TAG_DELTA_2CH : PORT_BUFFER_TAG_DELTA_8CH; for (u32 tag_pos = tag_first_pos, tag_nr = 0; tag_nr < PORT_BUFFER_TAG_COUNT; tag_pos += tag_delta, tag_nr++) { @@ -364,8 +370,8 @@ std::tuple cell_audio_thread::count_port_buffer_tags() auto port_buf = port.get_vm_ptr(); // Find the last tag that has been touched - const u32 tag_first_pos = port.num_channels == 2 ? PORT_BUFFER_TAG_FIRST_2CH : port.num_channels == 6 ? PORT_BUFFER_TAG_FIRST_6CH : PORT_BUFFER_TAG_FIRST_8CH; - const u32 tag_delta = port.num_channels == 2 ? PORT_BUFFER_TAG_DELTA_2CH : port.num_channels == 6 ? PORT_BUFFER_TAG_DELTA_6CH : PORT_BUFFER_TAG_DELTA_8CH; + const u32 tag_first_pos = port.num_channels == 2 ? PORT_BUFFER_TAG_FIRST_2CH : PORT_BUFFER_TAG_FIRST_8CH; + const u32 tag_delta = port.num_channels == 2 ? PORT_BUFFER_TAG_DELTA_2CH : PORT_BUFFER_TAG_DELTA_8CH; u32 last_touched_tag_nr = port.prev_touched_tag_nr; bool retouched = false; @@ -458,7 +464,7 @@ void cell_audio_thread::advance(u64 timestamp) port.timestamp = timestamp; port.cur_pos = port.position(1); - g_audio_indices[port.number] = port.cur_pos; + *port.index = port.cur_pos; } if (cfg.buffering_enabled) @@ -1116,7 +1122,7 @@ error_code cellAudioInit() { g_audio.ports[i].number = i; g_audio.ports[i].addr = g_audio_buffer + AUDIO_PORT_OFFSET * i; - g_audio.ports[i].index = g_audio_indices + i; + g_audio.ports[i].index = (g_audio_indices + i).ptr(&aligned_index_t::index); g_audio.ports[i].state = audio_port_state::closed; } @@ -1234,7 +1240,7 @@ error_code cellAudioPortOpen(vm::ptr audioParam, vm::ptrnum_channels = ::narrow(num_channels); port->num_blocks = ::narrow(num_blocks); port->attr = attr; - port->size = ::narrow(num_channels * num_blocks * port->block_size()); + port->size = ::narrow(num_channels * num_blocks * AUDIO_BUFFER_SAMPLES * sizeof(f32)); port->cur_pos = 0; port->global_counter = g_audio.m_counter; port->active_counter = 0; @@ -1729,18 +1735,6 @@ error_code cellAudioAdd2chData(u32 portNum, vm::ptr src, u32 samples, flo dst[i * 2 + 1] += src[i * 2 + 1] * volume; // mix R ch } } - else if (port.num_channels == 6) - { - for (u32 i = 0; i < samples; i++) - { - dst[i * 6 + 0] += src[i * 2 + 0] * volume; // mix L ch - dst[i * 6 + 1] += src[i * 2 + 1] * volume; // mix R ch - //dst[i * 6 + 2] += 0.0f; // center - //dst[i * 6 + 3] += 0.0f; // LFE - //dst[i * 6 + 4] += 0.0f; // rear L - //dst[i * 6 + 5] += 0.0f; // rear R - } - } else if (port.num_channels == 8) { for (u32 i = 0; i < samples; i++) @@ -1789,19 +1783,7 @@ error_code cellAudioAdd6chData(u32 portNum, vm::ptr src, float volume) volume = std::isfinite(volume) ? std::clamp(volume, -16.f, 16.f) : 0.f; - if (port.num_channels == 6) - { - for (u32 i = 0; i < CELL_AUDIO_BLOCK_SAMPLES; i++) - { - dst[i * 6 + 0] += src[i * 6 + 0] * volume; // mix L ch - dst[i * 6 + 1] += src[i * 6 + 1] * volume; // mix R ch - dst[i * 6 + 2] += src[i * 6 + 2] * volume; // mix center - dst[i * 6 + 3] += src[i * 6 + 3] * volume; // mix LFE - dst[i * 6 + 4] += src[i * 6 + 4] * volume; // mix rear L - dst[i * 6 + 5] += src[i * 6 + 5] * volume; // mix rear R - } - } - else if (port.num_channels == 8) + if (port.num_channels == 8) { for (u32 i = 0; i < CELL_AUDIO_BLOCK_SAMPLES; i++) { diff --git a/rpcs3/Emu/Cell/Modules/cellAudio.h b/rpcs3/Emu/Cell/Modules/cellAudio.h index c9b1f6709a..4cd0c94aff 100644 --- a/rpcs3/Emu/Cell/Modules/cellAudio.h +++ b/rpcs3/Emu/Cell/Modules/cellAudio.h @@ -111,7 +111,6 @@ enum : u32 MAX_AUDIO_EVENT_QUEUES = 64, AUDIO_BLOCK_SIZE_2CH = 2 * AUDIO_BUFFER_SAMPLES, - AUDIO_BLOCK_SIZE_6CH = 6 * AUDIO_BUFFER_SAMPLES, AUDIO_BLOCK_SIZE_8CH = 8 * AUDIO_BUFFER_SAMPLES, PORT_BUFFER_TAG_COUNT = 6, @@ -120,10 +119,6 @@ enum : u32 PORT_BUFFER_TAG_DELTA_2CH = PORT_BUFFER_TAG_LAST_2CH / (PORT_BUFFER_TAG_COUNT - 1), PORT_BUFFER_TAG_FIRST_2CH = PORT_BUFFER_TAG_LAST_2CH % (PORT_BUFFER_TAG_COUNT - 1), - PORT_BUFFER_TAG_LAST_6CH = AUDIO_BLOCK_SIZE_6CH - 1, - PORT_BUFFER_TAG_DELTA_6CH = PORT_BUFFER_TAG_LAST_6CH / (PORT_BUFFER_TAG_COUNT - 1), - PORT_BUFFER_TAG_FIRST_6CH = PORT_BUFFER_TAG_LAST_6CH % (PORT_BUFFER_TAG_COUNT - 1), - PORT_BUFFER_TAG_LAST_8CH = AUDIO_BLOCK_SIZE_8CH - 1, PORT_BUFFER_TAG_DELTA_8CH = PORT_BUFFER_TAG_LAST_8CH / (PORT_BUFFER_TAG_COUNT - 1), PORT_BUFFER_TAG_FIRST_8CH = PORT_BUFFER_TAG_LAST_8CH % (PORT_BUFFER_TAG_COUNT - 1),