You are not logged in.

#1 2023-04-05 21:54:14

scatherinch
Member
Registered: 2023-02-24
Posts: 160

[SOLVED] Pipewire w/ MPD: Audio Crackling/Popping

Here's an issue that's been annoying me for quite some time but I'm not really sure how to completely get rid of it. Maybe the Arch Community could help me?

I've been using a minimal setup for awhile now and so far, it's been going great, however, I find it extremely obnoxious that I just can't figure out how to eliminate crackling and popping in pipewire. I'm not really sure how to go about really solving this, as I'm not particularly a sound person, but I have been digging around the internet to try and troubleshoot much of it. Below, I am going to link a few things on my journey that I took in my process to troubleshoot these annoying crackles whilst listening to my music through MPD.

I expected the audio to work flawlessly like it did when I still used other distros, but this isn't the case on a DIY setup like this. Anyways, whenever I listen to music through MPD particulary, I'm experiencing these little pops during normal playback while an mp3 or some sort of audio file is playing.

First, I looked through the Arch Wiki on anything I might be able to find and came across this:  ( https://wiki.archlinux.org/title/PipeWi … g_playback ) Alright, I did that by making a directory path which would lead to a file: /etc/wireplumber/main.lua.d/ . Inside the file, I have this code:

table.insert (alsa_monitor.rules, {
  matches = {
    {
      -- Matches all sources.
      { "node.name", "matches", "alsa_input.*" },
    },
    {
      -- Matches all sinks.
      { "node.name", "matches", "alsa_output.*" },
    },
  },
  apply_properties = {
    ["session.suspend-timeout-seconds"] = 0,  -- 0 disables suspend
  },
})

This doesn't look like it did much, unfortunately, so that renders one step down the drain.

Next, I started looking for other possible causes and stumbled upon this topic here: ( https://bbs.archlinux.org/viewtopic.php?id=283324 ) By meddling around with the tmpfiles and altering the values in these two locations by setting both numerals to 2048, (If you're curious, you can visit my post here on what I did to override the default values of 64: https://bbs.archlinux.org/viewtopic.php?id=284875 ) I thought I finally nailed this problem for good. This seems to have reduced much of these crackles dramatically, but I can still hear them at certain intervals while playing music.

At this point, I am unsure what's causing this, so I've went to another possible troubleshooting test and noticed something while invoking

speaker-test

. I can see where my crackles are occuring, but that doesn't really tell me much about what's causing them:

 Everytime you see 'time per period', that's a crackle/pop.
Playback device is default
Stream parameters are 48000Hz, S16_LE, 1 channels
Using 16 octaves of pink noise
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 128 to 2097152
Period size range from 64 to 1048576
Using max buffer size 2097152
Periods = 4
was set period_size = 524288
was set buffer_size = 2097152
 0 - Mono
Time per period = 10.930313
 0 - Mono
Time per period = 10.928003
 0 - Mono
Time per period = 10.928076
 0 - Mono
Time per period = 10.928026
 0 - Mono
Time per period = 10.928044
 0 - Mono
Time per period = 10.928025
 0 - Mono
Time per period = 10.928046
 0 - Mono

I'm not sure if the above information is relevant or not, but it's worth something I guess. Anyways, that's why I've come here, to see if anyone knows anything or what I could do to snuff this out for good.

Last edited by scatherinch (2023-04-14 11:37:16)

Offline

#2 2023-04-05 22:14:07

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,892

Re: [SOLVED] Pipewire w/ MPD: Audio Crackling/Popping

Did you follow our suggestions in the other thread to actually enable higher priority for pipewire by either setting up rtkit or the security limits properly? Also in regards to MPD, which audio driver are you using? If you are going via the ALSA emulation layer you are generally going to fare much better with the pulseaudio or the pipewire audio backend directly but you'd have to configure MPD appropriately. The ALSA emulation layer is always a bit funky since it lacks a lot of context that allows the daemon to properly control the stream.

Offline

#3 2023-04-05 23:56:01

scatherinch
Member
Registered: 2023-02-24
Posts: 160

Re: [SOLVED] Pipewire w/ MPD: Audio Crackling/Popping

I have RTkit and I enabled/started the service. Now what? I need to set that up. You mentioned something here: "I know, but if you didn't want to set the limits globally for any reason, for RTkit to do anything it would have to be started to set niceness to -11" to quote you. So I have to figure out how to configure RTkit then.

I'm using ALSA, yes. I'd like to try and see if I can stamp the problem out with pipewire first before I consider going to pulse, though. You're right though, this behavior mainly occurs in MPD alone.

Last edited by scatherinch (2023-04-06 00:11:08)

Offline

#4 2023-04-06 09:07:27

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,892

Re: [SOLVED] Pipewire w/ MPD: Audio Crackling/Popping

systemctl status rtkit-daemon.service
ps -ef | grep pipewire

Configure MPD's output to use pulse or pipewire as the backend, this has no relation to whether you are using pipewire for pulseaudio as the sound server, you should configure MPD to not use the ALSA plugin but pipewire/pulseaudio. How are you starting MPD? System wide or specific for your user? See https://wiki.archlinux.org/title/Music_ … figuration and specifically: https://wiki.archlinux.org/title/Music_ … figuration to configure MPD to use pulseaudio or pipewire directly (the pulseaudio backend is more mature and should work easily with pipewire-pulse as well) the pipewire backend is newer and did at least have some issues when it was first released.

Last edited by V1del (2023-04-06 09:08:17)

Offline

#5 2023-04-06 11:06:12

scatherinch
Member
Registered: 2023-02-24
Posts: 160

Re: [SOLVED] Pipewire w/ MPD: Audio Crackling/Popping

rtkit-daemon.service - RealtimeKit Scheduling Policy Service
     Loaded: loaded (/usr/lib/systemd/system/rtkit-daemon.service; enabled; preset: disabled)
     Active: active (running) since Thu 2023-04-06 05:49:18 EDT; 1h 2min ago
   Main PID: 4109423 (rtkit-daemon)
      Tasks: 3 (limit: 38404)
     Memory: 544.0K
        CPU: 220ms
     CGroup: /system.slice/rtkit-daemon.service
             └─4109423 /usr/lib/rtkit-daemon

So the system looks good and the daemon is starting!

ps -ef | grep pipewire
user    212624    8456  0 06:52 pts/1    00:00:00 grep --color=auto pipewire
user    566300     808  1 Apr05 ?        00:09:40 /usr/bin/pipewire
user    566304     808  0 Apr05 ?        00:00:02 /usr/bin/pipewire-pulse

I'm not sure what this stuff means here, but I'm going to guess that these are my available backends that you are trying to show me. So, I'll see what happens if I switch my config file to use the last one.


Yes, I start MPD per-user. (.config)

audio_output {
	type		"pipewire"
	name		"pipewire-pulse"    (was set to just 'pipewire' so changed to pipewire-pulse )
	device		"hw:0,0"	# optional
	mixer_type      "hardware"	# optional
	mixer_device	"default"	# optional
	mixer_control	"PCM"		# optional
	mixer_index	"0"		# optional

Last edited by scatherinch (2023-04-06 11:07:02)

Offline

#6 2023-04-06 11:12:29

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,892

Re: [SOLVED] Pipewire w/ MPD: Audio Crackling/Popping

Test whether changing the type to "pulse" works without crackling, remove all the mixer definitions they make no sense in a pulse/pipewire context.

The name is irrelevant that you can set to whatever you want, the type defines which API MPD will use.

I'm looking for the niceness value and am realising that -ef won't show this but -elf will so

ps -elf | grep pipewire

Last edited by V1del (2023-04-06 11:15:48)

Offline

#7 2023-04-07 16:48:27

scatherinch
Member
Registered: 2023-02-24
Posts: 160

Re: [SOLVED] Pipewire w/ MPD: Audio Crackling/Popping

ps -elf | grep pipewire
4 S user    259456     818  1  69 -11 - 36237 ep_pol 08:00 ?        00:06:36 /usr/bin/pipewire
4 S user    259459     818  0  69 -11 - 16005 ep_pol 08:00 ?        00:01:16 /usr/bin/pipewire-pulse
0 S user   2800210 2799885  0  80   0 -  1905 pipe_r 16:59 pts/6    00:00:00 grep --color=auto pipewire

Look, an 11! Just like from the other thread that led me to this point.

So, I guess I misconfigured my config file for MPD, because the crackling is gone. So judging by what you told me, using 'pipewire' as the backend for MPD is faulty for this program.

I edited my file like so:

audio_output {
	type		"pulse"
	name		"pipewire-pulse"
#device		"hw:0,0"	# optional
#mixer_type      "hardware"	# optional
#mixer_device	"default"	# optional
#mixer_control	"PCM"		# optional
#mixer_index	"0"		# optional
}

When I installed rtkit, it fixed alot of issues. What exactly does rtkit do as far as pipewire is concerned?

Offline

#8 2023-04-11 13:48:43

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,892

Re: [SOLVED] Pipewire w/ MPD: Audio Crackling/Popping

RTKit allows a program to ask for lower niceness/higher priority without said program having to be elevated directly itself. Not entirely sure on the exact rules so that not everything can just elevate willy nilly but it ultimately leads to pipewire being able to get itself to -11 so that it has more priority so it can properly do it's mixing job without dropouts. The pipewire backend problems for MPD are in the pipewire backend for MPD itself and it is relatively new (afaik just released in the last version) while the pulse backend has existed for much longer and can be considered much more stable. 

If you consider this [SOLVED] please mark it as such by editing the title in your first post (might want to also elaborate on this primarily being an MPD issue)

Offline

#9 2023-04-14 11:36:42

scatherinch
Member
Registered: 2023-02-24
Posts: 160

Re: [SOLVED] Pipewire w/ MPD: Audio Crackling/Popping

Of course, and thanks for explaining it to me.

Offline

Board footer

Powered by FluxBB