[Previous] [Contents] [Next]

snd_pcm_open_preferred()

Create a new handle and open a connection to the audio interface

Synopsis:

#include <sys/asoundlib.h>

int snd_pcm_open_preferred( snd_pcm_t ** handle, 
                  int * rcard, 
                  int * rdevice, 
                  int mode );

Library:

libasound.so

Description:

The snd_pcm_open_preferred() function is an extension to the snd_pcm_open() function in that it attempts to open the user-preferred device for the system. However, in a system where more then one PCM device exists, the user may set a preference for one of these devices. This function attempts to open that device and return a PCM handle to it. The card number and device number can be returned if the arguments aren't NULL.

Here's the search order to find the preferred device:

  1. Read /etc/config/trap/audio/HOSTNAME-preferences. If this file doesn't exist or has no entry, step 2 is tried.
  2. PCM device 0 of card 0 is checked for a software mixing overlay device. If this overlay device is found, it's opened.
  3. Open the default device 0 of card 0.

If all of the above fail, you've no audio system running.

Returns:

Zero on success, or a negative value on error.

Errors:

-EINVAL
Invalid mode.
-EACCES
Search permission is denied on a component of the path prefix, or the device exists and the permissions specified are denied.
-EINTR
The open() operation was interrupted by a signal.
-EMFILE
Too many file descriptors are currently in use by this process.
-ENFILE
Too many files are currently open in the system.
-ENOENT
The named device doesn't exist.
-SND_ERROR_INCOMPATIBLE_VERSION
The audio driver version is incompatible with the client library that the application uses.
-ENOMEM
No memory available for data structure.

Examples:

See the obtaining Card and Device values example in the Playing audio data chapter.

Classification:

Neutrino

Safety:
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

snd_pcm_close(), snd_pcm_open()


[Previous] [Contents] [Next]