[alsa-devel] Warning/error from ALSA’s pcm_min.c example. Possible problem?
superquad.vortex2 at gmail.com
Sun Jan 31 05:43:48 CET 2010
2010/1/31 Louise Hoffman <louise.hoffman at gmail.com>
> Dear ALSA developers,
> When I compile ALSA's pcm_min.c example with
> gcc -Wall -lasound pcm_min.c -o pcm_min
> Everything is fine, but running it, I get the white noise as expected,
> but I also get this warning/error:
> Short write (expected 16384, wrote 7616)
> Which comes from the last if-statement.
> One bug is in this line
> frames = snd_pcm_writei(handle, buffer, sizeof(buffer));
> where "sizeof(buffer)" should be "number of frames in the buffer".
> But there are still some strange things going on. I still get those
> errors, and if I remove the for-loop, nothing is played.
> Here is my code. 
> Can someone see what's wrong?
>  http://pastebin.com/m2f28b578
> The correct way is to use snd_pcm_get_params() to get buffer_size and
*snd_pcm_set_params() has limitation
The most common sound card (e.g. HDA ) has the following constraints
on period bytes and buffer bytes
snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
you cannot get exactly 0.5 second period time when rate is multiple of 3 (
e.g. 48000 Hz )
More information about the Alsa-devel