[SOLVED] audio crackling in duplex mode

Optimize your system for ultimate performance.

Moderators: MattKingUSA, khz

nixit
Established Member
Posts: 24
Joined: Fri Jun 30, 2017 2:11 pm

[SOLVED] audio crackling in duplex mode

Postby nixit » Sat Jun 30, 2018 6:55 pm

Hello all, hope everyone is doing well.

I am having an issue with jack2dbus and my two sound cards. My setup is the following:

Code: Select all

$ cat /proc/asound/cards
0 [SB             ]: HDA-Intel - HDA ATI SB
                      HDA ATI SB at 0xfe300000 irq 16
 1 [NVidia         ]: HDA-Intel - HDA NVidia
                      HDA NVidia at 0xfe080000 irq 46
 2 [USB            ]: USB-Audio - Scarlett 2i2 USB
                      Focusrite Scarlett 2i2 USB at usb-0000:00:12.2-2.4.4.4, high speed


the NVidia entry is my GPU, and the audio is not used.
the SB card is connected to my 5.1 speakers for movies and games while the USB (Scarlett 2i2) is the mic in my recording booth.

I only run jack2dbus and qjackctl while I record and edit my voiceovers, and in qjackctl-->settings-->advanced I have the following set:

Audio: Duplex
Output device: (default) and I also tried hw:SB
Input device: USB

This appears to work, however after a few minutes I start receivig XRuns and the audio on playback starts to crack and pop.

After messing around with Sample Rate, Frames/Period and Periods/Buffer I could not get the Xruns to stop or the cracking in the audio. I then changed Audio to Capture Only and selected hw:USB all seemed fine except I didn't have any audio on playback while jack2dbus was running.

I then changed Audio to Playback Only and selected hw:SB, I received the proper result, no recording but playback worked.

With the audio set to Playback Only or Capture Only the Xrun's were drastically reduced to 1 about every hour.

Here is my lsmod:

Code: Select all

$ lsmod |grep snd
snd_seq_dummy          16384  0
snd_seq                81920  1 snd_seq_dummy
snd_usb_audio         225280  0
snd_usbmidi_lib        32768  1 snd_usb_audio
snd_rawmidi            36864  1 snd_usbmidi_lib
snd_seq_device         16384  2 snd_seq,snd_rawmidi
snd_hda_codec_hdmi     57344  1
snd_hda_codec_realtek   110592  1
snd_hda_codec_generic    86016  1 snd_hda_codec_realtek
snd_hda_intel          45056  2
snd_hda_codec         151552  4 snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec_realtek
snd_hda_core           94208  5 snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec,snd_hda_codec_realtek
snd_hwdep              16384  2 snd_usb_audio,snd_hda_codec
snd_pcm               135168  5 snd_hda_codec_hdmi,snd_hda_intel,snd_usb_audio,snd_hda_codec,snd_hda_core
snd_timer              36864  2 snd_seq,snd_pcm
snd                    98304  17 snd_hda_codec_generic,snd_seq,snd_seq_device,snd_hda_codec_hdmi,snd_hwdep,snd_hda_intel,snd_usb_audio,snd_usbmidi_lib,snd_hda_codec,snd_hda_codec_realtek,snd_timer,snd_pcm,snd_rawmidi
soundcore              16384  1 snd
usbcore               294912  9 xhci_hcd,ohci_hcd,ehci_pci,snd_usb_audio,usbhid,snd_usbmidi_lib,ehci_hcd,xhci_pci,ohci_pci


I normally launch qjackctl then start jack2dbus from there, but that produces an error/warning, so I've been using:

Code: Select all

jack_control start


and have jack2dbus use the config settings located in ~/.config/jack/conf.xml

Code: Select all

<?xml version="1.0"?>
<!--
JACK settings, as persisted by D-Bus object.
You probably don't want to edit this because
it will be overwritten next time jackdbus saves.
-->
<!-- Sat Jun 30 14:52:34 2018 -->
<jack>
 <engine>
  <option name="driver">alsa</option>
  <option name="realtime">true</option>
  <option name="verbose">false</option>
 </engine>
 <drivers>
  <driver name="netone">
  </driver>
  <driver name="firewire">
  </driver>
  <driver name="proxy">
  </driver>
  <driver name="dummy">
  </driver>
  <driver name="alsarawmidi">
  </driver>
  <driver name="loopback">
  </driver>
  <driver name="alsa">
   <option name="device">hw:0</option>
   <option name="capture">hw:USB</option>
   <option name="playback">hw:SB</option>
   <option name="rate">48000</option>
   <option name="period">128</option>
   <option name="nperiods">3</option>
   <option name="hwmon">false</option>
   <option name="hwmeter">false</option>
   <option name="duplex">true</option>
   <option name="softmode">false</option>
   <option name="monitor">false</option>
   <option name="dither">n</option>
   <option name="shorts">false</option>
  </driver>
  <driver name="net">
  </driver>
 </drivers>
 <internals>
  <internal name="netadapter">
  </internal>
  <internal name="profiler">
  </internal>
  <internal name="netmanager">
  </internal>
  <internal name="audioadapter">
  </internal>
 </internals>
</jack>


Is it possible to have the audio set to Duplex with 2 different sound devices and not have all the Xrun's or crackling audio playback?

I am on a fresh install of arch linux with only alsa installed, I have not installed PulseAudio, and if that will help resolve that's even better for me. :)

let me know if there is any other info I can supply for troubleshooting.

--nixIT

EDIT:
my solution can be found in my last post located here: https://linuxmusicians.com/viewtopic.php?f=27&t=18694&p=94808#p94808
Last edited by nixit on Fri Jul 13, 2018 4:28 pm, edited 1 time in total.

Jack Winter
Established Member
Posts: 293
Joined: Sun May 28, 2017 3:52 pm

Re: audio crackling in duplex mode

Postby Jack Winter » Sat Jun 30, 2018 10:21 pm

If you can run your I/O on a single card that would be better!

I would guess that the xruns come from drifting hardware clocks of the 2 sound cards. You'd need some external way to sync your 2 cards together for this to work well.

If you use JACK1 then you can use an internal client with the -A parameter to add a 2nd sound card. This will probably work better. JACK2 doesn't have this internal client implemented, so you can use the zita-ajbridge utilities instead. They will perform SRC to keep the 2 cards in sync, at the cost of some quality loss (probably not a lot).
Reaper/KDE/Archlinux. i7-2600k/16GB + i7-4700HQ/16GB, RME Multiface/Babyface, Behringer X32, WA273-EQ, 2 x WA-412, ADL-600, Tegeler TRC, etc 8) For REAPER on Linux information: https://wiki.cockos.com/wiki/index.php/REAPER_for_Linux

User avatar
lilith
Established Member
Posts: 577
Joined: Fri May 27, 2016 11:41 pm
Location: bLACK fOREST
Contact:

Re: audio crackling in duplex mode

Postby lilith » Sat Jun 30, 2018 10:26 pm

Same issue here with two usb devices for input and output. I tested it once and read that it causes problems.
https://soundcloud.com/lilith_93
_____________________________
Debian 9 (XFCE) & KXStudio repos

nixit
Established Member
Posts: 24
Joined: Fri Jun 30, 2017 2:11 pm

Re: audio crackling in duplex mode

Postby nixit » Sat Jun 30, 2018 10:41 pm

Jack Winter wrote:If you can run your I/O on a single card that would be better!

I would guess that the xruns come from drifting hardware clocks of the 2 sound cards. You'd need some external way to sync your 2 cards together for this to work well.

If you use JACK1 then you can use an internal client with the -A parameter to add a 2nd sound card. This will probably work better. JACK2 doesn't have this internal client implemented, so you can use the zita-ajbridge utilities instead. They will perform SRC to keep the 2 cards in sync, at the cost of some quality loss (probably not a lot).


than for the quick reply. unfortunately do to my setup computer & 5.1 in one room and recording booth separate.

I'm a little confused on the -A parameter for JACK1 and the zita-ajbridge for JACK2. Alsa can see both cards, and qjackctl can see both cards, why the need to add a 2nd card?

is Alsa_in and Alsa_out the same same as zita-ajbridge? I tried Alsa_out, and it "sort of" worked. I had audio playback through some apps, while not in others.

I recently ran across this link: http://www.jackaudio.org/faq/multiple_devices.html. would the section under LINUX for merging two cards work?

--nixIT

Pablo
Established Member
Posts: 1265
Joined: Thu Apr 17, 2008 9:57 pm

Re: audio crackling in duplex mode

Postby Pablo » Sun Jul 01, 2018 3:30 pm

alsa_in/alsa_out or the zita_a2jbridge[1], which are functionally equivalent, are jack clients so you won't get sound from applications that are not jack-aware.

For those, you also need either the alsa-loopback [2] or the pulseaudio jack sink.

Using two devices in jack, one for capture and another one for playback, only works smoothly when both belong to the same audio card and there is only one hardware clock. I don't think merging two cards in a virtual device is a good idea, for the same reason.

[1] https://kokkinizita.linuxaudio.org/linu ... guide.html
[2] https://alsa.opensrc.org/Jack_and_Loopb ... ack_bridge

nixit
Established Member
Posts: 24
Joined: Fri Jun 30, 2017 2:11 pm

Re: audio crackling in duplex mode

Postby nixit » Sun Jul 01, 2018 4:29 pm

@Pablo,

Thanx for the info, this makes sense. I guess I will install pulse as well as the pulseaudio jack sink to see if I can get that running. I've had inconsistent behavior with pulse audio and jack, then again I've always configured jack to be duplex with two audio cards.

I'll do some digging on the best way to get pulse set up and working with jack, so I can have input be on hw:USB and output go to hw:SB

have a great day!

--nixIT

User avatar
bluebell
Established Member
Posts: 778
Joined: Sat Sep 15, 2012 11:44 am
Location: Saarland & Frankfurt, Germany

Re: audio crackling in duplex mode

Postby bluebell » Tue Jul 03, 2018 1:17 pm

nixit wrote:@Pablo,

Thanx for the info, this makes sense. I guess I will install pulse as well as the pulseaudio jack sink to see if I can get that running. I've had inconsistent behavior with pulse audio and jack, then again I've always configured jack to be duplex with two audio cards.

I'll do some digging on the best way to get pulse set up and working with jack, so I can have input be on hw:USB and output go to hw:SB


It's not recommended to use 2 audio interfaces with jackd directly.

I have a setup with 2 audio interfaces that works. Unfortunately I can't use 2 interfaces of the same model because the Linux kernel can't distinguish beetween them. Their serial no is not available to Linux/ALSA (Focusrite Scarlett Solo, 2i2, 2i4).

So I have one interface (2i4) connected to jack for playback and capture, with -dhw:xxx, not with -Phw:xxx and -Chw:xxx.

The other one (2i2) is connected with alsa_out. If I needed its input I'd use alsa_in as well.

I use a shell script with "aplay -l | grep 2i2" and "aplay -l | grep 2i4" to find out with xxx I have to use with hw:xxx.

Works great. No sync problems, no xruns, no crackles.

Jack Winter
Established Member
Posts: 293
Joined: Sun May 28, 2017 3:52 pm

Re: audio crackling in duplex mode

Postby Jack Winter » Wed Jul 04, 2018 10:48 am

Trying to combine cards into a single device also won't work well. The problem being that for this to work well the soundcards would have to be externally synced via wordclock or similar.

The zita-ajbridge utilities do the same thing as the the alsa_in/out utilities, just with better sample rate conversion (that is to say with higher quality). FWIW the JACK1 built in client is based on zita-ajbridge.

You'd use the internal JACK1 client with a command line similar to this: "/bin/jackd -P80 -p512 -t5000 -A Intel -dalsa -dhw:DSP,0 -r44100 -p128 -n2 -Xseq" which runs jack on my rme multiface but adds the onboard intel soundcard for additional I/O.
Reaper/KDE/Archlinux. i7-2600k/16GB + i7-4700HQ/16GB, RME Multiface/Babyface, Behringer X32, WA273-EQ, 2 x WA-412, ADL-600, Tegeler TRC, etc 8) For REAPER on Linux information: https://wiki.cockos.com/wiki/index.php/REAPER_for_Linux

nixit
Established Member
Posts: 24
Joined: Fri Jun 30, 2017 2:11 pm

Re: audio crackling in duplex mode

Postby nixit » Thu Jul 05, 2018 11:47 pm

I've been messing with many different configurations within qjackctl:

interface: defauilt
audio: duplex
output: hw:SB
input: hw:USB

produces xruns

interface: hw:USB
audio: capture only
I can record, but no audio in playback

I installed pulseaudio and all relevant files, I can see that qjackctl recognizes pulse audio and makes the appropriate connections.

Since I have two audio devices hw:SB for playback (music, games, etc) and hw:USB for capture (it's routed to my voiceover booth), is there a way/setting within qjackctl to use jack and pulseaudio? Unfortunately I can't do one audio card with my setup.

I use PA to game and either listen to music or watch a movie at the same time.

thanx

--nixIT

Jack Winter
Established Member
Posts: 293
Joined: Sun May 28, 2017 3:52 pm

Re: audio crackling in duplex mode

Postby Jack Winter » Sat Jul 07, 2018 4:29 pm

At the risk of being repetitive. For this to work you'd need soundcards that are synced, in your case you don't have them so using separate input and output on 2 cards isn't going to work well, neither is concatenating them into a single device.

On Archlinux the pulseaudio/jack2 part ought to work well, and you shouldn't have any problem to output audio through pulse to jack once you've started jack. In fact that ought to be totally transparent and at the most require you to change sink/source with pavucontrol.

Now for the part of using 2 soundcards with jack. As you are using jack2 (jack1 has this builtin), you are going to have to use an external client to add another soundcard to your jack, this would be either alsa_in/out or zita-ajbridge (I'd recommend the zita one as it has better sample rate conversion which is going to be needed to keep things in sync with 2 soundcards using drifting clocks).

Now I don't use qjackctl/jack2 with dbus so am not quite sure how one would configure qjackctl to do this, but I think you can add the zita-a2j and/or zita-j2a command(s) to the "execute script after startup" field in qjackctl's options tab.

Use a terminal to experiment to find the right parameters for you card once you have started jack running on a single soundcard, both for input and output. You'd have to decide what is more important for you, to have sample rate conversion on the input or the output. Keep in mind that SRC will lower the quality of the audio.
Reaper/KDE/Archlinux. i7-2600k/16GB + i7-4700HQ/16GB, RME Multiface/Babyface, Behringer X32, WA273-EQ, 2 x WA-412, ADL-600, Tegeler TRC, etc 8) For REAPER on Linux information: https://wiki.cockos.com/wiki/index.php/REAPER_for_Linux

nixit
Established Member
Posts: 24
Joined: Fri Jun 30, 2017 2:11 pm

Re: audio crackling in duplex mode

Postby nixit » Sat Jul 07, 2018 8:43 pm

Thanx...

I understand if the cards aren't the same it won't work well, and depending on how they "won't work" I'm ok with it. Question I have is when using it in duplex mode and receiving the Xruns, what kinds of issues could those xruns cause? Should I be concerned with this if I am only recording from hw:USB?

I set up pulseaudio-jack sink/source following the arch wiki, but I'm not sure they are set up correctly. When jack2dbus is in duplex mode, I specify my capture and playback devices.

when I launch audacity, I select:

JACK Audio Connection Kit (not alsa)
mic: PulseAudio JACK SINK
speaker: PulseAudio JACK Source

This is where it's interesting, when I launch PA Volume Control under input devices I have PulseAudio JACK Source and under output devices I have PulseAudio JACK Sink, the opposite of what Audacity says. When I try to record with these selections, I notice in PA volume control under recording, nothing shows up, same goes for when trying to play back previously recorded audio via Audacity.

Could this be why I can't record and or playback with Audacity with these settings?

I've spent way too much time on something that seems so easy to do, with all the informative wiki's out there. At this point, I'm just trying to get audio to record and playback in audacity with jack running, which I know is possible. :(

I may just uninstall and delete all configs for pulse and jack and start over.

--nixIT

Jack Winter
Established Member
Posts: 293
Joined: Sun May 28, 2017 3:52 pm

Re: audio crackling in duplex mode

Postby Jack Winter » Sun Jul 08, 2018 12:32 am

I think that you ought to leave pulseaudio out of this, use that for playback from browsers etc.

Set up JACK to run on your SB device and get input / output working with audacity without xruns.
Then use zita-ajbridge to add your USB device to the existing jack server.

Regarding if you ought to be concerned by the xruns, have you listened to what you recorded? Are there glitches/dropouts? Are there dropouts on playback? I prefer to have no xruns as then I know that is not a problem. Not always easy :)
Reaper/KDE/Archlinux. i7-2600k/16GB + i7-4700HQ/16GB, RME Multiface/Babyface, Behringer X32, WA273-EQ, 2 x WA-412, ADL-600, Tegeler TRC, etc 8) For REAPER on Linux information: https://wiki.cockos.com/wiki/index.php/REAPER_for_Linux

nixit
Established Member
Posts: 24
Joined: Fri Jun 30, 2017 2:11 pm

Re: audio crackling in duplex mode

Postby nixit » Sun Jul 08, 2018 3:18 pm

@Jack Winter,

Thanx for the info. After completely removing pulse and getting my system back to basic alsa and jack. I reinstalled pulse by following the arch linux wiki, then followed your suggestion:

I set qjackctl up with the following:

Audio: Playback only
interface: hw:SB
server prefix: jack_control start
Execute script after start: zita-a2j -d hw:USB -r 48000 &

This allows my audio to be played as well as bridging in my mic for recording. best part is, ran some tests and no xruns!

question on the zita-ajbridge, when I issue the zita-a2j does that just do a passthru to my mic, or does that bridge my mic into jack and let jack control it?

As a test, I wanted to reverse the scene:
Audio: capture only
interface: hw:USB
server prefix: jack_control start
Execute script after start: zita-j2a -d hw:SB -r 48000 &

I appear to be able to record, but I don't get any audio out, and am curious why.

thanx for your help

--nixIT

Jack Winter
Established Member
Posts: 293
Joined: Sun May 28, 2017 3:52 pm

Re: audio crackling in duplex mode

Postby Jack Winter » Sun Jul 08, 2018 4:16 pm

nixit wrote:Audio: Playback only
interface: hw:SB
server prefix: jack_control start
Execute script after start: zita-a2j -d hw:USB -r 48000 &

This allows my audio to be played as well as bridging in my mic for recording. best part is, ran some tests and no xruns!


Good, you might even want to run full duplext on the SB, like that you would have access to the inputs as well.

question on the zita-ajbridge, when I issue the zita-a2j does that just do a passthru to my mic, or does that bridge my mic into jack and let jack control it?


Not sure how to explain it. The JACK server is driven by the clock on the soundcard, that is to say when data is available it gets woken up to do it's stuff, which ends when it delivers data back to the soundcard to be outputted next time around.

Then you have JACK clients, those are programs that connect to the server. When you run Audacious it connects to the server and asks to become a client. Each time JACK is running the graph it calls the connected clients to do their work.

The zita-ajbridge utilities are also JACK clients. When they get called by the JACK server they either read or write data to an additional soundcard, they also lets say stretch the audio to keep the audio glitchless even if the clocks of the cards drift away from each other (which is more or less certain to happen with unsynced cards). This probably results in slightly lower quality of the audio that has passed through the utilities.

Your second try to run JACK on USB and connect SB with the zita utility would have the best recording quality and probably result in slightly less pristine audio playback. Up to you to decide what is more important.

As a test, I wanted to reverse the scene:
Audio: capture only
interface: hw:USB
server prefix: jack_control start
Execute script after start: zita-j2a -d hw:SB -r 48000 &

I appear to be able to record, but I don't get any audio out, and am curious why.


Not sure. Did you connect the Audacious output ports to the SB's (zita) playback ports? You can do that in the connections window of qjackctl. Alternatively there is the jack_connect utility that you could run from a script.

Apart from this, if you install the pulseaudio-jack package then pulseaudio also ought to appear as a client for JACK, which allows you to easily output browser audio to your soundcards. On Archlinux this appears to work fine out of the box without any further configuration. Just use pavucontrol to switch pulse to output to JACK instead of the local soundcards. Mind you I don't think the zita utilities can ask the pulse server to release a soundcard, so maybe best to disable all cards except the JACK bridge in pavucontrol.

Disclaimer: Some of the above is not 100% factual, but in the interest of brevity and understanding..:)
Reaper/KDE/Archlinux. i7-2600k/16GB + i7-4700HQ/16GB, RME Multiface/Babyface, Behringer X32, WA273-EQ, 2 x WA-412, ADL-600, Tegeler TRC, etc 8) For REAPER on Linux information: https://wiki.cockos.com/wiki/index.php/REAPER_for_Linux

Pablo
Established Member
Posts: 1265
Joined: Thu Apr 17, 2008 9:57 pm

Re: audio crackling in duplex mode

Postby Pablo » Mon Jul 09, 2018 2:30 pm

I think that it makes more sense for your use case if you use jack with the USB card (capture-only mode seems more adequate if the audio outputs are not in use) and the pulseaudio jack sink for the SB and I will try to explain the reason why.

I assume that the SB live has an internal mixer which alsa can access to, via alsamixer. It could even have more than one internal device in which case things would be more involved. In contrast, the USB card is simpler; it only has a duplex device with no internal mixing so it is easy to get it up and running via jack.

The fact is that jack doesn't allow to touch the internal mixer whereas pulseadio does. So it is easy via pavucontrol or general sound configuration to make it work, rather than looking into internal devices and alsamixer, which is what jack understands.


Return to “System Tuning and Configuration”

Who is online

Users browsing this forum: No registered users and 2 guests