2000-08-04 13:26:03 +00:00
|
|
|
from test_support import verbose, findfile, TestFailed, TestSkipped
|
2000-10-06 19:39:55 +00:00
|
|
|
|
2000-08-04 12:59:40 +00:00
|
|
|
import errno
|
2000-10-06 19:39:55 +00:00
|
|
|
import fcntl
|
|
|
|
import linuxaudiodev
|
2000-06-10 04:22:57 +00:00
|
|
|
import os
|
2000-10-08 00:20:20 +00:00
|
|
|
import sys
|
2000-10-06 19:39:55 +00:00
|
|
|
import select
|
|
|
|
import sunaudio
|
|
|
|
import time
|
2000-10-08 00:20:20 +00:00
|
|
|
import audioop
|
2000-10-06 19:39:55 +00:00
|
|
|
|
|
|
|
SND_FORMAT_MULAW_8 = 1
|
2000-06-10 04:22:57 +00:00
|
|
|
|
|
|
|
def play_sound_file(path):
|
|
|
|
fp = open(path, 'r')
|
2000-10-06 19:39:55 +00:00
|
|
|
size, enc, rate, nchannels, extra = sunaudio.gethdr(fp)
|
2000-06-10 04:22:57 +00:00
|
|
|
data = fp.read()
|
|
|
|
fp.close()
|
2000-10-06 19:39:55 +00:00
|
|
|
|
|
|
|
if enc != SND_FORMAT_MULAW_8:
|
|
|
|
print "Expect .au file with 8-bit mu-law samples"
|
|
|
|
return
|
|
|
|
|
2000-06-10 04:22:57 +00:00
|
|
|
try:
|
|
|
|
a = linuxaudiodev.open('w')
|
|
|
|
except linuxaudiodev.error, msg:
|
2000-08-04 15:25:58 +00:00
|
|
|
if msg[0] in (errno.EACCES, errno.ENODEV):
|
|
|
|
raise TestSkipped, msg
|
2000-06-10 04:22:57 +00:00
|
|
|
raise TestFailed, msg
|
2000-10-06 19:39:55 +00:00
|
|
|
|
2000-10-08 00:20:20 +00: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 19:39:55 +00: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-08 00:20:20 +00:00
|
|
|
a.setparameters(rate, 16, nchannels, fmt)
|
2000-10-06 19:39:55 +00: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 04:22:57 +00:00
|
|
|
|
|
|
|
def test():
|
|
|
|
play_sound_file(findfile('audiotest.au'))
|
2000-10-06 19:39:55 +00:00
|
|
|
test_errors()
|
2000-06-10 04:22:57 +00:00
|
|
|
|
|
|
|
test()
|