[Python-Dev] Test results of linuxaudiodev.c
Michael Hudson
mwh21@cam.ac.uk
30 Jun 2000 01:06:04 +0100
Ka-Ping Yee <pingster@ilm.com> writes:
> On Thu, 29 Jun 2000, Ka-Ping Yee wrote:
> > Try setting the environment variable AUDIODEV to /dev/audio
> > before running the test script. Does that work any better?
>
> Even if that works, i realize that's not the way the interface
> was intended to be used. To play an AU file, the routine should
> look something like this (not tested, as i don't have a working
> Linux box)...
[snip]
Yup, that works fine. Don't understand the details - and as I have my
graduation ceremony tomorrow I'm going to go to bed and leave learning
them until some other occasion!
Cheers,
M.
PS: my Lib/test/test_linuxaudiodev.py is now this:
from test_support import verbose, findfile, TestFailed
import linuxaudiodev
import os,struct
def play_au_file(path):
fp = open(path, "r")
# Read the .au file header.
header = fp.read(24)
hdrsize, length, encoding, rate, channels = \
struct.unpack(">xxxxiiiii", header)
fp.read(hdrsize - 24)
data = fp.read()
fp.close()
# Set the data format according to the code in the .au header.
if encoding == 1:
size, fmt = 8, linuxaudiodev.AFMT_MU_LAW
elif encoding == 2:
size, fmt = 8, linuxaudiodev.AFMT_S8
elif encoding == 3:
size, fmt = 16, linuxaudiodev.AFMT_S16_BE
else:
raise "audio format not supported"
dsp = linuxaudiodev.open("w")
dsp.setparameters(rate, size, channels, fmt)
dsp.write(data)
dsp.close()
def test():
play_au_file(findfile('audiotest.au'))
test()
... which is an improvement on what's there now.