[SOLVED] How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?
Moderators: MattKingUSA, khz
-
- Established Member
- Posts: 1392
- Joined: Thu Oct 11, 2018 4:13 pm
- Has thanked: 168 times
- Been thanked: 247 times
Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?
You could try making the JACK buffer bigger, and the alsa_in buffer has to be at least the same size.
The Solution??
The following configuration seems to eliminate pops and crackles from alsa_in. zita-a2j seems more susceptible to pops and crackles than alsa_in. I'm still monitoring pops and crackles from alsa_in.
Note that jackd, jack_netsource, alsa_in, and alsa_out are run as system services. So, they are started automatically during boot.
It seems I can get back to my life. I had spent too much time on tuning the communication between ALSA and jack.
Raspberry Pi 3 B+
/etc/cgroup/cgconfig.conf
/etc/cgroup/cgrules.conf
/home/user/.asoundrc
System services
/etc/security/limits.d/40-realtime-base.conf
My Gentoo Desktop Computer
System services
/etc/security/limits.d/user.conf
/home/user/bin/mpv
or
/home/user/.config/mpv/mpv.conf
Kernel Config
/etc/cgroup/cgconfig.conf
/etc/cgroup/cgrules.conf
/etc/security/limits.d/40-realtime-base.conf
Note that jackd, jack_netsource, alsa_in, and alsa_out are run as system services. So, they are started automatically during boot.
It seems I can get back to my life. I had spent too much time on tuning the communication between ALSA and jack.
Raspberry Pi 3 B+
- Operating System // Gentoo Linux
- IP Address // 192.168.30.1
This is required for cgroup realtime cpu scheduling
Code: Select all
CONFIG_RT_GROUP_SCHED=y
This is for libcgroup
Code: Select all
CONFIG_PROC_EVENTS=y
This allocates up to 95% of CPU resource to real-time processes and threads executed by any user in audio group. Your normal user should belong to audio group for this to be effective.
Code: Select all
namespace {
cpu = /;
}
group rtaudio {
perm {
task {
uid = root;
gid = audio;
}
admin {
uid = root;
gid = root;
}
}
cpu {
cpu.rt_runtime_us = 950000;
}
}
User should belong to audio group in order for cgrules.conf to take effect.
If you add anything else to rtaudio cgroup, underruns can occur.
Code: Select all
@audio:jackd cpu rtaudio/
@audio:zita-a2j cpu rtaudio/
@audio:zita-j2a cpu rtaudio/
@audio:alsa_in cpu rtaudio/
@audio:alsa_out cpu rtaudio/
@audio:jack_netsource cpu rtaudio/
Code: Select all
pcm.speakers {
type hw
card sndrpihifiberry
device 0
subdevice 0
format S32_LE
rate 48000
channels 2
}
ctl.speakers {
type hw
card sndrpihifiberry
}
Code: Select all
sudo -u user jackd -P 90 -d alsa -d speakers -p 512 -n 2 -P
sudo -u user jack_netsource -H 192.168.30.2 -o 1 -i 2 -O 0 -I 0 -n 2 -N gentoo
This file is a part of realtime-base package which jack 1.9.12 depends on.
Your normal user should belong to realtime group in order to be able to execute important audio processes with real-time priorities.
Code: Select all
# Start of 40-realtime-base.conf from realtime-base-0.1
@realtime - rtprio 99
@realtime - memlock unlimited
# End of 40-realtime-base.conf from realtime-base-0.1
- IP Address // 192.168.30.2
period_size causes pops and crackles because it doesn't produce periods on a regular interval.
period_time removes the vast majority of pops and crackles by producing periods on a regular interval.
period_time = 4000 microseconds per period = 4 milliseconds per period = 4 ms per period.
3 periods per buffer.
12ms per buffer.
Experiment with period_time and period if you want
Code: Select all
pcm.loophw00 {
type hw
card Loopback
device 0
subdevice 0
format S32_LE
rate 48000
channels 2
}
pcm.lmix {
type dmix
ipc_key 1
slave {
pcm loophw00
format S32_LE
rate 48000
channels 2
period_time 4000
periods 3
}
bindings {
0 0
1 1
}
}
pcm.cloop {
type hw
card Loopback
device 1
subdevice 0
format S32_LE
rate 48000
channels 2
}
pcm.loophw01 {
type hw
card Loopback
device 0
subdevice 1
format S32_LE
rate 48000
channels 1
}
pcm.ploop {
type hw
card Loopback
device 1
subdevice 1
format S32_LE
rate 48000
channels 1
}
pcm.headphones {
type hw
card SB
device 0
subdevice 0
rate 48000
channels 2
format S32_LE
}
ctl.headphones {
type hw
card SB
}
pcm.hmix {
type dmix
ipc_key 2
slave {
pcm headphones
period_time 4000
periods 3
}
bindings {
0 0
1 1
}
}
pcm.!default {
type plug
slave.pcm {
type asym
playback.pcm "lmix"
capture.pcm "loophw01"
}
}
Since alsa_in and alsa_out have lower real-time priority than jackd, it is a good idea to allocate bigger periods to them than to jackd.
Although zita-a2j and zita-j2a have higher real-time priority than jackd, it is still a good idea to allocate bigger periods to them.
When CPU usage hits 100% due to various tasks, bigger periods are much less likely to produce pops, crackles, and xruns.
"-q 2" is the default for alsa_in and alsa_out. alsa_in on cloop is sensitive to the value of "-q". Experiment with "-q" for alsa_in.
Code: Select all
sudo -u user jackd -P 90 -d netone -p 512 -n 2
sudo -u user alsa_out -j ploop -d ploop -c 1 -p 1024 -n 2
sudo -u user alsa_in -j cloop -d cloop -c 2 -p 1024 -n 2 -q 1
sudo -u user alsa_out -j headphones -d headphones -c 2 -p 1024 -n 2
/usr/sbin/cgrulesengd # required for applying /etc/cgroup/cgrules.conf
This is necessary for allowing a normal user to decrease nice values of processes
Code: Select all
user - nice -20
Since $PATH includes /home/user/bin, /home/user/bin/mpv is going to be executed instead of /usr/bin/mpv.
Note that if real-time priority is given to mpv and mpv belongs to rtaudio cgroup, mpv competes with alsa_in, alsa_out, zita-a2j, and zita-j2a and causes them to lag behind jackd and produce underruns.
If it introduces more pops and crackles, execute "chmod -x /home/user/bin/mpv". Experiment more with process priorities.
Code: Select all
#!/bin/fish
exec nice -n -10 /usr/bin/mpv $argv
Code: Select all
#!/bin/fish
exec chrt 10 /usr/bin/mpv $argv
Adding 16MB of cache to mpv seems to help reduce pops and clicks
Code: Select all
cache=16384
This is required for cgroup realtime cpu scheduling
Code: Select all
CONFIG_RT_GROUP_SCHED=y
This is for libcgroup
Code: Select all
CONFIG_PROC_EVENTS=y
This allocates up to 95% of CPU resource to real-time processes and threads executed by any user in audio group. Your normal user should belong to audio group for this to be effective.
Code: Select all
namespace {
cpu = /;
}
group rtaudio {
perm {
task {
uid = root;
gid = audio;
}
admin {
uid = root;
gid = root;
}
}
cpu {
cpu.rt_runtime_us = 950000;
}
}
User should belong to audio group in order for cgrules.conf to take effect.
If you add anything else to rtaudio cgroup, underruns can occur.
Code: Select all
@audio:jackd cpu rtaudio/
@audio:zita-a2j cpu rtaudio/
@audio:zita-j2a cpu rtaudio/
@audio:alsa_in cpu rtaudio/
@audio:alsa_out cpu rtaudio/
This file is a part of realtime-base package which jack 1.9.12 depends on.
Your normal user should belong to realtime group in order to be able to execute important audio processes with real-time priorities.
Code: Select all
# Start of 40-realtime-base.conf from realtime-base-0.1
@realtime - rtprio 99
@realtime - memlock unlimited
# End of 40-realtime-base.conf from realtime-base-0.1
Last edited by crocket on Tue May 14, 2019 2:08 am, edited 18 times in total.
-
- Established Member
- Posts: 1392
- Joined: Thu Oct 11, 2018 4:13 pm
- Has thanked: 168 times
- Been thanked: 247 times
Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?
Wow. Thanks for sharing the process. I'm not at my desktop right now so I can't do a full reply.
Now that you've sorted that you can fix Firefox.
jackd has options to restrict self-connect requests. I think it's -e for ignore all.
Now that you've sorted that you can fix Firefox.
jackd has options to restrict self-connect requests. I think it's -e for ignore all.
Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?
I don't see an option to restrict self-connect or self-disconnect requests.merlyn wrote:Wow. Thanks for sharing the process. I'm not at my desktop right now so I can't do a full reply.
Now that you've sorted that you can fix Firefox.
jackd has options to restrict self-connect requests. I think it's -e for ignore all.
-
- Established Member
- Posts: 1392
- Joined: Thu Oct 11, 2018 4:13 pm
- Has thanked: 168 times
- Been thanked: 247 times
Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?
IIRC it's in
That should list all the options.
Code: Select all
jackd -h
Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?
merlyn wrote:IIRC it's inThat should list all the options.Code: Select all
jackd -h
Code: Select all
~> jackd -h
jackdmp 1.9.12
.....
.....
Usage: jackdmp [ --no-realtime OR -r ]
[ --realtime OR -R [ --realtime-priority OR -P priority ] ]
......
......
[ --autoconnect OR -a <modechar>]
where <modechar> is one of:
' ' - Don't restrict self connect requests (default)
'E' - Fail self connect requests to external ports only
'e' - Ignore self connect requests to external ports only
'A' - Fail all self connect requests
'a' - Ignore all self connect requests
-
- Established Member
- Posts: 1392
- Joined: Thu Oct 11, 2018 4:13 pm
- Has thanked: 168 times
- Been thanked: 247 times
Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?
Neither it does. Is that a problem?crocket wrote:It doesn't say anything about ignoring self-disconnect requests.
Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?
Yes, firefox disconnects connections to itself and makes connections to system ports.merlyn wrote:Neither it does. Is that a problem?crocket wrote:It doesn't say anything about ignoring self-disconnect requests.
I saw it happen on qjackctl.
Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?
It seems that I eliminated pops and crackles from alsa_in on ALSA loopback. But, I won't be totally sure until I have tested it for long enough.merlyn wrote:Neither it does. Is that a problem?crocket wrote:It doesn't say anything about ignoring self-disconnect requests.
Refer to the configuration I wrote above. I updated it.
Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?
I tested zita-a2j and alsa_in for days. It seems that there are occasional pops from zita-a2j and alsa_in.
Is it really impossible to eliminate pops from zita-a2j and alsa_in when they get sound from ALSA loopback?
Is it really impossible to eliminate pops from zita-a2j and alsa_in when they get sound from ALSA loopback?
-
- Established Member
- Posts: 381
- Joined: Sun May 28, 2017 3:52 pm
Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?
A couple of years ago I spent quite a bit of time on this, and never managed it to be xrun free. Nowadays I use the pulse to jack bridge instead YMMV and all that..
Something to try might be to test the internal clients of JACK1/JACK2 to bridge to other soundcards. In the case of JACK1 check out the A/I parameters, and for JACK2 the builtin audioadapter client. No idea if any of those work better...
Something to try might be to test the internal clients of JACK1/JACK2 to bridge to other soundcards. In the case of JACK1 check out the A/I parameters, and for JACK2 the builtin audioadapter client. No idea if any of those work better...
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 For REAPER on Linux information: https://wiki.cockos.com/wiki/index.php/REAPER_for_Linux
-
- Established Member
- Posts: 1392
- Joined: Thu Oct 11, 2018 4:13 pm
- Has thanked: 168 times
- Been thanked: 247 times
Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?
@crocket One thing I noticed is that on your desktop you're using the 'audio' group but /etc/security/limits.d/40-realtime-base.conf refers to the 'realtime' group.
Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?
My user belongs to realtime group and audio group.merlyn wrote:@crocket One thing I noticed is that on your desktop you're using the 'audio' group but /etc/security/limits.d/40-realtime-base.conf refers to the 'realtime' group.
-
- Established Member
- Posts: 381
- Joined: Sun May 28, 2017 3:52 pm
Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?
If you are on archlinux I don't think you need the audio group at all. In fact I think it conflicts with per-seat access to the soundcard, though I doubt that it has any practical consequences.crocket wrote:My user belongs to realtime group and audio group.
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 For REAPER on Linux information: https://wiki.cockos.com/wiki/index.php/REAPER_for_Linux
-
- Established Member
- Posts: 1392
- Joined: Thu Oct 11, 2018 4:13 pm
- Has thanked: 168 times
- Been thanked: 247 times
Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?
Just to get this straight:
You start JACK on the RPi. The RPi is the master and takes input over the network from your desktop using netone.
To use headphones on your desktop you need alsa_in. So clicks and pops through the speakers are nothing to do with alsa_in.
Are the clicks and pops you refer to only in the headphones?
You start JACK on the RPi. The RPi is the master and takes input over the network from your desktop using netone.
To use headphones on your desktop you need alsa_in. So clicks and pops through the speakers are nothing to do with alsa_in.
Are the clicks and pops you refer to only in the headphones?