[Python-Dev] Test results of linuxaudiodev.c

Ka-Ping Yee pingster@ilm.com
Thu, 29 Jun 2000 16:46:32 -0700 (PDT)


On Thu, 29 Jun 2000, Ka-Ping Yee wrote:
> Try setting the environment variable AUDIODEV to /dev/audio
> before running the test script.  Does that work any better?

Even if that works, i realize that's not the way the interface
was intended to be used.  To play an AU file, the routine should
look something like this (not tested, as i don't have a working
Linux box)...

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()


-- ?!ng

Explicit hoc totum;            This completes the whole;
Pro Christo da mihi potum.     For Christ's sake give me a drink.
    -- from the colophon of a 12th-century copyist