wwmm / easyeffects

Limiter, compressor, convolver, equalizer and auto volume and many other plugins for PipeWire applications
GNU General Public License v3.0
6.39k stars 267 forks source link

CPU usage increases when all audio stops #101

Closed jrudess closed 6 years ago

jrudess commented 6 years ago

While audio is playing, pulseeffects consumes around 9% of a core. However, when I stop all audio playback, the usage increases to 50%.

Testing is done with only the Equalizer enabled and with the stock pulseaudio configuration (archlinux, plasma). The system is using a 5.1 speaker configuration.

I am unsure if this is currently expected, or if this behavior is unique to my configuration. If it is not expected, is there any information I can provide that would help?

wwmm commented 6 years ago

By stopping you mean pause the audio applications or closing them so that there is no app shown in PulseEffects window?

In any case this should not happen. In my machines the cpu usage decreases when there is no audio. Does PulseEffects prints anything strange in the terminal when this happens?

jrudess commented 6 years ago

Unfortunately, there are no additional printouts that happen after pulseeffects starts up.

On initial load of pulseeffects, before any audio starts playing, the process rests at 7%. As soon as the first program plays audio, I see usage increase to 9%.

In the case of mpd, I'm using play/pause media-keys, so mpd does not close and remains in the pulseeffect list. When I pause the music, the CPU usage will increase to 50%.

To test the other scenario, I used deadbeef, and after starting some music, I closed deadbeef. It no longer was listed in the pulseeffects list, and CPU usage also increased to 50%.

It's definitely a weird behavior. I will experiment with dropping back to 2 channel stereo, a fresh user account, and another DE to weed out any other possible problems.

EDIT: Narrowed it down a bit more. This does appear to be related to pausing. KDE had a bunch of speech-dispatcher processes always in the pulseeffects app list which threw off my earlier results.

Now, with only mpd in the pulseeffects list, if I pause mpd, cpu usage goes up to 50%. If I stop mpd so that it is no longer in the list, cpu usage drops to 0%.

wwmm commented 6 years ago

When there is no app PulseEffects puts its gstreamer pipeline in the paused state. So 0% cpu usage is the expected behavior in this case.

I installed deadbeef here but I could not reproduce the problem. Cpu usage as measure by top is decreased by about 5% when deadbeef is paused.

Does this happen only with the equalizer? Is there any change if you try other plugins?

On a side note could you paste here the output of pactl list sink-inputs when you have a lot of kde speech-dispatcher processes? I think this is the kind of process that should be added to an app blacklist in PulseEffects code. This way they will not be shown in the window. pactl output will give me the info I need to blacklist (I do not have kde installed).

wwmm commented 6 years ago

In case it helps in the process of narrowing down the problem I am using gnome and stock pulseaudio configs in a updated Arch Linux.

jrudess commented 6 years ago

The issue appears confined to the equalizer effect. I tested each effect on its own, and while cpu usage never drops to zero while mpd is paused, it also doesn't increase.

Without the paused speech-dispatcher jobs in the background, deadbeef is unable to reproduce this problem because it never pauses its stream but always ends it. However, if any other process has a paused stream, then I can reproduce this with deadbeef.

This paused process just happened to be speech-dispatcher in my case.

Had to uninstall some packages to get rid of speech-dispatcher, but as soon as I can restart X this evening, I'll attach the pactl log.

jrudess commented 6 years ago

I have not yet been able to track down what is causing CPU usage to increase when a sink is paused.

Here is the pactl output for speech-dispatcher (plasma starts up three sinks on login).

Sink Input #0 Driver: protocol-native.c Owner Module: 10 Client: 7 Sink: 0 Sample Specification: s16le 1ch 44100Hz Channel Map: mono Format: pcm, format.sample_format = "\"s16le\"" format.rate = "44100" format.channels = "1" format.channel_map = "\"mono\"" Corked: no Mute: no Volume: mono: 43253 / 66% / -10.83 dB balance 0.00 Buffer Latency: 0 usec Sink Latency: 7038 usec Resample method: copy Properties: media.name = "playback" application.name = "speech-dispatcher" native-protocol.peer = "UNIX socket client" native-protocol.version = "32" application.process.id = "23453" application.process.user = "" application.process.host = "" application.process.binary = "sd_espeak" application.language = "C" window.x11.display = ":0" application.process.machine_id = "" application.process.session_id = "c4" module-stream-restore.id = "sink-input-by-application-name:speech-dispatcher"

wwmm commented 6 years ago

Ok. I added it to the blacklist.

mikhailnov commented 6 years ago

when you open pavucontrol, does the CPU usage grow?

jrudess commented 6 years ago

@mikhailnov my apologies, I missed your reply to this thread. No, pavucontrol being open does not grow CPU usage. It also doesn't show up on the pulseeffects applicaton list. At the moment, this only happens when a job is listed in pulseffects applications and is in 'paused' state.

Because speech-dispatcher is now blacklisted, this is rarely an issue for me because the only audio application I'm using that pauses the stream, rather than terminating, is mpd. Chromium will pause the stream for a few seconds, and pulseeffects will ramp up to 50% usage, but then chromium ends the stream after maybe 10s, and usage drops to 0.

Edit: In case I misunderstood, if I have mpd in a paused state with cpu-usage high, and then I open pavucontrol, cpu usage remains high.

wwmm commented 6 years ago

Hi, is this still an issue in latest PE?

evolbug commented 6 years ago

I seem to be having this issue, it has a sizeable CPU usage in general ~25%, pausing ramps it up more.

wwmm commented 6 years ago

Is there anything different in the logs when the cpu usage increases in the paused state? What are you using to measure the cpu usage? At least in gnome system monitor my cpu usage fluctuates around 1% or 2% depending on the number of effects enabled. I am also unable to reproduce the increase in usage when pausing the application. With which apps does this happen? All of them?

evolbug commented 6 years ago

Which logs should I look into?

I'm running xfce4 on Arch, top/gtop seems to more accurately identify processes which use CPU, CPU usage seems to be going between PulseAudio and PulseEffects.

When playing audio from Firefox - playing a YouTube video ramps up PEffects CPU, while something from Soundcloud ramps up all 3 - PEffects, FFox and PAudio. Pausing makes PEffects get stuck at ~20%, pulseaudio ~5%. Closing tab calms down PEffects, PAudio still uses extra CPU. Pavucontrol also seems to be contributing ~3%.

The only effect enabled is Equalizer.

Killing PEffects seems to corrupt the audio stack further, as VLC is unable to play anymore after that.

I'm gonna stick with pulseaudio-equalizer-ladspa for now.

wwmm commented 6 years ago

I think that in this case the lines printed by PE when executed from a terminal could have something useful if this cpu usage increase caused by paused apps triggers some kind of error.

top is more accurate but it uses a different scale. By default it has Irix mode on. In this case it does not divide the cpu usage by the number of cores and you can have cpu usages above 100% like the TombRaider process in the image below screenshot from 2018-03-31 14-45-38

Using top with irix mode on I have 20% cpu usage in a scale that goes to 1600%. It is not something that worries me. I have the limiter, equalizer, exciter, bass enhancer and delay plugins enabled: screenshot from 2018-03-31 14-54-28

In any case there is not much I can do about the plugins performance as I did not implement any of them. The increase in usage when an app is paused may be caused by something I am doing wrong. But I am still unable to reproduce that. I did some tests with firefox and PulseEffects cpu usage goes to zero when I pause the youtube video. So this problem is being triggered by something I do not have in my system.

jrudess commented 6 years ago

This appears to be resolved for me! Confirmed using both firefox and mpd as test cases. When all streams are paused, CPU usage now drops to 0 for me using the latest pulseeffects and arch/kde.

barjac commented 5 years ago

I was just about to report this issue which is happening in pulseeffects-4.4.7 with pulseaudio-12.2, when I saw these reports. I have a PA server running which takes short audio transmissions from rtl-airband running on a remote RPi. With PE equalizer switched OFF and no transmissions PE runs at about 4% (in top) With PE equalizer switched ON and no transmissions PE runs at about 10% When a transmission appears PE jumps to around 20% When that transmission stops PE then jumps to around 65% and stays there. When another transmission comes in PE drops back to around 20% but then goes back to 65% when the transmission stops. The only 'reset' back to lower usage is to switch the equalizer OFF and back ON, when the sequence repeats. I will try to get some logs but pushed for time just now :/

wwmm commented 5 years ago

I think it is better to open a new issue for this. The problem in this one was caused by the apps volume level meters that I removed from PE a long time ago. Your problem has a different source.

Put the output of the command G_MESSAGES_DEBUG=pulseeffects pulseeffects in the new issue. This way we will have more info about what is happening when these transmissions happen. At least here on my computer I can not reproduce this problem. Once all audio apps are paused PE cpu usage is essentially zero