Subject: alsa-utils:

From: Andoru <[email-masked]>
Date: Tue, 14 Nov 2017 16:13:44 +0200

Package: alsa-utils
Version: 1:7.7+16
Severity: normal

As the title says, I'm having a bit of an issue with ALSA, and the high
CPU (~15-20%) usage in some cases. So far on the default device, I've
only noticed this with VLC and foobar2000 (through Wine), but there are
other apps/games that might have the same problem. It's just easy to
tell if an app/ALSA uses too much CPU if you just play some audio files
and you don't have anything else that might need the extra CPU power,
like rendering the video stream or render the graphics. I can fix the
high CPU usage in VLC if I switch the audio sub-device from the Default
to a specific one (in my case: Analog Front Speakers). There is no
change in the audio quality, but the resources used instantly decrease.
The only problem with this is that I can no longer play/hear any audio
from other apps/games (so basically VLC monopolises the card). Also,
this is not possible under Wine, so I can't achieve the same thing for
foobar2000, or other Windows apps/games.
I haven't made any custom
config files for ALSA, except to disable the HDMI audio output (so that
the normal analogue output is used by default in all apps/games), and
I've done that in /etc/modprobe.d/intel-disable-hdmi.conf with this as
it's content:

_______________________________________________________________________

options snd_hda_intel enable=0,1
_______________________________________________________________________

The soundcard that I'm using is an integrated one, and it's a Realtek ALC887-VD.
Does anyone know what I could do to fix this issue, while still being able to
play multiple streams of audio at the same time?

-- System Information:
Debian Release: buster/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.13.0-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8),
LANGUAGE=en_GB:en (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages alsa-utils depends on:
ii  kmod              24-1
ii  libasound2        1.1.3-5
ii  libc6             2.24-17
ii  libfftw3-single3  3.3.6p2-2
ii  libncursesw5      6.0+20170902-1
ii  libsamplerate0    0.1.9-1
ii  libtinfo5         6.0+20170902-1
ii  lsb-base          9.20170808
ii  whiptail          0.52.20-1+b1

alsa-utils recommends no packages.

alsa-utils suggests no packages.

-- no debconf information

---

From: Elimar Riesebieter <[email-masked]>
Date: Tue, 14 Nov 2017 18:55:37 +0100

Control: found -1 1.1.3-1

Hi Andoru,

thanks for your bug report.

* Andoru <[email-masked]> [2017-11-14 16:13 +0200]:

> Version: 1:1.1.3-1
> other apps/games that might have the same problem.

What makes you think an alsa process eats high cpu usage? Can you
post the tespective line with column headers aou of htop or top
please?

Thanks
Elimar
-- 
  Obviously the human brain works like a computer.
  Since there are no stupid computers humans can't be stupid.
  There are just a few running with Windows or even CE ;-)

---

From: Andoru <[email-masked]>
Date: Tue, 14 Nov 2017 22:03:20 +0200

> What makes you think an alsa process eats high cpu usage?

You skipped a paragraph from my report:

> It's just easy to tell if an app/ALSA uses too much CPU if you just play
some audio files
> to a specific one (in my case: Analog Front Speakers).

///

> Can you post the tespective line with column
> headers aou of htop or top please?

Sorry... could you elaborate what you mean? What parameters should I start
htop to get he info you need?

---

From: Elimar Riesebieter <[email-masked]>
Date: Tue, 14 Nov 2017 22:14:08 +0100

> htop to get he info you need?

Just run htop while an alsa-process needs high cpu load. Copy the
line which shows that from (h)top to this bug report. Or just file a
screenshot to a puplic server somewhere.

Elimar
-- 
    .~.
    /V\   L   I   N   U   X
   /( )\ >Phear the Penguin<
   ^^-^^

---

From: Andoru <[email-masked]>
Date: Tue, 14 Nov 2017 23:45:21 +0200

> screenshot to a puplic server somewhere.

Alright:
VLC playing a FLAC file on the default device:

>  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+
COMMAND
> 26183 andoru    20   0 1191000  66424  46296 S  13.6  0.8   0:09.43 vlc
___________________________________________________________________________________________________

VLC playing the same file with "Analog Front Speakers" subdevice selected
under Audio -> Audio Device:

>  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+
COMMAND
> 26183 andoru    20   0 1195412  69176  48644 S   1.3  0.9   0:11.35 vlc

___________________________________________________________________________________________________

As you can see, the CPU decreased from 13.6% to 1.3% when switching the
device.
___________________________________________________________________________________________________
To confirm that this is not an issue with the decoder in VLC here's VLC
playing an OGG Vorbis file on the default device:

>  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+
COMMAND
> 26183 andoru    20   0 1263372  76228  48368 S  18.3  1.0   0:15.95 vlc
___________________________________________________________________________________________________

Same test as above, this time with an MP3 file:

>  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+
COMMAND
> 26183 andoru    20   0 1416816  91532  60188 S  17.0  1.2   0:19.64 vlc

___________________________________________________________________________________________________

And foobar2000 playing FLAC OGG and MP3 files, respectively:

>  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+
COMMAND
> 2375 andoru    20   0 1153140  62276  13140 S  21.3  0.8  29:36.91
foobar2000+

>  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+
COMMAND
> 2375 andoru    20   0 1153140  62032  13140 S  24.6  0.8  29:16.33
foobar2000+

>  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+
COMMAND
> 2375 andoru    20   0 1153140  72756  11808 S  22.6  0.9  29:03.99
foobar2000+

Let me know if you need any additional info.

Also, in the initial report, I forgot to mention that when I select "Analog
Front Speakers" subdevice in VLC, with some decoders (particularly APE) and
when the sample rate is below 44100Hz, I can hear some distortion
(crackling on high pitched sounds), so I'm guessing the high CPU usage is
maybe due to an inefficient resampler?

---

From: Elimar Riesebieter <[email-masked]>
Date: Wed, 15 Nov 2017 06:12:28 +0100

> > 26183 andoru    20   0 1191000  66424  46296 S  13.6  0.8   0:09.43 vlc

Did you started vlc within wine?

Elimar
-- 
  Learned men are the cisterns of knowledge,
  not the fountainheads ;-)

---

From: Andoru <[email-masked]>
Date: Wed, 15 Nov 2017 14:42:24 +0200

No...? Why would I do something silly like that?

---

From: Elimar Riesebieter <[email-masked]>
Date: Wed, 15 Nov 2017 18:52:26 +0100

Control: tags -1 unreproducible

> > 26183 andoru    20   0 1191000  66424  46296 S  13.6  0.8   0:09.43 vlc

I tried that on 3 different soundcards. I don't get vlc as a htop
COMMAND. It is always /usr/bin/vlc. Please tell me how you fired up
vlc. The %CPU usage isn't reproducible on none of the soundcards
handy for me. 

I don't know how you got foobar2000 into Debian but this isn't¬
maintained in the repos, so not relevant to this bug.

> maybe due to an inefficient resampler?

Try to cancel all pulseaudio stuff and test again. Let me know....

Elimar
-- 
  Never make anything simple and efficient when a way
  can be found to make it complex and wonderful ;-)

---

From: Andoru <[email-masked]>
Date: Thu, 16 Nov 2017 02:22:54 +0200

> I tried that on 3 different soundcards. I don't get vlc as a htop
COMMAND. It is always /usr/bin/vlc.

I swear I'm using the native VLC from the Debian repos.

> Please tell me how you fired up vlc.

I started VLC through OpenBox's menus, and on that menu the command to
start VLC is simply 'vlc', which probably translates to 'bash -c vlc'. If I
open a media file from the file manager, and there's no running instance of
VLC, I get "/usr/bin/vlc --started-from-file" as the command name under
htop.

> The %CPU usage isn't reproducible on none of the soundcards handy for me.

Have you actually tried it on a ALC887-VD or a similar integrated chip by
Realtek?

> maintained in the repos, so not relevant to this bug.

I did not get it through Debian, I simply installed it in the default Wine
prefix.

> Try to cancel all pulseaudio stuff and test again. Let me know....

I apologise, I think I did not mention this in the initial bug report, but
I'm not using PA, nor do I have it installed. That's why I submitted this
bug against ALSA.

---

From: Elimar Riesebieter <[email-masked]>
Date: Thu, 16 Nov 2017 22:39:05 +0100

> Have you actually tried it on a ALC887-VD or a similar integrated chip by

Tested on ALC892, CX20561, emu10k1 and ES1371/1. None of them showed
high cpu usage.

Elimar
-- 
  "Talking much about oneself can also
   be a means to conceal oneself."
         -Friedrich Nietzsche

---

From: Andoru <[email-masked]>
Date: Thu, 16 Nov 2017 23:47:58 +0200

> Tested on ALC892, CX20561, emu10k1 and ES1371/1. None of them showed high
cpu usage.

Could you let me know how you configured ALSA? It could be that I might
have misconfigured something, but I wouldn't know what...
Is there some advanced testing/diagnonsis that I could try to do to figure
out what's causing this?

---

From: Elimar Riesebieter <[email-masked]>
Date: Fri, 17 Nov 2017 08:28:26 +0100

> Is there some advanced testing/diagnonsis that I could try to do to figure

Nothing special. Just install alsa-utils. No asoundrc. Thats it.

Elimar
-- 
  On the keyboard of life you have always
  to keep a finger at the escape key;-)

---

From: Andoru <[email-masked]>
Date: Fri, 17 Nov 2017 15:12:20 +0200

Okay... then what is there to do next?
Call me technologically illiterate, or say that I don't know of the inner
workings of ALSA, but I don't think this can be a given that a simple task
such as outputting audio could take 13-20% of a quad core CPU!

---

From: Elimar Riesebieter <[email-masked]>
Date: Fri, 17 Nov 2017 16:09:46 +0100

> such as outputting audio could take 13-20% of a quad core CPU!

Maybe your speakersystem needs some rectification?

Or you can ask here:
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

Elimar
-- 
  Excellent day for drinking heavily.
  Spike the office water cooler;-)

---

From: Elimar Riesebieter <[email-masked]>
Date: Fri, 17 Nov 2017 16:32:44 +0100

> such as outputting audio could take 13-20% of a quad core CPU!

Do you have a $HOME/.asoundrc?

Did you tried mpg321, moc or any other console player?

Elimar
-- 
  The path to source is always uphill!
                                -unknown-

---

From: Andoru <[email-masked]>
Date: Sat, 18 Nov 2017 01:47:30 +0200

> Maybe your speakersystem needs some rectification?

You mean the external speakers? I use headphones. I don't know what those
have to do with ALSA or this issue I'm having.

> Or you can ask here:
<http://mailman.alsa-project.org/mailman/listinfo/alsa-devel>
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

I tried writing to alsa-devel, but I didn't get any reply:
http://mailman.alsa-project.org/pipermail/alsa-devel/2017-November/126934.html

> Do you have a $HOME/.asoundrc?

____________________________________________________________
_______________________
$ locate asoundrc
~/.steam/ubuntu12_32/steam-runtime/amd64/usr/share/doc/
libasound2/examples/asoundrc.txt.gz
~/.steam/ubuntu12_32/steam-runtime/i386/usr/share/doc/
libasound2/examples/asoundrc.txt.gz
/usr/share/doc/libasound2/examples/asoundrc.txt.gz
____________________________________________________________
_______________________

> Did you tried mpg321, moc or any other console player?

What should I try specifically?
What parameters should I use?

---

From: Elimar Riesebieter <[email-masked]>
Date: Sun, 19 Nov 2017 10:47:52 +0100

> > Do you have a $HOME/.asoundrc?

I meant .asoundrc. Please notice the dot.

$ find $HOME -name '.asoundrc*'

will do the trick

[...] 
> What parameters should I use

$ sudo apt install vorbis-tools
$ ogg123 -d alsa -o surround71 $YOUR_FAVORITE_OGG.ogg
$ man ogg123

With alsamixer you can control the output device.

Elimar

---

From: Elimar Riesebieter <[email-masked]>
Date: Wed, 22 Nov 2017 07:53:04 +0100

* Andoru <[email-masked]> [2017-11-19 15:11 +0200]:

> Of course, that file search was meant for demonstration. I've already
> looked at the home folder with the file manager, but there was no
> .asoundrc. Thank you for the example command.
> 
> > With alsamixer you can control the output device
> 
> I did that now, and even with the default device, ogg123 was using 3.5-5%
> CPU, which is way better than with VLC.
> Command used:
> 
> _____________________________________________________________________
> ogg123 -d alsa -o default -v ~/Desktop/sample2.ogg
> _____________________________________________________________________
> 
> I've also tried to use the "front" subdevice, but it keeps reporting it as
> busy who-knows-why:
> 
> _____________________________________________________________________
> ogg123 -d alsa -o dev:front -v ~/sample2.ogg
> _____________________________________________________________________
> 
> I've also tried mpg123, and got similar results (~3% on the default device)
> 
> I'm guessing then this isn't an ALSA issue... Though I'm not sure what's
> causing it in VLC and Wine.

So I am closing this bug hereby.

Thanks for cooperation
Elimar

---

From: Andoru <[email-masked]>
Date: Tue, 28 Nov 2017 15:19:25 +0200

Forgot to check previously, but whenever I use those CLI players you
suggested, they also monopolise the soundcard, making me unable to play
other stuff in parallel, just like how it would happen when setting the
specific subdevice in VLC. So, since I'm not able to use those CLI players
to play with the default device to see if they use the same amount of CPU
as VLC and other players/apps, this issue is still not solved.
That's why I asked you for specific commands that I can use with those CLI
players.

---

From: Elimar Riesebieter <[email-masked]>
Date: Tue, 28 Nov 2017 21:11:58 +0100

Hi Andoru,

> as VLC and other players/apps, this issue is still not solved.

There must be something configured on your system which cauuses your
issue. You don't have an .asoundrc. Did you created an /etc/asound.conf
or adapted some options loading your snd- modules? A clean install of
alsa-utils and libasound2 should work out of the box with no custom
settings!

> That's why I asked you for specific commands that I can use with those CLI

Do you think to solve your issue with "specific commands"? Just
install Debian's plain alsa and enjoy,

Elimar
-- 
  Experience is something you don't get until
  just after you need it!

---

From: Elimar Riesebieter <[email-masked]>
Date: Tue, 28 Nov 2017 21:43:53 +0100

* Elimar Riesebieter <[email-masked]> [2017-11-28 21:11 +0100]:

[...]
> alsa-utils and libasound2 should work out of the box with no custom

Remove /etc/modprobe.d/intel-disable-hdmi.conf and try again.

Elimar

---

From: Andoru <[email-masked]>
Date: Mon, 4 Dec 2017 17:02:01 +0200

> Did you created an /etc/asound.conf

No, I have no such file.

> or adapted some options loading your snd- modules?

Yes, I mentioned in the first post that I created a rule under
/etc/modprobe.d/ to disable HDMI audio output through the integrated chips.
But you added another reply so you probably noticed that I wrote that
afterwards.

> A clean install of
settings!

It *does* work, however, not as it should.

> install Debian's plain alsa and enjoy,

No, I meant specific commands to test those CLI players with the default
ALSA device (that has that issue with high CPU usage). Or at least to give
some output with which we could have a clue what's causing the CPU usage.

> Remove /etc/modprobe.d/intel-disable-hdmi.conf and try again.

I did, and unsurprisingly it did not help, the same high CPU usage on the
default device, the specific subdevice monopolises the sound card, and on
top of that, most applications that don't offer any settings for setting
which audio card/device/subdevice to use are left without sound because
they automatically choose the first card, which is the HDMI output.

---

From: Elimar Riesebieter <[email-masked]>
Date: Mon, 4 Dec 2017 20:09:54 +0100

Hi Andoru,

> It *does* work, however, not as it should.

As you are the only one out of 60thsd Debian Alsa users who
reported a high cpu-usage running alsa apps and I can't reproduce
and don't know your system I hereby cancel support from my side.
Hence you'll find a solution, please let me know with a ping to
[email-masked]. Maybe you'll find help on user-lists or
alsa-lists. I don't know, though

Elimar

---

From: Andoru <[email-masked]>
Date: Mon, 4 Dec 2017 21:54:22 +0200

> and don't know your system

What is there else that you'd like to know? What is it that I should be
doing to diagnose this? That's what I've been asking for the entirety of
this bug report!

> Hence you'll find a solution

I pretty much doubt it since I haven't got any useful info from you, nor
did I get any replies on alsa-users/alsa-dev.

---

From: Andoru <[email-masked]>
Date: Mon, 4 Dec 2017 23:41:45 +0200

> reported a high cpu-usage running alsa apps

Forgot to mention this: just because I'm the only one to report this issue
doesn't mean I'm the only one to experience it! I'm sure at least other
Debian users with the same sound chip as mine would probably experience the
same issue, if not users of other distros as well. They probably just
didn't bother reporting it as it is a sort of a minor-ish issue, or they
might've not even noticed it.

Could you (or someone else) perhaps let me know who provided the driver for
ALC887-VD? Maybe that way I could contact them directly.

---

From: Elimar Riesebieter <[email-masked]>
Date: Tue, 5 Dec 2017 08:27:45 +0100

* Andoru <[email-masked]> [2017-12-04 23:41 +0200]:

[...]
> ALC887-VD? Maybe that way I could contact them directly.

[email-masked]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

Elimar
-- 
  Numeric stability is probably not all that
  important when you're guessing;-)

---

From: Elimar Riesebieter <[email-masked]>
Date: Thu, 7 Dec 2017 08:20:32 +0100

> doing to diagnose this? That's what I've been asking for the entirety of

You can try to boot a live-linux like Debian-live, Knoppix, Ubuntu
whatever and check whether your symptoms persist.

Elimar

---

From: Andoru <[email-masked]>
Date: Thu, 7 Dec 2017 09:32:20 +0200

Yes, I was about to do that. Though those distros all have PulseAudio by
default, so I thought of installing Arch on a separate partition and test
ALSA there.

---

From: Andoru <[email-masked]>
Date: Wed, 13 Dec 2017 21:17:39 +0200

Okay, so I installed Arch from scratch with a minimalist set-up of OpenBox
and tint2, installed alsa-utils and alsa-tools, and made that modprobe
config file to disable HDMI output, just like I did when I did the
netinstall of Debian. Then installed vlc and played all the files I played
previously (in FLAC, ogg, mp3, etc), and both when using the default device
and when selecting Analog Front Speakers subdevice, the CPU usage rarely
passes the 5% mark. I've also tried foobar2000 through wine, and got the
same result.

Here's some info about the alsa-utils package under Arch:
____________________________________________________________________________________________________________________

$ pacman -Qi alsa-utils
Name            : alsa-utils
Version         : 1.1.5-2
Description     : An alternative implementation of Linux sound support
Architecture    : x86_64
URL             : http://www.alsa-project.org
Licenses        : GPL
Groups          : None
Provides        : None
Depends On      : alsa-lib>1.0.24  pciutils  ncurses  psmisc  libsamplerate
                  fftw
Optional Deps   : None
Required By     : None
Optional For    : None
Conflicts With  : None
Replaces        : None
Installed Size  : 2042.00 KiB
Packager        : Anatol Pomozov <[email-masked]>
Build Date      : Sat Nov 18 17:11:48 2017
Install Date    : Wed Dec 13 16:44:06 2017
Install Reason  : Explicitly installed
Install Script  : No
Validated By    : Signature
______________________________________________________________________________________________________________________

So this makes it pretty clear that I wasn't talking out of my ass, and that
there's something fishy going on with Debian's implementation of ALSA, or
there was something fixed between versions 1.1.3 and 1.1.5.