[Previous] [Contents] [Next]

snd_pcm_read()

Transfer PCM stream from capture subdevice

Synopsis:

#include <sys/asoundlib.h>

ssize_t snd_pcm_read( snd_pcm_t * handle, 
                      void * buffer, 
                      size_t size );

Library:

libasound.so

Description:

The snd_pcm_read() function reads samples from the device which must be in the proper format specified by snd_pcm_channel_prepare().

The function suspends the process if block behavior is active (see snd_pcm_nonblock_mode()).

When the subdevice is in block mode (SND_PCM_MODE_BLOCK), then the count of read bytes must fulfill the N * fragment-size expression, where N > 0. If the stream format is noninterleaved (the member interleave from the snd_pcm_format_t structure isn't set), then the driver returns data that's separated to single voice blocks encapsulated to fragments. For example, imagine you've two voices, and the fragment size is 512 bytes. The number of bytes per one voice is 256. The driver returns the first 256 bytes that contain samples for the first voice, and the second 256 bytes from the fragment size that contains samples for the second voice.

When the subdevice is in the stream mode (SND_PCM_MODE_STREAM), then the interleaved stream mode are only returned.

Returns:

A positive value that represents the count of bytes that were successfully written to the device if playback is successful, or an error value if an error occurs.

Errors:

-EAGAIN
The subdevice has no data available.
-EFAULT
Failed to copy data.
-EINVAL
Invalid handle; data pointer is NULL but size isn't zero or is negative.

Classification:

ALSA

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

[Previous] [Contents] [Next]