CDImage: Fix incorrect file offset being used for pregap

This commit is contained in:
Connor McLaughlin 2019-12-06 00:33:21 +10:00
parent 4798f35e40
commit d41a76ac5e

View file

@ -119,12 +119,11 @@ 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; bool pregap_in_file = pregap_frames > 0 && track_start >= pregap_frames;
if (pregap_frames < 0 && track_num == 1) if (pregap_frames < 0 && mode != TrackMode::Audio)
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 = {};
@ -139,9 +138,8 @@ bool CDImageCueSheet::OpenAndParse(const char* filename)
if (pregap_in_file) if (pregap_in_file)
{ {
pregap_index.file = it->second; pregap_index.file = it->second;
pregap_index.file_offset = file_offset; pregap_index.file_offset = static_cast<u64>(static_cast<s64>(track_start - pregap_frames)) * track_sector_size;
pregap_index.file_sector_size = track_sector_size; 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);
@ -162,7 +160,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 = file_offset; last_index.file_offset = static_cast<u64>(static_cast<s64>(track_start)) * track_sector_size;
last_index.mode = mode; last_index.mode = mode;
last_index.control.bits = control.bits; last_index.control.bits = control.bits;
last_index.is_pregap = false; last_index.is_pregap = false;