mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-22 12:33:29 +00:00
Added a guarantee that the TrackSerialiser won't modify tracks it receives.
This commit is contained in:
parent
ed06533e60
commit
8263c48a1d
@ -27,7 +27,7 @@ PCMPatchedTrack::PCMPatchedTrack(const PCMPatchedTrack &original) {
|
||||
active_period_ = periods_.begin();
|
||||
}
|
||||
|
||||
Track *PCMPatchedTrack::clone() {
|
||||
Track *PCMPatchedTrack::clone() const {
|
||||
return new PCMPatchedTrack(*this);
|
||||
}
|
||||
|
||||
|
@ -43,9 +43,9 @@ class PCMPatchedTrack: public Track {
|
||||
void add_segment(const Time &start_time, const PCMSegment &segment, bool clamp_to_index_hole);
|
||||
|
||||
// To satisfy Storage::Disk::Track
|
||||
Event get_next_event();
|
||||
Time seek_to(const Time &time_since_index_hole);
|
||||
Track *clone();
|
||||
Event get_next_event() override;
|
||||
Time seek_to(const Time &time_since_index_hole) override;
|
||||
Track *clone() const override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Track> underlying_track_;
|
||||
|
@ -46,7 +46,7 @@ PCMTrack::PCMTrack(const PCMTrack &original) : PCMTrack() {
|
||||
segment_event_sources_ = original.segment_event_sources_;
|
||||
}
|
||||
|
||||
Track *PCMTrack::clone() {
|
||||
Track *PCMTrack::clone() const {
|
||||
return new PCMTrack(*this);
|
||||
}
|
||||
|
||||
|
@ -42,9 +42,9 @@ class PCMTrack: public Track {
|
||||
PCMTrack(const PCMTrack &);
|
||||
|
||||
// as per @c Track
|
||||
Event get_next_event();
|
||||
Time seek_to(const Time &time_since_index_hole);
|
||||
Track *clone();
|
||||
Event get_next_event() override;
|
||||
Time seek_to(const Time &time_since_index_hole) override;
|
||||
Track *clone() const override;
|
||||
|
||||
private:
|
||||
// storage for the segments that describe this track
|
||||
|
@ -114,7 +114,7 @@ class Track {
|
||||
/*!
|
||||
The virtual copy constructor pattern; returns a copy of the Track.
|
||||
*/
|
||||
virtual Track *clone() = 0;
|
||||
virtual Track *clone() const = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -8,11 +8,14 @@
|
||||
|
||||
#include "TrackSerialiser.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
// TODO: if this is a PCMTrack with only one segment and that segment's bit rate is within tolerance,
|
||||
// just return a copy of that segment.
|
||||
Storage::Disk::PCMSegment Storage::Disk::track_serialisation(Track &track, Time length_of_a_bit) {
|
||||
Storage::Disk::PCMSegment Storage::Disk::track_serialisation(const Track &track, Time length_of_a_bit) {
|
||||
unsigned int history_size = 16;
|
||||
DigitalPhaseLockedLoop pll(100, history_size);
|
||||
std::unique_ptr<Track> track_copy(track.clone());
|
||||
|
||||
struct ResultAccumulator: public DigitalPhaseLockedLoop::Delegate {
|
||||
PCMSegment result;
|
||||
@ -29,12 +32,12 @@ Storage::Disk::PCMSegment Storage::Disk::track_serialisation(Track &track, Time
|
||||
length_multiplier.simplify();
|
||||
|
||||
// start at the index hole
|
||||
track.seek_to(Time(0));
|
||||
track_copy->seek_to(Time(0));
|
||||
|
||||
// grab events until the next index hole
|
||||
Time time_error = Time(0);
|
||||
while(true) {
|
||||
Track::Event next_event = track.get_next_event();
|
||||
Track::Event next_event = track_copy->get_next_event();
|
||||
if(next_event.type == Track::Event::IndexHole) break;
|
||||
|
||||
Time extended_length = next_event.length * length_multiplier + time_error;
|
||||
@ -47,7 +50,7 @@ Storage::Disk::PCMSegment Storage::Disk::track_serialisation(Track &track, Time
|
||||
if(history_size) {
|
||||
history_size--;
|
||||
if(!history_size) {
|
||||
track.seek_to(Time(0));
|
||||
track_copy->seek_to(Time(0));
|
||||
time_error.set_zero();
|
||||
pll.set_delegate(&result_accumulator);
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ namespace Disk {
|
||||
@param length_of_a_bit The expected length of a single bit, as a proportion of the
|
||||
track length.
|
||||
*/
|
||||
PCMSegment track_serialisation(Track &track, Time length_of_a_bit);
|
||||
PCMSegment track_serialisation(const Track &track, Time length_of_a_bit);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,6 @@ Storage::Time UnformattedTrack::seek_to(const Time &time_since_index_hole) {
|
||||
return Time(0);
|
||||
}
|
||||
|
||||
Track *UnformattedTrack::clone() {
|
||||
Track *UnformattedTrack::clone() const {
|
||||
return new UnformattedTrack;
|
||||
}
|
||||
|
@ -19,9 +19,9 @@ namespace Disk {
|
||||
*/
|
||||
class UnformattedTrack: public Track {
|
||||
public:
|
||||
Event get_next_event();
|
||||
Time seek_to(const Time &time_since_index_hole);
|
||||
Track *clone();
|
||||
Event get_next_event() override;
|
||||
Time seek_to(const Time &time_since_index_hole) override;
|
||||
Track *clone() const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user