mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-26 15:45:42 +00:00
CDImage: Handle cue sheets where pregap is in file
This commit is contained in:
parent
68fe492130
commit
2cc5084dd1
|
@ -95,7 +95,7 @@ bool CDImage::Seek(const Position& pos)
|
|||
|
||||
u32 CDImage::Read(ReadMode read_mode, u32 sector_count, void* buffer)
|
||||
{
|
||||
char* buffer_ptr = static_cast<char*>(buffer);
|
||||
u8* buffer_ptr = static_cast<u8*>(buffer);
|
||||
u32 sectors_read = 0;
|
||||
for (; sectors_read < sector_count; sectors_read++)
|
||||
{
|
||||
|
@ -105,16 +105,22 @@ u32 CDImage::Read(ReadMode read_mode, u32 sector_count, void* buffer)
|
|||
break;
|
||||
}
|
||||
|
||||
Assert(m_current_index->file);
|
||||
|
||||
// get raw sector
|
||||
char raw_sector[RAW_SECTOR_SIZE];
|
||||
u8 raw_sector[RAW_SECTOR_SIZE];
|
||||
if (m_current_index->file)
|
||||
{
|
||||
if (std::fread(raw_sector, RAW_SECTOR_SIZE, 1, m_current_index->file) != 1)
|
||||
{
|
||||
Log_ErrorPrintf("Read of LBA %u failed", m_position_on_disc);
|
||||
Seek(m_position_on_disc);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// This in an implicit pregap. Return silence.
|
||||
std::fill(raw_sector, raw_sector + RAW_SECTOR_SIZE, u8(0));
|
||||
}
|
||||
|
||||
switch (read_mode)
|
||||
{
|
||||
|
@ -155,15 +161,20 @@ bool CDImage::ReadRawSector(void* buffer)
|
|||
return false;
|
||||
}
|
||||
|
||||
Assert(m_current_index->file);
|
||||
|
||||
// get raw sector
|
||||
if (m_current_index->file)
|
||||
{
|
||||
if (std::fread(buffer, RAW_SECTOR_SIZE, 1, m_current_index->file) != 1)
|
||||
{
|
||||
Log_ErrorPrintf("Read of LBA %u failed", m_position_on_disc);
|
||||
Seek(m_position_on_disc);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// This in an implicit pregap. Return silence.
|
||||
std::fill(static_cast<u8*>(buffer), static_cast<u8*>(buffer) + RAW_SECTOR_SIZE, u8(0));
|
||||
}
|
||||
|
||||
m_position_on_disc++;
|
||||
m_position_in_index++;
|
||||
|
|
|
@ -107,10 +107,12 @@ bool CDImageCueSheet::OpenAndParse(const char* filename)
|
|||
|
||||
// two seconds pregap for track 1 is assumed if not specified
|
||||
long pregap_frames = track_get_zero_pre(track);
|
||||
bool pregap_in_file = pregap_frames > 0;
|
||||
if (pregap_frames < 0 && track_num == 1)
|
||||
pregap_frames = 2 * FRAMES_PER_SECOND;
|
||||
|
||||
// create the index for the pregap
|
||||
u64 file_offset = static_cast<u64>(static_cast<s64>(track_start)) * track_sector_size;
|
||||
if (pregap_frames > 0)
|
||||
{
|
||||
Index pregap_index = {};
|
||||
|
@ -120,6 +122,14 @@ bool CDImageCueSheet::OpenAndParse(const char* filename)
|
|||
pregap_index.track_number = track_num;
|
||||
pregap_index.index_number = 0;
|
||||
pregap_index.is_pregap = true;
|
||||
if (pregap_in_file)
|
||||
{
|
||||
pregap_index.file = it->second;
|
||||
pregap_index.file_offset = file_offset;
|
||||
pregap_index.file_sector_size = track_sector_size;
|
||||
file_offset += static_cast<u64>(pregap_index.length) * track_sector_size;
|
||||
}
|
||||
|
||||
m_indices.push_back(pregap_index);
|
||||
|
||||
disc_lba += pregap_index.length;
|
||||
|
@ -137,7 +147,7 @@ bool CDImageCueSheet::OpenAndParse(const char* filename)
|
|||
last_index.index_number = 1;
|
||||
last_index.file = it->second;
|
||||
last_index.file_sector_size = track_sector_size;
|
||||
last_index.file_offset = 0;
|
||||
last_index.file_offset = file_offset;
|
||||
last_index.is_pregap = false;
|
||||
|
||||
long last_index_offset = track_start;
|
||||
|
|
Loading…
Reference in a new issue