From b8c7949d8e1a27f521bbb898468e2fa0b6036ca8 Mon Sep 17 00:00:00 2001 From: Greg Hewgill Date: Tue, 16 Aug 2011 18:22:41 +1200 Subject: [PATCH] attempt to skip to data part of tape --- applepy.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/applepy.py b/applepy.py index 4fbfa37..5052474 100644 --- a/applepy.py +++ b/applepy.py @@ -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