Merge pull request #8059 from unknownbrackets/atrac-headermap

Atrac: calculate instead of using header value map
This commit is contained in:
Henrik Rydgård 2015-10-13 08:31:13 +02:00
commit 7924ccf64c
2 changed files with 22 additions and 64 deletions

View File

@ -2046,8 +2046,7 @@ static int _sceAtracGetContextAddress(int atracID) {
struct At3HeaderMap {
u16 bytes;
u16 channels;
u8 headerVal1;
u8 headerVal2;
u8 jointStereo;
bool Matches(const Atrac *at) const {
return bytes == at->atracBytesPerFrame && channels == at->atracChannels;
@ -2055,48 +2054,17 @@ struct At3HeaderMap {
};
static const u8 at3HeaderTemplate[] ={0x52,0x49,0x46,0x46,0x3b,0xbe,0x00,0x00,0x57,0x41,0x56,0x45,0x66,0x6d,0x74,0x20,0x20,0x00,0x00,0x00,0x70,0x02,0x02,0x00,0x44,0xac,0x00,0x00,0x4d,0x20,0x00,0x00,0xc0,0x00,0x00,0x00,0x0e,0x00,0x01,0x00,0x00,0x10,0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x00,0x00,0x64,0x61,0x74,0x61,0xc0,0xbd,0x00,0x00};
// These should represent all possible supported bitrates (66, 104, and 132 for stereo.)
static const At3HeaderMap at3HeaderMap[] = {
{ 0x00C0, 0x1, 0x8, 0x00 },
{ 0x0098, 0x1, 0x8, 0x00 },
{ 0x0180, 0x2, 0x10, 0x00 },
{ 0x0130, 0x2, 0x10, 0x00 },
{ 0x00C0, 0x2, 0x10, 0x01 }
};
struct At3plusHeaderMap {
u16 bytes;
u16 channels;
u16 headerVal;
bool Matches(const Atrac *at) const {
return bytes == at->atracBytesPerFrame && channels == at->atracChannels;
}
{ 0x00C0, 1, 0 }, // 132/2 (66) kbps mono
{ 0x0098, 1, 0 }, // 105/2 (52.5) kbps mono
{ 0x0180, 2, 0 }, // 132 kbps stereo
{ 0x0130, 2, 0 }, // 105 kbps stereo
// At this size, stereo can only use joint stereo.
{ 0x00C0, 2, 1 }, // 66 kbps stereo
};
static const u8 at3plusHeaderTemplate[] = { 0x52, 0x49, 0x46, 0x46, 0x00, 0xb5, 0xff, 0x00, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6d, 0x74, 0x20, 0x34, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x02, 0x00, 0x44, 0xac, 0x00, 0x00, 0xa0, 0x1f, 0x00, 0x00, 0xe8, 0x02, 0x00, 0x00, 0x22, 0x00, 0x00, 0x08, 0x03, 0x00, 0x00, 0x00, 0xbf, 0xaa, 0x23, 0xe9, 0x58, 0xcb, 0x71, 0x44, 0xa1, 0x19, 0xff, 0xfa, 0x01, 0xe4, 0xce, 0x62, 0x01, 0x00, 0x28, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x61, 0x63, 0x74, 0x08, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x08, 0x00, 0x00, 0x64, 0x61, 0x74, 0x61, 0xa8, 0xb4, 0xff, 0x00 };
static const At3plusHeaderMap at3plusHeaderMap[] = {
{ 0x00C0, 0x1, 0x1724 },
{ 0x0180, 0x1, 0x2224 },
{ 0x0178, 0x1, 0x2E24 },
{ 0x0230, 0x1, 0x4524 },
{ 0x02E8, 0x1, 0x5C24 },
{ 0x0118, 0x1, 0x2224 },
{ 0x0118, 0x2, 0x2228 },
{ 0x0178, 0x2, 0x2E28 },
{ 0x0230, 0x2, 0x4528 },
{ 0x02E8, 0x2, 0x5C28 },
{ 0x03A8, 0x2, 0x7428 },
{ 0x0460, 0x2, 0x8B28 },
{ 0x05D0, 0x2, 0xB928 },
{ 0x0748, 0x2, 0xE828 },
{ 0x0800, 0x2, 0xFF28 },
};
static bool initAT3Decoder(Atrac *atrac, u8 *at3Header, u32 dataSize = 0xffb4a8) {
for (size_t i = 0; i < ARRAY_SIZE(at3HeaderMap); ++i) {
@ -2107,9 +2075,9 @@ static bool initAT3Decoder(Atrac *atrac, u8 *at3Header, u32 dataSize = 0xffb4a8)
atrac->atracBitrate = ( atrac->atracBytesPerFrame * 352800 ) / 1000;
atrac->atracBitrate = (atrac->atracBitrate + 511) >> 10;
*(u32 *)(at3Header + 0x1c) = atrac->atracBitrate * 1000 / 8;
at3Header[0x29] = at3HeaderMap[i].headerVal1;
at3Header[0x2c] = at3HeaderMap[i].headerVal2;
at3Header[0x2e] = at3HeaderMap[i].headerVal2;
at3Header[0x29] = atrac->atracChannels << 3;
at3Header[0x2c] = at3HeaderMap[i].jointStereo;
at3Header[0x2e] = at3HeaderMap[i].jointStereo;
*(u32 *)(at3Header + sizeof(at3HeaderTemplate) - 4) = dataSize;
return true;
}
@ -2117,21 +2085,16 @@ static bool initAT3Decoder(Atrac *atrac, u8 *at3Header, u32 dataSize = 0xffb4a8)
return false;
}
static bool initAT3plusDecoder(Atrac *atrac, u8 *at3plusHeader, u32 dataSize = 0xffb4a8) {
for (size_t i = 0; i < ARRAY_SIZE(at3plusHeaderMap); ++i) {
if (at3plusHeaderMap[i].Matches(atrac)) {
*(u32 *)(at3plusHeader + 0x04) = dataSize + sizeof(at3plusHeaderTemplate) - 8;
*(u16 *)(at3plusHeader + 0x16) = atrac->atracChannels;
*(u16 *)(at3plusHeader + 0x20) = atrac->atracBytesPerFrame;
atrac->atracBitrate = ( atrac->atracBytesPerFrame * 352800 ) / 1000;
atrac->atracBitrate = ((atrac->atracBitrate >> 11) + 8) & 0xFFFFFFF0;
*(u32 *)(at3plusHeader + 0x1c) = atrac->atracBitrate * 1000 / 8;
*(u16 *)(at3plusHeader + 0x3e) = at3plusHeaderMap[i].headerVal;
*(u32 *)(at3plusHeader + sizeof(at3plusHeaderTemplate) - 4) = dataSize;
return true;
}
}
return false;
static void initAT3plusDecoder(Atrac *atrac, u8 *at3plusHeader, u32 dataSize = 0xffb4a8) {
*(u32 *)(at3plusHeader + 0x04) = dataSize + sizeof(at3plusHeaderTemplate) - 8;
*(u16 *)(at3plusHeader + 0x16) = atrac->atracChannels;
*(u16 *)(at3plusHeader + 0x20) = atrac->atracBytesPerFrame;
atrac->atracBitrate = ( atrac->atracBytesPerFrame * 352800 ) / 1000;
atrac->atracBitrate = ((atrac->atracBitrate >> 11) + 8) & 0xFFFFFFF0;
*(u32 *)(at3plusHeader + 0x1c) = atrac->atracBitrate * 1000 / 8;
u32 codecParams = ((atrac->atracBytesPerFrame - 7) << 5) | (atrac->atracChannels << 2);
*(u16 *)(at3plusHeader + 0x3e) = codecParams;
*(u32 *)(at3plusHeader + sizeof(at3plusHeaderTemplate) - 4) = dataSize;
}
static int sceAtracLowLevelInitDecoder(int atracID, u32 paramsAddr) {
@ -2186,10 +2149,7 @@ static int sceAtracLowLevelInitDecoder(int atracID, u32 paramsAddr) {
const int headersize = sizeof(at3plusHeaderTemplate);
u8 at3plusHeader[headersize];
memcpy(at3plusHeader, at3plusHeaderTemplate, headersize);
if (!initAT3plusDecoder(atrac, at3plusHeader)) {
ERROR_LOG_REPORT(ME, "AT3plus header map lacks entry for bpf: %i channels: %i", atrac->atracBytesPerFrame, atrac->atracChannels);
// TODO: What to do, if anything?
}
initAT3plusDecoder(atrac, at3plusHeader);
atrac->firstSampleoffset = headersize;
atrac->dataOff = headersize;

View File

@ -24,8 +24,6 @@ GPUCommon::GPUCommon() :
dumpNextFrame_(false),
dumpThisFrame_(false)
{
DisplayList x;
// This assert failed on GCC x86 32-bit (but not MSVC 32-bit!) before adding the
// "padding" field at the end. This is important for save state compatibility.
// The compiler was not rounding the struct size up to an 8 byte boundary, which