Re: [Python-Dev] Test results of linuxaudiodev.c

Ka-Ping Yee <pingster@ilm.com> writes:
Yup, that works fine. Don't understand the details - and as I have my graduation ceremony tomorrow I'm going to go to bed and leave learning them until some other occasion! Cheers, M. PS: my Lib/test/test_linuxaudiodev.py is now this: from test_support import verbose, findfile, TestFailed import linuxaudiodev import os,struct def play_au_file(path): fp = open(path, "r") # Read the .au file header. header = fp.read(24) hdrsize, length, encoding, rate, channels = \ struct.unpack(">xxxxiiiii", header) fp.read(hdrsize - 24) data = fp.read() fp.close() # Set the data format according to the code in the .au header. if encoding == 1: size, fmt = 8, linuxaudiodev.AFMT_MU_LAW elif encoding == 2: size, fmt = 8, linuxaudiodev.AFMT_S8 elif encoding == 3: size, fmt = 16, linuxaudiodev.AFMT_S16_BE else: raise "audio format not supported" dsp = linuxaudiodev.open("w") dsp.setparameters(rate, size, channels, fmt) dsp.write(data) dsp.close() def test(): play_au_file(findfile('audiotest.au')) test() ... which is an improvement on what's there now.

On 30 Jun 2000, Michael Hudson wrote:
Cool. Okay, i just discovered sunau.py. Here's my real shot at test_linuxaudiodev.py. Can you give this a try? ---- test_linuxaudiodev.py ---- from test_support import verbose, findfile, TestFailed import linuxaudiodev import os, sunau formats = {("ULAW", 1): linuxaudiodev.AFMT_MU_LAW, ("NONE", 1): linuxaudiodev.AFMT_S8, ("NONE", 2): linuxaudiodev.AFMT_S16_BE} def play_au_file(path): au = sunau.open(path, "r") data = au.readframes(sunau.AUDIO_UNKNOWN_SIZE) au.close() spec = (au.getcomptype(), au.getsampwidth()) if not has_key(formats, spec): raise "audio format not supported by linuxaudiodev" dsp = linuxaudiodev.open("w") dsp.setparameters(au.getframerate(), au.getsampwidth() * 8, au.getnchannels(), formats[spec]) dsp.write(data) dsp.close() def test(): play_au_file(findfile('audiotest.au')) test() ---- test_linuxaudiodev.py ---- -- ?!ng

Ka-Ping Yee wrote:
Yes, but this uses sunau which assumes the audioop.c module is enabled (imported by readframes(), sunau.py line 259) which might not be the case. Besides, Michael reported that it doesn't work quite right. So I'd blindly vote for Michael Hudson's improved version which uses only linuxaudiodev and plays the test sound without noise: ----------[ test_linuxaudiodev.py posted by Michael Hudson ]----------- from test_support import verbose, findfile, TestFailed import linuxaudiodev import os,struct def play_au_file(path): fp = open(path, "r") # Read the .au file header. header = fp.read(24) hdrsize, length, encoding, rate, channels = \ struct.unpack(">xxxxiiiii", header) fp.read(hdrsize - 24) data = fp.read() fp.close() # Set the data format according to the code in the .au header. if encoding == 1: size, fmt = 8, linuxaudiodev.AFMT_MU_LAW elif encoding == 2: size, fmt = 8, linuxaudiodev.AFMT_S8 elif encoding == 3: size, fmt = 16, linuxaudiodev.AFMT_S16_BE else: raise "audio format not supported" dsp = linuxaudiodev.open("w") dsp.setparameters(rate, size, channels, fmt) dsp.write(data) dsp.close() def test(): play_au_file(findfile('audiotest.au')) test() ---------------------------------------------------------------------- -- Vladimir MARANGOZOV | Vladimir.Marangozov@inrialpes.fr http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252

[Ping]
Okay, i just discovered sunau.py. Here's my real shot at test_linuxaudiodev.py. Can you give this a try?
Didn't work -- even after I changed has_key(formats, ...) to formats.has_key(...). Here's what I get: Traceback (most recent call last): File "test_linuxaudiodev-ping.py", line 37, in ? test() File "test_linuxaudiodev-ping.py", line 35, in test play_au_file(findfile('audiotest.au')) File "test_linuxaudiodev-ping.py", line 26, in play_au_file raise "audio format not supported by linuxaudiodev" audio format not supported by linuxaudiodev Sheesh, you'd think that plain old "Sun/NeXT audio data: 8-bit ISDN u-law, mono, 8000 Hz" (this is what "file" reports on "audiotest.au") would be supported. ;-) So I tried Michael Hudson's version. It also failed, but in a more interesting way. There mere traceback is not enough, but it's a start: Traceback (most recent call last): File "test_linuxaudiodev-hudson.py", line 62, in ? test() File "test_linuxaudiodev-hudson.py", line 60, in test play_au_file(findfile('audiotest.au')) File "test_linuxaudiodev-hudson.py", line 55, in play_au_file dsp.write(data) linuxaudiodev.error: (11, 'Resource temporarily unavailable') Here's the sequence of events I get: * run Michael's version of test_linuxaudiodev.py * it *immediately* dumps the above traceback, but does not return me to my shell prompt * Cardinal Fang *does* start his famous proclamation, and it sounds right (same as I get from "play audiotest.au") * but it's truncated about 3/4 of the way through: "Nobody expects the Spani----" * and then Python terminates with exit status 1 (presumably due to the traceback) Very curious! I know next-to-nothing about both Python's exception handling, sound drivers on Linux, and PC audio hardware. Any speculation I might offer would probably be useless, so I will merely comment that this is indeed curious. Greg -- Greg Ward - software developer gward@mems-exchange.org MEMS Exchange / CNRI voice: +1-703-262-5376 Reston, Virginia, USA fax: +1-703-262-5367

On 30 Jun 2000, Michael Hudson wrote:
Cool. Okay, i just discovered sunau.py. Here's my real shot at test_linuxaudiodev.py. Can you give this a try? ---- test_linuxaudiodev.py ---- from test_support import verbose, findfile, TestFailed import linuxaudiodev import os, sunau formats = {("ULAW", 1): linuxaudiodev.AFMT_MU_LAW, ("NONE", 1): linuxaudiodev.AFMT_S8, ("NONE", 2): linuxaudiodev.AFMT_S16_BE} def play_au_file(path): au = sunau.open(path, "r") data = au.readframes(sunau.AUDIO_UNKNOWN_SIZE) au.close() spec = (au.getcomptype(), au.getsampwidth()) if not has_key(formats, spec): raise "audio format not supported by linuxaudiodev" dsp = linuxaudiodev.open("w") dsp.setparameters(au.getframerate(), au.getsampwidth() * 8, au.getnchannels(), formats[spec]) dsp.write(data) dsp.close() def test(): play_au_file(findfile('audiotest.au')) test() ---- test_linuxaudiodev.py ---- -- ?!ng

Ka-Ping Yee wrote:
Yes, but this uses sunau which assumes the audioop.c module is enabled (imported by readframes(), sunau.py line 259) which might not be the case. Besides, Michael reported that it doesn't work quite right. So I'd blindly vote for Michael Hudson's improved version which uses only linuxaudiodev and plays the test sound without noise: ----------[ test_linuxaudiodev.py posted by Michael Hudson ]----------- from test_support import verbose, findfile, TestFailed import linuxaudiodev import os,struct def play_au_file(path): fp = open(path, "r") # Read the .au file header. header = fp.read(24) hdrsize, length, encoding, rate, channels = \ struct.unpack(">xxxxiiiii", header) fp.read(hdrsize - 24) data = fp.read() fp.close() # Set the data format according to the code in the .au header. if encoding == 1: size, fmt = 8, linuxaudiodev.AFMT_MU_LAW elif encoding == 2: size, fmt = 8, linuxaudiodev.AFMT_S8 elif encoding == 3: size, fmt = 16, linuxaudiodev.AFMT_S16_BE else: raise "audio format not supported" dsp = linuxaudiodev.open("w") dsp.setparameters(rate, size, channels, fmt) dsp.write(data) dsp.close() def test(): play_au_file(findfile('audiotest.au')) test() ---------------------------------------------------------------------- -- Vladimir MARANGOZOV | Vladimir.Marangozov@inrialpes.fr http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252

[Ping]
Okay, i just discovered sunau.py. Here's my real shot at test_linuxaudiodev.py. Can you give this a try?
Didn't work -- even after I changed has_key(formats, ...) to formats.has_key(...). Here's what I get: Traceback (most recent call last): File "test_linuxaudiodev-ping.py", line 37, in ? test() File "test_linuxaudiodev-ping.py", line 35, in test play_au_file(findfile('audiotest.au')) File "test_linuxaudiodev-ping.py", line 26, in play_au_file raise "audio format not supported by linuxaudiodev" audio format not supported by linuxaudiodev Sheesh, you'd think that plain old "Sun/NeXT audio data: 8-bit ISDN u-law, mono, 8000 Hz" (this is what "file" reports on "audiotest.au") would be supported. ;-) So I tried Michael Hudson's version. It also failed, but in a more interesting way. There mere traceback is not enough, but it's a start: Traceback (most recent call last): File "test_linuxaudiodev-hudson.py", line 62, in ? test() File "test_linuxaudiodev-hudson.py", line 60, in test play_au_file(findfile('audiotest.au')) File "test_linuxaudiodev-hudson.py", line 55, in play_au_file dsp.write(data) linuxaudiodev.error: (11, 'Resource temporarily unavailable') Here's the sequence of events I get: * run Michael's version of test_linuxaudiodev.py * it *immediately* dumps the above traceback, but does not return me to my shell prompt * Cardinal Fang *does* start his famous proclamation, and it sounds right (same as I get from "play audiotest.au") * but it's truncated about 3/4 of the way through: "Nobody expects the Spani----" * and then Python terminates with exit status 1 (presumably due to the traceback) Very curious! I know next-to-nothing about both Python's exception handling, sound drivers on Linux, and PC audio hardware. Any speculation I might offer would probably be useless, so I will merely comment that this is indeed curious. Greg -- Greg Ward - software developer gward@mems-exchange.org MEMS Exchange / CNRI voice: +1-703-262-5376 Reston, Virginia, USA fax: +1-703-262-5367
participants (4)
-
Greg Ward
-
Ka-Ping Yee
-
Michael Hudson
-
Vladimir.Marangozov@inrialpes.fr