All of lore.kernel.org
 help / color / mirror / Atom feed
* period crossing page boundary
@ 2003-03-19 12:24 Giuliano Pochini
  2003-03-19 17:06 ` Takashi Iwai
  0 siblings, 1 reply; 9+ messages in thread
From: Giuliano Pochini @ 2003-03-19 12:24 UTC (permalink / raw)
  To: alsa-devel


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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: period crossing page boundary
  2003-03-19 12:24 period crossing page boundary Giuliano Pochini
@ 2003-03-19 17:06 ` Takashi Iwai
  2003-03-19 21:06   ` Giuliano Pochini
  0 siblings, 1 reply; 9+ messages in thread
From: Takashi Iwai @ 2003-03-19 17:06 UTC (permalink / raw)
  To: Giuliano Pochini; +Cc: alsa-devel

At 19 Mar 2003 12:24:30 +0000,
Giuliano Pochini wrote:
> 
> 
> 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?

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

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

> //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?

> 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)

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: period crossing page boundary
  2003-03-19 21:06   ` Giuliano Pochini
@ 2003-03-19 20:16     ` Jaroslav Kysela
  2003-03-20  9:04       ` Giuliano Pochini
  0 siblings, 1 reply; 9+ messages in thread
From: Jaroslav Kysela @ 2003-03-19 20:16 UTC (permalink / raw)
  To: Giuliano Pochini; +Cc: Takashi Iwai, alsa-devel

On 19 Mar 2003, Giuliano Pochini wrote:

> > > 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. 
> 
> > > 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 

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 <perex@suse.cz>
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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: period crossing page boundary
  2003-03-19 17:06 ` Takashi Iwai
@ 2003-03-19 21:06   ` Giuliano Pochini
  2003-03-19 20:16     ` Jaroslav Kysela
  0 siblings, 1 reply; 9+ messages in thread
From: Giuliano Pochini @ 2003-03-19 21:06 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel

> > 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. 

> > 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 

> > //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.

>
> > Here is a log of sg list construction:
> > [...]
>
> the logs seem fine.
>
> did you set up page callback, too?

Yes I did.

> 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.

> 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/g_pochini@virgilio.it/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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: period crossing page boundary
  2003-03-19 20:16     ` Jaroslav Kysela
@ 2003-03-20  9:04       ` Giuliano Pochini
  2003-03-20 10:37         ` Takashi Iwai
  0 siblings, 1 reply; 9+ messages in thread
From: Giuliano Pochini @ 2003-03-20  9:04 UTC (permalink / raw)
  To: Jaroslav Kysela; +Cc: alsa-devel, Takashi Iwai


>> 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.


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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: period crossing page boundary
  2003-03-20  9:04       ` Giuliano Pochini
@ 2003-03-20 10:37         ` Takashi Iwai
  2003-03-20 14:13           ` Giuliano Pochini
  0 siblings, 1 reply; 9+ messages in thread
From: Takashi Iwai @ 2003-03-20 10:37 UTC (permalink / raw)
  To: Giuliano Pochini; +Cc: Jaroslav Kysela, alsa-devel

At Thu, 20 Mar 2003 10:04:39 +0100 (CET),
Giuliano Pochini wrote:
> 
> 
> >> 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.
> 
> 
> 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: period crossing page boundary
  2003-03-20 10:37         ` Takashi Iwai
@ 2003-03-20 14:13           ` Giuliano Pochini
  2003-03-20 14:24             ` Jaroslav Kysela
  0 siblings, 1 reply; 9+ messages in thread
From: Giuliano Pochini @ 2003-03-20 14:13 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel


>> 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] ?

> 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: period crossing page boundary
  2003-03-20 14:13           ` Giuliano Pochini
@ 2003-03-20 14:24             ` Jaroslav Kysela
  2003-03-20 14:45               ` Takashi Iwai
  0 siblings, 1 reply; 9+ messages in thread
From: Jaroslav Kysela @ 2003-03-20 14:24 UTC (permalink / raw)
  To: Giuliano Pochini; +Cc: Takashi Iwai, alsa-devel

On Thu, 20 Mar 2003, Giuliano Pochini wrote:

> 
> >> 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] ?

0 ... buffer_size

> > 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]
> ...

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 <perex@suse.cz>
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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: period crossing page boundary
  2003-03-20 14:24             ` Jaroslav Kysela
@ 2003-03-20 14:45               ` Takashi Iwai
  0 siblings, 0 replies; 9+ messages in thread
From: Takashi Iwai @ 2003-03-20 14:45 UTC (permalink / raw)
  To: Jaroslav Kysela; +Cc: Giuliano Pochini, alsa-devel

At Thu, 20 Mar 2003 15:24:20 +0100 (CET),
Jaroslav wrote:
> 
> On Thu, 20 Mar 2003, Giuliano Pochini wrote:
> 
> > 
> > >> 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] ?
> 
> 0 ... buffer_size
 
more accurately, 0 to (buffer_size - 1) :)

> > > 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]
> > ...
> 
> 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2003-03-20 14:45 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-19 12:24 period crossing page boundary Giuliano Pochini
2003-03-19 17:06 ` Takashi Iwai
2003-03-19 21:06   ` Giuliano Pochini
2003-03-19 20:16     ` Jaroslav Kysela
2003-03-20  9:04       ` Giuliano Pochini
2003-03-20 10:37         ` Takashi Iwai
2003-03-20 14:13           ` Giuliano Pochini
2003-03-20 14:24             ` Jaroslav Kysela
2003-03-20 14:45               ` Takashi Iwai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.