Skip to content

Commit 1a6012f

Browse files
committed
Fix TOC offset reporting
In ZuluIDE repo, the issue ZuluIDE/ZuluIDE-firmware#179 Shows Alcohol 120% reporting different LBA offsets than the bin/cue it mounts from the ZuluIDE. That particular bin/cue had both PREGAP and INDEX 0 directives. The PREGAP offset wasn't carrying over the LBA offset to the next tracks. Using an accumulator for PREGAP offset and adding it to data_start and track_start fixes the issue. And hopefully subtracting it from the file offset will fix the issue. The reporting side works in Alcohol 120%, have not tested if the data/audio side works yet.
1 parent 34c66f4 commit 1a6012f

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/CUEParser.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const CUETrackInfo *CUEParser::next_track(uint64_t prev_file_size)
6363
{
6464
// Previous track info is needed to track file offset
6565
uint32_t prev_track_start = m_track_info.track_start;
66+
m_track_info.cumulative_offset += m_track_info.unstored_pregap_length;
6667
uint32_t prev_sector_length = get_sector_length(m_track_info.file_mode, m_track_info.track_mode); // Defaults to 2352 before first track
6768

6869
bool got_file = false;
@@ -123,13 +124,13 @@ const CUETrackInfo *CUEParser::next_track(uint64_t prev_file_size)
123124
if (index == 0)
124125
{
125126
// Stored pregap that is present both on CD and in data file
126-
m_track_info.track_start = m_track_info.file_start + time;
127+
m_track_info.track_start = m_track_info.file_start + time + m_track_info.cumulative_offset;
127128
got_pause = true;
128129
}
129130
else if (index == 1)
130131
{
131132
// Data content of the track
132-
m_track_info.data_start = m_track_info.file_start + time;
133+
m_track_info.data_start = m_track_info.file_start + time + m_track_info.cumulative_offset;
133134
got_data = true;
134135
}
135136
}
@@ -148,11 +149,11 @@ const CUETrackInfo *CUEParser::next_track(uint64_t prev_file_size)
148149
if (!got_file)
149150
{
150151
// Advance file position by the length of previous track
151-
m_track_info.file_offset += (uint64_t)(m_track_info.track_start - prev_track_start) * prev_sector_length;
152+
m_track_info.file_offset += (uint64_t)(m_track_info.track_start - (prev_track_start + m_track_info.cumulative_offset)) * prev_sector_length;
152153
}
153154

154155
// Advance file position by any stored pregap
155-
uint32_t stored_pregap = m_track_info.data_start - (m_track_info.track_start + m_track_info.unstored_pregap_length);
156+
uint32_t stored_pregap = (m_track_info.data_start - m_track_info.cumulative_offset) - ((m_track_info.track_start - m_track_info.cumulative_offset) + m_track_info.unstored_pregap_length);
156157
m_track_info.file_offset += (uint64_t)stored_pregap * m_track_info.sector_length;
157158

158159
return &m_track_info;

src/CUEParser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ struct CUETrackInfo
6868
// These frames of silence are not stored in the underlying data file.
6969
uint32_t unstored_pregap_length;
7070

71+
// The cumulative lba offset of unstored data
72+
uint32_t cumulative_offset;
73+
7174
// LBA start position of this file
7275
uint32_t file_start;
7376

0 commit comments

Comments
 (0)