summaryrefslogtreecommitdiff
path: root/display/music1.py
diff options
context:
space:
mode:
Diffstat (limited to 'display/music1.py')
-rw-r--r--display/music1.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/display/music1.py b/display/music1.py
new file mode 100644
index 0000000..b5c0c6d
--- /dev/null
+++ b/display/music1.py
@@ -0,0 +1,33 @@
+class Music:
+ def __init__(self, filename):
+ self.filename = filename
+ self.w = None
+ self.sampledata = ''
+ def openchannel(self):
+ if self.w is not None:
+ self.w.close()
+ import wave
+ self.w = w = wave.open(open(self.filename, 'rb'), 'r')
+ self.w_params = (w.getnchannels(),
+ w.getsampwidth(),
+ w.getframerate())
+ chan, width, freq = self.w_params
+ self.dataleft = w.getnframes() * (chan*width)
+ self.sampledata = ''
+ def decode(self, mixer, bytecount):
+ result = self.sampledata
+ if not result and self.dataleft > 0:
+ # decode and convert some more data
+ chan, width, freq = self.w_params
+ #framecount = bytecount / (chan*width)
+ inputdata = self.w.readframes(bytecount) #(framecount)
+ self.dataleft -= len(inputdata)
+ result = mixer.resample(inputdata,
+ freq = freq,
+ bits = width * 8,
+ signed = width > 1,
+ channels = chan,
+ byteorder = 'little')
+ #print len(result)
+ self.sampledata = result[bytecount:]
+ return result[:bytecount]