1from Carbon.Sound import * 2from Carbon import Snd 3 4import aifc, audioop 5 6fn = 'f:just samples:2ndbeat.aif' 7af = aifc.open(fn, 'r') 8print af.getparams() 9print 'nframes =', af.getnframes() 10print 'nchannels =', af.getnchannels() 11print 'framerate =', af.getframerate() 12nframes = min(af.getnframes(), 100000) 13frames = af.readframes(nframes) 14print 'len(frames) =', len(frames) 15print repr(frames[:100]) 16frames = audioop.add(frames, '\x80'*len(frames), 1) 17print repr(frames[:100]) 18 19import struct 20 21header1 = struct.pack('llhhllbbl', 22 0, 23 af.getnchannels(), 24 af.getframerate(),0, 25 0, 26 0, 27 0xFF, 28 60, 29 nframes) 30print repr(header1) 31header2 = struct.pack('llhlll', 0, 0, 0, 0, 0, 0) 32header3 = struct.pack('hhlll', 33 af.getsampwidth()*8, 34 0, 35 0, 36 0, 37 0) 38print repr(header3) 39header = header1 + header2 + header3 40 41buffer = header + frames 42 43chan = Snd.SndNewChannel(5,0x00C0) 44 45Snd.SndDoCommand(chan, (bufferCmd, 0, buffer), 0) 46