- def decode(self, ss, es, data):
- if self.samplerate is None:
- raise Exception("Cannot decode without samplerate.")
- for self.samplenum, (sck, ws, sd) in data:
-
- # Ignore sample if the bit clock hasn't changed.
- if sck == self.oldsck:
- continue
-
- self.oldsck = sck
- if sck == 0: # Ignore the falling clock edge.
- continue
+ def wav_header(self):
+ # Chunk descriptor
+ h = b'RIFF'
+ h += b'\x24\x80\x00\x00' # Chunk size (2084)
+ h += b'WAVE'
+ # Fmt subchunk
+ h += b'fmt '
+ h += b'\x10\x00\x00\x00' # Subchunk size (16 bytes)
+ h += b'\x01\x00' # Audio format (0x0001 == PCM)
+ h += b'\x02\x00' # Number of channels (2)
+ h += b'\x80\x3e\x00\x00' # Samplerate (16000)
+ h += b'\x00\xfa\x00\x00' # Byterate (64000)
+ h += b'\x04\x00' # Blockalign (4)
+ h += b'\x20\x00' # Bits per sample (32)
+ # Data subchunk
+ h += b'data'
+ h += b'\xff\xff\xff\xff' # Subchunk size (4G bytes) TODO
+ return h
+
+ def wav_sample(self, sample):
+ return struct.pack('<I', self.data)
+
+ def decode(self):
+ while True:
+ # Wait for a rising edge on the SCK pin.
+ sck, ws, sd = self.wait({0: 'r'})