Live data from Hacker News

Lessons learnt building a real-time audio application in Python

vangemert.dev

11–20 of 35 posts

Re: Lessons learnt building a real-time audio application in Python

#11
post #9
post #6

Earlier quoted context omitted.

Yeah, your Scarlett should be capable of single-digit ms latency. If you're on Windows, you need to install its ASIO drivers and figure out how to use them from Python. Then, yes, use tiny buffers and run your audio processing very fast - which is where Python's slowness will probably become a real problem. 10ms latency is how long sound takes to travel 3-and-a-bit metres. So if your amp is a few metres from you, you…

With Ableton and the default ASIO configuration on my Scarlett I get 96 ms combined input+output latency without any processing in between, so that's probably what made my ears bleed before. Tweaking the sample rate and buffer size gets me indeed single digit latencies in Ableton. So I'm definitely going to adjust the section about latency, thanks for this! I'm a bit on the fence about what this means for the difficu…

I would disable any services and programs running in the background as well. Years ago I disabled the Windows print spooler and it greatly improved jitter. Not sure if that's still the case these days though, that was probably 10 years ago.

Re: Lessons learnt building a real-time audio application in Python

#12
post #9
post #6

Earlier quoted context omitted.

Yeah, your Scarlett should be capable of single-digit ms latency. If you're on Windows, you need to install its ASIO drivers and figure out how to use them from Python. Then, yes, use tiny buffers and run your audio processing very fast - which is where Python's slowness will probably become a real problem. 10ms latency is how long sound takes to travel 3-and-a-bit metres. So if your amp is a few metres from you, you…

With Ableton and the default ASIO configuration on my Scarlett I get 96 ms combined input+output latency without any processing in between, so that's probably what made my ears bleed before. Tweaking the sample rate and buffer size gets me indeed single digit latencies in Ableton. So I'm definitely going to adjust the section about latency, thanks for this! I'm a bit on the fence about what this means for the difficu…

Even without ASIO you should be able to hit 40 ms latency on pretty much any Windows audio hardware, including motherboard built-in.

If you get 300 ms you're doing something wrong. Note that Windows has multiple audio APIs, 300 ms is about the latency of the old MME api, you need to use the newer one, WASAPI.

Re: Lessons learnt building a real-time audio application in Python

#13
post #10
post #9

Earlier quoted context omitted.

With Ableton and the default ASIO configuration on my Scarlett I get 96 ms combined input+output latency without any processing in between, so that's probably what made my ears bleed before. Tweaking the sample rate and buffer size gets me indeed single digit latencies in Ableton. So I'm definitely going to adjust the section about latency, thanks for this! I'm a bit on the fence about what this means for the difficu…

try clarett interface. it also comes with pre amps which will make your sound less noisy , scarlet preamps are just absolutely terrible. you can debug your daw to see how it uses drivers and make a python module which exposes similar functions to python. you will likely still want a delay compensation to make things seem free of any latency, but it will be doing _much_ less compensating. maybe theres an opensource da…

Debugging an existing DAW to see how they do it under the hood is an interesting idea. Haven't done that yet.

About another interface: I do want to keep the application supporting cheaper interfaces such as the Scarlett, because the target audience (hobby musicians) will be using those. Still would be a nice upgrade for me!

Re: Lessons learnt building a real-time audio application in Python

#14
post #9

Earlier quoted context omitted.

With Ableton and the default ASIO configuration on my Scarlett I get 96 ms combined input+output latency without any processing in between, so that's probably what made my ears bleed before. Tweaking the sample rate and buffer size gets me indeed single digit latencies in Ableton. So I'm definitely going to adjust the section about latency, thanks for this! I'm a bit on the fence about what this means for the difficu…

Even without ASIO you should be able to hit 40 ms latency on pretty much any Windows audio hardware, including motherboard built-in. If you get 300 ms you're doing something wrong. Note that Windows has multiple audio APIs, 300 ms is about the latency of the old MME api, you need to use the newer one, WASAPI.

I apparently only have the old Windows MME drivers indeed (and ASIO, on Win10). Need to look into why I can't find WASAPI and if I can assume other Windows users have those by default.

Re: Lessons learnt building a real-time audio application in Python

#15
post #9

Earlier quoted context omitted.

With Ableton and the default ASIO configuration on my Scarlett I get 96 ms combined input+output latency without any processing in between, so that's probably what made my ears bleed before. Tweaking the sample rate and buffer size gets me indeed single digit latencies in Ableton. So I'm definitely going to adjust the section about latency, thanks for this! I'm a bit on the fence about what this means for the difficu…

I would disable any services and programs running in the background as well. Years ago I disabled the Windows print spooler and it greatly improved jitter. Not sure if that's still the case these days though, that was probably 10 years ago.

So far CPU usage hasn't been an issue at all (<1% usually on my not-very-impressive laptop), which surprised me as well

Re: Lessons learnt building a real-time audio application in Python

#16
post #9
post #6

Earlier quoted context omitted.

Yeah, your Scarlett should be capable of single-digit ms latency. If you're on Windows, you need to install its ASIO drivers and figure out how to use them from Python. Then, yes, use tiny buffers and run your audio processing very fast - which is where Python's slowness will probably become a real problem. 10ms latency is how long sound takes to travel 3-and-a-bit metres. So if your amp is a few metres from you, you…

With Ableton and the default ASIO configuration on my Scarlett I get 96 ms combined input+output latency without any processing in between, so that's probably what made my ears bleed before. Tweaking the sample rate and buffer size gets me indeed single digit latencies in Ableton. So I'm definitely going to adjust the section about latency, thanks for this! I'm a bit on the fence about what this means for the difficu…

I don't know windows audio, but on mac audio that's wildly high latency for a scarlett interface.

Re: Lessons learnt building a real-time audio application in Python

#17
post #14

Earlier quoted context omitted.

Even without ASIO you should be able to hit 40 ms latency on pretty much any Windows audio hardware, including motherboard built-in. If you get 300 ms you're doing something wrong. Note that Windows has multiple audio APIs, 300 ms is about the latency of the old MME api, you need to use the newer one, WASAPI.

I apparently only have the old Windows MME drivers indeed (and ASIO, on Win10). Need to look into why I can't find WASAPI and if I can assume other Windows users have those by default.

WASAPI has been available since Windows Vista. It isn’t its own set of drivers but rather a unifying layer for the WDM driver and the preceding mishmash of Windows audio APIs (MME, DirectAudio, etc). WASAPI supports low ish latencies with Exclusive Mode and then something like 10ms buffering in Shared Mode through the Windows audio server, I recall.

Put another way: any Windows audio device supports WASAPI unless it only ships with an ASIO driver which is unlikely, even in the pro audio space.

Re: Lessons learnt building a real-time audio application in Python

#19
post #2

"It turns out that the round-trip time from an audio interface, through a computer (DAW) and back to the speakers takes a few hundreds of milliseconds, making direct audio processing impossible using consumer hardware." - uh, what? Real-time audio processing has been a thing for at least a couple of decades. It doesn't work by default on Windows, but you can get free drivers (ASIO4All) which make it work on pretty mu…

+1. In Ableton on Windows you can get your latency down to ~40ms without a dedicated sound card using ASIO. Mac's drivers are even better with sub ~20 ms on my m2 pro IIRC.

> Mac's drivers are even better with sub ~20 ms on my m2 pro IIRC.

Just to be clear that you're measuring apples to apples with OP:

You are measuring less than 40ms roundtrip latency on your Mac. Is this correct?

Re: Lessons learnt building a real-time audio application in Python

#20
post #13
post #10

Earlier quoted context omitted.

try clarett interface. it also comes with pre amps which will make your sound less noisy , scarlet preamps are just absolutely terrible. you can debug your daw to see how it uses drivers and make a python module which exposes similar functions to python. you will likely still want a delay compensation to make things seem free of any latency, but it will be doing _much_ less compensating. maybe theres an opensource da…

Debugging an existing DAW to see how they do it under the hood is an interesting idea. Haven't done that yet. About another interface: I do want to keep the application supporting cheaper interfaces such as the Scarlett, because the target audience (hobby musicians) will be using those. Still would be a nice upgrade for me!

Can take a peek at how Tracktion engine does it too
Post reply on HN