From 38c3c9c74b704050d72e397feb290db2e616209a Mon Sep 17 00:00:00 2001 From: xperia64 Date: Tue, 21 Apr 2020 21:34:50 -0400 Subject: [PATCH] Add sample rate field to AAC decoder (#5195) * Add sample rate field to AAC decoder * Fix TODO comment * Remove unneeded conversion --- src/audio_core/hle/decoder.cpp | 26 +++++++++++++++++++++++++ src/audio_core/hle/decoder.h | 18 ++++++++++++++++- src/audio_core/hle/fdk_decoder.cpp | 1 + src/audio_core/hle/ffmpeg_decoder.cpp | 1 + src/audio_core/hle/mediandk_decoder.cpp | 1 + src/audio_core/hle/wmf_decoder.cpp | 1 + 6 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/audio_core/hle/decoder.cpp b/src/audio_core/hle/decoder.cpp index 6569a6f45b..06ee0bca43 100644 --- a/src/audio_core/hle/decoder.cpp +++ b/src/audio_core/hle/decoder.cpp @@ -6,6 +6,32 @@ namespace AudioCore::HLE { +DecoderSampleRate GetSampleRateEnum(u32 sample_rate) { + switch (sample_rate) { + case 48000: + return DecoderSampleRate::Rate48000; + case 44100: + return DecoderSampleRate::Rate44100; + case 32000: + return DecoderSampleRate::Rate32000; + case 24000: + return DecoderSampleRate::Rate24000; + case 22050: + return DecoderSampleRate::Rate22050; + case 16000: + return DecoderSampleRate::Rate16000; + case 12000: + return DecoderSampleRate::Rate12000; + case 11025: + return DecoderSampleRate::Rate11025; + case 8000: + return DecoderSampleRate::Rate8000; + default: + LOG_WARNING(Audio_DSP, "Unknown decoder sample rate: {}", sample_rate); + return DecoderSampleRate::Rate48000; + } +} + DecoderBase::~DecoderBase(){}; NullDecoder::NullDecoder() = default; diff --git a/src/audio_core/hle/decoder.h b/src/audio_core/hle/decoder.h index 7bb5a25f43..f713bb8955 100644 --- a/src/audio_core/hle/decoder.h +++ b/src/audio_core/hle/decoder.h @@ -24,6 +24,20 @@ enum class DecoderCodec : u16 { AAC, }; +// TODO(xperia64): I'm guessing that this is a u32 (from when it was an unknown) +// but it could be a u16 or u8 I suppose +enum class DecoderSampleRate : u32 { + Rate48000 = 0, + Rate44100 = 1, + Rate32000 = 2, + Rate24000 = 3, + Rate22050 = 4, + Rate16000 = 5, + Rate12000 = 6, + Rate11025 = 7, + Rate8000 = 8 +}; + struct BinaryRequest { enum_le codec = DecoderCodec::None; // this is a guess. until now only 0x1 was observed here @@ -43,7 +57,7 @@ struct BinaryResponse { DecoderCodec::None; // this could be something else. until now only 0x1 was observed here enum_le cmd = DecoderCommand::Init; u32_le unknown1 = 0; - u32_le unknown2 = 0; + enum_le sample_rate; u32_le num_channels = 0; // this is a guess, so far I only observed 2 here u32_le size = 0; u32_le unknown3 = 0; @@ -52,6 +66,8 @@ struct BinaryResponse { }; static_assert(sizeof(BinaryResponse) == 32, "Unexpected struct size for BinaryResponse"); +enum_le GetSampleRateEnum(u32 sample_rate); + class DecoderBase { public: virtual ~DecoderBase(); diff --git a/src/audio_core/hle/fdk_decoder.cpp b/src/audio_core/hle/fdk_decoder.cpp index c99e3d43ce..0dac8fd5de 100644 --- a/src/audio_core/hle/fdk_decoder.cpp +++ b/src/audio_core/hle/fdk_decoder.cpp @@ -175,6 +175,7 @@ std::optional FDKDecoder::Impl::Decode(const BinaryRequest& requ // get the stream information stream_info = aacDecoder_GetStreamInfo(decoder); // fill the stream information for binary response + response.sample_rate = GetSampleRateEnum(stream_info->sampleRate); response.num_channels = stream_info->aacNumChannels; response.num_samples = stream_info->frameSize; // fill the output diff --git a/src/audio_core/hle/ffmpeg_decoder.cpp b/src/audio_core/hle/ffmpeg_decoder.cpp index a1b6d141fc..fc2a1c87c9 100644 --- a/src/audio_core/hle/ffmpeg_decoder.cpp +++ b/src/audio_core/hle/ffmpeg_decoder.cpp @@ -211,6 +211,7 @@ std::optional FFMPEGDecoder::Impl::Decode(const BinaryRequest& r std::size_t size = bytes_per_sample * (decoded_frame->nb_samples); + response.sample_rate = GetSampleRateEnum(decoded_frame->sample_rate); response.num_channels = decoded_frame->channels; response.num_samples += decoded_frame->nb_samples; diff --git a/src/audio_core/hle/mediandk_decoder.cpp b/src/audio_core/hle/mediandk_decoder.cpp index f346f8f8fb..16fd0c81ee 100644 --- a/src/audio_core/hle/mediandk_decoder.cpp +++ b/src/audio_core/hle/mediandk_decoder.cpp @@ -138,6 +138,7 @@ std::optional MediaNDKDecoder::Impl::Decode(const BinaryRequest& u8* data = mMemory.GetFCRAMPointer(request.src_addr - Memory::FCRAM_PADDR); ADTSData adts_data = ParseADTS(reinterpret_cast(data)); SetMediaType(adts_data); + response.sample_rate = GetSampleRateEnum(adts_data.samplerate); response.num_channels = adts_data.channels; if (!mDecoder) { LOG_ERROR(Audio_DSP, "Missing decoder for profile: {}, channels: {}, samplerate: {}", diff --git a/src/audio_core/hle/wmf_decoder.cpp b/src/audio_core/hle/wmf_decoder.cpp index f188e5153b..02206ec013 100644 --- a/src/audio_core/hle/wmf_decoder.cpp +++ b/src/audio_core/hle/wmf_decoder.cpp @@ -219,6 +219,7 @@ std::optional WMFDecoder::Impl::Decode(const BinaryRequest& requ return response; } + response.sample_rate = GetSampleRateEnum(adts_meta->ADTSHeader.samplerate); response.num_channels = adts_meta->ADTSHeader.channels; if (!format_selected) {