jueves, 8 de agosto de 2013

System sound equalized with ALSA for Debian - Get-yo-self equalized!

(Still working on 2015. See workarounds at the end)

Motivation

Like many people, i really enjoy listening music, an, as many would know, having an equalizer can make a really big difference between "the ordinary experience" of listening music.
It's clear that many media players include plugins for audio enhancing, but, whan happens when you listen a music video on youtube, or just simply using grooveshark cloud music service?. For Windows machines the solution could be installing audio-enhancing software like DFX (A really good one, i can tell). But that kind of "stuff" isn't available for Linux. Maybe 'cause we have other kind of solutions, i have found one that works amazing, but you must have ALSA installed on your Linux distribution.

What is the ALSA System?

Many of you may wonder, hows that your Linux Distro communicates with your speakers/headphones/microphon/any-sound-device. Well, there are many ways to get the task donde, but, for Debian distributions (So, for the wide set of Debian-based distros like Ubunty, Mint, and so on) the ALSA system do the job. In words of Wikipedia [1]:
Advanced Linux Sound Architecture (known by the acronym ALSA) is a free, open source software framework released under the GNU GPL and the GNU LGPL[4] that provides an API for sound carddevice drivers. It is part of the Linux kernel. Some of the goals of the ALSA project at its inception were automatic configuration of sound-card hardware and graceful handling of multiple sound devices in a system, goals which it has largely met. A couple of different frameworks, such as JACK, use ALSA to allow performing low-latency professional-grade audio editing and mixing.
So

ALSA Equalizer

Getting the equalizer installed

Installing from repos (Debian Testing and Sid)

In the Debian Testing repositories we have the package libasound2-plugin-equal

The plugin on my Debian repository

In order to have the equalizer installed, as root, do:
# aptitude install libasound2-plugin-equal alsamixergui

  • libasound2-plugin-equal - The equalizer itself
  • alsamixergui - A GUI To control de plugin, but it's optional, cause you can use the command-line alsamixer. Unfortunatetly the only way to control the equalizer is to make use of the alsamixer utility

Manual Installing

For other linux distros, download the latest version of the plugin from here (look for "download")
Then, choose a folder and do

tar xvjf alsaequal-x.x.tar.bz2
cd alsaequal-x.x
make
sudo make install
You should read carefuly the reference [2]

Getting the equalizer to work

Single user

Into your "home" directory ("/home/user" for instance) create a file called ".asoundrc" and paste this code onto it (for more information see [2] and [3] from the references section below)
ctl.equal {
  type equal;
}
pcm.plugequal {
  type equal;
  # Modify the line below if you don't
  # want to use sound card 0.
  slave.pcm "plughw:0,0";
  # or if you want to use with multiple applications output to dmix
  # slave.pcm "plug:dmix"
}
# pcm.equal {
  # Or if you want the equalizer to be your
  # default soundcard uncomment the following
  # line and comment the above line.
 pcm.!default {
  type plug;
  slave.pcm plugequal;
}
Then, as root, you must do

# alsa force-reload

So the sound daemon restarts and loads the plugin. The equalizer should be working now.

Whole system (all users)

You must create the file

/etc/asound.conf

And paste this code onto it (for more information see [2] and [3] from the references section below, take a look at [4] too)
ctl.equal {
  type equal;
}
pcm.plugequal {
  type equal;
  # Modify the line below if you don't
  # want to use sound card 0.
  slave.pcm "plughw:0,0";
  # or if you want to use with multiple applications output to dmix
  # slave.pcm "plug:dmix"
}
# pcm.equal {
  # Or if you want the equalizer to be your
  # default soundcard uncomment the following
  # line and comment the above line.
 pcm.!default {
  type plug;
  slave.pcm plugequal;
}
Then, as root, you must do

# alsa force-reload

So the sound daemon restarts and loads the plugin. The equalizer should be working now.

Using the equalizer

The plugin installs a "virtual" audio device. This device is called "equal" (for obvious reasons).
If you followed the steps above, you shouln't have problems now.
To change the equalizer configuration, you must tell ALSA that you want to work with the "equal" device, so open a terminal and write either

$ alsamixer -D equal


This is how it looks on command line
or

$ alsamixergui -D equal


This is how it looks using alsamixergui

And choose your best audio configuration, and enjoy your audio-enhanced linux distro.

Some Workarounds (edit: 2015-Feb-04)


The above instructions still worked for me (I've resintalled Debian Testing on my PC on January of 2015), but I've noticed two little workarounds that might be of importance if you have more than a sound card or you have been experiencing no sound with web pages as youtube using google-chrome.

More than a soundcard

I've changed my motherd board and has two different sound cards which caused my system to direct the equalized sound stream to the "wrong" sound card.

Thanks to this post [7] I became aware of the need of tweaking the file /usr/share/alsa/alsa.conf in order to get ALSA using the "right" sound card.
If the working sound card is hw:0,1 and the "bad" sound card is hw:0,0, and you used hw:0,1 on your asound.conf as stated on the sections above, but still without equalized sound, you need to tell ALSA that start using sound card 1 (i.e. hw:0,1 in our example) on the file /usr/share/alsa/alsa.conf by changing the following lines:
defaults.ctl.card 0 to defaults.ctl.card 1
defaults.pcm.card 1 to defaults.pcm.card 1
defaults.rawmidi.card 1 to defaults.rawmidi.card 1
defaults.hwdep.card 1 to defaults.hwdep.card 1
defaults.timer.card 1 to defaults.timer.card 1

Youtube and HTML5 on google-chrome

Youtube video players were switched to use HTML5 (google it for more information). I don't know why the sound layer works if you use PulseAudio but if you have only ALSA, the sound migth not work (for me it was working anddd... the sound was gone).

The solution for google-chrome is to start the browser with the option

--try-supported-channel-layouts
So call google-chrome as

google-chrome --try-supported-channel-layouts

And play a nice youtube video, if that works for you, you can edit the menu entries and links to google-chrome adding the mentioned command option.
Resampling can be another issue (I can not tell about that but google product forum talks about it), some forums suggest to add the option --disable-audio-output-resampler, so another solution could be calling google-chrome as

google-chrome --disable-audio-output-resampler --try-supported-channel-layouts 
If that does not help you... Well... F*ck. 

References

  1. http://es.wikipedia.org/wiki/Advanced_Linux_Sound_Architecture
  2. http://www.thedigitalmachine.net/alsaequal.html
  3. http://wiki.linuxmce.org/index.php/Equalizer_for_ALSA
  4. http://www.alsa-project.org/main/index.php/Asoundrc
  5. http://packages.debian.org/source/sid/alsaequal
  6. Download my asound.conf 
  7. https://coderwall.com/p/wajiaq/replacing-pulseaudio-with-alsa-linux

No hay comentarios.:

Publicar un comentario