alsa-lib pcm not starting
Hi,
Could someone enlighten me about the way alsa-lib / alsa-driver are supposed to work when using mmap mode please? I'm looking at the 1.0.2 code, along with madplay and Linux 2.6.4-rc1.
madplay sets the start_threshold to the size of the buffer, and min_avail to one period size - in much the same way as the alsa-lib test/pcm.c program.
However, there appears to be a case where if snd_pcm_write_areas is called with non-period-sized blocks of samples, we end up waiting for the buffer to be emptied without starting the hardware.
This can be clearly seen from a couple of fprintf's placed into this function (buffer size 16384, start threshold 16384, min_avail = 2047)
snd_pcm_write_areas: offset 0 size 480snd_pcm_write_areas: avail = e80 avail_min = 7ff size = 480 xfer_align = 1snd_pcm_write_areas: hw_avail = 3600 start_threshold = 4000snd_pcm_write_areas: offset 0 size 480snd_pcm_write_areas: avail = a00 avail_min = 7ff size = 480 xfer_align = 1snd_pcm_write_areas: hw_avail = 3a80 start_threshold = 4000snd_pcm_write_areas: offset 0 size 480snd_pcm_write_areas: avail = 580 avail_min = 7ff size = 480 xfer_align = 1snd_pcm_write_areas: hw_avail = 3f00 start_threshold = 4000snd_pcm_write_areas: offset 0 size 480snd_pcm_write_areas: avail = 100 avail_min = 7ff size = 480 xfer_align = 1
Here, (avail < pcm->avail_min && size > avail) is true, so we end up calling snd_pcm_wait(). However, because hw_avail < start_threshold, we haven't called snd_pcm_start().
Here's the output of the /proc *_params and status files while the device is in this state:
/proc/asound/card0/pcm0p/sub0/hw_params:access: MMAP_INTERLEAVED /proc/asound/card0/pcm0p/sub0/hw_params:format: S16_LE /proc/asound/card0/pcm0p/sub0/hw_params:subformat: STD /proc/asound/card0/pcm0p/sub0/hw_params:channels: 2 /proc/asound/card0/pcm0p/sub0/hw_params:rate: 44100 (44100/1) /proc/asound/card0/pcm0p/sub0/hw_params:period_size: 2047 /proc/asound/card0/pcm0p/sub0/hw_params:buffer_size: 16384 /proc/asound/card0/pcm0p/sub0/hw_params:tick_time: 10000 /proc/asound/card0/pcm0p/sub0/status:state: PREPARED /proc/asound/card0/pcm0p/sub0/status:trigger_time: 0.000000000
/proc/asound/card0/pcm0p/sub0/status:tstamp : 1078051902.544283000 /proc/asound/card0/pcm0p/sub0/status:delay : 0 /proc/asound/card0/pcm0p/sub0/status:avail : 256 /proc/asound/card0/pcm0p/sub0/status:avail_max : 0
/proc/asound/card0/pcm0p/sub0/status:-----
/proc/asound/card0/pcm0p/sub0/status:hw_ptr : 0
/proc/asound/card0/pcm0p/sub0/status:appl_ptr : 16128
/proc/asound/card0/pcm0p/sub0/sw_params:tstamp_mode: NONE /proc/asound/card0/pcm0p/sub0/sw_params:period_step: 1 /proc/asound/card0/pcm0p/sub0/sw_params:sleep_min: 0 /proc/asound/card0/pcm0p/sub0/sw_params:avail_min: 2047 /proc/asound/card0/pcm0p/sub0/sw_params:xfer_align: 1 /proc/asound/card0/pcm0p/sub0/sw_params:start_threshold: 16384 /proc/asound/card0/pcm0p/sub0/sw_params:stop_threshold: 16384 /proc/asound/card0/pcm0p/sub0/sw_params:silence_threshold: 0 /proc/asound/card0/pcm0p/sub0/sw_params:silence_size: 0 /proc/asound/card0/pcm0p/sub0/sw_params:boundary: 1073741824
Signature · 11 lines
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of: 2.6 PCMCIA - http://pcmcia.arm.linux.org.uk/
2.6 Serial core
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=clickQuoted 9 lines · Russell King
Hi,
Could someone enlighten me about the way alsa-lib / alsa-driver are supposed to work when using mmap mode please? I'm looking at the 1.0.2 code, along with madplay and Linux 2.6.4-rc1.
madplay sets the
start_thresholdto the size of the buffer, andmin_availto one period size - in much the same way as the alsa-libtest/pcm.cprogram.
We know about this problem. The start_threshold must be equal or less than (buffer_size / avail_min) * avail_min in this case. The avail_min specifies the minimal transfer count (for optimization) so the start_threshold - in this case - violates the read/write policy. The new code in alsa-lib does not allow to install this "broken" sw_params configuration, so application developers can detect this mistake.
Also, alsa-lib/test/pcm.c code was fixed to follow this specification (I am sorry - it was my mistake). This fix will be available in 1.0.3 release.
So, the fault is on the application side.
Jaroslav
-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now. Build and deploy apps & Web services for Linux with a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
Quoted 11 lines · Jaroslav Kysela
Quoted 7 lines · Russell King
Could someone enlighten me about the way alsa-lib / alsa-driver are supposed to work when using mmap mode please? I'm looking at the 1.0.2 code, along with madplay and Linux 2.6.4-rc1.
madplay sets the
start_thresholdto the size of the buffer, andmin_availto one period size - in much the same way as the alsa-libtest/pcm.cprogram.We know about this problem. The
start_thresholdmust be equal or less than (buffer_size/avail_min) *avail_minin this case.
I think it's a little more complex than that. In my case, buffer_size = 16384, avail_min = 256, so:
(buffer_size / avail_min) * avail_min = 16384
which is what was being programmed anyway. However,
(int(buffer_size / avail_min) - 1) * avail_min = 16128
would make more sense. Do you agree?
Signature · 11 lines
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of: 2.6 PCMCIA - http://pcmcia.arm.linux.org.uk/
2.6 Serial core
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=clickQuoted 16 lines · Russell King
Quoted 11 lines · Jaroslav Kysela
Quoted 7 lines · Russell King
Could someone enlighten me about the way alsa-lib / alsa-driver are supposed to work when using mmap mode please? I'm looking at the 1.0.2 code, along with madplay and Linux 2.6.4-rc1.
madplay sets the
start_thresholdto the size of the buffer, andmin_availto one period size - in much the same way as the alsa-libtest/pcm.cprogram.We know about this problem. The
start_thresholdmust be equal or less than (buffer_size/avail_min) *avail_minin this case.I think it's a little more complex than that. In my case,
buffer_size= 16384,avail_min= 256, so:
Quoted 7 lines
(buffer_size / avail_min) * avail_min = 16384which is what was being programmed anyway. However,
(int(buffer_size / avail_min) - 1) * avail_min = 16128would make more sense. Do you agree?
No, this combination should work. In your first mail, the avail_min was 2047 bytes and buffer_size 16384 bytes. Note that xfer_align must pass same expression:
start_threshold = (buffer_size / xfer_align) * xfer_align
But xfer_align is usually 1 or avail_min anyway.
Jaroslav
-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now. Build and deploy apps & Web services for Linux with a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click