snd_pcm_read

Name

snd_pcm_read -- transfer PCM stream from capture subdevice

Synopsis

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

Description

Reads samples from the device which must be in the proper format specified by snd_pcm_channel_prepare function. Function returns positive value if playback was successful (value represents count of bytes which were successfully written to device) or an error value if an error occurred. If the subdevice has no data available, -EAGAIN result code is returned. Function will suspend process if block behaviour (see to snd_pcm_nonblock_mode) is active.

When the subdevice is in the block mode (SND_PCM_MODE_BLOCK), then the count of read bytes must fulfil the N * fragment size expression, where N is greater than zero. If the stream format is non-interleaved (the member interleave from the snd_pcm_format_t structure is not set), then the driver returns data which are separated to single voice blocks encapsulated to fragments. Lets imagine that we have two voices and the fragment size is 512 bytes. The number of bytes per one voice is 256. The driver returns first 256 bytes which contain samples for the first voice and the second 256 bytes from fragment which contain 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. You have to use snd_pcm_readv vector function to perform reading for the non-interleaved streams.