PortAudio M1 Latency

By admin
I recently tried to get my

whistle-controlled bass synthesizer working on my Mac, as a backup to my Raspberry Pi version . [

1
CARDINAL

] It’s written on top of

PortAudio
ORG

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

‘s demo

paex_read_write_wire.c
PERSON

[

2
CARDINAL

] with suggestedLatency changed from defaultHighOutputLatency to defaultLowInputLatency I see:

Input device #

2
MONEY

. Name:

MacBook Pro Microphone LL
ORG

:

0.0528542 s
QUANTITY

HL:

0.0621875 s Output
MONEY

device #

3
MONEY

. Name: MacBook Pro Speakers LL:

0.0187083
CARDINAL

s HL:

0.0280417 s Num
MONEY

channels =

1
CARDINAL

.

This is 72ms of round-trip latency, or

3,156
CARDINAL

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
CARDINAL

] Changing FRAMES_PER_BUFFER from the default of

512
CARDINAL

to

128
CARDINAL

doesn’t have any effect, so I think this is lower level buffering.

I also tried with a

Scarlett
PERSON


2i2
CARDINAL

audio interface, and latency wasn’t any lower. Setting

PA_MIN_LATENCY_MSEC
ORG

also doesn’t do anything. I’d try turning off ambient noise reduction but this option doesn’t exist for

M1 Macs
PRODUCT

.

I don’t have this problem when running

the Reaper DAW
FAC

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
ORG

doesn’t ask to turn it off?

(I could go back to running my code as a

Reaper
PRODUCT

plug-in, but I’d much rather have something stand-alone.)

[

1
CARDINAL

] In setting up at

Adirondack Dance Weekend
EVENT

I couldn’t find

one
CARDINAL

of my

two
CARDINAL

Pis. It turns out I’d missed that it was under my mixer and forgotten to pack it:

[

2
CARDINAL

] Built with gcc -I/opt/homebrew/include/ -L/opt/homebrew/lib/ -lportaudio

paex_read_write_wire.c
PERSON

-o paex_read_write_wire after brew install portaudio to get the library.

[

3
CARDINAL

] Suspiciously this is quite a bit higher than I used to see on my

Intel Mac
ORG

. I used to get 19ms in

Chrome
ORG

and 14ms in

Firefox
ORG

, and I’m now getting 67ms in

Chrome
ORG

and 64ms in

Firefox
ORG

.