Skip to contentSkip to conversation

ALSA skipping samples

DISCUSSION Russell King 2 participants 2 messages Jun 5, 2003 – Jun 6, 2003

lore
Share & tools
lore
#0 lore raw

Hi,

I'm working on some drivers for some custom AC'97 hardware on a development platform, and am seeing some weird behaviour.

The development platform is mostly FPGA-based, so it isn't the worlds most fastest machine. However, running madplay against the OSS emulation results in the following:

# time madplay sample.mp3
...
8670 frames decoded (0:03:46.4), +2.2 dB peak amplitude, 3882 clipped samples
133.99user 19.92system 2:33.95elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (1498major+69minor)pagefaults 0swaps

Note that the mp3 is 3mins46 long, but we took only 2mins33 to play it!

When listening to the output, it appears that we're randomly missing chunks of samples; when I added a printk into my PCM's trigger function, I noticed that we were frequently calling it with TRIGGER_START/ TRIGGER_STOP. I suspect this is because the mp3 player can't keep ALSAs buffers full.

The driver source can be found at:

http://patches.arm.linux.org.uk/alsa/aaci.c

(its not ready for release yet tho. oh, and yes, dma is missing off the hardware implementation so its currently using PIO, but it is expected that in real CPUs the device will have DMA available.)

The contents of /proc/asound/AACI/pcm0p/sub0/ while "playing":

hw_params:access: RW_INTERLEAVED
hw_params:format: S16_LE
hw_params:subformat: STD
hw_params:channels: 2
hw_params:rate: 44100 (44100/1)
hw_params:period_size: 1024
hw_params:buffer_size: 16384
hw_params:tick_time: 10000
hw_params:OSS format: S16_LE
hw_params:OSS channels: 2
hw_params:OSS rate: 44100
hw_params:OSS period bytes: 4096
hw_params:OSS periods: 16
info:card: 0
info:device: 0
info:subdevice: 0
info:stream: PLAYBACK
info:id: PCM0
info:name:
info:subname: subdevice #0
info:class: 0
info:subclass: 0
info:subdevices_count: 1
info:subdevices_avail: 0
prealloc:64
status:state: XRUN
status:trigger_time: 5365.000116784

status:tstamp      : 5365.000119486
status:delay       : 0
status:avail       : 16384
status:avail_max   : 16384

status:-----
status:hw_ptr : 1024
status:appl_ptr : 1024
sw_params:tstamp_mode: NONE
sw_params:period_step: 1
sw_params:sleep_min: 0
sw_params:avail_min: 1024
sw_params:xfer_align: 1
sw_params:start_threshold: 1
sw_params:stop_threshold: 16384
sw_params:silence_threshold: 0
sw_params:silence_size: 0
sw_params:boundary: 1073741824

(PS, playing the same mp3 using the same mp3 player binary on a faster system using real OSS drivers but different hardware has the expected results.)

Signature · 10 lines
Russell King ([email protected])                The developer of ARM Linux
             http://www.arm.linux.org.uk/personal/aboutme.html




-------------------------------------------------------
This SF.net email is sponsored by:  Etnus, makers of TotalView, The best
thread debugger on the planet. Designed with thread debugging features
you've never dreamed of, try TotalView 6 free at www.etnus.com.
#1 lore raw
Quoted 23 lines · Russell King

Hi,

I'm working on some drivers for some custom AC'97 hardware on a development platform, and am seeing some weird behaviour.

The development platform is mostly FPGA-based, so it isn't the worlds most fastest machine. However, running madplay against the OSS emulation results in the following:

# time madplay sample.mp3
...
8670 frames decoded (0:03:46.4), +2.2 dB peak amplitude, 3882 clipped samples
133.99user 19.92system 2:33.95elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (1498major+69minor)pagefaults 0swaps

Note that the mp3 is 3mins46 long, but we took only 2mins33 to play it!

When listening to the output, it appears that we're randomly missing chunks of samples; when I added a printk into my PCM's trigger function, I noticed that we were frequently calling it with TRIGGER_START/ TRIGGER_STOP. I suspect this is because the mp3 player can't keep ALSAs buffers full.

Quoted 7 lines

The driver source can be found at:

http://patches.arm.linux.org.uk/alsa/aaci.c

(its not ready for release yet tho. oh, and yes, dma is missing off the hardware implementation so its currently using PIO, but it is expected that in real CPUs the device will have DMA available.)

It seems that application is not fast enough to fill the right buffer or the ring buffer pointer is wrong (I think that it is later case because of measured time). I suggest to update ring buffer pointer at the beginning of the interrupt routine to value "just played" rather than "moved to FIFO". Yes, it creates a small window where the samples might be wrong in the ring buffer, but it is better than recover from underruns. Also, FIFO should be pre-filled in trigger-START, too.

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs

-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The best thread debugger on the planet. Designed with thread debugging features you've never dreamed of, try TotalView 6 free at www.etnus.com.