CHD: swap bytes of CHDv5+ audio tracks

Thanks @flyinghead
See https://github.com/libretro/reicast-emulator/pull/370
This commit is contained in:
Christoph "baka0815" Schwerdtfeger 2018-11-03 19:29:55 +01:00
parent 161e84598d
commit 001a767ab7
1 changed files with 16 additions and 2 deletions

View File

@ -37,13 +37,15 @@ struct CHDTrack : TrackFile
u32 StartFAD;
u32 Offset;
u32 fmt;
bool swap_bytes;
CHDTrack(CHDDisc* disc, u32 StartFAD, u32 Offset, u32 fmt)
CHDTrack(CHDDisc* disc, u32 StartFAD, u32 Offset, u32 fmt, bool swap_bytes)
{
this->disc=disc;
this->StartFAD=StartFAD;
this->Offset=Offset;
this->fmt=fmt;
this->swap_bytes = swap_bytes;
}
virtual void Read(u32 FAD, u8* dst, SectorFormat* sector_type, u8* subcode, SubcodeFormat* subcode_type)
@ -61,6 +63,15 @@ struct CHDTrack : TrackFile
memcpy(dst, disc->hunk_mem + hunk_ofs * (2352+96), fmt);
if (swap_bytes)
{
for (int i = 0; i < fmt; i += 2)
{
u8 b = dst[i];
dst[i] = dst[i + 1];
dst[i + 1] = b;
}
}
*sector_type=fmt==2352?SECFMT_2352:SECFMT_2048_MODE1;
//While space is reserved for it, the images contain no actual subcodes
@ -147,7 +158,10 @@ bool CHDDisc::TryOpen(const wchar* file)
t.EndFAD = total_frames - 1;
t.ADDR = 0;
t.CTRL = strcmp(type,"AUDIO") == 0 ? 0 : 4;
t.file = new CHDTrack(this, t.StartFAD, Offset - t.StartFAD, strcmp(type,"MODE1") ? 2352 : 2048);
t.file = new CHDTrack(this, t.StartFAD, Offset - t.StartFAD, strcmp(type, "MODE1") ? 2352 : 2048,
// audio tracks are byteswapped in CHDv5+
t.CTRL == 0 && head->version >= 5);
// CHD files are padded, so we have to respect the offset
int padded = (frames + CD_TRACK_PADDING - 1) / CD_TRACK_PADDING;