|
@@ -0,0 +1,104 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+import binascii
|
|
|
+from bitarray import bitarray
|
|
|
+from greaseweazle.flux import Flux
|
|
|
+
|
|
|
+
|
|
|
+class MasterTrack:
|
|
|
+
|
|
|
+ @property
|
|
|
+ def bitrate(self):
|
|
|
+ return len(self.bitarray) / self.time_per_rev
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ def __init__(self, bits, time_per_rev):
|
|
|
+ self.bits = bits
|
|
|
+ self.time_per_rev = time_per_rev
|
|
|
+ self.bit_ticks = None
|
|
|
+ self.splice = 0
|
|
|
+
|
|
|
+ def __str__(self):
|
|
|
+ s = "\nMaster Track:\n"
|
|
|
+ s += (" %d bits, %.1f kbit/s"
|
|
|
+ % (len(self.bits), self.bitrate))
|
|
|
+ if self.bit_ticks:
|
|
|
+ s += " (variable)"
|
|
|
+ s += ("\n Total Time = %.1f ms (%.1f rpm)\n "
|
|
|
+ % (self.time_per_rev * 1000, 60 / self.time_per_rev))
|
|
|
+
|
|
|
+ return s
|
|
|
+
|
|
|
+ def flux_for_writeout(self):
|
|
|
+
|
|
|
+
|
|
|
+ bits = self.bits.copy()
|
|
|
+ bitlen = len(bits)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ bit_ticks = self.bit_ticks.copy() if self.bit_ticks else [1] * bitlen
|
|
|
+ ticks_to_index = sum(bit_ticks)
|
|
|
+
|
|
|
+ splice_at_index = self.splice < 4 or bitlen - self.splice < 4
|
|
|
+
|
|
|
+ if splice_at_index:
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ pos = bitlen-4 if self.splice < 4 else self.splice-4
|
|
|
+ tick_pattern = bit_ticks[pos-32:pos]
|
|
|
+ fill_pattern = bits[pos-32:pos]
|
|
|
+
|
|
|
+ for i in range(bitlen // (10*32)):
|
|
|
+ bit_ticks[pos:pos+32] = tick_pattern
|
|
|
+ bits[pos:pos+32] = fill_pattern
|
|
|
+ pos += 32
|
|
|
+ else:
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ bit_ticks += bit_ticks[:self.splice-4]
|
|
|
+ bits += bits[:self.splice-4]
|
|
|
+ pos = self.splice+4
|
|
|
+ fill_pattern = bits[pos:pos+32]
|
|
|
+ while pos >= 32:
|
|
|
+ pos -= 32
|
|
|
+ bits[pos:pos+32] = fill_pattern
|
|
|
+
|
|
|
+
|
|
|
+ bit_ticks_i = iter(bit_ticks)
|
|
|
+ flux_list = []
|
|
|
+ flux_ticks = 0
|
|
|
+ for bit in bits:
|
|
|
+ flux_ticks += next(bit_ticks_i)
|
|
|
+ if bit:
|
|
|
+ flux_list.append(flux_ticks)
|
|
|
+ flux_ticks = 0
|
|
|
+ if flux_ticks:
|
|
|
+ flux_list.append(flux_ticks)
|
|
|
+
|
|
|
+
|
|
|
+ flux = Flux([ticks_to_index], flux_list,
|
|
|
+ self.time_per_rev / ticks_to_index)
|
|
|
+ flux.terminate_at_index = splice_at_index
|
|
|
+ return flux
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|