[Previous] [Contents] [Next]

snd_pcm_write()

Transfer PCM stream to playback subdevice

Synopsis:

#include <sys/asoundlib.h>

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

Library:

libasound.so

Description:

The snd_pcm_write() function writes samples to the device that must be in the proper format specified by snd_pcm_channel_prepare() function.

This function suspends a process if block behavior is active (see snd_pcm_nonblock_mode()).

When the subdevice is in the block mode (SND_PCM_MODE_BLOCK), then the count of written 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 expects that data in one fragment is separated to single voice blocks. For example, imagine that you've two voices and the fragment size is 512 bytes. The number of bytes per one voice is 256. The driver expects that the first 256 bytes contain samples for the first voice and the second 256 bytes from fragment contain samples for the second voice.

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

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
Try again later. The subchannel is opened nonblock (block and stream mode), or is in paused state (block mode).
-EINVAL
The channel isn't in the prepared or running state. In block mode: count isn't an even multiple of setup ->buf.block.frag_size. In stream mode: the format is set as interleaved (not allowed).
-EIO
Invalid mode (valid modes include: SND_PCM_MODE_BLOCK and SND_PCM_MODE_STREAM). In block mode: no space in buffers and subchannel isn't running, or the subchannel isn't in the prepared or running state. In stream mode: underrun.
-EWOULDBLOCK
Write would have blocked (nonblocking write).

Classification:

ALSA

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

[Previous] [Contents] [Next]