All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Ujfalusi <peter.ujfalusi@ti.com>
To: Leonardo Gabrielli <l.gabrielli@univpm.it>
Cc: alsa-devel@alsa-project.org
Subject: Re: twl4030 latency update
Date: Wed, 26 Mar 2014 14:51:04 +0200	[thread overview]
Message-ID: <5332CD38.3070700@ti.com> (raw)
In-Reply-To: <5332A1C9.3070802@univpm.it>

On 03/26/2014 11:45 AM, Leonardo Gabrielli wrote:
> 
> On 26/03/2014 09:26, Peter Ujfalusi wrote:
>> The McBSP2 FIFO will be always there. There's nothing can be done on that. The
>> size on McBSP2 is 1280 words -> 640 stereo samples, ie ~29ms with 22050,
>> 14.5ms with 44100.
>>
>> If you are staying in element mode this means that it is granted that the
>> sample at the DMA pointer will out on the i2s line about the mentioned times.
>> This is the delay caused by the FIFO itself. From where the rest is coming I'm
>> not really sure.

> BTW: I forgot to mention: the latency listed in my previous email is
> input+output (i.e. I record pulses from the beagleboard input jack and the
> delayed version to the beagleboard output jack). The twl4030 analog and
> digital loopback features have been of course disabled, in order to get the
> total latency due from A/D to D/A.

This means that the McBSP latency in worst case is 1280 + selected rx
threshold in words (so /2 in case of stereo.) If you lower the rx threshold
you decrease the latency on the capture side. On the playback side there's
nothing can be done.

> So just to get confirm I understood the McBSP mechanism well: even though I
> can transfer to/from DMA samples in bursts of <threshold> length, each sample
> will always "travel along" the whole FIFO buffer length, (as if in a delay
> line) and thus they will always have 640samples delay?

On the playback side this is pretty much true. On capture side the threshold
means that DMA will read from FIFO when threshold amount is available in it.

> Would it be possible to workaround this, e.g. by putting 4-channel audio
> frames instead of stereo frames in the FIFO (with 2 channels unused), in order
> to fill up the FIFO more quickly and have less latency? Or is it pure craze?

>From the FIFO McBSP takes data word by word. If you play stereo, you need to
have stereo data in the FIFO. You can not skip two words with McBSP.

The thing I tried for playback and did not worked AFAIR:
In general the idea was to configure DMA to send threshold/channel to every
request while configuring the McBSP threshold register to be 1280 - threshold.
In case of threshold 80 (40 stereo samples) it would play out:
transfer 40 samples to FIFO per DMA request
assert the DMA request when we have space for 1260 (630 samples). The number
is just a guess, keeping 10 samples in FIFO sounds safe enough
This would keep the FIFO fill between 10 and 50 samples.
But this does not work, I think McBSP is counting the received words also and
deasserts the DMA request based on this count and not the FIFO level.

Another thing which would be even more complicated is to play with the McBSP
threshold runtime. With the same 40 sample:
DMA is to transfer 40 samples per DMA requests.
start
1. McBSP threshold to 80
2. in dma interrupt callback McBSP threshold to 1260
3. in McBSP warning interrupt (that we will be reaching the threshold soon)
back to 80
4. goto 2

If we could do the step between 3 and 4 within one sample time this might work
but as soon as you are late the thing will fail.

I know this is working in realtime systems like in DSPs and non linux systems...

-- 
Péter

  reply	other threads:[~2014-03-26 12:51 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-20 11:13 twl4030 latency update Leonardo Gabrielli
2014-03-20 13:35 ` Peter Ujfalusi
2014-03-20 14:31   ` Leonardo Gabrielli
2014-03-21  7:08     ` Peter Ujfalusi
2014-03-25 18:50       ` Leonardo Gabrielli
2014-03-26  8:26         ` Peter Ujfalusi
2014-03-26  8:41           ` Peter Ujfalusi
2014-03-26  9:35           ` Leonardo Gabrielli
2014-03-26 12:28             ` Peter Ujfalusi
2014-03-26  9:45           ` Leonardo Gabrielli
2014-03-26 12:51             ` Peter Ujfalusi [this message]
2014-03-26 15:40               ` Leonardo Gabrielli
     [not found]               ` <533A89D2.5050906@univpm.it>
2014-04-01 13:31                 ` Peter Ujfalusi

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=5332CD38.3070700@ti.com \
    --to=peter.ujfalusi@ti.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=l.gabrielli@univpm.it \
    /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 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.