Skip to content

Commit 9ca55c9

Browse files
committed
Fix unstored pregap offset regression
The previous fix for mixed unstored and stored pregaps (CUE file PREGAP and INDEX 00) broke standard unstored pregap handling.
1 parent 0e957c5 commit 9ca55c9

3 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/CUEParser.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ const CUETrackInfo *CUEParser::next_track(uint64_t prev_file_size)
7575
bool got_track = false;
7676
bool got_data = false;
7777
bool got_pause = false; // true if a period of silence (INDEX 00) was encountered for a track
78-
uint32_t stored_pregap = 0;
7978
while(!(got_track && got_data) && start_line())
8079
{
8180
if (strncasecmp(m_parse_pos, "FILE ", 5) == 0)
@@ -105,6 +104,7 @@ const CUETrackInfo *CUEParser::next_track(uint64_t prev_file_size)
105104
m_track_info.track_mode = parse_track_mode(skip_space(endptr));
106105
m_track_info.sector_length = get_sector_length(m_track_info.file_mode, m_track_info.track_mode);
107106
m_track_info.unstored_pregap_length = 0;
107+
m_track_info.stored_pregap_length = 0;
108108
m_track_info.data_start = 0;
109109
m_track_info.track_start = 0;
110110
got_track = true;
@@ -131,14 +131,12 @@ const CUETrackInfo *CUEParser::next_track(uint64_t prev_file_size)
131131
{
132132
// Stored pregap that is present both on CD and in data file
133133
m_track_info.track_start = m_track_info.file_start + time + m_track_info.cumulative_offset;
134-
stored_pregap = time;
135134
got_pause = true;
136135
}
137136
else if (index == 1)
138137
{
139138
// Data content of the track
140139
m_track_info.data_start = m_track_info.file_start + time + m_track_info.cumulative_offset;
141-
stored_pregap = time - stored_pregap;
142140
got_data = true;
143141
}
144142
}
@@ -163,7 +161,15 @@ const CUETrackInfo *CUEParser::next_track(uint64_t prev_file_size)
163161
if (got_pause)
164162
{
165163
// Advance file position by any stored pregap
166-
m_track_info.file_offset += stored_pregap * m_track_info.sector_length;
164+
m_track_info.stored_pregap_length = m_track_info.data_start - m_track_info.track_start;
165+
m_track_info.file_offset += (uint64_t)(m_track_info.stored_pregap_length) * m_track_info.sector_length;
166+
m_track_info.track_start += m_track_info.unstored_pregap_length;
167+
m_track_info.data_start += m_track_info.unstored_pregap_length;
168+
}
169+
else
170+
{
171+
uint32_t adjustment = m_track_info.data_start - (m_track_info.track_start + m_track_info.unstored_pregap_length);
172+
m_track_info.file_offset += (uint64_t)adjustment * m_track_info.sector_length;
167173
}
168174

169175
return &m_track_info;

src/CUEParser.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ struct CUETrackInfo
7373
// These frames of silence are not stored in the underlying data file.
7474
uint32_t unstored_pregap_length;
7575

76+
// The CD frames of PREGAP time at the start of this track,
77+
// which are present both on CD and in data file.
78+
uint32_t stored_pregap_length;
79+
7680
// The cumulative lba offset of unstored data
7781
uint32_t cumulative_offset;
7882

test/CUEParser_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,12 @@ FILE "mixed-cd.bin" BINARY
409409
if (track)
410410
{
411411
uint32_t pregap_offset = 2 * 75;
412-
uint32_t start2_i0 = ((29 * 60) + 9) * 75 + 48;
413-
uint32_t start2_i1 = ((29 * 60) + 10) * 75 + 48;
412+
uint32_t start2_i0 = ((29 * 60) + 9) * 75 + 48 + pregap_offset;
413+
uint32_t start2_i1 = ((29 * 60) + 10) * 75 + 48 + pregap_offset;
414414

415415
TEST(strcmp(track->filename, "mixed-cd.bin") == 0);
416416
TEST(track->file_mode == CUEFile_BINARY);
417-
TEST(track->file_offset == start2_i1 * 2352);
417+
TEST(track->file_offset == (start2_i1 - pregap_offset) * 2352);
418418
TEST(track->file_index == 1);
419419
TEST(track->track_number == 2);
420420
TEST(track->track_mode == CUETrack_AUDIO);

0 commit comments

Comments
 (0)