Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/CUEParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const CUETrackInfo *CUEParser::next_track(uint64_t prev_file_size)
{
// Previous track info is needed to track file offset
uint32_t prev_track_start = m_track_info.track_start;
m_track_info.cumulative_offset += m_track_info.unstored_pregap_length;
uint32_t prev_sector_length = get_sector_length(m_track_info.file_mode, m_track_info.track_mode); // Defaults to 2352 before first track

bool got_file = false;
Expand Down Expand Up @@ -123,13 +124,13 @@ const CUETrackInfo *CUEParser::next_track(uint64_t prev_file_size)
if (index == 0)
{
// Stored pregap that is present both on CD and in data file
m_track_info.track_start = m_track_info.file_start + time;
m_track_info.track_start = m_track_info.file_start + time + m_track_info.cumulative_offset;
got_pause = true;
}
else if (index == 1)
{
// Data content of the track
m_track_info.data_start = m_track_info.file_start + time;
m_track_info.data_start = m_track_info.file_start + time + m_track_info.cumulative_offset;
got_data = true;
}
}
Expand All @@ -148,7 +149,7 @@ const CUETrackInfo *CUEParser::next_track(uint64_t prev_file_size)
if (!got_file)
{
// Advance file position by the length of previous track
m_track_info.file_offset += (uint64_t)(m_track_info.track_start - prev_track_start) * prev_sector_length;
m_track_info.file_offset += (uint64_t)(m_track_info.track_start - (prev_track_start + m_track_info.cumulative_offset)) * prev_sector_length;
}

// Advance file position by any stored pregap
Expand Down
3 changes: 3 additions & 0 deletions src/CUEParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ struct CUETrackInfo
// These frames of silence are not stored in the underlying data file.
uint32_t unstored_pregap_length;

// The cumulative lba offset of unstored data
uint32_t cumulative_offset;

// LBA start position of this file
uint32_t file_start;

Expand Down
21 changes: 14 additions & 7 deletions test/CUEParser_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ FILE "Sound.wav" WAVE
track = parser.next_track();
TEST(track != NULL);
uint32_t start2 = ((2 * 60) + 47) * 75 + 20;
uint32_t pregap_offset = 2 * 75;
if (track)
{
TEST(strcmp(track->filename, "Image Name.bin") == 0);
Expand All @@ -61,8 +62,8 @@ FILE "Sound.wav" WAVE
TEST(track->track_number == 2);
TEST(track->track_mode == CUETrack_AUDIO);
TEST(track->sector_length == 2352);
TEST(track->unstored_pregap_length == 2 * 75);
TEST(track->data_start == start2 + 2 * 75);
TEST(track->unstored_pregap_length == pregap_offset);
TEST(track->data_start == start2 + pregap_offset);
}

COMMENT("Test TRACK 03 (audio with index 0)");
Expand All @@ -78,13 +79,19 @@ FILE "Sound.wav" WAVE
TEST(track->track_number == 3);
TEST(track->track_mode == CUETrack_AUDIO);
TEST(track->sector_length == 2352);
TEST(track->track_start == start3_i0);
TEST(track->data_start == start3_i1);
TEST(track->track_start == start3_i0 + pregap_offset);
TEST(track->data_start == start3_i1 + pregap_offset);
}

COMMENT("Test TRACK 11 (audio from wav)");
track = parser.next_track(track->file_offset + 75 * 4 * 2352);
uint32_t track03_lba_length = 4 * 75;
uint32_t prev_data_start = track->data_start;
// Because the FILE restarts MSF locations we need the lba offset it starts at
uint32_t zeroed_lba_offset = prev_data_start + track03_lba_length;
track = parser.next_track(track->file_offset + track03_lba_length * 2352);
TEST(track != NULL);
uint32_t start11_i0 = zeroed_lba_offset + 0;
uint32_t start11_i1 = zeroed_lba_offset + (2 * 75);
if (track)
{
TEST(strcmp(track->filename, "Sound.wav") == 0);
Expand All @@ -93,8 +100,8 @@ FILE "Sound.wav" WAVE
TEST(track->track_number == 11);
TEST(track->track_mode == CUETrack_AUDIO);
TEST(track->sector_length == 0);
TEST(track->track_start == start3_i1 + 75 * 4);
TEST(track->data_start == start3_i1 + 75 * 6);
TEST(track->track_start == start11_i0 + pregap_offset);
TEST(track->data_start == start11_i1 + pregap_offset);
}

COMMENT("Test end of file");
Expand Down