mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-22 12:33:29 +00:00
Added seeking tests, correcting such errors as uncovered.
This commit is contained in:
parent
3297f6d545
commit
f9a5595dad
@ -77,4 +77,37 @@
|
||||
[self assertFirstTwoEventLengthsForSource:segmentSource];
|
||||
}
|
||||
|
||||
- (void)testSeekToSecondBit
|
||||
{
|
||||
Storage::Disk::PCMSegmentEventSource segmentSource = self.segmentSource;
|
||||
Storage::Time target_time(1, 10);
|
||||
|
||||
Storage::Time found_time = segmentSource.seek_to(target_time);
|
||||
found_time.simplify();
|
||||
|
||||
XCTAssertTrue(found_time.length == 1 && found_time.clock_rate == 20, @"A request to seek to 1/10th should have seeked to 1/20th");
|
||||
|
||||
Storage::Disk::Track::Event next_event = segmentSource.get_next_event();
|
||||
next_event.length.simplify();
|
||||
|
||||
XCTAssertTrue(next_event.length.length == 1 && next_event.length.clock_rate == 10, @"Next event should be 1/10th later");
|
||||
}
|
||||
|
||||
- (void)testSeekBeyondFinalBit
|
||||
{
|
||||
Storage::Disk::PCMSegmentEventSource segmentSource = self.segmentSource;
|
||||
Storage::Time target_time(24, 10);
|
||||
|
||||
Storage::Time found_time = segmentSource.seek_to(target_time);
|
||||
found_time.simplify();
|
||||
|
||||
XCTAssertTrue(found_time.length == 47 && found_time.clock_rate == 20, @"A request to seek to 24/10ths should have seeked to 47/20ths");
|
||||
|
||||
Storage::Disk::Track::Event next_event = segmentSource.get_next_event();
|
||||
next_event.length.simplify();
|
||||
|
||||
XCTAssertTrue(next_event.length.length == 17 && next_event.length.clock_rate == 20, @"Next event should be 17/20ths later");
|
||||
XCTAssertTrue(next_event.type == Storage::Disk::Track::Event::IndexHole, @"End should have been reached");
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -77,10 +77,12 @@ Storage::Time PCMSegmentEventSource::seek_to(const Time &time_from_start)
|
||||
return zero;
|
||||
}
|
||||
|
||||
// adjust for time to get to bit zero and determine number of bits in
|
||||
// adjust for time to get to bit zero and determine number of bits in;
|
||||
// bit_pointer_ always records _the next bit_ that might trigger an event,
|
||||
// so should be one beyond the one reached by a seek.
|
||||
Time relative_time = time_from_start - half_bit_length;
|
||||
bit_pointer_ = (relative_time / segment_.length_of_a_bit).get_unsigned_int();
|
||||
bit_pointer_ = 1 + (relative_time / segment_.length_of_a_bit).get_unsigned_int();
|
||||
|
||||
// map up to the correct amount of time
|
||||
return half_bit_length + segment_.length_of_a_bit * (unsigned int)bit_pointer_;
|
||||
return half_bit_length + segment_.length_of_a_bit * (unsigned int)(bit_pointer_ - 1);
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ namespace Storage {
|
||||
struct Time {
|
||||
unsigned int length, clock_rate;
|
||||
Time() : length(0), clock_rate(1) {}
|
||||
Time(unsigned int length, unsigned int clock_rate) : length(length), clock_rate(clock_rate) {}
|
||||
|
||||
/*!
|
||||
Reduces this @c Time to its simplest form — eliminates all common factors from @c length
|
||||
@ -116,8 +117,8 @@ struct Time {
|
||||
inline Time operator * (unsigned int multiplier) const
|
||||
{
|
||||
Time result;
|
||||
result.clock_rate = clock_rate * multiplier;
|
||||
result.length = length;
|
||||
result.clock_rate = clock_rate;
|
||||
result.length = length * multiplier;
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -142,6 +143,20 @@ struct Time {
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Time operator / (unsigned int divisor) const
|
||||
{
|
||||
Time result;
|
||||
result.length = length;
|
||||
result.clock_rate = clock_rate * divisor;
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Time &operator /= (unsigned int divisor)
|
||||
{
|
||||
clock_rate *= divisor;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void set_zero()
|
||||
{
|
||||
length = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user