attempt to skip to data part of tape

This commit is contained in:
Greg Hewgill 2011-08-16 18:22:41 +12:00
parent 6951db69ad
commit b8c7949d8e

View File

@ -294,9 +294,18 @@ class Cassette:
def __init__(self, fn):
wav = wave.open(fn, "r")
self.raw = wav.readframes(wav.getnframes())
self.start_cycle = 0
self.start_offset = 0
for i, b in enumerate(self.raw):
if ord(b) > 0xA0:
self.start_offset = i
break
def read_byte(self, cycle):
offset = cycle * 22000 / 1000000
if self.start_cycle == 0:
self.start_cycle = cycle
offset = self.start_offset + (cycle - self.start_cycle) * 22000 / 1000000
return ord(self.raw[offset]) if offset < len(self.raw) else 0x80