[Python-Dev] Test results of linuxaudiodev.c

Vladimir Marangozov Vladimir.Marangozov@inrialpes.fr
Sat, 1 Jul 2000 03:51:07 +0200 (CEST)


Ka-Ping Yee wrote:
> 
> On 30 Jun 2000, Michael Hudson wrote:
> > 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!
> 
> 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

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