~malept/ubuntu/lucid/python2.6/dev-dependency-fix

« back to all changes in this revision

Viewing changes to Mac/Demo/sound/playaiff.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-02-13 12:51:00 UTC
  • Revision ID: james.westby@ubuntu.com-20090213125100-uufgcb9yeqzujpqw
Tags: upstream-2.6.1
ImportĀ upstreamĀ versionĀ 2.6.1

Show diffs side-by-side

added added

removed removed

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