From 9541a2a5f06dd2e3ddbca4164c0587542474eff7 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 15 Aug 2017 15:54:09 -0400 Subject: [PATCH] Corrections: `seek_to` now takes the `segment_start_time` into account, correcting a windowing error where segments overlay other segments. Also added some asserts while bug hunting, and corrected the steps taken when inserting a longer-than-a-track segment so that each is correctly windowed. --- Storage/Disk/PCMPatchedTrack.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Storage/Disk/PCMPatchedTrack.cpp b/Storage/Disk/PCMPatchedTrack.cpp index db865b331..f71f56e39 100644 --- a/Storage/Disk/PCMPatchedTrack.cpp +++ b/Storage/Disk/PCMPatchedTrack.cpp @@ -8,6 +8,8 @@ #include "PCMPatchedTrack.hpp" +#include + using namespace Storage::Disk; PCMPatchedTrack::PCMPatchedTrack(std::shared_ptr underlying_track) : @@ -38,11 +40,13 @@ void PCMPatchedTrack::add_segment(const Time &start_time, const PCMSegment &segm // the new segment may wrap around, so divide it up into track-length parts if required Time one = Time(1); + assert(insertion_period.start_time <= one); while(insertion_period.end_time > one) { Time next_end_time = insertion_period.end_time - one; insertion_period.end_time = one; insert_period(insertion_period); + insertion_period.segment_start_time += one; insertion_period.start_time = zero; insertion_period.end_time = next_end_time; } @@ -127,8 +131,7 @@ void PCMPatchedTrack::insert_period(const Period &period) { } } -Track::Event PCMPatchedTrack::get_next_event() -{ +Track::Event PCMPatchedTrack::get_next_event() { const Time one(1); const Time zero(0); Time extra_time(0); @@ -184,11 +187,14 @@ Track::Event PCMPatchedTrack::get_next_event() Storage::Time PCMPatchedTrack::seek_to(const Time &time_since_index_hole) { // start at the beginning and continue while segments end before reaching the time sought active_period_ = periods_.begin(); - while(active_period_->end_time < time_since_index_hole) active_period_++; + while(active_period_->end_time < time_since_index_hole) { + assert(active_period_ != periods_.end()); + active_period_++; + } // allow whatever storage represents the period found to perform its seek if(active_period_->event_source) - current_time_ = active_period_->event_source->seek_to(time_since_index_hole - active_period_->start_time) + active_period_->start_time; + current_time_ = active_period_->event_source->seek_to(active_period_->segment_start_time + time_since_index_hole - active_period_->start_time) + active_period_->start_time; else current_time_ = underlying_track_->seek_to(time_since_index_hole); return current_time_;