File: playaiff.py

package info (click to toggle)
python2.3 2.3.5-3sarge2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 43,908 kB
  • ctags: 81,384
  • sloc: ansic: 266,250; python: 246,028; makefile: 4,194; perl: 3,702; lisp: 3,630; sh: 2,576; xml: 1,601; objc: 740; cpp: 106; sed: 2
file content (45 lines) | stat: -rw-r--r-- 1,183 bytes parent folder | download | duplicates (26)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from Carbon.Sound import *
from Carbon import Snd

import aifc, audioop

fn = 'f:just samples:2ndbeat.aif'
af = aifc.open(fn, 'r')
print af.getparams()
print 'nframes  =', af.getnframes()
print 'nchannels =', af.getnchannels()
print 'framerate =', af.getframerate()
nframes = min(af.getnframes(), 100000)
frames = af.readframes(nframes)
print 'len(frames) =', len(frames)
print repr(frames[:100])
frames = audioop.add(frames, '\x80'*len(frames), 1)
print repr(frames[:100])

import struct

header1 = struct.pack('llhhllbbl',
                      0,
                      af.getnchannels(),
                      af.getframerate(),0,
                      0,
                      0,
                      0xFF,
                      60,
                      nframes)
print repr(header1)
header2 = struct.pack('llhlll', 0, 0, 0, 0, 0, 0)
header3 = struct.pack('hhlll',
                      af.getsampwidth()*8,
                      0,
                      0,
                      0,
                      0)
print repr(header3)
header = header1 + header2 + header3

buffer = header + frames

chan = Snd.SndNewChannel(5,0x00C0)

Snd.SndDoCommand(chan, (bufferCmd, 0, buffer), 0)