weird xrun problem
I'm getting a lot of xruns with some buffer/period sizes and it's perfectly reproducible. It happens when the buffer is divided in two periods and the second period is a bit smaller of the first one. For example:
[Giu@Jay Giu]$ aplay -v -B300000 -F150000 something.wav
Playing WAVE 'something.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo Plug PCM: Hardware PCM card 0 'Gina24' device 0 subdevice 0
Its setup is:
stream : PLAYBACK
access : RW_INTERLEAVED
format : S16_LE
subformat : STD
channels : 2
rate : 44100
exact rate : 44100 (44100/1)
msbits : 16buffer_size : 13216period_size : 6624period_time : 150204tick_time : 1000tstamp_mode : NONEperiod_step : 1sleep_min : 0avail_min : 6624xfer_align : 6624start_threshold : 6624stop_threshold : 13216silence_threshold: 0silence_size : 0
boundary : 1732247552
xrun!!! (at least 0.000 ms long)
Status:
state : XRUNtrigger_time: 1085219431.336894000
tstamp : 1085219431.336894000
delay : 0
avail : 13248avail_max : 13248
Period 0 is 6624 frames and Period 1 is 6592 frames long (32 frames shorter). I put some debug code and this is the output for a the playback test above:
May 22 11:54:22 localhost kernel: pcm_trigger start May 22 11:54:22 localhost kernel: pointer=6656 period=1 May 22 11:54:22 localhost kernel: pcm_trigger stop May 22 11:54:22 localhost kernel: Prepare May 22 11:54:22 localhost kernel: pcm_trigger start May 22 11:54:22 localhost kernel: pointer=6656 period=1 May 22 11:54:22 localhost kernel: pcm_trigger stop May 22 11:54:22 localhost kernel: Prepare May 22 11:54:22 localhost kernel: pcm_trigger start May 22 11:54:22 localhost kernel: pointer=6656 period=1 May 22 11:54:23 localhost kernel: pcm_trigger stop May 22 11:54:23 localhost kernel: Prepare May 22 11:54:23 localhost kernel: pcm_trigger start
Note that I get an xrun after every period. Most xruns are 0ms long, sometimes they are 1ms and there are no other values. Only 1 or 0.
If the periods have the same size or there are three or more periods it works fine:
[Giu@Jay Giu]$ aplay -v -B200000 -F100000 something.wav
May 22 11:59:38 localhost kernel: pcm_hw_params ok May 22 11:59:38 localhost kernel: Prepare May 22 11:59:38 localhost kernel: pcm_trigger start May 22 11:59:38 localhost kernel: pointer=4448 period=1 May 22 11:59:38 localhost kernel: pointer=32 period=0 May 22 11:59:38 localhost kernel: pointer=4448 period=1 May 22 11:59:38 localhost kernel: pointer=32 period=0 May 22 11:59:38 localhost kernel: pointer=4448 period=1 May 22 11:59:38 localhost kernel: pointer=32 period=0
(alsa-driver 1.0.4)
--
Giuliano.
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
Quoted 3 lines · Giuliano Pochini
Period 0 is 6624 frames and Period 1 is 6592 frames long (32 frames shorter). I put some debug code and this is the output for a the playback test above:
ALSA does not know about this. All period sizes must be equal. It's a bug in your driver which must avoid this configuration.
For alsa-lib and applications - it looks that you have only one full period. Most of applications work with the whole periods to optimize transfers, so this configuration will end with xruns.
Jaroslav
-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
Quoted 8 lines · On Sun, 23 May 2004 11:21:41 +0200 (CEST) Jaroslav Kysela <[email protected]> wrote:
Quoted 3 lines · Giuliano Pochini
Period 0 is 6624 frames and Period 1 is 6592 frames long (32 frames shorter). I put some debug code and this is the output for a the playback test above:
ALSA does not know about this. All period sizes must be equal. It's a bug in your driver which must avoid this configuration.
Yep, there is a bug indeed. I just noticed that some dolt (me) wrote .periods_min=1 in the snd_pcm_hardware_t struct for some cards. Now running the same "aplay -B300000 -F200000" plays fine.
Still, there is a thing which is not clear. When I type the command above I get:
bufsize=52864 bytes
periods=2
persize=26368 bytes
allocated buffer size=131072 (pages=32)
52864 holds two periods 26368 bytes long, with a rest of 128 bytes. Have I to simply ignore the remaining space ? And the that case, must the .pointer callback return a value within 0..persize*2-1 or 0..bufsize-1 ?
--
Giuliano.
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
Quoted 7 lines · On Sun, 23 May 2004 11:21:41 +0200 (CEST) Jaroslav Kysela <[email protected]> wrote:
Quoted 3 lines · Giuliano Pochini
Period 0 is 6624 frames and Period 1 is 6592 frames long (32 frames shorter). I put some debug code and this is the output for a the playback test above:
ALSA does not know about this. All period sizes must be equal.
I thought about this again. Are you sure all periods must be aqual ? When I record or play something using unequal periods, sound is perfect. It means ALSA reads and writes the last (sometimes a lot) smaller period as well.
--
Giuliano.
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
Quoted 9 lines · Giuliano Pochini
Quoted 6 lines · On Sun, 23 May 2004 11:21:41 +0200 (CEST) Jaroslav Kysela <[email protected]> wrote:
Quoted 3 lines · Giuliano Pochini
Period 0 is 6624 frames and Period 1 is 6592 frames long (32 frames shorter). I put some debug code and this is the output for a the playback test above:
Quoted 6 lines
Quoted 1 line
ALSA does not know about this. All period sizes must be equal.
I thought about this again. Are you sure all periods must be aqual ? When I record or play something using unequal periods, sound is perfect. It means ALSA reads and writes the last (sometimes a lot) smaller period as well.
The driver must not acknowledge the settled period with the midlevel and application before the specified time. Of course, if you're running into a rounding problem, you can acknowledge more periods at one time. In other cases, it's not very practical to program hardware to use different period sizes, because you need more interrupts for processing.
Jaroslav
-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
Quoted 7 lines · On Wed, 26 May 2004 09:52:06 +0200 (CEST) Jaroslav Kysela <[email protected]> wrote:
Quoted 6 lines
Quoted 1 line
ALSA does not know about this. All period sizes must be equal.
I thought about this again. Are you sure all periods must be aqual ? When I record or play something using unequal periods, sound is perfect. It means ALSA reads and writes the last (sometimes a lot) smaller period as well.
Quoted 5 lines
The driver must not acknowledge the settled period with the midlevel and application before the specified time. Of course, if you're running into a rounding problem, you can acknowledge more periods at one time. In other cases, it's not very practical to program hardware to use different period sizes, because you need more interrupts for processing.
My question was about your sentence: "All period sizes must be equal". Is it true ? It seems quite strange to me because ALSA passes a buffer size that is not multiple than the period size almost always. This is not a problem in my case because the s-g list is generic enough to handle it.
--
Giuliano.
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
Quoted 10 lines · Giuliano Pochini
Quoted 7 lines · On Wed, 26 May 2004 09:52:06 +0200 (CEST) Jaroslav Kysela <[email protected]> wrote:
Quoted 6 lines
Quoted 1 line
ALSA does not know about this. All period sizes must be equal.
I thought about this again. Are you sure all periods must be aqual ? When I record or play something using unequal periods, sound is perfect. It means ALSA reads and writes the last (sometimes a lot) smaller period as well.
Quoted 8 lines
Quoted 5 lines
The driver must not acknowledge the settled period with the midlevel and application before the specified time. Of course, if you're running into a rounding problem, you can acknowledge more periods at one time. In other cases, it's not very practical to program hardware to use different period sizes, because you need more interrupts for processing.
My question was about your sentence: "All period sizes must be equal". Is it true ? It seems quite strange to me because ALSA passes a buffer size that
Yes, the time distance between period boundaries must be equal in longer term. Of course, interrupt/hardware latencies might shift the interrupt processing a few samples after.
Quoted 1 line
is not multiple than the period size almost always. This is not a problem in
I don't say that periods * period_size == buffer_size. It's another special case.
Quoted 1 line
my case because the s-g list is generic enough to handle it.
Yes, that's right.
Jaroslav
-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click