Closed gopalakr closed 4 years ago
The latency is a measure of the total hardware latency from issuing the playback buffer to actually measuring anything on the soundcard output (loudspeakers add some more physical latency that the computer can't know about).
Audio data is posted to the sound card in blocks. By default, these blocks are long. In your case, apparently, 1.6 s. So pulseaudio collects audio data for 1.6 seconds, and only then sends it to the sound card. This saves computation time, as interacting with the hardware is somewhat expensive.
For that very reason, very short block sizes can become problematic: If your computer can't keep up with all the audio data being posted, it will intersperse silence in between the blocks it manages to push through, which sounds choppy and long. This depends on many things: Your current system load, your current Python load, your processor speed, your sound card...
You'll have to experiment with your hardware what block sizes work for you. In general, block sizes of 512 or 1024 samples are usually a good compromise (unless you're doing live music).
Also, make absolutely sure that you're doing as little work as possible on your audio thread. Audio is inherently real-time, and even a single missed block is immediately audible. SoundCard is trying hard to make this as painless as possible, but there's only so much we can do in Python.
You are sending stuff to hardware twice. Once by playing sound and a second by telling the machine to show in your screen the amount of time it takes to run. This is extremely expensive, there is a lot of syscalls in between, and these are even more expensive.
This article is very enlightening on this topic, it is a must-read
Hope it helps you
I am using the player context manager (loopback_player) with a Blocksize = None I am printing the latency of the player which shows it as 1.6 seconds. When the same block of code is run with Blocksize = 80 latency is much lower (~2 ms)but the sound is chopped up and long.
I am running this in linux and I need minimal latency streaming of the audio output.
Any ideas whats happening here ?