* Warning/error from ALSA’s pcm_min.c example. Possible problem?
@ 2010-01-30 19:51 Louise Hoffman
2010-01-31 4:43 ` Raymond Yau
2010-01-31 8:46 ` Jaroslav Kysela
0 siblings, 2 replies; 7+ messages in thread
From: Louise Hoffman @ 2010-01-30 19:51 UTC (permalink / raw)
To: alsa-devel
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#4FSOSMZ6Pxc/distfiles/alsa-lib-1.0.14rc2.tar.bz2|ZScnKi-LryE/alsa-lib-1.0.14rc2/test/pcm_min.c&q=pcm_min.c
[1] http://pastebin.com/m2f28b578
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Warning/error from ALSA’s pcm_min.c example. Possible problem?
2010-01-30 19:51 Warning/error from ALSA’s pcm_min.c example. Possible problem? Louise Hoffman
@ 2010-01-31 4:43 ` Raymond Yau
2010-01-31 20:53 ` Louise Hoffman
2010-01-31 8:46 ` Jaroslav Kysela
1 sibling, 1 reply; 7+ messages in thread
From: Raymond Yau @ 2010-01-31 4:43 UTC (permalink / raw)
To: alsa-devel
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#4FSOSMZ6Pxc/distfiles/alsa-lib-1.0.14rc2.tar.bz2|ZScnKi-LryE/alsa-lib-1.0.14rc2/test/pcm_min.c&q=pcm_min.c<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 )
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Warning/error from ALSA’s pcm_min.c example. Possible problem?
2010-01-30 19:51 Warning/error from ALSA’s pcm_min.c example. Possible problem? Louise Hoffman
2010-01-31 4:43 ` Raymond Yau
@ 2010-01-31 8:46 ` Jaroslav Kysela
2010-01-31 20:41 ` Louise Hoffman
1 sibling, 1 reply; 7+ messages in thread
From: Jaroslav Kysela @ 2010-01-31 8:46 UTC (permalink / raw)
To: Louise Hoffman; +Cc: alsa-devel
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=2e48439ad93f6c8d99a2d72928ac71285b5211bb
Jaroslav
-----
Jaroslav Kysela <perex@perex.cz>
Linux Kernel Sound Maintainer
ALSA Project, Red Hat, Inc.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Warning/error from ALSA’s pcm_min.c example. Possible problem?
2010-01-31 8:46 ` Jaroslav Kysela
@ 2010-01-31 20:41 ` Louise Hoffman
0 siblings, 0 replies; 7+ messages in thread
From: Louise Hoffman @ 2010-01-31 20:41 UTC (permalink / raw)
To: Jaroslav Kysela; +Cc: alsa-devel
> It was a bug in alsa-lib. I fixed it in patch bellow. Thank you for your
> report.
Cool. And that was the big one, you fixed there =)
Can you also patch pcm_min.c ?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Warning/error from ALSA’s pcm_min.c example. Possible problem?
2010-01-31 4:43 ` Raymond Yau
@ 2010-01-31 20:53 ` Louise Hoffman
0 siblings, 0 replies; 7+ messages in thread
From: Louise Hoffman @ 2010-01-31 20:53 UTC (permalink / raw)
To: Raymond Yau; +Cc: alsa-devel
>> 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?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Warning/error from ALSA’s pcm_min.c example. Possible problem?
@ 2010-10-29 3:49 Raymond Yau
2010-10-29 7:19 ` Jaroslav Kysela
0 siblings, 1 reply; 7+ messages in thread
From: Raymond Yau @ 2010-10-29 3:49 UTC (permalink / raw)
To: ALSA Development Mailing List
>> 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=2e48439ad93f6c8d99a2d72928ac71285b5211bb <http://git.alsa-project.org/?p=alsa-lib.git;a=commitdiff;h=2e48439ad93f6c8d99a2d72928ac71285b5211bb>
Add snd_pcm_dump() after call snd_pcm_set_params in pcm_min.c
The start threshold is equal to buffer size , so there should be a
short write at the second write since
16384 + 7616 = 24000 ( start threshold )
your patch had changed the behaviour
./pcm_min
ALSA <-> PulseAudio PCM I/O Plugin
Its setup is:
stream : PLAYBACK
access : RW_INTERLEAVED
format : U8
subformat : STD
channels : 1
rate : 48000
exact rate : 48000 (48000/1)
msbits : 8
buffer_size : 24000
period_size : 6000
period_time : 125000
tstamp_mode : NONE
period_step : 1
avail_min : 6000
period_event : 0
start_threshold : 24000
stop_threshold : 24000
silence_threshold: 0
silence_size : 0
boundary : 1572864000
state = 2
write 16384 frames
state = 2
write 16384 frames
state = 3
write 16384 frames
state = 3
write 16384 frames
state = 3
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Warning/error from ALSA’s pcm_min.c example. Possible problem?
2010-10-29 3:49 Raymond Yau
@ 2010-10-29 7:19 ` Jaroslav Kysela
0 siblings, 0 replies; 7+ messages in thread
From: Jaroslav Kysela @ 2010-10-29 7:19 UTC (permalink / raw)
To: Raymond Yau; +Cc: ALSA Development Mailing List
On Fri, 29 Oct 2010, Raymond Yau wrote:
>>> 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=2e48439ad93f6c8d99a2d72928ac71285b5211bb <http://git.alsa-project.org/?p=alsa-lib.git;a=commitdiff;h=2e48439ad93f6c8d99a2d72928ac71285b5211bb>
>
> Add snd_pcm_dump() after call snd_pcm_set_params in pcm_min.c
>
> The start threshold is equal to buffer size , so there should be a
> short write at the second write since
> 16384 + 7616 = 24000 ( start threshold )
>
> your patch had changed the behaviour
The pcm_min uses the blocked mode, so all layers tries to queue all given
samples and wait for the ring buffer.
> buffer_size : 24000
> start_threshold : 24000
> state = 2
> write 16384 frames
> state = 2
> write 16384 frames
> state = 3
This looks correct.
Jaroslav
-----
Jaroslav Kysela <perex@perex.cz>
Linux Kernel Sound Maintainer
ALSA Project, Red Hat, Inc.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-10-29 7:19 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-30 19:51 Warning/error from ALSA’s pcm_min.c example. Possible problem? Louise Hoffman
2010-01-31 4:43 ` Raymond Yau
2010-01-31 20:53 ` Louise Hoffman
2010-01-31 8:46 ` Jaroslav Kysela
2010-01-31 20:41 ` Louise Hoffman
-- strict thread matches above, loose matches on Subject: below --
2010-10-29 3:49 Raymond Yau
2010-10-29 7:19 ` Jaroslav Kysela
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).