[Portaudio] Latency computation is fundamentally wrong (Windows)

Trond Seip Gundersen trondsg at gmail.com
Sat Jan 23 13:16:13 EST 2010


Hi
The OS is Windows XP. The computer is a dell vostro with an integrated sound
chip. I am using the ASIO4ALL drivers, which wraps normal sound drivers but
acheives better performance by bypassing normal kernel mixing.
The CPU is a Core 2 Duo T8100 2.10 Ghz.
ASIO4ALL provides its own control panel, curiously the latency values
specified when calling PA_OpenStream() (or specified in Audiomunch's control
panel) are not reflected in ASIO4ALL's control panel, which would normally
be the case.
When getting low latency with Cubase I use a buffer size of 192 to 224
samples and 4 buffers.
I could also try again later with a Presonus Firebox.

Regards,
Trond

On 22 January 2010 04:18, Ross Bencina <rossb-lists at audiomulch.com> wrote:

>  HI Trond
>
> Lets backtrack a bit.
>
> What hardware are you using (CPU, clock rate, sound card)
> What OS?
> What ASIO drivers?
>
> Do your ASIO drivers provide their own buffer settings? What values are you
> using?
>
> Thanks
>
> Ross.
>
>
>
>
>
>
>
> ----- Original Message -----
> *From:* Trond Seip Gundersen <trondsg at gmail.com>
> *To:* Portaudio Mailing List <portaudio at music.columbia.edu>
> *Sent:* Friday, January 22, 2010 1:07 AM
> *Subject:* Re: [Portaudio] Latency computation is fundamentally wrong
> (Windows)
>
> Hi Ross
>
> 2010/1/21 Ross Bencina <rossb-lists at audiomulch.com>
>
>> Hello Trond
>>
>> >>>>>
>> Problem 1: Specifying the latency as double doesn't match well with the
>> coarse resolution of this parameter.
>> <<<<<
>> ...
>>
>> If you want a device-model-specific interface you will find that most of
>> the
>> portaudio implementations provide an API for setting buffer sizes in
>> samplesand for querying for other buffer size constraints (see pa_asio.h
>> for
>> example).
>>
>
> Does GetAvailableLatencyValues() return buffer sizes? I think this tip is
> what I'm looking for, but the documentation isn't very helpful. PA wants
> latency as a double, but this function returns latency as long. I'd use the
> buffer size and the sample rate to calculate what kind of latency in ms I'd
> pass to OpenStream(), is that right?
>
>
>>
>> >>>
>> Problem 2: On integrated chips you may (for some strange reason) be able
>> to
>> acheive a lower latency without getting crackle by using a bigger number
>> of
>> smaller buffers (compared to one or two large buffers). Specifying the
>> number of buffers directly is not possible with PortAudio.
>> <<<
>>
>> For MME it is (see pa_win_wmme.h), and on Windows at least AFAIK MME is
>> the
>> only driver model which supports multi-buffer scatter gather. ASIO is
>>  strictly a 2-buffer interface.
>>
> ASIO4ALL allows the use of more buffers, but I guess it's not standard
> then. Some Linux Firewire drivers for Jack also allow more buffers. But I
> guess these have their own control panel, so it's not controlled from PA.
>
>
>>
>> >>>>
>> Problem 3: ASIO latency values are not rounded up to the next practical
>> value - the are rounded up more!
>> With a buffer size of 128 I get these numbers (in ms):
>> suggested latency 25, actual latency 35.8
>> suggested latency 30, actual latency 40.8
>> suggested latency 35, actual latency 45.8
>> Now common sense dictates that suggested latency 35 would give the actual
>> latency 35.8 or in the worst case 40, since it's the next-to-next
>> practical
>> value rounded up. The ASIO api skips past two possible latency values.
>> <<<<
>>
>> This may be a bug but without more information its difficult to say. There
>> are a few factors:
>>
>> - the reported stream latency is actually computed by the ASIO driver
>> (ASIOGetLatencies() in pa_asio.cpp line 2271). These values may include
>> hardware latencies as well as the buffering requested by PortAudio. Since
>> PA
>> has no way to access this information without opening the ASIO device
>> there
>> is not really a workaround for this.
>>
>> - the current suggested latency computation doesn't take into acount the
>> requested client buffer size. This can lead to PortAudio introducing
>> additional buffering to adapt the host buffer size with the callback
>> buffer
>> size. I think this is a bug, since if possible PA should try to make the
>> host buffer size be an integer multiple of the client buffer size. In a
>> worst-case scenario this would lead to higher latency and unstable
>> performance under high CPU load.
>>
>> - If PA introduces additional buffering (see previous point) the latency
>> of
>> this buffering is reported in the actual latency, but isn't taken into
>> account when computing buffer sizes from suggested latency. This is
>> arguably
>>  a bug but the complexity of resolving this may be higher than warranted.
>
>
>> >>>>
>> Problem 4: Latency with ASIO output is very bad with PortAudio compared to
>> other applications.
>> <<<<
>>
>> Are you sure? I easily get 5ms latency with ASIO and PortAudio. Sounds to
>> me
>> like you have some bug in your code. Try AudioMulch with an ASIO driver
>> and
>> see what you get (www.audiomulch.com) that uses the current PortAudio
>> trunk.
>>
> I am absolutely sure. I use the PortAudio snapshot from a few days ago.
> Cubase can go down to 15 ms without any problems, 11 ms is fine with an
> occassional "thrkc" sound. My own test program gives a lot of crackle at 35
> ms, AudioMulch works at 33 ms, but there is a lot more crackling than with
> 11 ms and Cubase. The CPU usage doesn't go above 25%.
>
>
>>
>> >>>>
>> I don't know what kind of bug that may cause such bad latencies with the
>> asio output, could it be that PortAudio does some kind of extra buffering?
>> <<<<
>>
>> Are you using the blocking read/write API or the callback API? For lowest
>> latency use the callback API.
>>
> I'm using the callback API.
>
>
>> >>>>
>> Also I have problem with a crackle/"thud" sound when starting and stopping
>> a
>> stream. Do you have any idea about what I can do about that?
>> <<<<
>>
>> Make sure you are outputting zeros not some DC offset value.
>>
>> I'm outputting a sine wave. The first sample is 0. I want to make sound,
> why would I output all zeroes? AudioMulch also has this same sound, so I'm
> not sure it's my code.
>
>
> Regards,
> Trond
>
>
>  ------------------------------
> _______________________________________________
> Portaudio mailing list
> Portaudio at music.columbia.edu
> http://music.columbia.edu/mailman/listinfo/portaudio
>
>
> _______________________________________________
> Portaudio mailing list
> Portaudio at music.columbia.edu
> http://music.columbia.edu/mailman/listinfo/portaudio
>



-- 
Never hit a man with glasses. Hit him with a baseball bat.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://music.columbia.edu/pipermail/portaudio/attachments/20100123/e837d03b/attachment-0001.html 


More information about the Portaudio mailing list