mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
Factor endian-ness check out of play_sound_file(), and fix
test_setparameters() to use it -- don't assume AFMT_S16_NE is always defined!
This commit is contained in:
parent
3800ef7ae2
commit
8a709b3049
1 changed files with 12 additions and 7 deletions
|
@ -13,6 +13,17 @@ import sunaudio
|
||||||
import time
|
import time
|
||||||
import audioop
|
import audioop
|
||||||
|
|
||||||
|
# Arggh, AFMT_S16_NE not defined on all platforms -- seems to be a
|
||||||
|
# fairly recent addition to OSS.
|
||||||
|
try:
|
||||||
|
from ossaudiodev import AFMT_S16_NE
|
||||||
|
except ImportError:
|
||||||
|
if sys.byteorder == "little":
|
||||||
|
AFMT_S16_NE = ossaudiodev.AFMT_S16_LE
|
||||||
|
else:
|
||||||
|
AFMT_S16_NE = ossaudiodev.AFMT_S16_BE
|
||||||
|
|
||||||
|
|
||||||
SND_FORMAT_MULAW_8 = 1
|
SND_FORMAT_MULAW_8 = 1
|
||||||
|
|
||||||
def read_sound_file(path):
|
def read_sound_file(path):
|
||||||
|
@ -38,12 +49,6 @@ def play_sound_file(data, rate, ssize, nchannels):
|
||||||
raise TestSkipped, msg
|
raise TestSkipped, msg
|
||||||
raise TestFailed, msg
|
raise TestFailed, msg
|
||||||
|
|
||||||
# set the data format
|
|
||||||
if sys.byteorder == 'little':
|
|
||||||
fmt = ossaudiodev.AFMT_S16_LE
|
|
||||||
else:
|
|
||||||
fmt = ossaudiodev.AFMT_S16_BE
|
|
||||||
|
|
||||||
# at least check that these methods can be invoked
|
# at least check that these methods can be invoked
|
||||||
dsp.bufsize()
|
dsp.bufsize()
|
||||||
dsp.obufcount()
|
dsp.obufcount()
|
||||||
|
@ -52,7 +57,7 @@ def play_sound_file(data, rate, ssize, nchannels):
|
||||||
dsp.fileno()
|
dsp.fileno()
|
||||||
|
|
||||||
# set parameters based on .au file headers
|
# set parameters based on .au file headers
|
||||||
dsp.setparameters(fmt, nchannels, rate)
|
dsp.setparameters(AFMT_S16_NE, nchannels, rate)
|
||||||
t1 = time.time()
|
t1 = time.time()
|
||||||
print "playing test sound file..."
|
print "playing test sound file..."
|
||||||
dsp.write(data)
|
dsp.write(data)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue