AF Application Note

# Automatic Datatype Conversion in AF3

# Introduction

AF audio servers may support one or more audio devices. Each audio device will have a native sampling rate and datatype that is visible to client applications.

With AF3, client applications may choose to use their own preferred datatype when communicating with an audio server. They do not need to use the datatype native to an audio device.

To use automatic datatype conversion, client applications must set the ACEncodingType attribute in an AC (audio context.) Clients may set their preferred encoding type on the call to AFCreateAC(3) or through a call to AFChangeACAtributes(3).

All popular scalar datatypes are currently supported as well as several compressed datatypes.

AFFindEncodeType(3) will accept a encoding type string and return the matching enumerated encoding type for setting the attribute type. AFPrintKnownEncodingTypes(3) will print to stderr all defined strings and their accepted alternate names.

# AF3 Clients

As shipped with AF3, the aplay, arecord, and apass clients support a command line switch (-e encoding_type) that is used to convey the audio sample datatype between the client and server.

To play a mu-law sound file against an audio device with a native datatype other than mu-255, use

    	aplay [-d device no.] -e ulaw filename

# Client Example

The following example demonstrates how to take a given audio device and force client-server communication to use mu-255 (log PCM) samples. Assume the audio device was properly selected by FindDefaultDevice(), is running at the correct sampling rate, and has the correct number of channels.

    #include <AF/AFlib.h>
    #include <AF/AFUtils.h>

        AFAudioConn *aud;
        AC ac;
        AFSetACAttributes attributes;
        int device;

        /* Open connection to default audio server */
        if ( (aud = AFOpenAudioConn(NULL)) == NULL) {
    	fprintf(stderr, "%s: can't open connection.\n", argv[0]);
    	exit(1);
        }

        /* Select the proper audio device */
        device = FindDefaultDevice(aud);

        /* Set the preferred attributes for audio context, include datatype */
        attributes.preempt = Mix;
        attributes.play_gain = 0;
        attributes.type = MU255;

        /* Now create the audio context */
        ac = AFCreateAC(aud, device, (ACPlayGain | ACEncodingType)), &attributes);

        /* Make sure we confirm encoding type is supported. */
        AFSync(aud, 0);

See this file for Copyright information.