mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-12-25 10:52:48 -06:00
commit
e5fed31009
17 changed files with 889 additions and 884 deletions
5
.git-blame-ignore-revs
Normal file
5
.git-blame-ignore-revs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# SPDX-FileCopyrightText: 2023 yuzu Emulator Project
|
||||||
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
# CRLF -> LF
|
||||||
|
90aa937593e53a5d5e070fb623b228578b0b225f
|
|
@ -1,107 +1,107 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include "audio_core/adsp/apps/opus/opus_decode_object.h"
|
#include "audio_core/adsp/apps/opus/opus_decode_object.h"
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
|
|
||||||
namespace AudioCore::ADSP::OpusDecoder {
|
namespace AudioCore::ADSP::OpusDecoder {
|
||||||
namespace {
|
namespace {
|
||||||
bool IsValidChannelCount(u32 channel_count) {
|
bool IsValidChannelCount(u32 channel_count) {
|
||||||
return channel_count == 1 || channel_count == 2;
|
return channel_count == 1 || channel_count == 2;
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
u32 OpusDecodeObject::GetWorkBufferSize(u32 channel_count) {
|
u32 OpusDecodeObject::GetWorkBufferSize(u32 channel_count) {
|
||||||
if (!IsValidChannelCount(channel_count)) {
|
if (!IsValidChannelCount(channel_count)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return static_cast<u32>(sizeof(OpusDecodeObject)) + opus_decoder_get_size(channel_count);
|
return static_cast<u32>(sizeof(OpusDecodeObject)) + opus_decoder_get_size(channel_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
OpusDecodeObject& OpusDecodeObject::Initialize(u64 buffer, u64 buffer2) {
|
OpusDecodeObject& OpusDecodeObject::Initialize(u64 buffer, u64 buffer2) {
|
||||||
auto* new_decoder = reinterpret_cast<OpusDecodeObject*>(buffer);
|
auto* new_decoder = reinterpret_cast<OpusDecodeObject*>(buffer);
|
||||||
auto* comparison = reinterpret_cast<OpusDecodeObject*>(buffer2);
|
auto* comparison = reinterpret_cast<OpusDecodeObject*>(buffer2);
|
||||||
|
|
||||||
if (new_decoder->magic == DecodeObjectMagic) {
|
if (new_decoder->magic == DecodeObjectMagic) {
|
||||||
if (!new_decoder->initialized ||
|
if (!new_decoder->initialized ||
|
||||||
(new_decoder->initialized && new_decoder->self == comparison)) {
|
(new_decoder->initialized && new_decoder->self == comparison)) {
|
||||||
new_decoder->state_valid = true;
|
new_decoder->state_valid = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
new_decoder->initialized = false;
|
new_decoder->initialized = false;
|
||||||
new_decoder->state_valid = true;
|
new_decoder->state_valid = true;
|
||||||
}
|
}
|
||||||
return *new_decoder;
|
return *new_decoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 OpusDecodeObject::InitializeDecoder(u32 sample_rate, u32 channel_count) {
|
s32 OpusDecodeObject::InitializeDecoder(u32 sample_rate, u32 channel_count) {
|
||||||
if (!state_valid) {
|
if (!state_valid) {
|
||||||
return OPUS_INVALID_STATE;
|
return OPUS_INVALID_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (initialized) {
|
if (initialized) {
|
||||||
return OPUS_OK;
|
return OPUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unfortunately libopus does not expose the OpusDecoder struct publicly, so we can't include
|
// Unfortunately libopus does not expose the OpusDecoder struct publicly, so we can't include
|
||||||
// it in this class. Nintendo does not allocate memory, which is why we have a workbuffer
|
// it in this class. Nintendo does not allocate memory, which is why we have a workbuffer
|
||||||
// provided.
|
// provided.
|
||||||
// We could use _create and have libopus allocate it for us, but then we have to separately
|
// We could use _create and have libopus allocate it for us, but then we have to separately
|
||||||
// track which decoder is being used between this and multistream in order to call the correct
|
// track which decoder is being used between this and multistream in order to call the correct
|
||||||
// destroy from the host side.
|
// destroy from the host side.
|
||||||
// This is a bit cringe, but is safe as these objects are only ever initialized inside the given
|
// This is a bit cringe, but is safe as these objects are only ever initialized inside the given
|
||||||
// workbuffer, and GetWorkBufferSize will guarantee there's enough space to follow.
|
// workbuffer, and GetWorkBufferSize will guarantee there's enough space to follow.
|
||||||
decoder = (LibOpusDecoder*)(this + 1);
|
decoder = (LibOpusDecoder*)(this + 1);
|
||||||
s32 ret = opus_decoder_init(decoder, sample_rate, channel_count);
|
s32 ret = opus_decoder_init(decoder, sample_rate, channel_count);
|
||||||
if (ret == OPUS_OK) {
|
if (ret == OPUS_OK) {
|
||||||
magic = DecodeObjectMagic;
|
magic = DecodeObjectMagic;
|
||||||
initialized = true;
|
initialized = true;
|
||||||
state_valid = true;
|
state_valid = true;
|
||||||
self = this;
|
self = this;
|
||||||
final_range = 0;
|
final_range = 0;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 OpusDecodeObject::Shutdown() {
|
s32 OpusDecodeObject::Shutdown() {
|
||||||
if (!state_valid) {
|
if (!state_valid) {
|
||||||
return OPUS_INVALID_STATE;
|
return OPUS_INVALID_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (initialized) {
|
if (initialized) {
|
||||||
magic = 0x0;
|
magic = 0x0;
|
||||||
initialized = false;
|
initialized = false;
|
||||||
state_valid = false;
|
state_valid = false;
|
||||||
self = nullptr;
|
self = nullptr;
|
||||||
final_range = 0;
|
final_range = 0;
|
||||||
decoder = nullptr;
|
decoder = nullptr;
|
||||||
}
|
}
|
||||||
return OPUS_OK;
|
return OPUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 OpusDecodeObject::ResetDecoder() {
|
s32 OpusDecodeObject::ResetDecoder() {
|
||||||
return opus_decoder_ctl(decoder, OPUS_RESET_STATE);
|
return opus_decoder_ctl(decoder, OPUS_RESET_STATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 OpusDecodeObject::Decode(u32& out_sample_count, u64 output_data, u64 output_data_size,
|
s32 OpusDecodeObject::Decode(u32& out_sample_count, u64 output_data, u64 output_data_size,
|
||||||
u64 input_data, u64 input_data_size) {
|
u64 input_data, u64 input_data_size) {
|
||||||
ASSERT(initialized);
|
ASSERT(initialized);
|
||||||
out_sample_count = 0;
|
out_sample_count = 0;
|
||||||
|
|
||||||
if (!state_valid) {
|
if (!state_valid) {
|
||||||
return OPUS_INVALID_STATE;
|
return OPUS_INVALID_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ret_code_or_samples = opus_decode(
|
auto ret_code_or_samples = opus_decode(
|
||||||
decoder, reinterpret_cast<const u8*>(input_data), static_cast<opus_int32>(input_data_size),
|
decoder, reinterpret_cast<const u8*>(input_data), static_cast<opus_int32>(input_data_size),
|
||||||
reinterpret_cast<opus_int16*>(output_data), static_cast<opus_int32>(output_data_size), 0);
|
reinterpret_cast<opus_int16*>(output_data), static_cast<opus_int32>(output_data_size), 0);
|
||||||
|
|
||||||
if (ret_code_or_samples < OPUS_OK) {
|
if (ret_code_or_samples < OPUS_OK) {
|
||||||
return ret_code_or_samples;
|
return ret_code_or_samples;
|
||||||
}
|
}
|
||||||
|
|
||||||
out_sample_count = ret_code_or_samples;
|
out_sample_count = ret_code_or_samples;
|
||||||
return opus_decoder_ctl(decoder, OPUS_GET_FINAL_RANGE_REQUEST, &final_range);
|
return opus_decoder_ctl(decoder, OPUS_GET_FINAL_RANGE_REQUEST, &final_range);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace AudioCore::ADSP::OpusDecoder
|
} // namespace AudioCore::ADSP::OpusDecoder
|
||||||
|
|
|
@ -1,111 +1,111 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include "audio_core/adsp/apps/opus/opus_multistream_decode_object.h"
|
#include "audio_core/adsp/apps/opus/opus_multistream_decode_object.h"
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
|
|
||||||
namespace AudioCore::ADSP::OpusDecoder {
|
namespace AudioCore::ADSP::OpusDecoder {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
bool IsValidChannelCount(u32 channel_count) {
|
bool IsValidChannelCount(u32 channel_count) {
|
||||||
return channel_count == 1 || channel_count == 2;
|
return channel_count == 1 || channel_count == 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsValidStreamCounts(u32 total_stream_count, u32 stereo_stream_count) {
|
bool IsValidStreamCounts(u32 total_stream_count, u32 stereo_stream_count) {
|
||||||
return total_stream_count > 0 && stereo_stream_count > 0 &&
|
return total_stream_count > 0 && stereo_stream_count > 0 &&
|
||||||
stereo_stream_count <= total_stream_count && IsValidChannelCount(total_stream_count);
|
stereo_stream_count <= total_stream_count && IsValidChannelCount(total_stream_count);
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
u32 OpusMultiStreamDecodeObject::GetWorkBufferSize(u32 total_stream_count,
|
u32 OpusMultiStreamDecodeObject::GetWorkBufferSize(u32 total_stream_count,
|
||||||
u32 stereo_stream_count) {
|
u32 stereo_stream_count) {
|
||||||
if (IsValidStreamCounts(total_stream_count, stereo_stream_count)) {
|
if (IsValidStreamCounts(total_stream_count, stereo_stream_count)) {
|
||||||
return static_cast<u32>(sizeof(OpusMultiStreamDecodeObject)) +
|
return static_cast<u32>(sizeof(OpusMultiStreamDecodeObject)) +
|
||||||
opus_multistream_decoder_get_size(total_stream_count, stereo_stream_count);
|
opus_multistream_decoder_get_size(total_stream_count, stereo_stream_count);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
OpusMultiStreamDecodeObject& OpusMultiStreamDecodeObject::Initialize(u64 buffer, u64 buffer2) {
|
OpusMultiStreamDecodeObject& OpusMultiStreamDecodeObject::Initialize(u64 buffer, u64 buffer2) {
|
||||||
auto* new_decoder = reinterpret_cast<OpusMultiStreamDecodeObject*>(buffer);
|
auto* new_decoder = reinterpret_cast<OpusMultiStreamDecodeObject*>(buffer);
|
||||||
auto* comparison = reinterpret_cast<OpusMultiStreamDecodeObject*>(buffer2);
|
auto* comparison = reinterpret_cast<OpusMultiStreamDecodeObject*>(buffer2);
|
||||||
|
|
||||||
if (new_decoder->magic == DecodeMultiStreamObjectMagic) {
|
if (new_decoder->magic == DecodeMultiStreamObjectMagic) {
|
||||||
if (!new_decoder->initialized ||
|
if (!new_decoder->initialized ||
|
||||||
(new_decoder->initialized && new_decoder->self == comparison)) {
|
(new_decoder->initialized && new_decoder->self == comparison)) {
|
||||||
new_decoder->state_valid = true;
|
new_decoder->state_valid = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
new_decoder->initialized = false;
|
new_decoder->initialized = false;
|
||||||
new_decoder->state_valid = true;
|
new_decoder->state_valid = true;
|
||||||
}
|
}
|
||||||
return *new_decoder;
|
return *new_decoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 OpusMultiStreamDecodeObject::InitializeDecoder(u32 sample_rate, u32 total_stream_count,
|
s32 OpusMultiStreamDecodeObject::InitializeDecoder(u32 sample_rate, u32 total_stream_count,
|
||||||
u32 channel_count, u32 stereo_stream_count,
|
u32 channel_count, u32 stereo_stream_count,
|
||||||
u8* mappings) {
|
u8* mappings) {
|
||||||
if (!state_valid) {
|
if (!state_valid) {
|
||||||
return OPUS_INVALID_STATE;
|
return OPUS_INVALID_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (initialized) {
|
if (initialized) {
|
||||||
return OPUS_OK;
|
return OPUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// See OpusDecodeObject::InitializeDecoder for an explanation of this
|
// See OpusDecodeObject::InitializeDecoder for an explanation of this
|
||||||
decoder = (LibOpusMSDecoder*)(this + 1);
|
decoder = (LibOpusMSDecoder*)(this + 1);
|
||||||
s32 ret = opus_multistream_decoder_init(decoder, sample_rate, channel_count, total_stream_count,
|
s32 ret = opus_multistream_decoder_init(decoder, sample_rate, channel_count, total_stream_count,
|
||||||
stereo_stream_count, mappings);
|
stereo_stream_count, mappings);
|
||||||
if (ret == OPUS_OK) {
|
if (ret == OPUS_OK) {
|
||||||
magic = DecodeMultiStreamObjectMagic;
|
magic = DecodeMultiStreamObjectMagic;
|
||||||
initialized = true;
|
initialized = true;
|
||||||
state_valid = true;
|
state_valid = true;
|
||||||
self = this;
|
self = this;
|
||||||
final_range = 0;
|
final_range = 0;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 OpusMultiStreamDecodeObject::Shutdown() {
|
s32 OpusMultiStreamDecodeObject::Shutdown() {
|
||||||
if (!state_valid) {
|
if (!state_valid) {
|
||||||
return OPUS_INVALID_STATE;
|
return OPUS_INVALID_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (initialized) {
|
if (initialized) {
|
||||||
magic = 0x0;
|
magic = 0x0;
|
||||||
initialized = false;
|
initialized = false;
|
||||||
state_valid = false;
|
state_valid = false;
|
||||||
self = nullptr;
|
self = nullptr;
|
||||||
final_range = 0;
|
final_range = 0;
|
||||||
decoder = nullptr;
|
decoder = nullptr;
|
||||||
}
|
}
|
||||||
return OPUS_OK;
|
return OPUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 OpusMultiStreamDecodeObject::ResetDecoder() {
|
s32 OpusMultiStreamDecodeObject::ResetDecoder() {
|
||||||
return opus_multistream_decoder_ctl(decoder, OPUS_RESET_STATE);
|
return opus_multistream_decoder_ctl(decoder, OPUS_RESET_STATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 OpusMultiStreamDecodeObject::Decode(u32& out_sample_count, u64 output_data,
|
s32 OpusMultiStreamDecodeObject::Decode(u32& out_sample_count, u64 output_data,
|
||||||
u64 output_data_size, u64 input_data, u64 input_data_size) {
|
u64 output_data_size, u64 input_data, u64 input_data_size) {
|
||||||
ASSERT(initialized);
|
ASSERT(initialized);
|
||||||
out_sample_count = 0;
|
out_sample_count = 0;
|
||||||
|
|
||||||
if (!state_valid) {
|
if (!state_valid) {
|
||||||
return OPUS_INVALID_STATE;
|
return OPUS_INVALID_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ret_code_or_samples = opus_multistream_decode(
|
auto ret_code_or_samples = opus_multistream_decode(
|
||||||
decoder, reinterpret_cast<const u8*>(input_data), static_cast<opus_int32>(input_data_size),
|
decoder, reinterpret_cast<const u8*>(input_data), static_cast<opus_int32>(input_data_size),
|
||||||
reinterpret_cast<opus_int16*>(output_data), static_cast<opus_int32>(output_data_size), 0);
|
reinterpret_cast<opus_int16*>(output_data), static_cast<opus_int32>(output_data_size), 0);
|
||||||
|
|
||||||
if (ret_code_or_samples < OPUS_OK) {
|
if (ret_code_or_samples < OPUS_OK) {
|
||||||
return ret_code_or_samples;
|
return ret_code_or_samples;
|
||||||
}
|
}
|
||||||
|
|
||||||
out_sample_count = ret_code_or_samples;
|
out_sample_count = ret_code_or_samples;
|
||||||
return opus_multistream_decoder_ctl(decoder, OPUS_GET_FINAL_RANGE_REQUEST, &final_range);
|
return opus_multistream_decoder_ctl(decoder, OPUS_GET_FINAL_RANGE_REQUEST, &final_range);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace AudioCore::ADSP::OpusDecoder
|
} // namespace AudioCore::ADSP::OpusDecoder
|
||||||
|
|
|
@ -1,179 +1,179 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include "audio_core/opus/decoder.h"
|
#include "audio_core/opus/decoder.h"
|
||||||
#include "audio_core/opus/hardware_opus.h"
|
#include "audio_core/opus/hardware_opus.h"
|
||||||
#include "audio_core/opus/parameters.h"
|
#include "audio_core/opus/parameters.h"
|
||||||
#include "common/alignment.h"
|
#include "common/alignment.h"
|
||||||
#include "common/swap.h"
|
#include "common/swap.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
|
|
||||||
namespace AudioCore::OpusDecoder {
|
namespace AudioCore::OpusDecoder {
|
||||||
using namespace Service::Audio;
|
using namespace Service::Audio;
|
||||||
namespace {
|
namespace {
|
||||||
OpusPacketHeader ReverseHeader(OpusPacketHeader header) {
|
OpusPacketHeader ReverseHeader(OpusPacketHeader header) {
|
||||||
OpusPacketHeader out;
|
OpusPacketHeader out;
|
||||||
out.size = Common::swap32(header.size);
|
out.size = Common::swap32(header.size);
|
||||||
out.final_range = Common::swap32(header.final_range);
|
out.final_range = Common::swap32(header.final_range);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
OpusDecoder::OpusDecoder(Core::System& system_, HardwareOpus& hardware_opus_)
|
OpusDecoder::OpusDecoder(Core::System& system_, HardwareOpus& hardware_opus_)
|
||||||
: system{system_}, hardware_opus{hardware_opus_} {}
|
: system{system_}, hardware_opus{hardware_opus_} {}
|
||||||
|
|
||||||
OpusDecoder::~OpusDecoder() {
|
OpusDecoder::~OpusDecoder() {
|
||||||
if (decode_object_initialized) {
|
if (decode_object_initialized) {
|
||||||
hardware_opus.ShutdownDecodeObject(shared_buffer.get(), shared_buffer_size);
|
hardware_opus.ShutdownDecodeObject(shared_buffer.get(), shared_buffer_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Result OpusDecoder::Initialize(OpusParametersEx& params, Kernel::KTransferMemory* transfer_memory,
|
Result OpusDecoder::Initialize(OpusParametersEx& params, Kernel::KTransferMemory* transfer_memory,
|
||||||
u64 transfer_memory_size) {
|
u64 transfer_memory_size) {
|
||||||
auto frame_size{params.use_large_frame_size ? 5760 : 1920};
|
auto frame_size{params.use_large_frame_size ? 5760 : 1920};
|
||||||
shared_buffer_size = transfer_memory_size;
|
shared_buffer_size = transfer_memory_size;
|
||||||
shared_buffer = std::make_unique<u8[]>(shared_buffer_size);
|
shared_buffer = std::make_unique<u8[]>(shared_buffer_size);
|
||||||
shared_memory_mapped = true;
|
shared_memory_mapped = true;
|
||||||
|
|
||||||
buffer_size =
|
buffer_size =
|
||||||
Common::AlignUp((frame_size * params.channel_count) / (48'000 / params.sample_rate), 16);
|
Common::AlignUp((frame_size * params.channel_count) / (48'000 / params.sample_rate), 16);
|
||||||
|
|
||||||
out_data = {shared_buffer.get() + shared_buffer_size - buffer_size, buffer_size};
|
out_data = {shared_buffer.get() + shared_buffer_size - buffer_size, buffer_size};
|
||||||
size_t in_data_size{0x600u};
|
size_t in_data_size{0x600u};
|
||||||
in_data = {out_data.data() - in_data_size, in_data_size};
|
in_data = {out_data.data() - in_data_size, in_data_size};
|
||||||
|
|
||||||
ON_RESULT_FAILURE {
|
ON_RESULT_FAILURE {
|
||||||
if (shared_memory_mapped) {
|
if (shared_memory_mapped) {
|
||||||
shared_memory_mapped = false;
|
shared_memory_mapped = false;
|
||||||
ASSERT(R_SUCCEEDED(hardware_opus.UnmapMemory(shared_buffer.get(), shared_buffer_size)));
|
ASSERT(R_SUCCEEDED(hardware_opus.UnmapMemory(shared_buffer.get(), shared_buffer_size)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
R_TRY(hardware_opus.InitializeDecodeObject(params.sample_rate, params.channel_count,
|
R_TRY(hardware_opus.InitializeDecodeObject(params.sample_rate, params.channel_count,
|
||||||
shared_buffer.get(), shared_buffer_size));
|
shared_buffer.get(), shared_buffer_size));
|
||||||
|
|
||||||
sample_rate = params.sample_rate;
|
sample_rate = params.sample_rate;
|
||||||
channel_count = params.channel_count;
|
channel_count = params.channel_count;
|
||||||
use_large_frame_size = params.use_large_frame_size;
|
use_large_frame_size = params.use_large_frame_size;
|
||||||
decode_object_initialized = true;
|
decode_object_initialized = true;
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result OpusDecoder::Initialize(OpusMultiStreamParametersEx& params,
|
Result OpusDecoder::Initialize(OpusMultiStreamParametersEx& params,
|
||||||
Kernel::KTransferMemory* transfer_memory, u64 transfer_memory_size) {
|
Kernel::KTransferMemory* transfer_memory, u64 transfer_memory_size) {
|
||||||
auto frame_size{params.use_large_frame_size ? 5760 : 1920};
|
auto frame_size{params.use_large_frame_size ? 5760 : 1920};
|
||||||
shared_buffer_size = transfer_memory_size;
|
shared_buffer_size = transfer_memory_size;
|
||||||
shared_buffer = std::make_unique<u8[]>(shared_buffer_size);
|
shared_buffer = std::make_unique<u8[]>(shared_buffer_size);
|
||||||
shared_memory_mapped = true;
|
shared_memory_mapped = true;
|
||||||
|
|
||||||
buffer_size =
|
buffer_size =
|
||||||
Common::AlignUp((frame_size * params.channel_count) / (48'000 / params.sample_rate), 16);
|
Common::AlignUp((frame_size * params.channel_count) / (48'000 / params.sample_rate), 16);
|
||||||
|
|
||||||
out_data = {shared_buffer.get() + shared_buffer_size - buffer_size, buffer_size};
|
out_data = {shared_buffer.get() + shared_buffer_size - buffer_size, buffer_size};
|
||||||
size_t in_data_size{Common::AlignUp(1500ull * params.total_stream_count, 64u)};
|
size_t in_data_size{Common::AlignUp(1500ull * params.total_stream_count, 64u)};
|
||||||
in_data = {out_data.data() - in_data_size, in_data_size};
|
in_data = {out_data.data() - in_data_size, in_data_size};
|
||||||
|
|
||||||
ON_RESULT_FAILURE {
|
ON_RESULT_FAILURE {
|
||||||
if (shared_memory_mapped) {
|
if (shared_memory_mapped) {
|
||||||
shared_memory_mapped = false;
|
shared_memory_mapped = false;
|
||||||
ASSERT(R_SUCCEEDED(hardware_opus.UnmapMemory(shared_buffer.get(), shared_buffer_size)));
|
ASSERT(R_SUCCEEDED(hardware_opus.UnmapMemory(shared_buffer.get(), shared_buffer_size)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
R_TRY(hardware_opus.InitializeMultiStreamDecodeObject(
|
R_TRY(hardware_opus.InitializeMultiStreamDecodeObject(
|
||||||
params.sample_rate, params.channel_count, params.total_stream_count,
|
params.sample_rate, params.channel_count, params.total_stream_count,
|
||||||
params.stereo_stream_count, params.mappings.data(), shared_buffer.get(),
|
params.stereo_stream_count, params.mappings.data(), shared_buffer.get(),
|
||||||
shared_buffer_size));
|
shared_buffer_size));
|
||||||
|
|
||||||
sample_rate = params.sample_rate;
|
sample_rate = params.sample_rate;
|
||||||
channel_count = params.channel_count;
|
channel_count = params.channel_count;
|
||||||
total_stream_count = params.total_stream_count;
|
total_stream_count = params.total_stream_count;
|
||||||
stereo_stream_count = params.stereo_stream_count;
|
stereo_stream_count = params.stereo_stream_count;
|
||||||
use_large_frame_size = params.use_large_frame_size;
|
use_large_frame_size = params.use_large_frame_size;
|
||||||
decode_object_initialized = true;
|
decode_object_initialized = true;
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result OpusDecoder::DecodeInterleaved(u32* out_data_size, u64* out_time_taken,
|
Result OpusDecoder::DecodeInterleaved(u32* out_data_size, u64* out_time_taken,
|
||||||
u32* out_sample_count, std::span<const u8> input_data,
|
u32* out_sample_count, std::span<const u8> input_data,
|
||||||
std::span<u8> output_data, bool reset) {
|
std::span<u8> output_data, bool reset) {
|
||||||
u32 out_samples;
|
u32 out_samples;
|
||||||
u64 time_taken{};
|
u64 time_taken{};
|
||||||
|
|
||||||
R_UNLESS(input_data.size_bytes() > sizeof(OpusPacketHeader), ResultInputDataTooSmall);
|
R_UNLESS(input_data.size_bytes() > sizeof(OpusPacketHeader), ResultInputDataTooSmall);
|
||||||
|
|
||||||
auto* header_p{reinterpret_cast<const OpusPacketHeader*>(input_data.data())};
|
auto* header_p{reinterpret_cast<const OpusPacketHeader*>(input_data.data())};
|
||||||
OpusPacketHeader header{ReverseHeader(*header_p)};
|
OpusPacketHeader header{ReverseHeader(*header_p)};
|
||||||
|
|
||||||
R_UNLESS(in_data.size_bytes() >= header.size &&
|
R_UNLESS(in_data.size_bytes() >= header.size &&
|
||||||
header.size + sizeof(OpusPacketHeader) <= input_data.size_bytes(),
|
header.size + sizeof(OpusPacketHeader) <= input_data.size_bytes(),
|
||||||
ResultBufferTooSmall);
|
ResultBufferTooSmall);
|
||||||
|
|
||||||
if (!shared_memory_mapped) {
|
if (!shared_memory_mapped) {
|
||||||
R_TRY(hardware_opus.MapMemory(shared_buffer.get(), shared_buffer_size));
|
R_TRY(hardware_opus.MapMemory(shared_buffer.get(), shared_buffer_size));
|
||||||
shared_memory_mapped = true;
|
shared_memory_mapped = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::memcpy(in_data.data(), input_data.data() + sizeof(OpusPacketHeader), header.size);
|
std::memcpy(in_data.data(), input_data.data() + sizeof(OpusPacketHeader), header.size);
|
||||||
|
|
||||||
R_TRY(hardware_opus.DecodeInterleaved(out_samples, out_data.data(), out_data.size_bytes(),
|
R_TRY(hardware_opus.DecodeInterleaved(out_samples, out_data.data(), out_data.size_bytes(),
|
||||||
channel_count, in_data.data(), header.size,
|
channel_count, in_data.data(), header.size,
|
||||||
shared_buffer.get(), time_taken, reset));
|
shared_buffer.get(), time_taken, reset));
|
||||||
|
|
||||||
std::memcpy(output_data.data(), out_data.data(), out_samples * channel_count * sizeof(s16));
|
std::memcpy(output_data.data(), out_data.data(), out_samples * channel_count * sizeof(s16));
|
||||||
|
|
||||||
*out_data_size = header.size + sizeof(OpusPacketHeader);
|
*out_data_size = header.size + sizeof(OpusPacketHeader);
|
||||||
*out_sample_count = out_samples;
|
*out_sample_count = out_samples;
|
||||||
if (out_time_taken) {
|
if (out_time_taken) {
|
||||||
*out_time_taken = time_taken / 1000;
|
*out_time_taken = time_taken / 1000;
|
||||||
}
|
}
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result OpusDecoder::SetContext([[maybe_unused]] std::span<const u8> context) {
|
Result OpusDecoder::SetContext([[maybe_unused]] std::span<const u8> context) {
|
||||||
R_SUCCEED_IF(shared_memory_mapped);
|
R_SUCCEED_IF(shared_memory_mapped);
|
||||||
shared_memory_mapped = true;
|
shared_memory_mapped = true;
|
||||||
R_RETURN(hardware_opus.MapMemory(shared_buffer.get(), shared_buffer_size));
|
R_RETURN(hardware_opus.MapMemory(shared_buffer.get(), shared_buffer_size));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result OpusDecoder::DecodeInterleavedForMultiStream(u32* out_data_size, u64* out_time_taken,
|
Result OpusDecoder::DecodeInterleavedForMultiStream(u32* out_data_size, u64* out_time_taken,
|
||||||
u32* out_sample_count,
|
u32* out_sample_count,
|
||||||
std::span<const u8> input_data,
|
std::span<const u8> input_data,
|
||||||
std::span<u8> output_data, bool reset) {
|
std::span<u8> output_data, bool reset) {
|
||||||
u32 out_samples;
|
u32 out_samples;
|
||||||
u64 time_taken{};
|
u64 time_taken{};
|
||||||
|
|
||||||
R_UNLESS(input_data.size_bytes() > sizeof(OpusPacketHeader), ResultInputDataTooSmall);
|
R_UNLESS(input_data.size_bytes() > sizeof(OpusPacketHeader), ResultInputDataTooSmall);
|
||||||
|
|
||||||
auto* header_p{reinterpret_cast<const OpusPacketHeader*>(input_data.data())};
|
auto* header_p{reinterpret_cast<const OpusPacketHeader*>(input_data.data())};
|
||||||
OpusPacketHeader header{ReverseHeader(*header_p)};
|
OpusPacketHeader header{ReverseHeader(*header_p)};
|
||||||
|
|
||||||
LOG_ERROR(Service_Audio, "header size 0x{:X} input data size 0x{:X} in_data size 0x{:X}",
|
LOG_ERROR(Service_Audio, "header size 0x{:X} input data size 0x{:X} in_data size 0x{:X}",
|
||||||
header.size, input_data.size_bytes(), in_data.size_bytes());
|
header.size, input_data.size_bytes(), in_data.size_bytes());
|
||||||
|
|
||||||
R_UNLESS(in_data.size_bytes() >= header.size &&
|
R_UNLESS(in_data.size_bytes() >= header.size &&
|
||||||
header.size + sizeof(OpusPacketHeader) <= input_data.size_bytes(),
|
header.size + sizeof(OpusPacketHeader) <= input_data.size_bytes(),
|
||||||
ResultBufferTooSmall);
|
ResultBufferTooSmall);
|
||||||
|
|
||||||
if (!shared_memory_mapped) {
|
if (!shared_memory_mapped) {
|
||||||
R_TRY(hardware_opus.MapMemory(shared_buffer.get(), shared_buffer_size));
|
R_TRY(hardware_opus.MapMemory(shared_buffer.get(), shared_buffer_size));
|
||||||
shared_memory_mapped = true;
|
shared_memory_mapped = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::memcpy(in_data.data(), input_data.data() + sizeof(OpusPacketHeader), header.size);
|
std::memcpy(in_data.data(), input_data.data() + sizeof(OpusPacketHeader), header.size);
|
||||||
|
|
||||||
R_TRY(hardware_opus.DecodeInterleavedForMultiStream(
|
R_TRY(hardware_opus.DecodeInterleavedForMultiStream(
|
||||||
out_samples, out_data.data(), out_data.size_bytes(), channel_count, in_data.data(),
|
out_samples, out_data.data(), out_data.size_bytes(), channel_count, in_data.data(),
|
||||||
header.size, shared_buffer.get(), time_taken, reset));
|
header.size, shared_buffer.get(), time_taken, reset));
|
||||||
|
|
||||||
std::memcpy(output_data.data(), out_data.data(), out_samples * channel_count * sizeof(s16));
|
std::memcpy(output_data.data(), out_data.data(), out_samples * channel_count * sizeof(s16));
|
||||||
|
|
||||||
*out_data_size = header.size + sizeof(OpusPacketHeader);
|
*out_data_size = header.size + sizeof(OpusPacketHeader);
|
||||||
*out_sample_count = out_samples;
|
*out_sample_count = out_samples;
|
||||||
if (out_time_taken) {
|
if (out_time_taken) {
|
||||||
*out_time_taken = time_taken / 1000;
|
*out_time_taken = time_taken / 1000;
|
||||||
}
|
}
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace AudioCore::OpusDecoder
|
} // namespace AudioCore::OpusDecoder
|
||||||
|
|
|
@ -1,53 +1,53 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <span>
|
#include <span>
|
||||||
|
|
||||||
#include "audio_core/opus/parameters.h"
|
#include "audio_core/opus/parameters.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "core/hle/kernel/k_transfer_memory.h"
|
#include "core/hle/kernel/k_transfer_memory.h"
|
||||||
#include "core/hle/service/audio/errors.h"
|
#include "core/hle/service/audio/errors.h"
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
class System;
|
class System;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace AudioCore::OpusDecoder {
|
namespace AudioCore::OpusDecoder {
|
||||||
class HardwareOpus;
|
class HardwareOpus;
|
||||||
|
|
||||||
class OpusDecoder {
|
class OpusDecoder {
|
||||||
public:
|
public:
|
||||||
explicit OpusDecoder(Core::System& system, HardwareOpus& hardware_opus_);
|
explicit OpusDecoder(Core::System& system, HardwareOpus& hardware_opus_);
|
||||||
~OpusDecoder();
|
~OpusDecoder();
|
||||||
|
|
||||||
Result Initialize(OpusParametersEx& params, Kernel::KTransferMemory* transfer_memory,
|
Result Initialize(OpusParametersEx& params, Kernel::KTransferMemory* transfer_memory,
|
||||||
u64 transfer_memory_size);
|
u64 transfer_memory_size);
|
||||||
Result Initialize(OpusMultiStreamParametersEx& params, Kernel::KTransferMemory* transfer_memory,
|
Result Initialize(OpusMultiStreamParametersEx& params, Kernel::KTransferMemory* transfer_memory,
|
||||||
u64 transfer_memory_size);
|
u64 transfer_memory_size);
|
||||||
Result DecodeInterleaved(u32* out_data_size, u64* out_time_taken, u32* out_sample_count,
|
Result DecodeInterleaved(u32* out_data_size, u64* out_time_taken, u32* out_sample_count,
|
||||||
std::span<const u8> input_data, std::span<u8> output_data, bool reset);
|
std::span<const u8> input_data, std::span<u8> output_data, bool reset);
|
||||||
Result SetContext([[maybe_unused]] std::span<const u8> context);
|
Result SetContext([[maybe_unused]] std::span<const u8> context);
|
||||||
Result DecodeInterleavedForMultiStream(u32* out_data_size, u64* out_time_taken,
|
Result DecodeInterleavedForMultiStream(u32* out_data_size, u64* out_time_taken,
|
||||||
u32* out_sample_count, std::span<const u8> input_data,
|
u32* out_sample_count, std::span<const u8> input_data,
|
||||||
std::span<u8> output_data, bool reset);
|
std::span<u8> output_data, bool reset);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Core::System& system;
|
Core::System& system;
|
||||||
HardwareOpus& hardware_opus;
|
HardwareOpus& hardware_opus;
|
||||||
std::unique_ptr<u8[]> shared_buffer{};
|
std::unique_ptr<u8[]> shared_buffer{};
|
||||||
u64 shared_buffer_size;
|
u64 shared_buffer_size;
|
||||||
std::span<u8> in_data{};
|
std::span<u8> in_data{};
|
||||||
std::span<u8> out_data{};
|
std::span<u8> out_data{};
|
||||||
u64 buffer_size{};
|
u64 buffer_size{};
|
||||||
s32 sample_rate{};
|
s32 sample_rate{};
|
||||||
s32 channel_count{};
|
s32 channel_count{};
|
||||||
bool use_large_frame_size{false};
|
bool use_large_frame_size{false};
|
||||||
s32 total_stream_count{};
|
s32 total_stream_count{};
|
||||||
s32 stereo_stream_count{};
|
s32 stereo_stream_count{};
|
||||||
bool shared_memory_mapped{false};
|
bool shared_memory_mapped{false};
|
||||||
bool decode_object_initialized{false};
|
bool decode_object_initialized{false};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace AudioCore::OpusDecoder
|
} // namespace AudioCore::OpusDecoder
|
||||||
|
|
|
@ -1,102 +1,102 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include "audio_core/adsp/apps/opus/opus_decoder.h"
|
#include "audio_core/adsp/apps/opus/opus_decoder.h"
|
||||||
#include "audio_core/opus/decoder_manager.h"
|
#include "audio_core/opus/decoder_manager.h"
|
||||||
#include "common/alignment.h"
|
#include "common/alignment.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
|
|
||||||
namespace AudioCore::OpusDecoder {
|
namespace AudioCore::OpusDecoder {
|
||||||
using namespace Service::Audio;
|
using namespace Service::Audio;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
bool IsValidChannelCount(u32 channel_count) {
|
bool IsValidChannelCount(u32 channel_count) {
|
||||||
return channel_count == 1 || channel_count == 2;
|
return channel_count == 1 || channel_count == 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsValidMultiStreamChannelCount(u32 channel_count) {
|
bool IsValidMultiStreamChannelCount(u32 channel_count) {
|
||||||
return channel_count > 0 && channel_count <= OpusStreamCountMax;
|
return channel_count > 0 && channel_count <= OpusStreamCountMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsValidSampleRate(u32 sample_rate) {
|
bool IsValidSampleRate(u32 sample_rate) {
|
||||||
return sample_rate == 8'000 || sample_rate == 12'000 || sample_rate == 16'000 ||
|
return sample_rate == 8'000 || sample_rate == 12'000 || sample_rate == 16'000 ||
|
||||||
sample_rate == 24'000 || sample_rate == 48'000;
|
sample_rate == 24'000 || sample_rate == 48'000;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsValidStreamCount(u32 channel_count, u32 total_stream_count, u32 stereo_stream_count) {
|
bool IsValidStreamCount(u32 channel_count, u32 total_stream_count, u32 stereo_stream_count) {
|
||||||
return total_stream_count > 0 && static_cast<s32>(stereo_stream_count) >= 0 &&
|
return total_stream_count > 0 && static_cast<s32>(stereo_stream_count) >= 0 &&
|
||||||
stereo_stream_count <= total_stream_count &&
|
stereo_stream_count <= total_stream_count &&
|
||||||
total_stream_count + stereo_stream_count <= channel_count;
|
total_stream_count + stereo_stream_count <= channel_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
OpusDecoderManager::OpusDecoderManager(Core::System& system_)
|
OpusDecoderManager::OpusDecoderManager(Core::System& system_)
|
||||||
: system{system_}, hardware_opus{system} {
|
: system{system_}, hardware_opus{system} {
|
||||||
for (u32 i = 0; i < MaxChannels; i++) {
|
for (u32 i = 0; i < MaxChannels; i++) {
|
||||||
required_workbuffer_sizes[i] = hardware_opus.GetWorkBufferSize(1 + i);
|
required_workbuffer_sizes[i] = hardware_opus.GetWorkBufferSize(1 + i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Result OpusDecoderManager::GetWorkBufferSize(OpusParameters& params, u64& out_size) {
|
Result OpusDecoderManager::GetWorkBufferSize(OpusParameters& params, u64& out_size) {
|
||||||
OpusParametersEx ex{
|
OpusParametersEx ex{
|
||||||
.sample_rate = params.sample_rate,
|
.sample_rate = params.sample_rate,
|
||||||
.channel_count = params.channel_count,
|
.channel_count = params.channel_count,
|
||||||
.use_large_frame_size = false,
|
.use_large_frame_size = false,
|
||||||
};
|
};
|
||||||
R_RETURN(GetWorkBufferSizeExEx(ex, out_size));
|
R_RETURN(GetWorkBufferSizeExEx(ex, out_size));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result OpusDecoderManager::GetWorkBufferSizeEx(OpusParametersEx& params, u64& out_size) {
|
Result OpusDecoderManager::GetWorkBufferSizeEx(OpusParametersEx& params, u64& out_size) {
|
||||||
R_RETURN(GetWorkBufferSizeExEx(params, out_size));
|
R_RETURN(GetWorkBufferSizeExEx(params, out_size));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result OpusDecoderManager::GetWorkBufferSizeExEx(OpusParametersEx& params, u64& out_size) {
|
Result OpusDecoderManager::GetWorkBufferSizeExEx(OpusParametersEx& params, u64& out_size) {
|
||||||
R_UNLESS(IsValidChannelCount(params.channel_count), ResultInvalidOpusChannelCount);
|
R_UNLESS(IsValidChannelCount(params.channel_count), ResultInvalidOpusChannelCount);
|
||||||
R_UNLESS(IsValidSampleRate(params.sample_rate), ResultInvalidOpusSampleRate);
|
R_UNLESS(IsValidSampleRate(params.sample_rate), ResultInvalidOpusSampleRate);
|
||||||
|
|
||||||
auto work_buffer_size{required_workbuffer_sizes[params.channel_count - 1]};
|
auto work_buffer_size{required_workbuffer_sizes[params.channel_count - 1]};
|
||||||
auto frame_size{params.use_large_frame_size ? 5760 : 1920};
|
auto frame_size{params.use_large_frame_size ? 5760 : 1920};
|
||||||
work_buffer_size +=
|
work_buffer_size +=
|
||||||
Common::AlignUp((frame_size * params.channel_count) / (48'000 / params.sample_rate), 64);
|
Common::AlignUp((frame_size * params.channel_count) / (48'000 / params.sample_rate), 64);
|
||||||
out_size = work_buffer_size + 0x600;
|
out_size = work_buffer_size + 0x600;
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result OpusDecoderManager::GetWorkBufferSizeForMultiStream(OpusMultiStreamParameters& params,
|
Result OpusDecoderManager::GetWorkBufferSizeForMultiStream(OpusMultiStreamParameters& params,
|
||||||
u64& out_size) {
|
u64& out_size) {
|
||||||
OpusMultiStreamParametersEx ex{
|
OpusMultiStreamParametersEx ex{
|
||||||
.sample_rate = params.sample_rate,
|
.sample_rate = params.sample_rate,
|
||||||
.channel_count = params.channel_count,
|
.channel_count = params.channel_count,
|
||||||
.total_stream_count = params.total_stream_count,
|
.total_stream_count = params.total_stream_count,
|
||||||
.stereo_stream_count = params.stereo_stream_count,
|
.stereo_stream_count = params.stereo_stream_count,
|
||||||
.use_large_frame_size = false,
|
.use_large_frame_size = false,
|
||||||
.mappings = {},
|
.mappings = {},
|
||||||
};
|
};
|
||||||
R_RETURN(GetWorkBufferSizeForMultiStreamExEx(ex, out_size));
|
R_RETURN(GetWorkBufferSizeForMultiStreamExEx(ex, out_size));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result OpusDecoderManager::GetWorkBufferSizeForMultiStreamEx(OpusMultiStreamParametersEx& params,
|
Result OpusDecoderManager::GetWorkBufferSizeForMultiStreamEx(OpusMultiStreamParametersEx& params,
|
||||||
u64& out_size) {
|
u64& out_size) {
|
||||||
R_RETURN(GetWorkBufferSizeForMultiStreamExEx(params, out_size));
|
R_RETURN(GetWorkBufferSizeForMultiStreamExEx(params, out_size));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result OpusDecoderManager::GetWorkBufferSizeForMultiStreamExEx(OpusMultiStreamParametersEx& params,
|
Result OpusDecoderManager::GetWorkBufferSizeForMultiStreamExEx(OpusMultiStreamParametersEx& params,
|
||||||
u64& out_size) {
|
u64& out_size) {
|
||||||
R_UNLESS(IsValidMultiStreamChannelCount(params.channel_count), ResultInvalidOpusChannelCount);
|
R_UNLESS(IsValidMultiStreamChannelCount(params.channel_count), ResultInvalidOpusChannelCount);
|
||||||
R_UNLESS(IsValidSampleRate(params.sample_rate), ResultInvalidOpusSampleRate);
|
R_UNLESS(IsValidSampleRate(params.sample_rate), ResultInvalidOpusSampleRate);
|
||||||
R_UNLESS(IsValidStreamCount(params.channel_count, params.total_stream_count,
|
R_UNLESS(IsValidStreamCount(params.channel_count, params.total_stream_count,
|
||||||
params.stereo_stream_count),
|
params.stereo_stream_count),
|
||||||
ResultInvalidOpusSampleRate);
|
ResultInvalidOpusSampleRate);
|
||||||
|
|
||||||
auto work_buffer_size{hardware_opus.GetWorkBufferSizeForMultiStream(
|
auto work_buffer_size{hardware_opus.GetWorkBufferSizeForMultiStream(
|
||||||
params.total_stream_count, params.stereo_stream_count)};
|
params.total_stream_count, params.stereo_stream_count)};
|
||||||
auto frame_size{params.use_large_frame_size ? 5760 : 1920};
|
auto frame_size{params.use_large_frame_size ? 5760 : 1920};
|
||||||
work_buffer_size += Common::AlignUp(1500 * params.total_stream_count, 64);
|
work_buffer_size += Common::AlignUp(1500 * params.total_stream_count, 64);
|
||||||
work_buffer_size +=
|
work_buffer_size +=
|
||||||
Common::AlignUp((frame_size * params.channel_count) / (48'000 / params.sample_rate), 64);
|
Common::AlignUp((frame_size * params.channel_count) / (48'000 / params.sample_rate), 64);
|
||||||
out_size = work_buffer_size;
|
out_size = work_buffer_size;
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace AudioCore::OpusDecoder
|
} // namespace AudioCore::OpusDecoder
|
||||||
|
|
|
@ -1,38 +1,38 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "audio_core/opus/hardware_opus.h"
|
#include "audio_core/opus/hardware_opus.h"
|
||||||
#include "audio_core/opus/parameters.h"
|
#include "audio_core/opus/parameters.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "core/hle/service/audio/errors.h"
|
#include "core/hle/service/audio/errors.h"
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
class System;
|
class System;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace AudioCore::OpusDecoder {
|
namespace AudioCore::OpusDecoder {
|
||||||
|
|
||||||
class OpusDecoderManager {
|
class OpusDecoderManager {
|
||||||
public:
|
public:
|
||||||
OpusDecoderManager(Core::System& system);
|
OpusDecoderManager(Core::System& system);
|
||||||
|
|
||||||
HardwareOpus& GetHardwareOpus() {
|
HardwareOpus& GetHardwareOpus() {
|
||||||
return hardware_opus;
|
return hardware_opus;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result GetWorkBufferSize(OpusParameters& params, u64& out_size);
|
Result GetWorkBufferSize(OpusParameters& params, u64& out_size);
|
||||||
Result GetWorkBufferSizeEx(OpusParametersEx& params, u64& out_size);
|
Result GetWorkBufferSizeEx(OpusParametersEx& params, u64& out_size);
|
||||||
Result GetWorkBufferSizeExEx(OpusParametersEx& params, u64& out_size);
|
Result GetWorkBufferSizeExEx(OpusParametersEx& params, u64& out_size);
|
||||||
Result GetWorkBufferSizeForMultiStream(OpusMultiStreamParameters& params, u64& out_size);
|
Result GetWorkBufferSizeForMultiStream(OpusMultiStreamParameters& params, u64& out_size);
|
||||||
Result GetWorkBufferSizeForMultiStreamEx(OpusMultiStreamParametersEx& params, u64& out_size);
|
Result GetWorkBufferSizeForMultiStreamEx(OpusMultiStreamParametersEx& params, u64& out_size);
|
||||||
Result GetWorkBufferSizeForMultiStreamExEx(OpusMultiStreamParametersEx& params, u64& out_size);
|
Result GetWorkBufferSizeForMultiStreamExEx(OpusMultiStreamParametersEx& params, u64& out_size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Core::System& system;
|
Core::System& system;
|
||||||
HardwareOpus hardware_opus;
|
HardwareOpus hardware_opus;
|
||||||
std::array<u64, MaxChannels> required_workbuffer_sizes{};
|
std::array<u64, MaxChannels> required_workbuffer_sizes{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace AudioCore::OpusDecoder
|
} // namespace AudioCore::OpusDecoder
|
||||||
|
|
|
@ -1,241 +1,241 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
#include "audio_core/audio_core.h"
|
#include "audio_core/audio_core.h"
|
||||||
#include "audio_core/opus/hardware_opus.h"
|
#include "audio_core/opus/hardware_opus.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
|
|
||||||
namespace AudioCore::OpusDecoder {
|
namespace AudioCore::OpusDecoder {
|
||||||
namespace {
|
namespace {
|
||||||
using namespace Service::Audio;
|
using namespace Service::Audio;
|
||||||
|
|
||||||
static constexpr Result ResultCodeFromLibOpusErrorCode(u64 error_code) {
|
static constexpr Result ResultCodeFromLibOpusErrorCode(u64 error_code) {
|
||||||
s32 error{static_cast<s32>(error_code)};
|
s32 error{static_cast<s32>(error_code)};
|
||||||
ASSERT(error <= OPUS_OK);
|
ASSERT(error <= OPUS_OK);
|
||||||
switch (error) {
|
switch (error) {
|
||||||
case OPUS_ALLOC_FAIL:
|
case OPUS_ALLOC_FAIL:
|
||||||
R_THROW(ResultLibOpusAllocFail);
|
R_THROW(ResultLibOpusAllocFail);
|
||||||
case OPUS_INVALID_STATE:
|
case OPUS_INVALID_STATE:
|
||||||
R_THROW(ResultLibOpusInvalidState);
|
R_THROW(ResultLibOpusInvalidState);
|
||||||
case OPUS_UNIMPLEMENTED:
|
case OPUS_UNIMPLEMENTED:
|
||||||
R_THROW(ResultLibOpusUnimplemented);
|
R_THROW(ResultLibOpusUnimplemented);
|
||||||
case OPUS_INVALID_PACKET:
|
case OPUS_INVALID_PACKET:
|
||||||
R_THROW(ResultLibOpusInvalidPacket);
|
R_THROW(ResultLibOpusInvalidPacket);
|
||||||
case OPUS_INTERNAL_ERROR:
|
case OPUS_INTERNAL_ERROR:
|
||||||
R_THROW(ResultLibOpusInternalError);
|
R_THROW(ResultLibOpusInternalError);
|
||||||
case OPUS_BUFFER_TOO_SMALL:
|
case OPUS_BUFFER_TOO_SMALL:
|
||||||
R_THROW(ResultBufferTooSmall);
|
R_THROW(ResultBufferTooSmall);
|
||||||
case OPUS_BAD_ARG:
|
case OPUS_BAD_ARG:
|
||||||
R_THROW(ResultLibOpusBadArg);
|
R_THROW(ResultLibOpusBadArg);
|
||||||
case OPUS_OK:
|
case OPUS_OK:
|
||||||
R_RETURN(ResultSuccess);
|
R_RETURN(ResultSuccess);
|
||||||
}
|
}
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
HardwareOpus::HardwareOpus(Core::System& system_)
|
HardwareOpus::HardwareOpus(Core::System& system_)
|
||||||
: system{system_}, opus_decoder{system.AudioCore().ADSP().OpusDecoder()} {
|
: system{system_}, opus_decoder{system.AudioCore().ADSP().OpusDecoder()} {
|
||||||
opus_decoder.SetSharedMemory(shared_memory);
|
opus_decoder.SetSharedMemory(shared_memory);
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 HardwareOpus::GetWorkBufferSize(u32 channel) {
|
u64 HardwareOpus::GetWorkBufferSize(u32 channel) {
|
||||||
if (!opus_decoder.IsRunning()) {
|
if (!opus_decoder.IsRunning()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
std::scoped_lock l{mutex};
|
std::scoped_lock l{mutex};
|
||||||
shared_memory.host_send_data[0] = channel;
|
shared_memory.host_send_data[0] = channel;
|
||||||
opus_decoder.Send(ADSP::Direction::DSP, ADSP::OpusDecoder::Message::GetWorkBufferSize);
|
opus_decoder.Send(ADSP::Direction::DSP, ADSP::OpusDecoder::Message::GetWorkBufferSize);
|
||||||
auto msg = opus_decoder.Receive(ADSP::Direction::Host);
|
auto msg = opus_decoder.Receive(ADSP::Direction::Host);
|
||||||
if (msg != ADSP::OpusDecoder::Message::GetWorkBufferSizeOK) {
|
if (msg != ADSP::OpusDecoder::Message::GetWorkBufferSizeOK) {
|
||||||
LOG_ERROR(Service_Audio, "OpusDecoder returned invalid message. Expected {} got {}",
|
LOG_ERROR(Service_Audio, "OpusDecoder returned invalid message. Expected {} got {}",
|
||||||
ADSP::OpusDecoder::Message::GetWorkBufferSizeOK, msg);
|
ADSP::OpusDecoder::Message::GetWorkBufferSizeOK, msg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return shared_memory.dsp_return_data[0];
|
return shared_memory.dsp_return_data[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 HardwareOpus::GetWorkBufferSizeForMultiStream(u32 total_stream_count, u32 stereo_stream_count) {
|
u64 HardwareOpus::GetWorkBufferSizeForMultiStream(u32 total_stream_count, u32 stereo_stream_count) {
|
||||||
std::scoped_lock l{mutex};
|
std::scoped_lock l{mutex};
|
||||||
shared_memory.host_send_data[0] = total_stream_count;
|
shared_memory.host_send_data[0] = total_stream_count;
|
||||||
shared_memory.host_send_data[1] = stereo_stream_count;
|
shared_memory.host_send_data[1] = stereo_stream_count;
|
||||||
opus_decoder.Send(ADSP::Direction::DSP,
|
opus_decoder.Send(ADSP::Direction::DSP,
|
||||||
ADSP::OpusDecoder::Message::GetWorkBufferSizeForMultiStream);
|
ADSP::OpusDecoder::Message::GetWorkBufferSizeForMultiStream);
|
||||||
auto msg = opus_decoder.Receive(ADSP::Direction::Host);
|
auto msg = opus_decoder.Receive(ADSP::Direction::Host);
|
||||||
if (msg != ADSP::OpusDecoder::Message::GetWorkBufferSizeForMultiStreamOK) {
|
if (msg != ADSP::OpusDecoder::Message::GetWorkBufferSizeForMultiStreamOK) {
|
||||||
LOG_ERROR(Service_Audio, "OpusDecoder returned invalid message. Expected {} got {}",
|
LOG_ERROR(Service_Audio, "OpusDecoder returned invalid message. Expected {} got {}",
|
||||||
ADSP::OpusDecoder::Message::GetWorkBufferSizeForMultiStreamOK, msg);
|
ADSP::OpusDecoder::Message::GetWorkBufferSizeForMultiStreamOK, msg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return shared_memory.dsp_return_data[0];
|
return shared_memory.dsp_return_data[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
Result HardwareOpus::InitializeDecodeObject(u32 sample_rate, u32 channel_count, void* buffer,
|
Result HardwareOpus::InitializeDecodeObject(u32 sample_rate, u32 channel_count, void* buffer,
|
||||||
u64 buffer_size) {
|
u64 buffer_size) {
|
||||||
std::scoped_lock l{mutex};
|
std::scoped_lock l{mutex};
|
||||||
shared_memory.host_send_data[0] = (u64)buffer;
|
shared_memory.host_send_data[0] = (u64)buffer;
|
||||||
shared_memory.host_send_data[1] = buffer_size;
|
shared_memory.host_send_data[1] = buffer_size;
|
||||||
shared_memory.host_send_data[2] = sample_rate;
|
shared_memory.host_send_data[2] = sample_rate;
|
||||||
shared_memory.host_send_data[3] = channel_count;
|
shared_memory.host_send_data[3] = channel_count;
|
||||||
|
|
||||||
opus_decoder.Send(ADSP::Direction::DSP, ADSP::OpusDecoder::Message::InitializeDecodeObject);
|
opus_decoder.Send(ADSP::Direction::DSP, ADSP::OpusDecoder::Message::InitializeDecodeObject);
|
||||||
auto msg = opus_decoder.Receive(ADSP::Direction::Host);
|
auto msg = opus_decoder.Receive(ADSP::Direction::Host);
|
||||||
if (msg != ADSP::OpusDecoder::Message::InitializeDecodeObjectOK) {
|
if (msg != ADSP::OpusDecoder::Message::InitializeDecodeObjectOK) {
|
||||||
LOG_ERROR(Service_Audio, "OpusDecoder returned invalid message. Expected {} got {}",
|
LOG_ERROR(Service_Audio, "OpusDecoder returned invalid message. Expected {} got {}",
|
||||||
ADSP::OpusDecoder::Message::InitializeDecodeObjectOK, msg);
|
ADSP::OpusDecoder::Message::InitializeDecodeObjectOK, msg);
|
||||||
R_THROW(ResultInvalidOpusDSPReturnCode);
|
R_THROW(ResultInvalidOpusDSPReturnCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
R_RETURN(ResultCodeFromLibOpusErrorCode(shared_memory.dsp_return_data[0]));
|
R_RETURN(ResultCodeFromLibOpusErrorCode(shared_memory.dsp_return_data[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result HardwareOpus::InitializeMultiStreamDecodeObject(u32 sample_rate, u32 channel_count,
|
Result HardwareOpus::InitializeMultiStreamDecodeObject(u32 sample_rate, u32 channel_count,
|
||||||
u32 total_stream_count,
|
u32 total_stream_count,
|
||||||
u32 stereo_stream_count, void* mappings,
|
u32 stereo_stream_count, void* mappings,
|
||||||
void* buffer, u64 buffer_size) {
|
void* buffer, u64 buffer_size) {
|
||||||
std::scoped_lock l{mutex};
|
std::scoped_lock l{mutex};
|
||||||
shared_memory.host_send_data[0] = (u64)buffer;
|
shared_memory.host_send_data[0] = (u64)buffer;
|
||||||
shared_memory.host_send_data[1] = buffer_size;
|
shared_memory.host_send_data[1] = buffer_size;
|
||||||
shared_memory.host_send_data[2] = sample_rate;
|
shared_memory.host_send_data[2] = sample_rate;
|
||||||
shared_memory.host_send_data[3] = channel_count;
|
shared_memory.host_send_data[3] = channel_count;
|
||||||
shared_memory.host_send_data[4] = total_stream_count;
|
shared_memory.host_send_data[4] = total_stream_count;
|
||||||
shared_memory.host_send_data[5] = stereo_stream_count;
|
shared_memory.host_send_data[5] = stereo_stream_count;
|
||||||
|
|
||||||
ASSERT(channel_count <= MaxChannels);
|
ASSERT(channel_count <= MaxChannels);
|
||||||
std::memcpy(shared_memory.channel_mapping.data(), mappings, channel_count * sizeof(u8));
|
std::memcpy(shared_memory.channel_mapping.data(), mappings, channel_count * sizeof(u8));
|
||||||
|
|
||||||
opus_decoder.Send(ADSP::Direction::DSP,
|
opus_decoder.Send(ADSP::Direction::DSP,
|
||||||
ADSP::OpusDecoder::Message::InitializeMultiStreamDecodeObject);
|
ADSP::OpusDecoder::Message::InitializeMultiStreamDecodeObject);
|
||||||
auto msg = opus_decoder.Receive(ADSP::Direction::Host);
|
auto msg = opus_decoder.Receive(ADSP::Direction::Host);
|
||||||
if (msg != ADSP::OpusDecoder::Message::InitializeMultiStreamDecodeObjectOK) {
|
if (msg != ADSP::OpusDecoder::Message::InitializeMultiStreamDecodeObjectOK) {
|
||||||
LOG_ERROR(Service_Audio, "OpusDecoder returned invalid message. Expected {} got {}",
|
LOG_ERROR(Service_Audio, "OpusDecoder returned invalid message. Expected {} got {}",
|
||||||
ADSP::OpusDecoder::Message::InitializeMultiStreamDecodeObjectOK, msg);
|
ADSP::OpusDecoder::Message::InitializeMultiStreamDecodeObjectOK, msg);
|
||||||
R_THROW(ResultInvalidOpusDSPReturnCode);
|
R_THROW(ResultInvalidOpusDSPReturnCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
R_RETURN(ResultCodeFromLibOpusErrorCode(shared_memory.dsp_return_data[0]));
|
R_RETURN(ResultCodeFromLibOpusErrorCode(shared_memory.dsp_return_data[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result HardwareOpus::ShutdownDecodeObject(void* buffer, u64 buffer_size) {
|
Result HardwareOpus::ShutdownDecodeObject(void* buffer, u64 buffer_size) {
|
||||||
std::scoped_lock l{mutex};
|
std::scoped_lock l{mutex};
|
||||||
shared_memory.host_send_data[0] = (u64)buffer;
|
shared_memory.host_send_data[0] = (u64)buffer;
|
||||||
shared_memory.host_send_data[1] = buffer_size;
|
shared_memory.host_send_data[1] = buffer_size;
|
||||||
|
|
||||||
opus_decoder.Send(ADSP::Direction::DSP, ADSP::OpusDecoder::Message::ShutdownDecodeObject);
|
opus_decoder.Send(ADSP::Direction::DSP, ADSP::OpusDecoder::Message::ShutdownDecodeObject);
|
||||||
auto msg = opus_decoder.Receive(ADSP::Direction::Host);
|
auto msg = opus_decoder.Receive(ADSP::Direction::Host);
|
||||||
ASSERT_MSG(msg == ADSP::OpusDecoder::Message::ShutdownDecodeObjectOK,
|
ASSERT_MSG(msg == ADSP::OpusDecoder::Message::ShutdownDecodeObjectOK,
|
||||||
"Expected Opus shutdown code {}, got {}",
|
"Expected Opus shutdown code {}, got {}",
|
||||||
ADSP::OpusDecoder::Message::ShutdownDecodeObjectOK, msg);
|
ADSP::OpusDecoder::Message::ShutdownDecodeObjectOK, msg);
|
||||||
|
|
||||||
R_RETURN(ResultCodeFromLibOpusErrorCode(shared_memory.dsp_return_data[0]));
|
R_RETURN(ResultCodeFromLibOpusErrorCode(shared_memory.dsp_return_data[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result HardwareOpus::ShutdownMultiStreamDecodeObject(void* buffer, u64 buffer_size) {
|
Result HardwareOpus::ShutdownMultiStreamDecodeObject(void* buffer, u64 buffer_size) {
|
||||||
std::scoped_lock l{mutex};
|
std::scoped_lock l{mutex};
|
||||||
shared_memory.host_send_data[0] = (u64)buffer;
|
shared_memory.host_send_data[0] = (u64)buffer;
|
||||||
shared_memory.host_send_data[1] = buffer_size;
|
shared_memory.host_send_data[1] = buffer_size;
|
||||||
|
|
||||||
opus_decoder.Send(ADSP::Direction::DSP,
|
opus_decoder.Send(ADSP::Direction::DSP,
|
||||||
ADSP::OpusDecoder::Message::ShutdownMultiStreamDecodeObject);
|
ADSP::OpusDecoder::Message::ShutdownMultiStreamDecodeObject);
|
||||||
auto msg = opus_decoder.Receive(ADSP::Direction::Host);
|
auto msg = opus_decoder.Receive(ADSP::Direction::Host);
|
||||||
ASSERT_MSG(msg == ADSP::OpusDecoder::Message::ShutdownMultiStreamDecodeObjectOK,
|
ASSERT_MSG(msg == ADSP::OpusDecoder::Message::ShutdownMultiStreamDecodeObjectOK,
|
||||||
"Expected Opus shutdown code {}, got {}",
|
"Expected Opus shutdown code {}, got {}",
|
||||||
ADSP::OpusDecoder::Message::ShutdownMultiStreamDecodeObjectOK, msg);
|
ADSP::OpusDecoder::Message::ShutdownMultiStreamDecodeObjectOK, msg);
|
||||||
|
|
||||||
R_RETURN(ResultCodeFromLibOpusErrorCode(shared_memory.dsp_return_data[0]));
|
R_RETURN(ResultCodeFromLibOpusErrorCode(shared_memory.dsp_return_data[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result HardwareOpus::DecodeInterleaved(u32& out_sample_count, void* output_data,
|
Result HardwareOpus::DecodeInterleaved(u32& out_sample_count, void* output_data,
|
||||||
u64 output_data_size, u32 channel_count, void* input_data,
|
u64 output_data_size, u32 channel_count, void* input_data,
|
||||||
u64 input_data_size, void* buffer, u64& out_time_taken,
|
u64 input_data_size, void* buffer, u64& out_time_taken,
|
||||||
bool reset) {
|
bool reset) {
|
||||||
std::scoped_lock l{mutex};
|
std::scoped_lock l{mutex};
|
||||||
shared_memory.host_send_data[0] = (u64)buffer;
|
shared_memory.host_send_data[0] = (u64)buffer;
|
||||||
shared_memory.host_send_data[1] = (u64)input_data;
|
shared_memory.host_send_data[1] = (u64)input_data;
|
||||||
shared_memory.host_send_data[2] = input_data_size;
|
shared_memory.host_send_data[2] = input_data_size;
|
||||||
shared_memory.host_send_data[3] = (u64)output_data;
|
shared_memory.host_send_data[3] = (u64)output_data;
|
||||||
shared_memory.host_send_data[4] = output_data_size;
|
shared_memory.host_send_data[4] = output_data_size;
|
||||||
shared_memory.host_send_data[5] = 0;
|
shared_memory.host_send_data[5] = 0;
|
||||||
shared_memory.host_send_data[6] = reset;
|
shared_memory.host_send_data[6] = reset;
|
||||||
|
|
||||||
opus_decoder.Send(ADSP::Direction::DSP, ADSP::OpusDecoder::Message::DecodeInterleaved);
|
opus_decoder.Send(ADSP::Direction::DSP, ADSP::OpusDecoder::Message::DecodeInterleaved);
|
||||||
auto msg = opus_decoder.Receive(ADSP::Direction::Host);
|
auto msg = opus_decoder.Receive(ADSP::Direction::Host);
|
||||||
if (msg != ADSP::OpusDecoder::Message::DecodeInterleavedOK) {
|
if (msg != ADSP::OpusDecoder::Message::DecodeInterleavedOK) {
|
||||||
LOG_ERROR(Service_Audio, "OpusDecoder returned invalid message. Expected {} got {}",
|
LOG_ERROR(Service_Audio, "OpusDecoder returned invalid message. Expected {} got {}",
|
||||||
ADSP::OpusDecoder::Message::DecodeInterleavedOK, msg);
|
ADSP::OpusDecoder::Message::DecodeInterleavedOK, msg);
|
||||||
R_THROW(ResultInvalidOpusDSPReturnCode);
|
R_THROW(ResultInvalidOpusDSPReturnCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto error_code{static_cast<s32>(shared_memory.dsp_return_data[0])};
|
auto error_code{static_cast<s32>(shared_memory.dsp_return_data[0])};
|
||||||
if (error_code == OPUS_OK) {
|
if (error_code == OPUS_OK) {
|
||||||
out_sample_count = static_cast<u32>(shared_memory.dsp_return_data[1]);
|
out_sample_count = static_cast<u32>(shared_memory.dsp_return_data[1]);
|
||||||
out_time_taken = 1000 * shared_memory.dsp_return_data[2];
|
out_time_taken = 1000 * shared_memory.dsp_return_data[2];
|
||||||
}
|
}
|
||||||
R_RETURN(ResultCodeFromLibOpusErrorCode(error_code));
|
R_RETURN(ResultCodeFromLibOpusErrorCode(error_code));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result HardwareOpus::DecodeInterleavedForMultiStream(u32& out_sample_count, void* output_data,
|
Result HardwareOpus::DecodeInterleavedForMultiStream(u32& out_sample_count, void* output_data,
|
||||||
u64 output_data_size, u32 channel_count,
|
u64 output_data_size, u32 channel_count,
|
||||||
void* input_data, u64 input_data_size,
|
void* input_data, u64 input_data_size,
|
||||||
void* buffer, u64& out_time_taken,
|
void* buffer, u64& out_time_taken,
|
||||||
bool reset) {
|
bool reset) {
|
||||||
std::scoped_lock l{mutex};
|
std::scoped_lock l{mutex};
|
||||||
shared_memory.host_send_data[0] = (u64)buffer;
|
shared_memory.host_send_data[0] = (u64)buffer;
|
||||||
shared_memory.host_send_data[1] = (u64)input_data;
|
shared_memory.host_send_data[1] = (u64)input_data;
|
||||||
shared_memory.host_send_data[2] = input_data_size;
|
shared_memory.host_send_data[2] = input_data_size;
|
||||||
shared_memory.host_send_data[3] = (u64)output_data;
|
shared_memory.host_send_data[3] = (u64)output_data;
|
||||||
shared_memory.host_send_data[4] = output_data_size;
|
shared_memory.host_send_data[4] = output_data_size;
|
||||||
shared_memory.host_send_data[5] = 0;
|
shared_memory.host_send_data[5] = 0;
|
||||||
shared_memory.host_send_data[6] = reset;
|
shared_memory.host_send_data[6] = reset;
|
||||||
|
|
||||||
opus_decoder.Send(ADSP::Direction::DSP,
|
opus_decoder.Send(ADSP::Direction::DSP,
|
||||||
ADSP::OpusDecoder::Message::DecodeInterleavedForMultiStream);
|
ADSP::OpusDecoder::Message::DecodeInterleavedForMultiStream);
|
||||||
auto msg = opus_decoder.Receive(ADSP::Direction::Host);
|
auto msg = opus_decoder.Receive(ADSP::Direction::Host);
|
||||||
if (msg != ADSP::OpusDecoder::Message::DecodeInterleavedForMultiStreamOK) {
|
if (msg != ADSP::OpusDecoder::Message::DecodeInterleavedForMultiStreamOK) {
|
||||||
LOG_ERROR(Service_Audio, "OpusDecoder returned invalid message. Expected {} got {}",
|
LOG_ERROR(Service_Audio, "OpusDecoder returned invalid message. Expected {} got {}",
|
||||||
ADSP::OpusDecoder::Message::DecodeInterleavedForMultiStreamOK, msg);
|
ADSP::OpusDecoder::Message::DecodeInterleavedForMultiStreamOK, msg);
|
||||||
R_THROW(ResultInvalidOpusDSPReturnCode);
|
R_THROW(ResultInvalidOpusDSPReturnCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto error_code{static_cast<s32>(shared_memory.dsp_return_data[0])};
|
auto error_code{static_cast<s32>(shared_memory.dsp_return_data[0])};
|
||||||
if (error_code == OPUS_OK) {
|
if (error_code == OPUS_OK) {
|
||||||
out_sample_count = static_cast<u32>(shared_memory.dsp_return_data[1]);
|
out_sample_count = static_cast<u32>(shared_memory.dsp_return_data[1]);
|
||||||
out_time_taken = 1000 * shared_memory.dsp_return_data[2];
|
out_time_taken = 1000 * shared_memory.dsp_return_data[2];
|
||||||
}
|
}
|
||||||
R_RETURN(ResultCodeFromLibOpusErrorCode(error_code));
|
R_RETURN(ResultCodeFromLibOpusErrorCode(error_code));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result HardwareOpus::MapMemory(void* buffer, u64 buffer_size) {
|
Result HardwareOpus::MapMemory(void* buffer, u64 buffer_size) {
|
||||||
std::scoped_lock l{mutex};
|
std::scoped_lock l{mutex};
|
||||||
shared_memory.host_send_data[0] = (u64)buffer;
|
shared_memory.host_send_data[0] = (u64)buffer;
|
||||||
shared_memory.host_send_data[1] = buffer_size;
|
shared_memory.host_send_data[1] = buffer_size;
|
||||||
|
|
||||||
opus_decoder.Send(ADSP::Direction::DSP, ADSP::OpusDecoder::Message::MapMemory);
|
opus_decoder.Send(ADSP::Direction::DSP, ADSP::OpusDecoder::Message::MapMemory);
|
||||||
auto msg = opus_decoder.Receive(ADSP::Direction::Host);
|
auto msg = opus_decoder.Receive(ADSP::Direction::Host);
|
||||||
if (msg != ADSP::OpusDecoder::Message::MapMemoryOK) {
|
if (msg != ADSP::OpusDecoder::Message::MapMemoryOK) {
|
||||||
LOG_ERROR(Service_Audio, "OpusDecoder returned invalid message. Expected {} got {}",
|
LOG_ERROR(Service_Audio, "OpusDecoder returned invalid message. Expected {} got {}",
|
||||||
ADSP::OpusDecoder::Message::MapMemoryOK, msg);
|
ADSP::OpusDecoder::Message::MapMemoryOK, msg);
|
||||||
R_THROW(ResultInvalidOpusDSPReturnCode);
|
R_THROW(ResultInvalidOpusDSPReturnCode);
|
||||||
}
|
}
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result HardwareOpus::UnmapMemory(void* buffer, u64 buffer_size) {
|
Result HardwareOpus::UnmapMemory(void* buffer, u64 buffer_size) {
|
||||||
std::scoped_lock l{mutex};
|
std::scoped_lock l{mutex};
|
||||||
shared_memory.host_send_data[0] = (u64)buffer;
|
shared_memory.host_send_data[0] = (u64)buffer;
|
||||||
shared_memory.host_send_data[1] = buffer_size;
|
shared_memory.host_send_data[1] = buffer_size;
|
||||||
|
|
||||||
opus_decoder.Send(ADSP::Direction::DSP, ADSP::OpusDecoder::Message::UnmapMemory);
|
opus_decoder.Send(ADSP::Direction::DSP, ADSP::OpusDecoder::Message::UnmapMemory);
|
||||||
auto msg = opus_decoder.Receive(ADSP::Direction::Host);
|
auto msg = opus_decoder.Receive(ADSP::Direction::Host);
|
||||||
if (msg != ADSP::OpusDecoder::Message::UnmapMemoryOK) {
|
if (msg != ADSP::OpusDecoder::Message::UnmapMemoryOK) {
|
||||||
LOG_ERROR(Service_Audio, "OpusDecoder returned invalid message. Expected {} got {}",
|
LOG_ERROR(Service_Audio, "OpusDecoder returned invalid message. Expected {} got {}",
|
||||||
ADSP::OpusDecoder::Message::UnmapMemoryOK, msg);
|
ADSP::OpusDecoder::Message::UnmapMemoryOK, msg);
|
||||||
R_THROW(ResultInvalidOpusDSPReturnCode);
|
R_THROW(ResultInvalidOpusDSPReturnCode);
|
||||||
}
|
}
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace AudioCore::OpusDecoder
|
} // namespace AudioCore::OpusDecoder
|
||||||
|
|
|
@ -1,45 +1,45 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <opus.h>
|
#include <opus.h>
|
||||||
|
|
||||||
#include "audio_core/adsp/apps/opus/opus_decoder.h"
|
#include "audio_core/adsp/apps/opus/opus_decoder.h"
|
||||||
#include "audio_core/adsp/apps/opus/shared_memory.h"
|
#include "audio_core/adsp/apps/opus/shared_memory.h"
|
||||||
#include "audio_core/adsp/mailbox.h"
|
#include "audio_core/adsp/mailbox.h"
|
||||||
#include "core/hle/service/audio/errors.h"
|
#include "core/hle/service/audio/errors.h"
|
||||||
|
|
||||||
namespace AudioCore::OpusDecoder {
|
namespace AudioCore::OpusDecoder {
|
||||||
class HardwareOpus {
|
class HardwareOpus {
|
||||||
public:
|
public:
|
||||||
HardwareOpus(Core::System& system);
|
HardwareOpus(Core::System& system);
|
||||||
|
|
||||||
u64 GetWorkBufferSize(u32 channel);
|
u64 GetWorkBufferSize(u32 channel);
|
||||||
u64 GetWorkBufferSizeForMultiStream(u32 total_stream_count, u32 stereo_stream_count);
|
u64 GetWorkBufferSizeForMultiStream(u32 total_stream_count, u32 stereo_stream_count);
|
||||||
|
|
||||||
Result InitializeDecodeObject(u32 sample_rate, u32 channel_count, void* buffer,
|
Result InitializeDecodeObject(u32 sample_rate, u32 channel_count, void* buffer,
|
||||||
u64 buffer_size);
|
u64 buffer_size);
|
||||||
Result InitializeMultiStreamDecodeObject(u32 sample_rate, u32 channel_count,
|
Result InitializeMultiStreamDecodeObject(u32 sample_rate, u32 channel_count,
|
||||||
u32 totaL_stream_count, u32 stereo_stream_count,
|
u32 totaL_stream_count, u32 stereo_stream_count,
|
||||||
void* mappings, void* buffer, u64 buffer_size);
|
void* mappings, void* buffer, u64 buffer_size);
|
||||||
Result ShutdownDecodeObject(void* buffer, u64 buffer_size);
|
Result ShutdownDecodeObject(void* buffer, u64 buffer_size);
|
||||||
Result ShutdownMultiStreamDecodeObject(void* buffer, u64 buffer_size);
|
Result ShutdownMultiStreamDecodeObject(void* buffer, u64 buffer_size);
|
||||||
Result DecodeInterleaved(u32& out_sample_count, void* output_data, u64 output_data_size,
|
Result DecodeInterleaved(u32& out_sample_count, void* output_data, u64 output_data_size,
|
||||||
u32 channel_count, void* input_data, u64 input_data_size, void* buffer,
|
u32 channel_count, void* input_data, u64 input_data_size, void* buffer,
|
||||||
u64& out_time_taken, bool reset);
|
u64& out_time_taken, bool reset);
|
||||||
Result DecodeInterleavedForMultiStream(u32& out_sample_count, void* output_data,
|
Result DecodeInterleavedForMultiStream(u32& out_sample_count, void* output_data,
|
||||||
u64 output_data_size, u32 channel_count,
|
u64 output_data_size, u32 channel_count,
|
||||||
void* input_data, u64 input_data_size, void* buffer,
|
void* input_data, u64 input_data_size, void* buffer,
|
||||||
u64& out_time_taken, bool reset);
|
u64& out_time_taken, bool reset);
|
||||||
Result MapMemory(void* buffer, u64 buffer_size);
|
Result MapMemory(void* buffer, u64 buffer_size);
|
||||||
Result UnmapMemory(void* buffer, u64 buffer_size);
|
Result UnmapMemory(void* buffer, u64 buffer_size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Core::System& system;
|
Core::System& system;
|
||||||
std::mutex mutex;
|
std::mutex mutex;
|
||||||
ADSP::OpusDecoder::OpusDecoder& opus_decoder;
|
ADSP::OpusDecoder::OpusDecoder& opus_decoder;
|
||||||
ADSP::OpusDecoder::SharedMemory shared_memory;
|
ADSP::OpusDecoder::SharedMemory shared_memory;
|
||||||
};
|
};
|
||||||
} // namespace AudioCore::OpusDecoder
|
} // namespace AudioCore::OpusDecoder
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// SPDX-FileCopyrightText: 2014 Citra Emulator Project
|
// SPDX-FileCopyrightText: 2014 Citra Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Text : Copyright 2022 yuzu Emulator Project
|
// Text : Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
|
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
|
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
|
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
Loading…
Reference in a new issue