Skip to content

Commit

Permalink
TOC non-zero data range correction
Browse files Browse the repository at this point in the history
move out of TOC support
signed output range
  • Loading branch information
superg committed Jan 9, 2023
1 parent 9e5ecfd commit ca42638
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions split.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1299,10 +1299,10 @@ void redumper_split(const Options &options)
toc.sessions.front().tracks.insert(toc.sessions.front().tracks.begin(), t0);
}

std::pair<int32_t, int32_t> nonzero_toc_range(toc.sessions.front().tracks.front().lba_start * CD_DATA_SIZE_SAMPLES, toc.sessions.back().tracks.back().lba_end * CD_DATA_SIZE_SAMPLES);
std::pair<int32_t, int32_t> nonzero_toc_range(toc.sessions.front().tracks.front().lba_start * CD_DATA_SIZE_SAMPLES, toc.sessions.back().tracks.back().lba_start * CD_DATA_SIZE_SAMPLES);
auto nonzero_data_range = audio_get_sample_range(scm_fs, sectors_count);
LOG("non-zero TOC sample range: [{:9} .. {:9}]", nonzero_toc_range.first, nonzero_toc_range.second);
LOG("non-zero data sample range: [{:9} .. {:9}]", nonzero_data_range.first, nonzero_data_range.second);
LOG("non-zero TOC sample range: [{:+9} .. {:+9}]", nonzero_toc_range.first, nonzero_toc_range.second);
LOG("non-zero data sample range: [{:+9} .. {:+9}]", nonzero_data_range.first, nonzero_data_range.second);
LOG("Universal Hash (SHA-1): {}", calculate_universal_hash(scm_fs, nonzero_data_range));
LOG("");

Expand Down Expand Up @@ -1430,22 +1430,28 @@ void redumper_split(const Options &options)
if(write_offset == std::numeric_limits<int32_t>::max())
{
int32_t toc_sample_size = nonzero_toc_range.second - nonzero_toc_range.first;
int32_t nonzero_sample_size = nonzero_data_range.second - nonzero_data_range.first;
int32_t pregap_sample_size = CD_PREGAP_SIZE * CD_DATA_SIZE_SAMPLES;
int32_t data_sample_size = nonzero_data_range.second - nonzero_data_range.first;

if(nonzero_sample_size <= toc_sample_size)
// attempt to move data only if sample data range fits into TOC calculated range
if(data_sample_size <= toc_sample_size)
{
// move data out of lead-out
if(nonzero_data_range.second > nonzero_toc_range.second)
{
write_offset = nonzero_data_range.second - nonzero_toc_range.second;
LOG("moving data out of lead-out (difference: {:+})", write_offset);
}
// move data out of pre-gap only if we can get rid of it whole
else if(nonzero_data_range.first < nonzero_toc_range.first + pregap_sample_size && nonzero_sample_size + pregap_sample_size <= toc_sample_size)
// move data out of lead-in only if we can get rid of it whole
else if(nonzero_data_range.first < 0 && data_sample_size <= nonzero_toc_range.second)
{
write_offset = nonzero_data_range.first - (nonzero_toc_range.first + pregap_sample_size);
LOG("moving data out of pre-gap (difference: {:+})", write_offset);
write_offset = nonzero_data_range.first;
LOG("moving data out of lead-in (difference: {:+})", write_offset);
}
// move data out of TOC
else if(nonzero_data_range.first < nonzero_toc_range.first && data_sample_size <= toc_sample_size)
{
write_offset = nonzero_data_range.first - nonzero_toc_range.first;
LOG("moving data out of TOC (difference: {:+})", write_offset);
}
}
}
Expand Down

0 comments on commit ca42638

Please sign in to comment.