From d41a76ac5e474e76a62315061ae8a11a0fa626f1 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Fri, 6 Dec 2019 00:33:21 +1000 Subject: [PATCH] CDImage: Fix incorrect file offset being used for pregap --- src/common/cd_image_cue.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/common/cd_image_cue.cpp b/src/common/cd_image_cue.cpp index ba8ea396f..91f9ec66c 100644 --- a/src/common/cd_image_cue.cpp +++ b/src/common/cd_image_cue.cpp @@ -119,12 +119,11 @@ 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) + bool pregap_in_file = pregap_frames > 0 && track_start >= pregap_frames; + if (pregap_frames < 0 && mode != TrackMode::Audio) pregap_frames = 2 * FRAMES_PER_SECOND; // create the index for the pregap - u64 file_offset = static_cast(static_cast(track_start)) * track_sector_size; if (pregap_frames > 0) { Index pregap_index = {}; @@ -139,9 +138,8 @@ bool CDImageCueSheet::OpenAndParse(const char* filename) if (pregap_in_file) { pregap_index.file = it->second; - pregap_index.file_offset = file_offset; + pregap_index.file_offset = static_cast(static_cast(track_start - pregap_frames)) * track_sector_size; pregap_index.file_sector_size = track_sector_size; - file_offset += static_cast(pregap_index.length) * track_sector_size; } m_indices.push_back(pregap_index); @@ -162,7 +160,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 = file_offset; + last_index.file_offset = static_cast(static_cast(track_start)) * track_sector_size; last_index.mode = mode; last_index.control.bits = control.bits; last_index.is_pregap = false;