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)
|
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;
|
u32 sectors_read = 0;
|
||||||
for (; sectors_read < sector_count; sectors_read++)
|
for (; sectors_read < sector_count; sectors_read++)
|
||||||
{
|
{
|
||||||
|
@ -105,16 +105,22 @@ u32 CDImage::Read(ReadMode read_mode, u32 sector_count, void* buffer)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert(m_current_index->file);
|
|
||||||
|
|
||||||
// get raw sector
|
// 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)
|
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);
|
Log_ErrorPrintf("Read of LBA %u failed", m_position_on_disc);
|
||||||
Seek(m_position_on_disc);
|
Seek(m_position_on_disc);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// This in an implicit pregap. Return silence.
|
||||||
|
std::fill(raw_sector, raw_sector + RAW_SECTOR_SIZE, u8(0));
|
||||||
|
}
|
||||||
|
|
||||||
switch (read_mode)
|
switch (read_mode)
|
||||||
{
|
{
|
||||||
|
@ -155,15 +161,20 @@ bool CDImage::ReadRawSector(void* buffer)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert(m_current_index->file);
|
if (m_current_index->file)
|
||||||
|
{
|
||||||
// get raw sector
|
|
||||||
if (std::fread(buffer, RAW_SECTOR_SIZE, 1, m_current_index->file) != 1)
|
if (std::fread(buffer, RAW_SECTOR_SIZE, 1, m_current_index->file) != 1)
|
||||||
{
|
{
|
||||||
Log_ErrorPrintf("Read of LBA %u failed", m_position_on_disc);
|
Log_ErrorPrintf("Read of LBA %u failed", m_position_on_disc);
|
||||||
Seek(m_position_on_disc);
|
Seek(m_position_on_disc);
|
||||||
return false;
|
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_on_disc++;
|
||||||
m_position_in_index++;
|
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
|
// two seconds pregap for track 1 is assumed if not specified
|
||||||
long pregap_frames = track_get_zero_pre(track);
|
long pregap_frames = track_get_zero_pre(track);
|
||||||
|
bool pregap_in_file = pregap_frames > 0;
|
||||||
if (pregap_frames < 0 && track_num == 1)
|
if (pregap_frames < 0 && track_num == 1)
|
||||||
pregap_frames = 2 * FRAMES_PER_SECOND;
|
pregap_frames = 2 * FRAMES_PER_SECOND;
|
||||||
|
|
||||||
// create the index for the pregap
|
// create the index for the pregap
|
||||||
|
u64 file_offset = static_cast<u64>(static_cast<s64>(track_start)) * track_sector_size;
|
||||||
if (pregap_frames > 0)
|
if (pregap_frames > 0)
|
||||||
{
|
{
|
||||||
Index pregap_index = {};
|
Index pregap_index = {};
|
||||||
|
@ -120,6 +122,14 @@ bool CDImageCueSheet::OpenAndParse(const char* filename)
|
||||||
pregap_index.track_number = track_num;
|
pregap_index.track_number = track_num;
|
||||||
pregap_index.index_number = 0;
|
pregap_index.index_number = 0;
|
||||||
pregap_index.is_pregap = true;
|
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);
|
m_indices.push_back(pregap_index);
|
||||||
|
|
||||||
disc_lba += pregap_index.length;
|
disc_lba += pregap_index.length;
|
||||||
|
@ -137,7 +147,7 @@ bool CDImageCueSheet::OpenAndParse(const char* filename)
|
||||||
last_index.index_number = 1;
|
last_index.index_number = 1;
|
||||||
last_index.file = it->second;
|
last_index.file = it->second;
|
||||||
last_index.file_sector_size = track_sector_size;
|
last_index.file_sector_size = track_sector_size;
|
||||||
last_index.file_offset = 0;
|
last_index.file_offset = file_offset;
|
||||||
last_index.is_pregap = false;
|
last_index.is_pregap = false;
|
||||||
|
|
||||||
long last_index_offset = track_start;
|
long last_index_offset = track_start;
|
||||||
|
|
Loading…
Reference in New Issue