2002-07-23 16:04:11 -03:00
|
|
|
from test.test_support import verbose, findfile, TestFailed, TestSkipped
|
2000-10-06 16:39:55 -03:00
|
|
|
|
2000-08-04 09:59:40 -03:00
|
|
|
import errno
|
2000-10-06 16:39:55 -03:00
|
|
|
import fcntl
|
|
|
|
import linuxaudiodev
|
2000-06-10 01:22:57 -03:00
|
|
|
import os
|
2000-10-07 21:20:20 -03:00
|
|
|
import sys
|
2000-10-06 16:39:55 -03:00
|
|
|
import select
|
|
|
|
import sunaudio
|
|
|
|
import time
|
2000-10-07 21:20:20 -03:00
|
|
|
import audioop
|
2000-10-06 16:39:55 -03:00
|
|
|
|
|
|
|
SND_FORMAT_MULAW_8 = 1
|
2000-06-10 01:22:57 -03:00
|
|
|
|
|
|
|
def play_sound_file(path):
|
|
|
|
fp = open(path, 'r')
|
2000-10-06 16:39:55 -03:00
|
|
|
size, enc, rate, nchannels, extra = sunaudio.gethdr(fp)
|
2000-06-10 01:22:57 -03:00
|
|
|
data = fp.read()
|
|
|
|
fp.close()
|
2000-10-06 16:39:55 -03:00
|
|
|
|
|
|
|
if enc != SND_FORMAT_MULAW_8:
|
|
|
|
print "Expect .au file with 8-bit mu-law samples"
|
|
|
|
return
|
|
|
|
|
2000-06-10 01:22:57 -03:00
|
|
|
try:
|
|
|
|
a = linuxaudiodev.open('w')
|
|
|
|
except linuxaudiodev.error, msg:
|
2002-04-22 23:20:46 -03:00
|
|
|
if msg[0] in (errno.EACCES, errno.ENODEV, errno.EBUSY):
|
2000-08-04 12:25:58 -03:00
|
|
|
raise TestSkipped, msg
|
2000-06-10 01:22:57 -03:00
|
|
|
raise TestFailed, msg
|
2000-10-06 16:39:55 -03:00
|
|
|
|
2000-10-07 21:20:20 -03:00
|
|
|
# convert the data to 16-bit signed
|
|
|
|
data = audioop.ulaw2lin(data, 2)
|
|
|
|
|
|
|
|
# set the data format
|
|
|
|
if sys.byteorder == 'little':
|
|
|
|
fmt = linuxaudiodev.AFMT_S16_LE
|
|
|
|
else:
|
|
|
|
fmt = linuxaudiodev.AFMT_S16_BE
|
|
|
|
|
2000-10-06 16:39:55 -03:00
|
|
|
# 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
|
2000-10-07 21:20:20 -03:00
|
|
|
a.setparameters(rate, 16, nchannels, fmt)
|
2000-10-06 16:39:55 -03:00
|
|
|
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
|
2000-06-10 01:22:57 -03:00
|
|
|
|
|
|
|
def test():
|
|
|
|
play_sound_file(findfile('audiotest.au'))
|
2000-10-06 16:39:55 -03:00
|
|
|
test_errors()
|
2000-06-10 01:22:57 -03:00
|
|
|
|
|
|
|
test()
|