summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_ossaudiodev.py
diff options
context:
space:
mode:
authorGreg Ward <gward@python.net>2002-12-10 16:27:35 (GMT)
committerGreg Ward <gward@python.net>2002-12-10 16:27:35 (GMT)
commit55a8790c41dd1c67895b9b1f6a7cfd86e5caf771 (patch)
tree5820822b57d928e59014ceae96a81b2e544426f3 /Lib/test/test_ossaudiodev.py
parent36dacfa49c8385efa59a1f57c3476dfc6e1e15b5 (diff)
downloadcpython-55a8790c41dd1c67895b9b1f6a7cfd86e5caf771.zip
cpython-55a8790c41dd1c67895b9b1f6a7cfd86e5caf771.tar.gz
cpython-55a8790c41dd1c67895b9b1f6a7cfd86e5caf771.tar.bz2
Aesthetic tweakery: factor read_sound_file() out of play_sound_file().
Diffstat (limited to 'Lib/test/test_ossaudiodev.py')
-rw-r--r--Lib/test/test_ossaudiodev.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/Lib/test/test_ossaudiodev.py b/Lib/test/test_ossaudiodev.py
index 1aa0f92..371d1a7 100644
--- a/Lib/test/test_ossaudiodev.py
+++ b/Lib/test/test_ossaudiodev.py
@@ -12,7 +12,7 @@ import audioop
SND_FORMAT_MULAW_8 = 1
-def play_sound_file(path):
+def read_sound_file(path):
fp = open(path, 'r')
size, enc, rate, nchannels, extra = sunaudio.gethdr(fp)
data = fp.read()
@@ -22,6 +22,12 @@ def play_sound_file(path):
print "Expect .au file with 8-bit mu-law samples"
return
+ # Convert the data to 16-bit signed.
+ data = audioop.ulaw2lin(data, 2)
+ return (data, rate, 16, nchannels)
+
+
+def play_sound_file(data, rate, ssize, nchannels):
try:
a = ossaudiodev.open('w')
except ossaudiodev.error, msg:
@@ -29,9 +35,6 @@ def play_sound_file(path):
raise TestSkipped, msg
raise TestFailed, msg
- # convert the data to 16-bit signed
- data = audioop.ulaw2lin(data, 2)
-
# set the data format
if sys.byteorder == 'little':
fmt = ossaudiodev.AFMT_S16_LE
@@ -83,7 +86,8 @@ def test_errors():
print msg
def test():
- play_sound_file(findfile('audiotest.au'))
+ (data, rate, ssize, nchannels) = read_sound_file(findfile('audiotest.au'))
+ play_sound_file(data, rate, ssize, nchannels)
test_errors()
test()