2019-01-06 05:53:24 +01:00
|
|
|
// Copyright 2019 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
2018-12-19 17:12:57 +01:00
|
|
|
#include "adts.h"
|
|
|
|
|
2019-01-06 05:53:24 +01:00
|
|
|
constexpr std::array<u32, 16> freq_table = {96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
|
2019-01-06 06:28:56 +01:00
|
|
|
16000, 12000, 11025, 8000, 7350, 0, 0, 0};
|
2019-01-06 05:53:24 +01:00
|
|
|
constexpr std::array<u8, 8> channel_table = {0, 1, 2, 3, 4, 5, 6, 8};
|
2018-12-19 17:12:57 +01:00
|
|
|
|
2019-01-29 05:47:41 +01:00
|
|
|
u32 ParseADTS(char* buffer, ADTSData* out) {
|
2019-01-06 05:53:24 +01:00
|
|
|
u32 tmp = 0;
|
2018-12-19 17:12:57 +01:00
|
|
|
|
|
|
|
// sync word 0xfff
|
|
|
|
tmp = (buffer[0] << 8) | (buffer[1] & 0xf0);
|
|
|
|
if ((tmp & 0xffff) != 0xfff0)
|
|
|
|
return 0;
|
|
|
|
out->MPEG2 = (buffer[1] >> 3) & 0x1;
|
|
|
|
// bit 17 to 18
|
|
|
|
out->profile = (buffer[2] >> 6) + 1;
|
|
|
|
// bit 19 to 22
|
|
|
|
tmp = (buffer[2] >> 2) & 0xf;
|
|
|
|
out->samplerate_idx = tmp;
|
|
|
|
out->samplerate = (tmp > 15) ? 0 : freq_table[tmp];
|
|
|
|
// bit 24 to 26
|
|
|
|
tmp = ((buffer[2] & 0x1) << 2) | ((buffer[3] >> 6) & 0x3);
|
|
|
|
out->channel_idx = tmp;
|
|
|
|
out->channels = (tmp > 7) ? 0 : channel_table[tmp];
|
|
|
|
|
|
|
|
// bit 55 to 56
|
|
|
|
out->framecount = (buffer[6] & 0x3) + 1;
|
|
|
|
|
|
|
|
// bit 31 to 43
|
|
|
|
tmp = (buffer[3] & 0x3) << 11;
|
|
|
|
tmp |= (buffer[4] << 3) & 0x7f8;
|
|
|
|
tmp |= (buffer[5] >> 5) & 0x7;
|
|
|
|
|
|
|
|
out->length = tmp;
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// last two bytes of MF AAC decoder user data
|
2019-01-29 05:47:41 +01:00
|
|
|
// Audio object type (5 bits)
|
|
|
|
// Sample rate profile (4 bits)
|
|
|
|
// Channel configuration profile (4 bits)
|
|
|
|
// Frame length flag (1 bit)
|
|
|
|
// Depends on core coder (1 bit)
|
|
|
|
// Extension flag (1 bit)
|
|
|
|
u16 MFGetAACTag(ADTSData input) {
|
2019-01-06 05:53:24 +01:00
|
|
|
u16 tag = 0;
|
2018-12-19 17:12:57 +01:00
|
|
|
|
|
|
|
tag |= input.profile << 11;
|
|
|
|
tag |= input.samplerate_idx << 7;
|
|
|
|
tag |= input.channel_idx << 3;
|
|
|
|
|
|
|
|
return tag;
|
|
|
|
}
|