@@ -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;
0 commit comments