Create a new handle and open a connection to the audio interface
#include <sys/asoundlib.h>
int snd_pcm_open( snd_pcm_t ** handle,
int card,
int device,
int mode );
libasound.so
The snd_pcm_open() function creates a new handle and opens a connection to the audio interface for soundcard number card (0-N) and audio device number device. It also checks if the protocol is compatible to prevent the use of old programs with a new driver API.
There is no default setup, everything must be prepared with an application.
The following modes should be used for the mode argument:
| Mode | Description |
|---|---|
| SND_PCM_OPEN_PLAYBACK | The playback channel (direction) is opened. |
| SND_PCM_OPEN_CAPTURE | The capture channel (direction) is opened. |
| SND_PCM_OPEN_DUPLEX | Both (playback and capture) channels (directions) are opened. |
| SND_PCM_OPEN_NONBLOCK | This flag may be ORed with any previous modes to force the nonblock mode. The blocking setup may be changed later with snd_pcm_nonblock_mode function(). When this flag isn't, the driver waits until the device isn't free again. Use this flag if you want immediate response. |
Zero on success, or an error code.
See the example in Opening your audio device in the Playing audio data chapter.
| Safety: | |
|---|---|
| Cancellation point | No |
| Interrupt handler | No |
| Signal handler | Yes |
| Thread | Yes |
snd_pcm_close(), snd_pcm_open_preferred()