Skip to contentSkip to conversation

period crossing page boundary

DISCUSSION Giuliano Pochini 3 participants 9 messages Mar 19, 2003 – Mar 20, 2003

lore
Share & tools
lore
#0 lore raw

I'm facing another *£%@ problem. When period size is a multiple or submultiple of PAGE_SIZE, it works fine, but when it isn't, sound clicks, pops, repeapeapeats, skps :(( And since the period never crosses physically the page boundary because I split it when it happens, I can't imagine what's wrong. Perhaps some of you had the same problem.

.period callback does this:

bufsize=substream->runtime->periods*substream->runtime->period_size; //addr==number of bytes transferred. pos=bytes_to_frames(substream->runtime, addr); return(pos%bufsize);

Here is a log of sg list construction:

AddX=period n
pa=page addr
phy=snd_sgbuf_get_addr(sgbuf, offs)
sz=sub-period size

aplay -B139319 -F69660 (OK)
pcm_hw_params (bufsize=24576 periods=2 persize=12288) pcm_hw_params table size=131072 pages=32
pcm_hw_params Add0 (off=0 pa=f3ff000 phy=f3ff000 sz=4096) pcm_hw_params Add0 (off=4096 pa=f3fe000 phy=f3fe000 sz=4096) pcm_hw_params Add0 (off=8192 pa=f3fd000 phy=f3fd000 sz=4096)irq pcm_hw_params Add1 (off=12288 pa=f3fc000 phy=f3fc000 sz=4096) pcm_hw_params Add1 (off=16384 pa=f417000 phy=f417000 sz=4096) pcm_hw_params Add1 (off=20480 pa=f416000 phy=f416000 sz=4096)irq pcm_hw_params End (off=24576 rest=0)

aplay -B139319 -F34830 (noise-party)
pcm_hw_params (bufsize=24576 periods=4 persize=6144) pcm_hw_params table size=131072 pages=32
pcm_hw_params Add0 (off=0 pa=f3ff000 phy=f3ff000 sz=4096) pcm_hw_params Add0 (off=4096 pa=f3fe000 phy=f3fe000 sz=2048)irq pcm_hw_params Add1 (off=6144 pa=f3fe000 phy=f3fe800 sz=2048) pcm_hw_params Add1 (off=8192 pa=f3fd000 phy=f3fd000 sz=4096)irq pcm_hw_params Add2 (off=12288 pa=f3fc000 phy=f3fc000 sz=4096) pcm_hw_params Add2 (off=16384 pa=f417000 phy=f417000 sz=2048)irq pcm_hw_params Add3 (off=18432 pa=f417000 phy=f417800 sz=2048) pcm_hw_params Add3 (off=20480 pa=f416000 phy=f416000 sz=4096)irq pcm_hw_params End (off=24576 rest=0)

Bye.

-------------------------------------------------------
This SF.net email is sponsored by: Does your code think in ink? You could win a Tablet PC. Get a free Tablet PC hat just for playing. What are you waiting for?
http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en

#1 lore raw

At 19 Mar 2003 12:24:30 +0000,

Quoted 9 lines · Giuliano Pochini

I'm facing another *£%@ problem. When period size is a multiple or submultiple of PAGE_SIZE, it works fine, but when it isn't, sound clicks, pops, repeapeapeats, skps :(( And since the period never crosses physically the page boundary because I split it when it happens, I can't imagine what's wrong. Perhaps some of you had the same problem.

.period callback does this:

do you mean pointer callback?

Quoted 2 lines

bufsize=substream->runtime->periods*substream->runtime->period_size;

you already have substream->runtime->buffer_size for this.

Quoted 3 lines

//addr==number of bytes transferred.
pos=bytes_to_frames(substream->runtime, addr);
return(pos%bufsize);

i suppose addr is updated in the interrupt handler, right?

Quoted 18 lines

Here is a log of sg list construction:

AddX=period n
pa=page addr
phy=snd_sgbuf_get_addr(sgbuf, offs)
sz=sub-period size

aplay -B139319 -F69660 (OK)
pcm_hw_params (bufsize=24576 periods=2 persize=12288) pcm_hw_params table size=131072 pages=32
pcm_hw_params Add0 (off=0 pa=f3ff000 phy=f3ff000 sz=4096) pcm_hw_params Add0 (off=4096 pa=f3fe000 phy=f3fe000 sz=4096) pcm_hw_params Add0 (off=8192 pa=f3fd000 phy=f3fd000 sz=4096)irq pcm_hw_params Add1 (off=12288 pa=f3fc000 phy=f3fc000 sz=4096) pcm_hw_params Add1 (off=16384 pa=f417000 phy=f417000 sz=4096) pcm_hw_params Add1 (off=20480 pa=f416000 phy=f416000 sz=4096)irq pcm_hw_params End (off=24576 rest=0)

Quoted 12 lines

aplay -B139319 -F34830 (noise-party)
pcm_hw_params (bufsize=24576 periods=4 persize=6144) pcm_hw_params table size=131072 pages=32
pcm_hw_params Add0 (off=0 pa=f3ff000 phy=f3ff000 sz=4096) pcm_hw_params Add0 (off=4096 pa=f3fe000 phy=f3fe000 sz=2048)irq pcm_hw_params Add1 (off=6144 pa=f3fe000 phy=f3fe800 sz=2048) pcm_hw_params Add1 (off=8192 pa=f3fd000 phy=f3fd000 sz=4096)irq pcm_hw_params Add2 (off=12288 pa=f3fc000 phy=f3fc000 sz=4096) pcm_hw_params Add2 (off=16384 pa=f417000 phy=f417000 sz=2048)irq pcm_hw_params Add3 (off=18432 pa=f417000 phy=f417800 sz=2048) pcm_hw_params Add3 (off=20480 pa=f416000 phy=f416000 sz=4096)irq pcm_hw_params End (off=24576 rest=0)

the logs seem fine.

did you set up page callback, too?

were the irqs issued correctly with the 1.5 page periods? i mean, at the proper timing?

maybe it would be easier to debug if you show the actual code and the hardware spec...

Takashi

-------------------------------------------------------
This SF.net email is sponsored by: Does your code think in ink? You could win a Tablet PC. Get a free Tablet PC hat just for playing. What are you waiting for?
http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en

#3 lore raw
In reply to Giuliano Pochini
Quoted 14 lines · Giuliano Pochini
Quoted 9 lines
Quoted 7 lines

I'm facing another *Ł%@ problem. When period size is a multiple or submultiple of PAGE_SIZE, it works fine, but when it isn't, sound clicks, pops, repeapeapeats, skps :(( And since the period never crosses physically the page boundary because I split it when it happens, I can't imagine what's wrong. Perhaps some of you had the same problem.

.period callback does this:

do you mean pointer callback?

Yes, sorry.

Quoted 2 lines
Quoted 1 line

bufsize=substream->runtime->periods*substream->runtime->period_size;

Quoted 8 lines
Quoted 1 line

you already have substream->runtime->buffer_size for this.

They are different:

[aplay <no options> track.wav]

Mar 19 19:21:23 localhost kernel: pcm_hw_params (bufsize=88200 periods=3

persize=22052)

bufsize==88200 != 3*22052 == 66156

Note that there is no guarantee that the periods == integer value. If your hardware doesn't allow to set period_size and buffer_size independently (if buffer_size must be multiple of period_size) then put this code to the open callback:

if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
return err;

See alsa-kernel/pci/via82xx.c for an example.

In other cases, runtime->buffer_size MUST BE USED.

Jaroslav

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

-------------------------------------------------------
This SF.net email is sponsored by: Does your code think in ink? You could win a Tablet PC. Get a free Tablet PC hat just for playing. What are you waiting for?
http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en

#2 lore raw
In reply to Takashi Iwai
Quoted 9 lines
Quoted 7 lines

I'm facing another *£%@ problem. When period size is a multiple or submultiple of PAGE_SIZE, it works fine, but when it isn't, sound clicks, pops, repeapeapeats, skps :(( And since the period never crosses physically the page boundary because I split it when it happens, I can't imagine what's wrong. Perhaps some of you had the same problem.

.period callback does this:

do you mean pointer callback?

Yes, sorry.

Quoted 3 lines
Quoted 1 line

bufsize=substream->runtime->periods*substream->runtime->period_size;

you already have substream->runtime->buffer_size for this.

They are different:

[aplay <no options> track.wav]

Mar 19 19:21:23 localhost kernel: pcm_hw_params (bufsize=88200 periods=3

persize=22052)

bufsize==88200 != 3*22052 == 66156

Quoted 5 lines
Quoted 3 lines

//addr==number of bytes transferred.
pos=bytes_to_frames(substream->runtime, addr);
return(pos%bufsize);

i suppose addr is updated in the interrupt handler, right?

No, I read it from the hardware every time. I tried to store the value in the irq handler and it's the same.

Quoted 7 lines
Quoted 3 lines

Here is a log of sg list construction:
[...]

the logs seem fine.

did you set up page callback, too?

Yes I did.

Quoted 2 lines

were the irqs issued correctly with the 1.5 page periods? i mean, at the proper timing?

Yes, I believe. When period size is 2048 or 1024 it works fine. I put a printk in the pointer callback to monitor the frame position and it always seems correct despite the bad output. "irq" is a command I insert in the sg list, because the hw don't generate it automatically at the and of each block. IMO the bug is around the .pointer callback function.

Quoted 2 lines

maybe it would be easier to debug if you show the actual code and the hardware spec...

I'm writing my driver around the open source generic driver released by the manufacturer (in C++ argh!). I'm trying to keep the generic code as-is to make upgrades to future releases easier. I don't have hw specs but the sources are full of comments. As far as I can see there are no hw limits about the size of the sg list and its entries.

You can get my (very-ugly-pre-alpha) sources here:
http://space.virgilio.it/[email protected]/ea.tgz
and the generic driver here:
http://www.echoaudio.com/Downloads/Developer/EchoGenericDriverA0.zip

Bye.

-------------------------------------------------------
This SF.net email is sponsored by: Does your code think in ink? You could win a Tablet PC. Get a free Tablet PC hat just for playing. What are you waiting for?
http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en

#4 lore raw
In reply to Jaroslav Kysela
Quoted 14 lines
Quoted 8 lines

They are different:

[aplay <no options> track.wav]

Mar 19 19:21:23 localhost kernel: pcm_hw_params (bufsize=88200 periods=3

persize=22052)

bufsize==88200 != 3*22052 == 66156

Note that there is no guarantee that the periods == integer value. If your hardware doesn't allow to set period_size and buffer_size independently (if buffer_size must be multiple of period_size) then put this code to the open callback:

Quoted 6 lines

if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
return err;

See alsa-kernel/pci/via82xx.c for an example.

In other cases, runtime->buffer_size MUST BE USED.

Ok, but how do I build the sg list when bufsize!=sz*periods ? Take the example above: have I to build 4 periods and let the last one smaller than 22052 ?

Bye.

-------------------------------------------------------
This SF.net email is sponsored by: Tablet PC.
Does your code think in ink? You could win a Tablet PC. Get a free Tablet PC hat just for playing. What are you waiting for?
http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en

#5 lore raw

At Thu, 20 Mar 2003 10:04:39 +0100 (CET),

Quoted 18 lines · Giuliano Pochini
Quoted 18 lines
Quoted 9 lines

They are different:

[aplay <no options> track.wav]

Mar 19 19:21:23 localhost kernel: pcm_hw_params (bufsize=88200 periods=3

persize=22052)

bufsize==88200 != 3*22052 == 66156

Note that there is no guarantee that the periods == integer value. If your hardware doesn't allow to set period_size and buffer_size independently (if buffer_size must be multiple of period_size) then put this code to the open callback:

if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
return err;

Quoted 8 lines
Quoted 3 lines

See alsa-kernel/pci/via82xx.c for an example.

In other cases, runtime->buffer_size MUST BE USED.

Ok, but how do I build the sg list when bufsize!=sz*periods ? Take the example above: have I to build 4 periods and let the last one smaller than 22052 ?

it depends on the hardware.

if you need to set up a buffer-descriptor list like via82xx, the above h/w constraint (integer periods) will be most likely necessary. then the buffer size will be aligned to the period size automatically.

otherwise, you'll need to change the BD list dynamically with different sizes.

Takashi

-------------------------------------------------------
This SF.net email is sponsored by: Tablet PC.
Does your code think in ink? You could win a Tablet PC. Get a free Tablet PC hat just for playing. What are you waiting for?
http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en

#6 lore raw
Quoted 6 lines
Quoted 4 lines

Ok, but how do I build the sg list when bufsize!=sz*periods ? Take the example above: have I to build 4 periods and let the last one smaller than 22052 ?

it depends on the hardware.

There are no hw constraints IFAIK, but the hw does not provide the current dma address. It tells me how many bytes it transferred from the trigger-start command, so I need a way to translate that number into a frame pointer inside the buffer. To do that I must know exactly how long is the buffer to build the sg list and to stranslate the byte count in the pointer callback. (it's not enough see below) What does alsa expect from .pointer() ? [0-bufsz] or [0-pe*sz] ?

Quoted 4 lines

if you need to set up a buffer-descriptor list like via82xx, the above h/w constraint (integer periods) will be most likely necessary. then the buffer size will be aligned to the period size automatically.

It's a quick and simple way to make things work, but it should't be necessary.
The driver currently behaves correctly in two cases:

a - period size is a multiple of PAGE_SIZE
b - PAGE_SIZE is a multiple of period size

In both cases periods*periodsize matches buffer_size. But if periods*periodsize==buffer_size and !a and !b (eg. pe=4, psz=6K, bufsz=24K), it doesn't work:

page0 per0[0-4095]
page1 per0[4096-6143] per1[0-2048]
page2 per1[2048-6143]
...

There must be something I don't see/know. Before calling Echoaudio dev support I want be sure it's not my fault.

Bye.

-------------------------------------------------------
This SF.net email is sponsored by: Tablet PC.
Does your code think in ink? You could win a Tablet PC. Get a free Tablet PC hat just for playing. What are you waiting for?
http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en

#7 lore raw
Quoted 7 lines · Giuliano Pochini
Quoted 6 lines
Quoted 4 lines

Ok, but how do I build the sg list when bufsize!=sz*periods ? Take the example above: have I to build 4 periods and let the last one smaller than 22052 ?

it depends on the hardware.

Quoted 7 lines

There are no hw constraints IFAIK, but the hw does not provide the current dma address. It tells me how many bytes it transferred from the trigger-start command, so I need a way to translate that number into a frame pointer inside the buffer. To do that I must know exactly how long is the buffer to build the sg list and to stranslate the byte count in the pointer callback. (it's not enough see below) What does alsa expect from .pointer() ? [0-bufsz] or [0-pe*sz] ?

0 ... buffer_size

Quoted 12 lines
Quoted 4 lines

if you need to set up a buffer-descriptor list like via82xx, the above h/w constraint (integer periods) will be most likely necessary. then the buffer size will be aligned to the period size automatically.

It's a quick and simple way to make things work, but it should't be necessary.
The driver currently behaves correctly in two cases:

a - period size is a multiple of PAGE_SIZE
b - PAGE_SIZE is a multiple of period size

Quoted 8 lines

In both cases periods*periodsize matches buffer_size. But if periods*periodsize==buffer_size and !a and !b (eg. pe=4, psz=6K, bufsz=24K), it doesn't work:

page0 per0[0-4095]
page1 per0[4096-6143] per1[0-2048]
page2 per1[2048-6143]
...

Note that you'll have to call snd_pcm_period_elapsed() only after the whole period is elapsed and not fragment of it.

Jaroslav

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

-------------------------------------------------------
This SF.net email is sponsored by: Tablet PC.
Does your code think in ink? You could win a Tablet PC. Get a free Tablet PC hat just for playing. What are you waiting for?
http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en

#8 lore raw

At Thu, 20 Mar 2003 15:24:20 +0100 (CET),

Quoted 18 lines · Jaroslav
Quoted 7 lines · Giuliano Pochini
Quoted 6 lines
Quoted 4 lines

Ok, but how do I build the sg list when bufsize!=sz*periods ? Take the example above: have I to build 4 periods and let the last one smaller than 22052 ?

it depends on the hardware.

Quoted 7 lines

There are no hw constraints IFAIK, but the hw does not provide the current dma address. It tells me how many bytes it transferred from the trigger-start command, so I need a way to translate that number into a frame pointer inside the buffer. To do that I must know exactly how long is the buffer to build the sg list and to stranslate the byte count in the pointer callback. (it's not enough see below) What does alsa expect from .pointer() ? [0-bufsz] or [0-pe*sz] ?

Quoted 1 line

0 ... buffer_size

more accurately, 0 to (buffer_size - 1) :)

Quoted 16 lines
Quoted 16 lines
Quoted 4 lines

if you need to set up a buffer-descriptor list like via82xx, the above h/w constraint (integer periods) will be most likely necessary. then the buffer size will be aligned to the period size automatically.

It's a quick and simple way to make things work, but it should't be necessary.
The driver currently behaves correctly in two cases:

a - period size is a multiple of PAGE_SIZE
b - PAGE_SIZE is a multiple of period size

In both cases periods*periodsize matches buffer_size. But if periods*periodsize==buffer_size and !a and !b (eg. pe=4, psz=6K, bufsz=24K), it doesn't work:

Quoted 7 lines
Quoted 4 lines

page0 per0[0-4095]
page1 per0[4096-6143] per1[0-2048]
page2 per1[2048-6143]
...

Note that you'll have to call snd_pcm_period_elapsed() only after the whole period is elapsed and not fragment of it.

and just make sure: if the buffer is linear, does this period size work?

Takashi

-------------------------------------------------------
This SF.net email is sponsored by: Tablet PC.
Does your code think in ink? You could win a Tablet PC. Get a free Tablet PC hat just for playing. What are you waiting for?
http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en