Audio delay outputting to Pulseaudio - Jack

The issues found when using the Input/Output Manager panel
Post Reply
User avatar
sbenejam
Posts: 607
Joined: Sun Apr 12, 2015 6:28 pm
Real Name: Santiago Benejam Torres
Contact:

I have a usb audio interface with 4 outputs and I'm trying to route some audio effects or music to 1-2 out o to 3-4 outs to make it sound from FOH or from stage. I detected that if I use Jack_out audio starts with a little delay (around 0.5s or little). Using default audio output the delay disappear. After starting Jack I create two Pulseaudio sinks with:

pacmd load-module module-jack-source channels=2
pacmd load-module module-jack-sink channels=2

This exposes two jack outputs Jack_out and Jack_out2 in QLC+ and I can output for example a telephone ring effect to the output that sound in the stage, but it starts with a delay. For playing background music is not a problem, but for triggering an effect in time when an actor says a phrase or specific word is complicated. I made some adjustments in pulseaudio and jack config and nothing works to avoid this behavior. I think that QLC+ starts playing delayed for some reason.
User avatar
sbenejam
Posts: 607
Joined: Sun Apr 12, 2015 6:28 pm
Real Name: Santiago Benejam Torres
Contact:

I made some more tests. I played with mplayer directly to jack_out o jack_out.2 and it starts playing immediately as expected. In QLC+ setting in function manager Output Audio Device of an audio file to jack_out or jack_out.2 when I play it with a button for example it starts delayed. Another issue, in the properties of an audio file the Output Audio Device is not showed correctly if I open the project file I could see that this audio function has jack_out assigned but in QLC+ shows a Default Device or a random audio device listed in Inputs/Outputs.

<Function ID="1" Type="Audio" Name="Vent.mp3">
<Speed FadeIn="0" FadeOut="0" Duration="0"/>
<RunOrder>SingleShot</RunOrder>
<Source Device="jack_out">Vent.mp3</Source>
</Function>
User avatar
sbenejam
Posts: 607
Joined: Sun Apr 12, 2015 6:28 pm
Real Name: Santiago Benejam Torres
Contact:

I have done a lot of tests on different computers. Changing settings in jack and pulseaudio config and I have not been able to eliminate the delay at the beginning of the playback using jack_out and not the default device. The delay seems to be more serious if I use a USB sound card instead of the built-in one.
OS Ubuntu 18.04, QLC+ 4.12.2.
User avatar
mcallegari
Posts: 4710
Joined: Sun Apr 12, 2015 9:09 am
Location: Italy
Real Name: Massimo Callegari
Contact:

Hi Santiago, it probably boils down to the QtMultimedia implementation
One thing I'd suggest is to use WAV files instead of MP3.
WAV is so easy to decode that it doesn't even require any buffering, so the delay might be minimum

Otherwise, we need to have a look at how QMediaPlayer is implemented and why it buffers so much, introducing delay
User avatar
sbenejam
Posts: 607
Joined: Sun Apr 12, 2015 6:28 pm
Real Name: Santiago Benejam Torres
Contact:

I will try it this weekend.
User avatar
sbenejam
Posts: 607
Joined: Sun Apr 12, 2015 6:28 pm
Real Name: Santiago Benejam Torres
Contact:

I made a video (I forgot to record audio, sorry) where you can see the QLC+ behavior when playing an audio file to the default device and to jack_out, jack_out2 devices, etc.
Playing to default device audio files don't have initial delay, playing a video with audio there is no delay. Configuring jack_out o jack_out2 in the audio properties the delay is almost a second. Also when the button is pressed the slider does not work until the playback starts. This not happens when playing audio on the default device.
In the properties of the audio file even if jack_out is selected, for example when you leave and return to the tab of audio properties it shows a device that is not the one selected above.
My setup is:
Ubuntu 18.04, QLC+ 4.12.2, UMC404HD USB Sound Device, NanoKontrol2, Cadence for jack control, non-mixer.

[youtube]https://youtu.be/wUpATAJYuu8[/youtube]
User avatar
sbenejam
Posts: 607
Joined: Sun Apr 12, 2015 6:28 pm
Real Name: Santiago Benejam Torres
Contact:

mcallegari wrote: Thu Mar 05, 2020 7:57 am Hi Santiago, it probably boils down to the QtMultimedia implementation
One thing I'd suggest is to use WAV files instead of MP3.
WAV is so easy to decode that it doesn't even require any buffering, so the delay might be minimum

Otherwise, we need to have a look at how QMediaPlayer is implemented and why it buffers so much, introducing delay
Hi Massimo, yesterday I was trying to identify what happens when you want to play an audio function to a device other than the default device. I did this with Qt Creator in debug mode.

It seems that the AudioDeviceInfo () function is runned again to check if the output device exists before playing it If not the default device. I think this is what causes the delay before the sound is heard through the audio output. My system shows about 50 output devices in the ComboBox list.

AudioDeviceInfo () runs too in the Audio Editor if the output device is changed to the audio function or when another audio function is selected. But once the output device has been changed, although it is successfully saved in the project file, the ComboBox displays the name of the previous output device in the list that generates AudioDeviceInfo () if you select another function and return to the previous one.
Today I will do more tests now that I am confined at home because of the Covid-19.
Regards Santi
User avatar
sbenejam
Posts: 607
Joined: Sun Apr 12, 2015 6:28 pm
Real Name: Santiago Benejam Torres
Contact:

To avoid the delay I tried a solution. I blacklisted the internal sound card modules. And now the delay is less. Maybe less than 0.5 seconds not closer to 1 sec or more as before.
QAudioDeviceInfo searches in the system all the output devices, the internal sound card creates about 40 output devices (HDMI, dmix, dsnoop, etc.). With UMC404HD connected the OS creates 10-12 output devices.
I don't know if it possible to get the audio devices information in other manner to avoid this delay. Maybe by saving the information in memory or to an external file and then using that saved information to get the device features and information when playing audio during the show.
User avatar
mcallegari
Posts: 4710
Joined: Sun Apr 12, 2015 9:09 am
Location: Italy
Real Name: Massimo Callegari
Contact:

Hi Santiago, thanks for the analysis.
I'm gonna take a look at this once I find some time.
I think looking for the device existance at playback is useful for USB devices (they can be plugged after QLC+ is started)
Perhaps this can be "optimized" by caching devices only on activating Operate mode. Or something like that.
User avatar
sbenejam
Posts: 607
Joined: Sun Apr 12, 2015 6:28 pm
Real Name: Santiago Benejam Torres
Contact:

mcallegari wrote: Thu Apr 02, 2020 9:14 am Hi Santiago, thanks for the analysis.
I'm gonna take a look at this once I find some time.
I think looking for the device existance at playback is useful for USB devices (they can be plugged after QLC+ is started)
Perhaps this can be "optimized" by caching devices only on activating Operate mode. Or something like that.
Hi Massimo, good news to hear this, many thanks for your patience. If you need more information or tests, please do not hesitate to tell me.
FYI a few weeks ago I started to translate the QLC+ documentation into Catalan, when finished and reviewed, I'll maybe translated into Spanish from the Catalan translation.
The last month I translated too Linux Show Player to catalan and looking at the code I see that LiSP is using Gstreamer for playing audio and it support Jack too.
What about to support Jack Audio natively in QLC+?. ;-)

Kind regards

Santi
User avatar
mcallegari
Posts: 4710
Joined: Sun Apr 12, 2015 9:09 am
Location: Italy
Real Name: Massimo Callegari
Contact:

sbenejam wrote: Thu Apr 02, 2020 10:28 am Hi Massimo, good news to hear this, many thanks for your patience. If you need more information or tests, please do not hesitate to tell me.
Hi Santiago, do you know how to apply a patch with git?
See attached. Please let me know if you manage to apply it.
Just type "git apply audiocache.patch" from the source base folder.
In my environment it works but I have a simple audio card configuration.
Unfortunately I haven't moved all my stuff yet, so I don't have all my USB soundcards to do more tests. Plus, the lockdown....sooo....
sbenejam wrote: Thu Apr 02, 2020 10:28 am FYI a few weeks ago I started to translate the QLC+ documentation into Catalan, when finished and reviewed, I'll maybe translated into Spanish from the Catalan translation.
Wow, that's a huge work! Thanks!
sbenejam wrote: Thu Apr 02, 2020 10:28 am What about to support Jack Audio natively in QLC+?. ;-)
I think we discussed this before.
Problem is maintaining it. And it would be only for Linux, which represents the minority of QLC+ users.
In the beginning QLC+ audio support was native for each platform. It was a nightmare to maintain it and it had severe limitations (e.g. no multiple audio)
I chose QtMultimedia, even if it sucks, because it's cross platform and I don't have to maintain it.
I hoped it was going to improve over time...but unfortunately it didn't.

However, in my TODO list there's "support external clocks" which include MTC and JACK. It's a quite difficult task but it's in the list.
Attachments
audiocache.patch
(4.09 KiB) Downloaded 172 times
User avatar
sbenejam
Posts: 607
Joined: Sun Apr 12, 2015 6:28 pm
Real Name: Santiago Benejam Torres
Contact:

Hi Massimo, I'll try it later and let you know the results.
User avatar
sbenejam
Posts: 607
Joined: Sun Apr 12, 2015 6:28 pm
Real Name: Santiago Benejam Torres
Contact:

The translation It's a huge job, but I found a great tool for translations OmegaT. I started a few months ago with Google Translator Tools and then with SmartCat, Google discontinued this tools and SmartCat has deadline time to complete the translations and is not perfect. OmegaT works great with html files.

About the patch, this works as expected. I tried with my two USB audio devices and the delay disappeared, aplay -L returns 56 devices and the audio play starts in time. I reconfigured the project to play to jack_out all music and effects that must be played from FOH, all audios that must be played through scene speakers to jack_out.2 and an audio (a wind effect) that must be played all the time to jack_out.3.
All played fine and in time without delay.

My setup is:
-Ubuntu 18.04
-QLC+
-Qt5.14.1
-Cadence to configure and start Jack Audio.
-Non-Session-Manager to start Non-Mixer and Non-MIDI-Mapper to control jack_out's audio levels.
-2 extra jack_out created executing two times

Code: Select all

pacmd load-module module-jack-sink channels=2
-aj-snapshoot, to save and restore Jack connections from command line when all is started and connected correctly.
-UMC404HD USB Audio device, with 4 inputs and 4 outputs:
  • jack_out -> non-mixer-1 -> FOH (UMC404HD 1/2 out)
  • Jack_out.2 -> non-mixer-2 -> Escene (UMC404HD 3/4 out)
  • jack_out.3 -> non-mixer-3 -> FOH (UMC404HD 1/2 out)
-NanoKontrol2

I think this modification will work and give us many configuration options for those who use Jack. This weekend we had to represent the play Aïllats in our city in the newly restored theater, but the COVID-19 has delayed it. I hope that in the coming months we can perform it and I'll use this new patch.

Good job Massimo.
Post Reply