* Buffer management questions
@ 2006-03-13 19:24 Carlos Munoz
2006-03-13 19:25 ` Adrian McMenamin
0 siblings, 1 reply; 6+ messages in thread
From: Carlos Munoz @ 2006-03-13 19:24 UTC (permalink / raw)
To: alsa-devel
Hi all,
I'm writing my first alsa driver and I have the following questions
regarding buffer management (I've read all the documents in the alsa
site but none answered my questions):
How is the sound data replenished in the dma buffer for playback ? I
call snd_pcm_lib_malloc_pages() to allocate the buffer. I assume when
the trigger function is called, there is valid data in the buffer.
However, once the driver sends all the data in the buffer, how does it
get more data ? Should I assume the data is there and just wrap around
the buffer ?
I'm used to the write()/read() function calls to pass data in/out of
drivers, but don't yet understand how data is passed in the alsa model.
Any help is appreciated.
Thanks,
Carlos
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Buffer management questions
2006-03-13 19:24 Buffer management questions Carlos Munoz
@ 2006-03-13 19:25 ` Adrian McMenamin
2006-03-13 20:03 ` Carlos Munoz
0 siblings, 1 reply; 6+ messages in thread
From: Adrian McMenamin @ 2006-03-13 19:25 UTC (permalink / raw)
To: Carlos Munoz; +Cc: alsa-devel
On Mon, 2006-03-13 at 11:24 -0800, Carlos Munoz wrote:
> Hi all,
>
> I'm writing my first alsa driver and I have the following questions
> regarding buffer management (I've read all the documents in the alsa
> site but none answered my questions):
>
> How is the sound data replenished in the dma buffer for playback ? I
> call snd_pcm_lib_malloc_pages() to allocate the buffer. I assume when
> the trigger function is called, there is valid data in the buffer.
> However, once the driver sends all the data in the buffer, how does it
> get more data ? Should I assume the data is there and just wrap around
> the buffer ?
>
Just been through all this myself :)
The alsa middle layer will handle this for if your driver is coded
correctly. In my case that means having a timer check that a period has
been played out, transferring new bytes across and then calling
snd_pcm_period_elapsed which manages the refill - give us some more
details of your hardware and I am sure others can help
> I'm used to the write()/read() function calls to pass data in/out of
> drivers, but don't yet understand how data is passed in the alsa model.
> Any help is appreciated.
>
The middle layer does most of the work for you though the implementation
details depend on how your hardware works. you don't need a write()
> Thanks,
>
>
> Carlos
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by xPML, a groundbreaking scripting language
> that extends applications into web and mobile media. Attend the live webcast
> and join the prime developer group breaking into this new coding territory!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/alsa-devel
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Buffer management questions
2006-03-13 19:25 ` Adrian McMenamin
@ 2006-03-13 20:03 ` Carlos Munoz
2006-03-13 20:07 ` Adrian McMenamin
2006-03-13 20:10 ` Takashi Iwai
0 siblings, 2 replies; 6+ messages in thread
From: Carlos Munoz @ 2006-03-13 20:03 UTC (permalink / raw)
To: Adrian McMenamin; +Cc: alsa-devel
Adrian McMenamin wrote:
>On Mon, 2006-03-13 at 11:24 -0800, Carlos Munoz wrote:
>
>
>>Hi all,
>>
>>I'm writing my first alsa driver and I have the following questions
>>regarding buffer management (I've read all the documents in the alsa
>>site but none answered my questions):
>>
>>How is the sound data replenished in the dma buffer for playback ? I
>>call snd_pcm_lib_malloc_pages() to allocate the buffer. I assume when
>>the trigger function is called, there is valid data in the buffer.
>>However, once the driver sends all the data in the buffer, how does it
>>get more data ? Should I assume the data is there and just wrap around
>>the buffer ?
>>
>>
>>
>
>Just been through all this myself :)
>
>The alsa middle layer will handle this for if your driver is coded
>correctly. In my case that means having a timer check that a period has
>been played out, transferring new bytes across and then calling
>snd_pcm_period_elapsed which manages the refill - give us some more
>details of your hardware and I am sure others can help
>
>
>
>
>
Hi Adrian,
The driver is for the Sound Interface Unit (SIU) peripheral on the
Renesas SH7343 processor. This chip has several peripherals including
the SIU and a DMA controller. The end product is a cell phone that will
play music as well. The DMA controller can be optimized for transfers
to/from internal peripherals. I was planning to use the DMA controller
to write the sound data from the memory to the SIU fifo. The DMA
transfer will be 1024 bytes (period) and I will call
snd_pcm_period_elapsed() after each transfer completes. However, I don't
know what to do when I get to the end of the buffer. How do I know there
is new data in the buffer. Should I just wrap around ? Also, I need to
know if caching is disabled for the buffer, since the DMA controller is
not cache coherent and will not read the data from the cache but
directly from the memory.
Please let me know if you have any questions.
Thanks,
Carlos
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Buffer management questions
2006-03-13 20:03 ` Carlos Munoz
@ 2006-03-13 20:07 ` Adrian McMenamin
2006-03-13 20:09 ` Adrian McMenamin
2006-03-13 20:10 ` Takashi Iwai
1 sibling, 1 reply; 6+ messages in thread
From: Adrian McMenamin @ 2006-03-13 20:07 UTC (permalink / raw)
To: Carlos Munoz; +Cc: alsa-devel
On Mon, 2006-03-13 at 12:03 -0800, Carlos Munoz wrote:
> Adrian McMenamin wrote:
>
>
> Hi Adrian,
>
> The driver is for the Sound Interface Unit (SIU) peripheral on the
> Renesas SH7343 processor.
Ah, mine was for the Dreamcast :)
> This chip has several peripherals including
> the SIU and a DMA controller. The end product is a cell phone that will
> play music as well. The DMA controller can be optimized for transfers
> to/from internal peripherals. I was planning to use the DMA controller
> to write the sound data from the memory to the SIU fifo. The DMA
> transfer will be 1024 bytes (period) and I will call
> snd_pcm_period_elapsed() after each transfer completes. However, I don't
> know what to do when I get to the end of the buffer. How do I know there
> is new data in the buffer. Should I just wrap around ? Also, I need to
> know if caching is disabled for the buffer, since the DMA controller is
> not cache coherent and will not read the data from the cache but
> directly from the memory.
The DMA stuff is beyond me - but you can wrap around: have a look at my
sources - still under development and the stereo separation stuff I
added last night is broken, but it sounds similar to your box and you
may even be using the same DMA API
>
> Please let me know if you have any questions.
>
> Thanks,
>
>
> Carlos
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Buffer management questions
2006-03-13 20:07 ` Adrian McMenamin
@ 2006-03-13 20:09 ` Adrian McMenamin
0 siblings, 0 replies; 6+ messages in thread
From: Adrian McMenamin @ 2006-03-13 20:09 UTC (permalink / raw)
To: Carlos Munoz; +Cc: alsa-devel
err the sources are at http://newgolddream.dyndns.info/cgi-bin/cvsweb
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Buffer management questions
2006-03-13 20:03 ` Carlos Munoz
2006-03-13 20:07 ` Adrian McMenamin
@ 2006-03-13 20:10 ` Takashi Iwai
1 sibling, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2006-03-13 20:10 UTC (permalink / raw)
To: Carlos Munoz; +Cc: Adrian McMenamin, alsa-devel
At Mon, 13 Mar 2006 12:03:29 -0800,
Carlos Munoz wrote:
>
> Adrian McMenamin wrote:
>
> >On Mon, 2006-03-13 at 11:24 -0800, Carlos Munoz wrote:
> >
> >
> >>Hi all,
> >>
> >>I'm writing my first alsa driver and I have the following questions
> >>regarding buffer management (I've read all the documents in the alsa
> >>site but none answered my questions):
> >>
> >>How is the sound data replenished in the dma buffer for playback ? I
> >>call snd_pcm_lib_malloc_pages() to allocate the buffer. I assume when
> >>the trigger function is called, there is valid data in the buffer.
> >>However, once the driver sends all the data in the buffer, how does it
> >>get more data ? Should I assume the data is there and just wrap around
> >>the buffer ?
> >>
> >>
> >>
> >
> >Just been through all this myself :)
> >
> >The alsa middle layer will handle this for if your driver is coded
> >correctly. In my case that means having a timer check that a period has
> >been played out, transferring new bytes across and then calling
> >snd_pcm_period_elapsed which manages the refill - give us some more
> >details of your hardware and I am sure others can help
> >
> >
> >
> >
> >
>
> Hi Adrian,
>
> The driver is for the Sound Interface Unit (SIU) peripheral on the
> Renesas SH7343 processor. This chip has several peripherals including
> the SIU and a DMA controller. The end product is a cell phone that will
> play music as well. The DMA controller can be optimized for transfers
> to/from internal peripherals. I was planning to use the DMA controller
> to write the sound data from the memory to the SIU fifo. The DMA
> transfer will be 1024 bytes (period) and I will call
> snd_pcm_period_elapsed() after each transfer completes. However, I don't
> know what to do when I get to the end of the buffer. How do I know there
> is new data in the buffer. Should I just wrap around ?
ALSA assumues a ring-buffer, so yes, you need a wrap of pointer.
You don't have to take care of buffer filling since the data is filled
on the ring-buffer automagically by the middle layer.
> Also, I need to
> know if caching is disabled for the buffer, since the DMA controller is
> not cache coherent and will not read the data from the cache but
> directly from the memory.
It depends on what memory you allocated. If you allocate a buffer
with dma_alloc_coherent() (SNDRV_DMA_TYPE_DEV type if you use
snd_pcm_lib_preallocate_*), the buffer is guaranteed to be coherent,
i.e. caches are disabled.
BTW, the buffer management will be changed in near future a little
bit, especially for problems with mmap and cache-coherency. But, the
basic mechanism will be kept, and the transition should be easy.
Takashi
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-03-13 20:10 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-13 19:24 Buffer management questions Carlos Munoz
2006-03-13 19:25 ` Adrian McMenamin
2006-03-13 20:03 ` Carlos Munoz
2006-03-13 20:07 ` Adrian McMenamin
2006-03-13 20:09 ` Adrian McMenamin
2006-03-13 20:10 ` 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.