Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e2b7c4d

Browse files
committed
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
1 parent d88d0a1 commit e2b7c4d

3 files changed

Lines changed: 194 additions & 90 deletions

File tree

Lib/test/output/test_linuxaudiodev

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
test_linuxaudiodev
2+
expected rate >= 0, not -1
3+
expected sample size >= 0, not -2
4+
nchannels must be 1 or 2, not 3
5+
unknown audio encoding: 177
6+
sample size 16 expected for Little-endian 16-bit unsigned format: 8 received
7+
sample size 8 expected for Logarithmic mu-law audio: 16 received

Lib/test/test_linuxaudiodev.py

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,78 @@
11
from test_support import verbose, findfile, TestFailed, TestSkipped
2-
import linuxaudiodev
2+
33
import errno
4+
import fcntl
5+
import linuxaudiodev
46
import os
7+
import select
8+
import sunaudio
9+
import time
10+
11+
SND_FORMAT_MULAW_8 = 1
512

613
def play_sound_file(path):
714
fp = open(path, 'r')
15+
size, enc, rate, nchannels, extra = sunaudio.gethdr(fp)
816
data = fp.read()
917
fp.close()
18+
19+
if enc != SND_FORMAT_MULAW_8:
20+
print "Expect .au file with 8-bit mu-law samples"
21+
return
22+
1023
try:
1124
a = linuxaudiodev.open('w')
1225
except linuxaudiodev.error, msg:
1326
if msg[0] in (errno.EACCES, errno.ENODEV):
1427
raise TestSkipped, msg
1528
raise TestFailed, msg
16-
else:
17-
a.write(data)
18-
a.close()
29+
30+
# at least check that these methods can be invoked
31+
a.bufsize()
32+
a.obufcount()
33+
a.obuffree()
34+
a.getptr()
35+
a.fileno()
36+
37+
# set parameters based on .au file headers
38+
a.setparameters(rate, 8, nchannels, linuxaudiodev.AFMT_MU_LAW, 1)
39+
a.write(data)
40+
a.flush()
41+
a.close()
42+
43+
def test_errors():
44+
a = linuxaudiodev.open("w")
45+
size = 8
46+
fmt = linuxaudiodev.AFMT_U8
47+
rate = 8000
48+
nchannels = 1
49+
try:
50+
a.setparameters(-1, size, nchannels, fmt)
51+
except ValueError, msg:
52+
print msg
53+
try:
54+
a.setparameters(rate, -2, nchannels, fmt)
55+
except ValueError, msg:
56+
print msg
57+
try:
58+
a.setparameters(rate, size, 3, fmt)
59+
except ValueError, msg:
60+
print msg
61+
try:
62+
a.setparameters(rate, size, nchannels, 177)
63+
except ValueError, msg:
64+
print msg
65+
try:
66+
a.setparameters(rate, size, nchannels, linuxaudiodev.AFMT_U16_LE)
67+
except ValueError, msg:
68+
print msg
69+
try:
70+
a.setparameters(rate, 16, nchannels, fmt)
71+
except ValueError, msg:
72+
print msg
1973

2074
def test():
2175
play_sound_file(findfile('audiotest.au'))
76+
test_errors()
2277

2378
test()

0 commit comments

Comments
 (0)