Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audible stutter, crackle or pops occur when an application changes volume or state #350

Closed
Vectrobe opened this issue Oct 11, 2018 · 55 comments

Comments

@Vectrobe
Copy link

Whenever an application changes audio volume in some way, usually via the user, or if an application changes state or its media is skipped ahead or behind, also usually via the user; an audible crack or pop, or occasionally a stutter/glitch, is heard.

The displayed buffer latency for that application also changes erratically each time the above event occurs.

This does not occur with regular pulseaudio, or if 'pulseaudio -k' is called to reset PA, in turn disabling pulseaudio-effects.

@wwmm
Copy link
Owner

wwmm commented Oct 11, 2018

This is a known problem we have had since forever. Recently I asked in Pulseaudio's mailing list about this and I found out this is a problem in Pulseaudio. You can read their answer here https://lists.freedesktop.org/archives/pulseaudio-discuss/2018-October/030553.html. Unfortunately it seems there is no one looking at this bug at this moment. So we may have to live with this for a while.

For now I suggest we let this issue opened for people noticing this bug to find the link above easily. But there is nothing we can do in PulseEffects that could fix this.

@Vectrobe
Copy link
Author

I see, so it only occurs via pa monitoring as a result of buffer overlapping, which makes sense. Fixing the bug could involve either disabling rewind (first thing I looked for prior to reporting) or using a buffer copy-through akin to running a virtual device loop, the later adding additional latency but effectively sandboxing pa-effects.

I'll look at pa's code anyway to see what can be done, might only need some interpolation.

@sebastien
Copy link

sebastien commented Oct 12, 2018

The PulseAudio's ML answer is a bit depressing, especially when you see that the problem has been known for 4 years. Is there anything we can do to help, besides actually fixing the bug (I don't know enough about PulseAudio to try).

@wwmm
Copy link
Owner

wwmm commented Oct 12, 2018

I don't know. At this moment I do not have any idea :-(

@sebastien
Copy link

And I just wanted to say that the equalizer kicks ass, much better than the PulseAudio LADSPA equalizer. I own a ThinkPad X1 and the Dolby driver does not exists on Linux, so the sound is garbage by default, but I managed to salvage a lot of depth and clarity using the many bands available in PulseEffects. Thanks a lot for making this tool available!

@PilotBob42
Copy link

PilotBob42 commented Oct 13, 2018

Found this really good explanation of how rewinding works in PulseAudio. It also mentions several known bugs (none of which seem to have ever been addressed) any one of which could be causing the crackling we hear when rewinds occur in PA. The one mentioned at the end of the "buffers" section seems suspiciously capable of being the culprit (but the whole page is a good read on rewinding in PA and how it all works).

PulseAudio Rewinding Developer Documentation

There's actually another buffer between render_memblockq and the sink input implementor (in the example above the native protocol stream): if a resampler is used, it may sometimes have some data in its leftover buffer. BUG: That buffer is not currently taken into account when rewinding (https://bugs.freedesktop.org/show_bug.cgi?id=53911).

@Utini2000
Copy link

Utini2000 commented Mar 26, 2019

Does this crackle also occur when pausing/playing a file?
I recently noticed that I also get a nasty crackling from time to time when listening with the EQ of pulseeffects. Also my DAC will show "192kHz" for a half second and then jumps to 48kHz although the file is 44.1kHz.
It also crackles once as soon as I use the toggle to disable the EQ.
How ever, it does not happen when changing tracks (or atleast not always).
Or should I rather open a new issue ticket?

@edit: Changing the active profile of pulseeffects to my "all off profile" and then back to my "Sennheiser" profile which has EQ enabled, fixes the issue.

@wwmm
Copy link
Owner

wwmm commented Mar 26, 2019

The source of the noise are the rewinds done by Pulseaudio while we are recording from the sink monitor. So any action that can cause a rewind will generate noise. If I am not mistaken playing/pausing may cause rewinds too because when you have only 1 audio app running and you pause/unpause it PulseEffects will alternate its pipeline between the playing and paused state in order to save cpu usage.

Something to have in mind is that the intensity of the noise seems to be dependent on factors like the audio buffer size. So there are rewinds that do not cause audible noises and others that do...

I think that this sampling rate change must have happened for other reason. It does not depend on the equalizer. When PulseEffects starts it reads the rate of the default output device and the whole pipeline is locked to this value while PulseEffects is running. Just take a look at the values in our headerbar
Screenshot from 2019-03-26 18-12-23
In my case all processing stages are using 44.1 kHz because that was the value the defaut device was using when PE started. I hope to implement #288 in the future but at this moment there is no change to the rate on the fly. Pulseaudio did this sampling rate change you saw. Why I have no idea...

@wwmm
Copy link
Owner

wwmm commented Mar 26, 2019

The crackles when enabling/disabling are intense? I can listen to a very small noise when the eq is enabled. It is not related to the eq but to the fact that the pipeline has to be "cut" on the fly so that we can insert the eq there. And as it is being done now some audio buffers may be lost a long the way... What is probably causing this noise. There is a better way to insert/remove the plugins from the pipeline on the fly and I tried it a long time ago. Introduced so many problems I gave up. Dynamic GStreamer pipelines can be hard to get right when they are large as the ones we have. Maybe one day I will take a look at this again...

@Vectrobe
Copy link
Author

Yes, play-pausing will trigger rewinds, and the crackle will vary in intensity simply by whatever the last bits in the stream were. PA is the only library with this fault as it's the only one that does rewinding (for reasons still unknown to me...).

The only real solution is to disable/remove rewinding from PA, but I'm not aware of any [proper] ways to do that...

@Vectrobe
Copy link
Author

Oh, it'd also vary in intensity based on the user's balance between physical speaker/head volume and mixing volume. I tend to have my physical volume at a fixed, high value, so that each application gets a high volume range to chose from. This of course makes small crackles and stutter very predominant, often as a loud crack or thump.

@Utini2000
Copy link

To me the cracks only happen when pause/playing/rewinding/changing track or audio/video files.
And it gets to a point where I am starting to wonder if I can keep using Pulseeffects because it seriously causes headaches to me and I am afraid that my HD800S could take damage from it.

If it is a fault from PA-side, why does it not occur when using only PA without pulseeffects?

@wwmm
Copy link
Owner

wwmm commented Apr 2, 2019

Because without PE there is nothing recording audio from a sink monitor. But in order to apply effects we have to record from the sink monitor we redirect apps output to

@wwmm
Copy link
Owner

wwmm commented Apr 2, 2019

I almost can not listen these cracklings unless I change the app volume. I definitely do not have a noticeable noise when just alternating between the playing and paused state. What values are you using for buffer and latency in the settings menu?

@wwmm
Copy link
Owner

wwmm commented Apr 2, 2019

It feels like this can get worse on some hardwares. 99% of the time I forget we have this problem

@wwmm
Copy link
Owner

wwmm commented Apr 2, 2019

Maybe the reason why I do not notice them is because I never have the system volume at its highest value. I set each app volume to it's maximum and control the system volume through my keyboard multimedia keys

@wwmm
Copy link
Owner

wwmm commented Apr 2, 2019

Using low latency and buffer values may help. This the most that can be done on our side. Some months ago I really tried everything I could do to no avail. This has to be fixed in Pulseaudio. This is happening deep inside its code and here on PE we are coding from a high level API. My hands are tied =/

@betterphp
Copy link

I also use the system volume and have everything else set to about 70% to avoid clipping and hardly notice this issue during normal use. @Utini2000 it might be worth lowering the volume of the application playing audio and see if that helps.

I do sometimes get the crackle when a new stream starts to play, even if it's not going through pulseeffects but that's rare.

@Utini2000
Copy link

Buffer: 200000
Latency: 10000
Block size: 512
Priority: Real time
Priority: 4

My DAC vendor (Meier Audio Daccord FF) recommend in the manual to have the system volume at 100% and use the DAC/AMP to change the volume level. This is also how the driver works in its default state. As soon as I plug in my DAC, the volume will go to 100%.

I just want to re-try it with a lower system/app volume but ofcourse I can't reproduce the error now :D
But the crackling was very very noticable even on low volume level of my amplifier. So system volume was at 100% but my amplifier volume was one "tick" away from being mute. And still it was like a needle in my ears whenever I changed the track or pause/play.

@wwmm
Copy link
Owner

wwmm commented Apr 3, 2019

I have been using a buffer of 50000
Screenshot from 2019-04-03 19-48-57

@Utini2000
Copy link

Okay, I will give it a try tonight :)

@betterphp
Copy link

I'm on 500000 for buffer which I found makes the audio much more stable - although there is a noticeable delay, which doesn't bother me.
image

Something else to consider, pulseeffects will amplify the sound slightly too, which can be seen here
image
When recording and playing a stream with no effects applied (this is how I used to play music on another set of speakers in my house) the two volume levels are perfectly in sync. If the source stream is not turned down puleeffects will amplify it to the point where the waveform is clipped producing pretty bad distortion.

The system volume (as in what's controlled with the media keys or volume thing in the system tray) is applied after pulseeffects so turning that down has no effect - the damage is already done by the puleeffects stream clipping. It works in the same way as video or image encoding, once it's been compressed and the detail is lost there is no way to get it back.

Analogue amplifiers will normally say you need the source volume at max because if it's too quiet you'll have to turn the volume way up which will add a horrible buzzing noise from electrical noise being amplified.

@Utini2000 If the sounds is very loud with the amp on a low setting I'd say try turning the app volume down to about 40% and leave system at 100%. That should eliminate any clipping that might be happeneing and you could turn the amp up a bit so the volume control on it would actually be usable :)

@betterphp
Copy link

Also just btw, @wwmm Pulseeffects is awesome :D

@wwmm
Copy link
Owner

wwmm commented Apr 4, 2019

Thanks @betterphp! :-)

The volume amplification will depend on which plugins are enabled and on how they are being used. Let's consider as an example that the equalizer is the only plugin enabled. If you use subtractive equalization(all gains are below zero) the output level will be smaller than the one in the input. But if you boost weak frequencies instead of cutting the strongest ones it will happen what you described. When boosting I suggest using the input or the output gain controls to reduce the signal level.

Based on your image you are using a bluetooth device as output. For some reason I do not know bluetooth devices need more buffering. My bluetooth headphone does not work with anything less than 200000 or 250000.

@wwmm
Copy link
Owner

wwmm commented Apr 4, 2019

@Utini2000 the section Pops when starting and stopping playback in this link https://wiki.archlinux.org/index.php/PulseAudio/Troubleshooting may help. My sound card(ALC1220) makes noises when Pulseaudio suspends its sinks even when not using PulseEffects. The config described in the wiki fixes that. But it may not be good from power saving point of view

@Utini2000
Copy link

@wwmm thanks for that link. It would make sense because the wikie mentions the problems especially in connection with KDE4. I switched from XFCE to KDE-Plasma pretty much at the same time when I installed pulseeffects. That might make me believe it is a pulseeffects fault.

So I tried what the wiki states and it doesnt really work for me.

If I add both lines then my system becomes unresponsive and I have to force off the system.
If I only add "unload-module module-suspend-on-idle" then my system doesn't detect any sound devices anymore :(

Also I already have that file on my Arch installation with lots of content.

@Utini2000
Copy link

I just noticed that my problem could be related to what the wiki mentions because I just had cracks when opening a window (twice in a row). Now I just need to figure out how to apply that fix in a way that it works for me :o

@wwmm
Copy link
Owner

wwmm commented May 17, 2019

I have good news for you! Although the rewind bug is still there I was able to submit a few patches to Pulseaudio that helped me to workaround it. It was already merged as you can see here https://gitlab.freedesktop.org/pulseaudio/pulseaudio/merge_requests/93. I have already updated PulseEffects so that rewinds are disabled when Pulseaudio 13(not released yet) or its development branch is being used.

People willing to try it now will have to install both Pulseaudio and PulseEffects from sources. Pulseaudio can be installed this way

git clone https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
cd pulseaudio
NOCONFIGURE=1 ./bootstrap.sh
./configure --prefix=/tmp/pulseaudio
make -j1
make install

You have to kill the current instance before running the new one

systemctl --user mask pulseaudio.socket
pulseeffects -q (if PE is running kill it before stopping Pulseaudio)
systemctl --user stop pulseaudio

Now you can start the Pulseaudio version you compiled

cd /tmp/pulseaudio/bin
export LD_LIBRARY_PATH=/tmp/pulseaudio/lib
./pulseaudio

After that you can open PulseEffects and the other audio apps. To go back to the Pulseaudio installed in your system kill the one you compiled from sources and run

systemctl --user unmask pulseaudio.socket
systemctl --user start pulseaudio

I know. Doing tests with Pulseaudio compiled from sources is a pain. But it would be nice to know if the issue is fixed for everybody. At least for me it is :-)

@AlexWayfer
Copy link
Contributor

make install

Small notice:

I need to run it by root (sudo), otherwise I'm getting permissions error:

 /usr/bin/mkdir -p '/lib/udev/rules.d'
 /usr/bin/install -c -m 644 modules/alsa/mixer/profile-sets/90-pulseaudio.rules '/lib/udev/rules.d'
/usr/bin/install: cannot remove '/lib/udev/rules.d/90-pulseaudio.rules': Permission denied
make[4]: *** [Makefile:11206: install-dist_udevrulesDATA] Error 1
make[4]: Leaving directory '/home/alex/Projects/pulseaudio/src'
make[3]: *** [Makefile:11844: install-am] Error 2
make[3]: Leaving directory '/home/alex/Projects/pulseaudio/src'
make[2]: *** [Makefile:11838: install] Error 2
make[2]: Leaving directory '/home/alex/Projects/pulseaudio/src'
make[1]: *** [Makefile:800: install-recursive] Error 1
make[1]: Leaving directory '/home/alex/Projects/pulseaudio'
make: *** [Makefile:1102: install] Error 2

(Arch Linux)


After all operations, there are still lags, described here: #222 (comment) (when I change volume of application in PE).

@wwmm
Copy link
Owner

wwmm commented May 17, 2019

I had this error too. It makes no difference. Pulseaudio runs even if this file is not installed. Honestly I don't know why Pulseaudio is trying to put stuff in /etc when the prefix is in /tmp. It may be better to not run as root

@wwmm
Copy link
Owner

wwmm commented May 17, 2019

Did you update PE too?

@AlexWayfer
Copy link
Contributor

It may be better to not run as root

Yes, but I don't know how, if make install want to remove file in /lib/udev/.

Did you update PE too?

Sorry, no. I'll try a little bit later.

@ferreum
Copy link

ferreum commented May 17, 2019

I installed both pulseaudio-git and pulseeffects-git from the AUR and it works like a charm! I didn't think this would get fixed any time soon, good work!

@wwmm
Copy link
Owner

wwmm commented May 17, 2019

@AlexWayfer install as normal user. These errors are not relevant to us.

Good to know @ferreum! I tried to use pulseaudio-git from aur but for some reason it fails to compile on my Arch install. Strange.

@ferreum
Copy link

ferreum commented May 17, 2019

Right, the PKGBUILD contained a patch command that I had to comment out. I figured it was not needed any more because it complained about already having been applied.

@wwmm
Copy link
Owner

wwmm commented May 17, 2019

Oh! I did not think about that. @AlexWayfer in this case it is better to do the same as @ferreum and install the aur package

@AlexWayfer
Copy link
Contributor

@AlexWayfer in this case it is better to do the same as @ferreum and install the aur package

Thank you! I did that. There are no more lags when I change volume of application in PE. I'll look if it resolves #222 too.

@Utini2000
Copy link

I am not able to test and verify this right now (+the next 2 weeks) but given by the effort you put into fixing this and actually fixing PulseAudio, you are simply awesome!

@wwmm
Copy link
Owner

wwmm commented May 19, 2019

I think we can close this.

@mikhailnov
Copy link
Contributor

I have good news for you! Although the rewind bug is still there I was able to submit a few patches to Pulseaudio that helped me to workaround it. It was already merged as you can see here https://gitlab.freedesktop.org/pulseaudio/pulseaudio/merge_requests/93. I have already updated PulseEffects so that rewinds are disabled when Pulseaudio 13(not released yet) or its development branch is being used.

If I cherry-pick those patches to PulseAudio in ppa:milkhailnov/pulseeffects, will pulseeffects be able to detect that to disable rewinds?

@wwmm
Copy link
Owner

wwmm commented May 19, 2019

Only if you also compile PulseEffects from git. PE 4.6.0 does not have the necessary changes implemented.

@wwmm
Copy link
Owner

wwmm commented May 19, 2019

You would also need to make Pulseaudio identify itself as something newer than 12.2. It is not necessary that it identify itself as 13. When you build it from git it will show something like 12.2-309-geadd9. This is enough. The - character will tell PE that it is a Pulseaudio's development version and it will assume that it accepts the new null sink option.

@mikhailnov
Copy link
Contributor

Only if you also compile PulseEffects from git. PE 4.6.0 does not have the necessary changes implemented.

Let's wait for the next version of PulseEffects and prepare Pulseaudio now.

You would also need to make Pulseaudio identify itself as something newer than 12.2. It is not necessary that it identify itself as 13. When you build it from git it will show something like 12.2-309-geadd9. This is enough. The - character will tell PE that it is a Pulseaudio's development version and it will assume that it accepts the new null sink option.

I think it will be easier and more reliable to patch PulseEffects when building in the PPA, please give a link to the code that checks it.

@mikhailnov
Copy link
Contributor

Hm, if doing like this, if PulseEffects is installed from the PPA and Pulseaudio is not, then PE will try to use this new option and fail, will it lead to a crash?

@mikhailnov
Copy link
Contributor

If I do like this

--- pulseaudio-12.2/src/pulse/version.h.orig    2019-05-19 18:27:18.631772055 +0300
+++ pulseaudio-12.2/src/pulse/version.h 2019-05-19 18:27:46.587081404 +0300
@@ -56,7 +56,7 @@
 #define PA_MINOR 2
 
 /** The micro version of PA (will always be 0 from v1.0 onwards). \since 0.9.15 */
-#define PA_MICRO 0
+#define PA_MICRO 1
 
 /** Evaluates to TRUE if the PulseAudio library version is equal or
  * newer than the specified. \since 0.9.16 */

will pulseeffects understand it? (PA_MICRO seems to be used only in vala/libpulse.vapi)

@wwmm
Copy link
Owner

wwmm commented May 19, 2019

This is where Pulseaudio version is checked https://github.com/wwmm/pulseeffects/blob/57d1811011c9b229e7d4d889a3101dbd8b72184b/src/pulse_manager.cpp#L542

As PulseEffects is right now it works for all Pulseaudio versions. But if you force the new null sink option norewinds to be used on any Pulseaudio version older than the current code in its git repository PE will crash because the option norewinds does not exist in this case.

@wwmm
Copy link
Owner

wwmm commented May 19, 2019

I don't know if patching Pulseaudio this way will work. Whatever you do you can test by running the command pactl info. If the Server Version printed is higher than 12 or has - it will be enough.

@mikhailnov
Copy link
Contributor

mikhailnov commented May 19, 2019

I've packported the fix to Pulseaudio 12.2 and it did fix crackling when changing sound volume via Pulseeffects for me. Have commited the updated PulseAudio into the PulseEffects PPA for Ubuntu 18.04, 18.10, 19.04 and 19.10.
The patch is here: https://gitlab.com/nixtux-packaging/pulseaudio-ubuntu/blob/master/pulseaudio-12.2/debian/patches/0001-Backport-add-an-option-that-allows-rewinds-to-be-dis.patch
You may recommend people to attach it to their distribution package of PulseAudio 12.2.

user@pay2:~$ LANG=c pactl info | grep 12
Server Version: 12.2-2
user@pay2:~$ pulseaudio --version
pulseaudio 12.2-2

@Utini2000
Copy link

@wwmm @mikhailnov

Archlinux has 12.2-2 (although the terminal reports back 12.2) which still has the crackling issue :(
I couldn't test it before today but it still gives me the cracking just as before.

https://www.archlinux.org/packages/extra/x86_64/pulseaudio/

@AlexWayfer
Copy link
Contributor

Archlinux has 12.2-2 (although the terminal reports back 12.2) which still has the crackling issue :(

Just install pulseaudio-git from AUR.

@wwmm
Copy link
Owner

wwmm commented Jun 18, 2019

You will have to do what @AlexWayfer said. Pulseaudio 12.2 in Arch Linux repository does not have the patches I sent to Pulseaudio devs. Until Pulseaudio 13 is released(what may take a while) pulseaudio-git will have to be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants