I recently tried to get my whistle-controlled bass synthesizer working on my Mac, as a backup to my Raspberry Pi version. [1] It's written on top of PortAudio, a cross-platform audio library, so getting it to compile and run was mostly a matter of getting the library installed, which went quickly. Unfortunately, the latency was far too high to be useful as a real-time musical instrument.

Testing with PortAudio's demo paex_read_write_wire.c [2] with suggestedLatency changed from defaultHighOutputLatency to defaultLowInputLatency I see:

Input device # 2.
    Name: MacBook Pro Microphone
      LL: 0.0528542 s
      HL: 0.0621875 s
Output device # 3.
   Name: MacBook Pro Speakers
     LL: 0.0187083 s
     HL: 0.0280417 s
Num channels = 1.

This is 72ms of round-trip latency, or 3,156 samples. You can easily hear the latency, and it's pretty painful for live music. It's even higher than the 67ms I see in the web browser. [3] Changing FRAMES_PER_BUFFER from the default of 512 to 128 doesn't have any effect, so I think this is lower level buffering.

I also tried with a Scarlett 2i2 audio interface, and latency wasn't any lower. Setting PA_MIN_LATENCY_MSEC also doesn't do anything. I'd try turning off ambient noise reduction but this option doesn't exist for M1 Macs.

I don't have this problem when running the Reaper DAW so it's definitely possible to get low latency on this machine. I wonder if there's some kind of default processing running on the audio system, and Portaudio doesn't ask to turn it off?

(I could go back to running my code as a Reaper plug-in, but I'd much rather have something stand-alone.)


[1] In setting up at Adirondack Dance Weekend I couldn't find one of my two Pis. It turns out I'd missed that it was under my mixer and forgotten to pack it:

[2] Built with gcc -I/opt/homebrew/include/ -L/opt/homebrew/lib/ -lportaudio paex_read_write_wire.c -o paex_read_write_wire after brew install portaudio to get the library.

[3] Suspiciously this is quite a bit higher than I used to see on my Intel Mac. I used to get 19ms in Chrome and 14ms in Firefox, and I'm now getting 67ms in Chrome and 64ms in Firefox.

Comment via: facebook, mastodon

New Comment
5 comments, sorted by Click to highlight new comments since: Today at 5:23 AM

Testing with PortAudio's demo paex_read_write_wire.c [2]

It looks like this uses the blocking IO interface, I guess that adds its own buffering on top of everything else. For minimal latency you want the callback interface. Try adapting test/patest_wire.c or test/pa_minlat.c.

I've been thinking of buying an M1 MacBook because everyone says that Apple's sound system is great and works out of the box correctly with low latency and no problems, unlike Windows+Wasapi, Windows+ASIO, and Linux. I want to use it for music stuff without an external audio interface. How true is this and would you recommend it?

I get great latency with Reaper, so my guess is as long as you're using standard audio tools you'll be fine?

My issue is that I want a custom stand-alone program, and there's something extra you need to do to get good latency I'm missing.

Are you able to play sounds using other programs (e.g. open a YouTube video in the background) while getting great latency in reaper or in something similar to reaper?