AF Application Note

# Selecting an Audio Device

# 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 (See app note #1). They do not need to use the datatype native to an audio device. Therefore, it is only necessary to choose the audio device based on its sampling rate and number of channels.

Client applications can determine the audio device attributes by looking in the AAudioDeviceDescriptor data structure.

# Example

The following example finds a single channel device sampling at an 8 KHz rate.

    #include <AF/AFlib.h>

    int FindDefaultDevice(AFAudioConn *aud)
    {
      AFDeviceDescriptor *aDev;
      int     i;

      for(i=0; i<ANumberOfAudioDevices(aud); i++) {
        aDev = AAudioDeviceDescriptor(aud, i);
        if ((aDev->inputsFromPhone == 0) &&
            (aDev->outputsToPhone == 0) &&
            (aDev->playSampleFreq == 8000) &&
            (aDev->playNchannels == 1))
          return i;
      }
      return -1;
    }

Clearly, there is room for improvement in this simple interface. But the essentials are here for you to customize for your client applications. Given time, a more general version of this interface should be part of the client library.

See this file for Copyright information.