[alsa-devel] Warning/error from ALSA’s pcm_min.c example. Possible problem?
Dear ALSA developers,
When I compile ALSA's pcm_min.c[0] 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. [1]
Can someone see what's wrong?
Hugs, Louise
[0] http://www.google.com/codesearch/p?hl=en&sa=N&cd=1&ct=rc#4FSOSMZ...
2010/1/31 Louise Hoffman louise.hoffman@gmail.com
Dear ALSA developers,
When I compile ALSA's pcm_min.c[0] 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. [1]
Can someone see what's wrong?
Hugs, Louise
[0] http://www.google.com/codesearch/p?hl=en&sa=N&cd=1&ct=rc#4FSOSMZ...http://www.google.com/codesearch/p?hl=en&sa=N&cd=1&ct=rc#4FSOSMZ6Pxc/distfiles/alsa-lib-1.0.14rc2.tar.bz2%7CZScnKi-LryE/alsa-lib-1.0.14rc2/test/pcm_min.c&q=pcm_min.c
[1] http://pastebin.com/m2f28b578
The correct way is to use snd_pcm_get_params() to get buffer_size and
period_size
*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, 128); snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 128); *
you cannot get exactly 0.5 second period time when rate is multiple of 3 ( e.g. 48000 Hz )
The correct way is to use snd_pcm_get_params() to get buffer_size and
period_size
*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, 128); snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 128);
I am probably not good enough to understand these changes =( Pretty hard core stuff =)
you cannot get exactly 0.5 second period time when rate is multiple of 3 ( e.g. 48000 Hz )
Does this mean, that I shouldn't give snd_pcm_writei() the number of all the frames in the buffer, but only
sample_rate * latency = frames
?
So if I e.g. have: sample_rate = 44100 latency = 0.5 [s] all_frames = 100000
The number of frames that I should give to snd_pcm_writei() would be
sample_rate * latency = frames 44100*0.5 = 22050
and the number of iterations the for-loop should be?:
(int) 100000/22050 = 4; with frames=22050
and one extra, but only with
100000 mod 22050 = 11800
frames?
On Sat, 30 Jan 2010, Louise Hoffman wrote:
Dear ALSA developers,
When I compile ALSA's pcm_min.c[0] 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)
It was a bug in alsa-lib. I fixed it in patch bellow. Thank you for your report.
http://git.alsa-project.org/?p=alsa-lib.git;a=commitdiff;h=2e48439ad93f6c8d9...
Jaroslav
----- Jaroslav Kysela perex@perex.cz Linux Kernel Sound Maintainer ALSA Project, Red Hat, Inc.
participants (3)
-
Jaroslav Kysela
-
Louise Hoffman
-
Raymond Yau