mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
It seems our sound cards can't play mulaw data. Use native-format
16-bit signed data instead. Hope this works for you; it works for me.
This commit is contained in:
parent
830b37bd74
commit
923ebe4dc6
1 changed files with 12 additions and 1 deletions
|
@ -4,9 +4,11 @@ import errno
|
||||||
import fcntl
|
import fcntl
|
||||||
import linuxaudiodev
|
import linuxaudiodev
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import select
|
import select
|
||||||
import sunaudio
|
import sunaudio
|
||||||
import time
|
import time
|
||||||
|
import audioop
|
||||||
|
|
||||||
SND_FORMAT_MULAW_8 = 1
|
SND_FORMAT_MULAW_8 = 1
|
||||||
|
|
||||||
|
@ -27,6 +29,15 @@ def play_sound_file(path):
|
||||||
raise TestSkipped, msg
|
raise TestSkipped, msg
|
||||||
raise TestFailed, 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 = linuxaudiodev.AFMT_S16_LE
|
||||||
|
else:
|
||||||
|
fmt = linuxaudiodev.AFMT_S16_BE
|
||||||
|
|
||||||
# at least check that these methods can be invoked
|
# at least check that these methods can be invoked
|
||||||
a.bufsize()
|
a.bufsize()
|
||||||
a.obufcount()
|
a.obufcount()
|
||||||
|
@ -35,7 +46,7 @@ def play_sound_file(path):
|
||||||
a.fileno()
|
a.fileno()
|
||||||
|
|
||||||
# set parameters based on .au file headers
|
# set parameters based on .au file headers
|
||||||
a.setparameters(rate, 8, nchannels, linuxaudiodev.AFMT_MU_LAW, 1)
|
a.setparameters(rate, 16, nchannels, fmt)
|
||||||
a.write(data)
|
a.write(data)
|
||||||
a.flush()
|
a.flush()
|
||||||
a.close()
|
a.close()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue