Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: James Courtier-Dutton <James@superbug.co.uk>
To: Adrian McMenamin <adrian@mcmen.demon.co.uk>
Cc: Lee Revell <rlrevell@joe-job.com>,
	Alsa-devel <alsa-devel@lists.sourceforge.net>
Subject: Re: pointer callback in pcm
Date: Sat, 11 Mar 2006 15:42:57 +0000	[thread overview]
Message-ID: <4412F001.5020404@superbug.co.uk> (raw)
In-Reply-To: <1142076452.9496.8.camel@localhost.localdomain>

Adrian McMenamin wrote:
> On Sat, 2006-03-11 at 11:16 +0000, James Courtier-Dutton wrote:
>   
>> Adrian,
>>
>> Here is a quick summary of what I think you have been saying.
>> 1) Your hardware has min and max periods set to 8.
>> 2) Your hardware can do DMA, but not periodic DMA.   <- This is really 
>> the crux of the problem.
>> 3) You wish to use DMA.
>>     
>
> I really need to because transfers between the sound memory and the main
> memory are very slow otherwise. When I wrote the OSS driver for this a
> few years ago I simply copied stuff over, but it would effectively lock
> the machine up at high sample rates.
>   
The "problem" is that the DMA is not periodic, DMA itself is not the 
problem.
>   
>> 4) Unknown:  What triggers the audio interrupt? It should be triggered 
>> once each period is completed.
>>     
>
>
> This is done by the ARM7 spu that controls the sound output. I write the
> "firmware" for that so I have written some code that puts an IRQ on the
> SH4 (main CPU) bus every time a period has been played out.
>   
Can you get the "firmware" to initiate the DMA transfer, and then only 
IRQ the SH4 when the DMA completes?
>   
>> Now, here is what the ALSA model assumes:
>> 1) hardware period sizes are exactly the same size as the memory mapped 
>> DMA pages.
>>     
>
> I wasn't aware of that but I think I've done that anyway (4k period
> size)
>
>   
>> 2) snd_period_ellapsed() is called at periodic intervals dependent on 
>> where the ADC is playing samples.
>> 3) If the copy callback is NULL, ALSA assumes the DMA has already completed.
>> 4) If the copy callback is not NULL, ALSA calls it, but when the copy 
>> callback returns, the copy has been completed.
>>     
>
> I haven't got a copy callback - should I write one?
>   
You have to write one, but the ack() callback is probably more suitable 
in your case, if the period_ellapsed is called without the audio samples 
already being in main memory. (i.e. after the DMA is complete)
>   
>> 5) The pointer callback is then called that should return the position 
>> of the ADC in frames (not bytes) within the audio buffer.
>>
>> So, if you wish to use DMA, you should be calling snd_period_ellapsed() 
>> only after the DMA has completed, alternatively, the copy() callback 
>> should only return after the DMA transaction has completed, but I don't 
>> know if delaying the copy() return is allowed.
>> Can you get it to interrupt on each DMA completion?
>>
>>     
>
> In theory yes, but nobody seems have managed to reverse that bit of the
> spu function effectively yet, so I'd have to use polling on the progress
> of the transfer.
>   
>
>   
>> I would recommend you trying to do the following:
>> 1) Discover when the ADC has played the entire period.
>> 2) start the DMA transfer.
>> 3) At the DMA transfer complete interrrupt, call period_ellapsed().
>>
>> So, the problem might be how to discover that the ADC has played the 
>> entire period.
>>     
>
> I've got that covered (see above).
>
> How do I start? I am copying over 8 periods via DMA on the trigger, is
> that ok? (These are all I ever hear getting played). What about the ack
> callback that was recommended to me yesterday?
>
>   
>> You might have to use some sort of timer based polling to discover this.
>>
>> James
>>     

Some questions:
1) How does the main CPU discover the hardware pointer of the current 
ADC position? Needed for the pointer() callback.
2) Can you start and stop the samples being played?

Initialisation:
1) Wait for the application to fill 8 periods.  (you can simulate other 
periods models later if you wish. e.g You could simulate 2 periods to 
the application, even though you have 8 in hardware.)
2) The application will then call trigger to start playing the samples 
in the buffer.

I would recommend you try the following in the audio interrupt:
1) receive audio interrupt
2) start DMA transfer of one period.
    Which period you copy is the important bit here. At this point the 
hardware will have played 1 period, so you replace the period that has 
just played, not the period that is about to be played.
3) call snd_period_elapsed()
4) poll for DMA complete in the ack() callback.
5) period_elapsed will in turn call the pointer() callback.

James




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

  reply	other threads:[~2006-03-11 15:42 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-09 22:21 pointer callback in pcm Adrian McMenamin
2006-03-10  0:53 ` Lee Revell
2006-03-10 19:51   ` Adrian McMenamin
2006-03-10 20:16     ` Takashi Iwai
2006-03-10 20:21       ` Adrian McMenamin
2006-03-10 20:23       ` Lee Revell
2006-03-11 11:16     ` James Courtier-Dutton
2006-03-11 11:27       ` Adrian McMenamin
2006-03-11 15:42         ` James Courtier-Dutton [this message]
2006-03-11 15:53           ` Adrian McMenamin
2006-03-11 17:30           ` Adrian McMenamin
2006-03-11 18:47             ` James Courtier-Dutton
2006-03-11 19:08               ` Adrian McMenamin
2006-03-11 19:15                 ` James Courtier-Dutton
2006-03-11 19:18                   ` Adrian McMenamin
2006-03-11 19:37                     ` James Courtier-Dutton
2006-03-11 19:55                       ` Adrian McMenamin
2006-03-11 19:26               ` Adrian McMenamin
2006-03-11 19:35                 ` James Courtier-Dutton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4412F001.5020404@superbug.co.uk \
    --to=james@superbug.co.uk \
    --cc=adrian@mcmen.demon.co.uk \
    --cc=alsa-devel@lists.sourceforge.net \
    --cc=rlrevell@joe-job.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox