[linux-audio-dev] absolute minimum latency (was Re: ADAT clicks)

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: [linux-audio-dev] absolute minimum latency (was Re: ADAT clicks)
From: Paul Barton-Davis (pbd_AT_Op.Net)
Date: Thu Apr 06 2000 - 17:38:14 EEST


>This makes no difference except that you can cut latency from some
>3-5 ms down to around one sample + whatever delay there is in the
>converters and analog cirquitry.
>
>Oh, AFAIK, ProTools has more than 3 ms latency anyway, BTW. I don't

Warning: 24 channels of audio 32 bit audio data at 48kHz = 4.39MB/sec

I ran the following test program on my machine:

#include <stdio.h>
#include <stdlib.h>
#include <asm/msr.h>
#include <sys/mman.h>
#include <sched.h>

#define BUFSIZE 4608000
#define CYCLES_PER_USEC 450.0f

main ()

{
        char *abuf;
        char *bbuf;
        unsigned long now, then;
        int n;
        unsigned long min = 999999;
        unsigned long max = 0;

        unsigned long diff;
        struct sched_param sp;

        abuf = (char *) malloc (BUFSIZE);
        bbuf = (char *) malloc (BUFSIZE);

        memset (&sp, 0, sizeof sp);
        sp.sched_priority = 10;

        if (sched_setscheduler (0, SCHED_FIFO, &sp) != 0) {
                fprintf (stderr, "can't become realtime thread\n");
                return 1;
        }
        
        if (mlockall (MCL_CURRENT | MCL_FUTURE) != 0) {
                fprintf (stderr, "can't lock down pages\n");
                return 1;
        }

        for (n = 0; n < 1000; n++) {
                rdtscl (then);
                memcpy (abuf, bbuf, BUFSIZE);
                rdtscl (now);

                diff = now - then;
                if (diff < min) {
                        min = diff;
                }
                if (diff > max) {
                        max = diff;
                }
        }

        printf ("Minimum usecs for 1 copy: %.2f\n",
                (float) min / CYCLES_PER_USEC);
        printf ("Maximum usecs for 1 copy: %.2f\n",
                (float) max / CYCLES_PER_USEC);
}

On my machine it prints:

  Minimum usecs for 1 copy: 2222.22
  Maximum usecs for 1 copy: 42504.73

The minimum value never varies, the maximum value has about +/-
500usecs of variation.

To put this in slightly starker terms: just *copying* the data from
the buffer used by the audio h/w to some other piece of RAM takes
2.2msec. You can forget *ever* getting lower latency than this, since
this figure (or its value on your machine) is the *absolute* minimum
time it will take to do absolutely zero processing on the audio data
(it has to be copied at least once before it can be written to disk,
to avoid dropouts caused by disk i/o; likewise for the simple "direct
through via software" case, where the copy is simply back to the
playback buffer used by the audio h/w).

This includes no surrounding code, no logic, no cache misses, no
nothing. Worse, it doesn't take into account that the copy doesn't
happen as one single chunk of 4.39MB, but as 24 copies of 192000
bytes. How do the numbers look for this case ?

  Minimum usecs for 1 copy: 813.12
  Maximum usecs for 1 copy: 1042.6

Thats about 20msec (24 * 0.813) absolute minimum latency for 24
channels.

So, talking about latencies of 3msec for this kind of application is
shouting into the wind without significantly faster low level system
throughput.

>instead, if you use the digital I/O. Involving a digital console very
>likely adds some more latency.

Mackie claims 1.3ms. I don't know if I believe them.

--p

        


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : Thu Apr 06 2000 - 19:10:04 EEST