Add sample rate field to AAC decoder (#5195)
* Add sample rate field to AAC decoder * Fix TODO comment * Remove unneeded conversion
This commit is contained in:
parent
8b43dff849
commit
38c3c9c74b
6 changed files with 47 additions and 1 deletions
|
@ -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;
|
||||
|
|
|
@ -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<DecoderCodec> 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<DecoderCommand> cmd = DecoderCommand::Init;
|
||||
u32_le unknown1 = 0;
|
||||
u32_le unknown2 = 0;
|
||||
enum_le<DecoderSampleRate> 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<DecoderSampleRate> GetSampleRateEnum(u32 sample_rate);
|
||||
|
||||
class DecoderBase {
|
||||
public:
|
||||
virtual ~DecoderBase();
|
||||
|
|
|
@ -175,6 +175,7 @@ std::optional<BinaryResponse> 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
|
||||
|
|
|
@ -211,6 +211,7 @@ std::optional<BinaryResponse> 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;
|
||||
|
||||
|
|
|
@ -138,6 +138,7 @@ std::optional<BinaryResponse> MediaNDKDecoder::Impl::Decode(const BinaryRequest&
|
|||
u8* data = mMemory.GetFCRAMPointer(request.src_addr - Memory::FCRAM_PADDR);
|
||||
ADTSData adts_data = ParseADTS(reinterpret_cast<const char*>(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: {}",
|
||||
|
|
|
@ -219,6 +219,7 @@ std::optional<BinaryResponse> 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) {
|
||||
|
|
Loading…
Reference in a new issue