[SOLVED] How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?

Optimize your system for ultimate performance.

Moderators: khz, MattKingUSA

merlyn
Established Member
Posts: 480
Joined: Thu Oct 11, 2018 4:13 pm

Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?

Postby merlyn » Sun Apr 28, 2019 4:15 pm

You could try making the JACK buffer bigger, and the alsa_in buffer has to be at least the same size.

crocket
Established Member
Posts: 60
Joined: Fri Mar 29, 2019 11:56 am

The Solution??

Postby crocket » Mon Apr 29, 2019 3:09 pm

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+

  • Operating System // Gentoo Linux
  • IP Address // 192.168.30.1

Kernel Config

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


/etc/cgroup/cgconfig.conf

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;
  }
}


/etc/cgroup/cgrules.conf

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/


/home/user/.asoundrc

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
}


System services

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


/etc/security/limits.d/40-realtime-base.conf

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


My Gentoo Desktop Computer

  • IP Address // 192.168.30.2

/home/user/.asoundrc

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"
 }
}


System services

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


/etc/security/limits.d/user.conf

This is necessary for allowing a normal user to decrease nice values of processes


Code: Select all

user - nice -20


/home/user/bin/mpv

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


or

Code: Select all

#!/bin/fish

exec chrt 10 /usr/bin/mpv $argv


/home/user/.config/mpv/mpv.conf

Adding 16MB of cache to mpv seems to help reduce pops and clicks


Code: Select all

cache=16384


Kernel Config

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


/etc/cgroup/cgconfig.conf

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;
  }
}


/etc/cgroup/cgrules.conf

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/


/etc/security/limits.d/40-realtime-base.conf

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.

merlyn
Established Member
Posts: 480
Joined: Thu Oct 11, 2018 4:13 pm

Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?

Postby merlyn » Mon Apr 29, 2019 4:48 pm

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.

crocket
Established Member
Posts: 60
Joined: Fri Mar 29, 2019 11:56 am

Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?

Postby crocket » Tue Apr 30, 2019 1:06 am

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.


I don't see an option to restrict self-connect or self-disconnect requests.

merlyn
Established Member
Posts: 480
Joined: Thu Oct 11, 2018 4:13 pm

Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?

Postby merlyn » Tue Apr 30, 2019 7:47 am

IIRC it's in

Code: Select all

jackd -h

That should list all the options.

crocket
Established Member
Posts: 60
Joined: Fri Mar 29, 2019 11:56 am

Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?

Postby crocket » Tue Apr 30, 2019 7:56 am

merlyn wrote:IIRC it's in

Code: Select all

jackd -h

That should list all the options.


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


It doesn't say anything about ignoring self-disconnect requests.

merlyn
Established Member
Posts: 480
Joined: Thu Oct 11, 2018 4:13 pm

Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?

Postby merlyn » Wed May 01, 2019 9:54 am

crocket wrote:It doesn't say anything about ignoring self-disconnect requests.
Neither it does. Is that a problem?

crocket
Established Member
Posts: 60
Joined: Fri Mar 29, 2019 11:56 am

Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?

Postby crocket » Wed May 01, 2019 2:39 pm

merlyn wrote:
crocket wrote:It doesn't say anything about ignoring self-disconnect requests.
Neither it does. Is that a problem?


Yes, firefox disconnects connections to itself and makes connections to system ports.
I saw it happen on qjackctl.

crocket
Established Member
Posts: 60
Joined: Fri Mar 29, 2019 11:56 am

Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?

Postby crocket » Wed May 01, 2019 3:09 pm

merlyn wrote:
crocket wrote:It doesn't say anything about ignoring self-disconnect requests.
Neither it does. Is that a problem?


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.

Refer to the configuration I wrote above. I updated it.

crocket
Established Member
Posts: 60
Joined: Fri Mar 29, 2019 11:56 am

Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?

Postby crocket » Sun May 12, 2019 1:49 pm

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?

Jack Winter
Established Member
Posts: 376
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?

Postby Jack Winter » Sun May 12, 2019 3:58 pm

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...
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

merlyn
Established Member
Posts: 480
Joined: Thu Oct 11, 2018 4:13 pm

Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?

Postby merlyn » Mon May 13, 2019 10:28 am

@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.

crocket
Established Member
Posts: 60
Joined: Fri Mar 29, 2019 11:56 am

Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?

Postby crocket » Tue May 14, 2019 2:06 am

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.


My user belongs to realtime group and audio group.

Jack Winter
Established Member
Posts: 376
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?

Postby Jack Winter » Tue May 14, 2019 7:49 am

crocket wrote:My user belongs to realtime group and audio group.


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.
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

merlyn
Established Member
Posts: 480
Joined: Thu Oct 11, 2018 4:13 pm

Re: How can I eliminate pop sounds from alsa_in and zita-a2j working on ALSA loopback?

Postby merlyn » Tue May 14, 2019 11:57 am

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?


Return to “System Tuning and Configuration”

Who is online

Users browsing this forum: No registered users and 2 guests