Commit 7c908744 authored by Jeremy Hylton's avatar Jeremy Hylton

test_linuxaudio:

    read the header from the .au file and do a sanity check
    pass only the data to the audio device
    call flush() so that program does not exit until playback is complete
    call all the other methods to verify that they work minimally
    call setparameters with a bunch of bugs arguments

linuxaudiodev.c:
    use explicit O_WRONLY and O_RDONLY instead of 1 and 0
    add a string name to each of the entries in audio_types[]
    add AFMT_A_LAW to the list of known formats
    add x_mode attribute to lad object, stores imode from open call
    test ioctl return value as == -1, not < 0
    in read() method, resize string before return
    add getptr() method, that calls does ioctl on GETIPTR or GETOPTR
        depending on x_mode
    in setparameters() method, do better error checking and raise
        ValueErrors; also use ioctl calls recommended by Open Sound
        System Programmer's Guido (www.opensound.com)
    use PyModule_AddXXX to define names in module
parent 4ffefcb0
test_linuxaudiodev
expected rate >= 0, not -1
expected sample size >= 0, not -2
nchannels must be 1 or 2, not 3
unknown audio encoding: 177
sample size 16 expected for Little-endian 16-bit unsigned format: 8 received
sample size 8 expected for Logarithmic mu-law audio: 16 received
from test_support import verbose, findfile, TestFailed, TestSkipped
import linuxaudiodev
import errno
import fcntl
import linuxaudiodev
import os
import select
import sunaudio
import time
SND_FORMAT_MULAW_8 = 1
def play_sound_file(path):
fp = open(path, 'r')
size, enc, rate, nchannels, extra = sunaudio.gethdr(fp)
data = fp.read()
fp.close()
if enc != SND_FORMAT_MULAW_8:
print "Expect .au file with 8-bit mu-law samples"
return
try:
a = linuxaudiodev.open('w')
except linuxaudiodev.error, msg:
if msg[0] in (errno.EACCES, errno.ENODEV):
raise TestSkipped, msg
raise TestFailed, msg
else:
a.write(data)
a.close()
# at least check that these methods can be invoked
a.bufsize()
a.obufcount()
a.obuffree()
a.getptr()
a.fileno()
# set parameters based on .au file headers
a.setparameters(rate, 8, nchannels, linuxaudiodev.AFMT_MU_LAW, 1)
a.write(data)
a.flush()
a.close()
def test_errors():
a = linuxaudiodev.open("w")
size = 8
fmt = linuxaudiodev.AFMT_U8
rate = 8000
nchannels = 1
try:
a.setparameters(-1, size, nchannels, fmt)
except ValueError, msg:
print msg
try:
a.setparameters(rate, -2, nchannels, fmt)
except ValueError, msg:
print msg
try:
a.setparameters(rate, size, 3, fmt)
except ValueError, msg:
print msg
try:
a.setparameters(rate, size, nchannels, 177)
except ValueError, msg:
print msg
try:
a.setparameters(rate, size, nchannels, linuxaudiodev.AFMT_U16_LE)
except ValueError, msg:
print msg
try:
a.setparameters(rate, 16, nchannels, fmt)
except ValueError, msg:
print msg
def test():
play_sound_file(findfile('audiotest.au'))
test_errors()
test()
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment