1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-26 09:29:45 +00:00

Two quick fixes: correctly set segment size, and flip bytes to match HFE's bit ordering to PCMTrack's.

This commit is contained in:
Thomas Harte 2017-08-17 22:28:00 -04:00
parent c8c1792c3f
commit af61a7fa28

View File

@ -53,6 +53,7 @@ std::shared_ptr<Track> HFE::get_uncached_track_at_position(unsigned int head, un
PCMSegment segment;
uint16_t side_length = track_length / 2;
segment.data.resize(side_length);
segment.number_of_bits = side_length * 8;
uint16_t c = 0;
while(c < side_length) {
@ -62,6 +63,24 @@ std::shared_ptr<Track> HFE::get_uncached_track_at_position(unsigned int head, un
fseek(file_, 256, SEEK_CUR);
}
// Flip bytes; HFE's preference is that the least-significant bit
// is serialised first, but PCMTrack posts the most-significant first.
for(size_t i = 0; i < segment.data.size(); i++) {
uint8_t original = segment.data[i];
uint8_t flipped_byte =
(uint8_t)(
((original & 0x01) << 7) |
((original & 0x02) << 5) |
((original & 0x04) << 3) |
((original & 0x08) << 1) |
((original & 0x10) >> 1) |
((original & 0x20) >> 3) |
((original & 0x40) >> 5) |
((original & 0x80) >> 7)
);
segment.data[i] = flipped_byte;
}
std::shared_ptr<Track> track(new PCMTrack(segment));
return track;
}