Head-Fi.org › Forums › Equipment Forums › Computer Audio › [GUIDE] NEWB guide to Bit-Perfect Linux audio.
New Posts  All Forums:Forum Nav:

[GUIDE] NEWB guide to Bit-Perfect Linux audio.

post #1 of 10
Thread Starter 

My guide to Linux audio for beginners.

 

This applies to many, many distributions and should work regardless of the tools you prefer. I am not going into a great deal of detail to keep it short and easy to read for average users, don’t expect alsa vs oss vs jack vs pipe discussions.

 


 

Output options:

There are several options for audio output in Linux. Where windows has kmixer (mixing, lossy) and wasapi (direct control, lossless) linux uses pulseaudio (mixing, lossy) and alsa (direct control, lossless).

 

The general rule is to have pulseaudio only on when you are not listening to music, this means you can still watch youtube videos and hear notifications from skype at the same time.

 

But when you are listening to music the aim is to have only one source, your player, having priority control over your sound card.

 

 

 

Ubuntu 14.04 and debian testing (Click to show)


The only requirement is nano, no gui or desktop environment is necessary. Installing nano on debian or ubuntu is as simple as:

 

Quote:
 sudo apt-get install nano

 


 

Setting up Alsa and gstreamer support:

Firstly make sure alsa, alsa-utils gstreamer0.10-alsa are all installed and up to date.

 

For debian/ ubuntu:

 

Quote:
sudo apt-get update && sudo apt-get install -y alsa alsa-utils gstreamer0.10-alsa
 

Detecting your proper sound card:

For the uses of this guide i will assume you are using a USB DAC.

Running the below in a terminal will list your devices detected by alsa as valid output devices:

 
Quote:
aplay -l

 

The output on my machine is:

 
Quote:

**** List of PLAYBACK Hardware Devices ****

card 0: NVidia [HDA NVidia], device 3: HDMI 0 [HDMI 0]

 Subdevices: 1/1

 Subdevice #0: subdevice #0

card 0: NVidia [HDA NVidia], device 7: HDMI 1 [HDMI 1]

 Subdevices: 1/1

 Subdevice #0: subdevice #0

card 1: DAC [UAC1 DAC], device 0: USB Audio [USB Audio]

 Subdevices: 0/1

 Subdevice #0: subdevice #0

 

Here you can easily see that card 1, device 0 is my usb sound card. If i was to use HDMI output i would set it to card 0 device 3 or card 0 device 7.

 

Quote:

Note: Sometimes if you get two HDMI outputs one is actually your DVI output, its a cheap trick hardware OEMs use to add ports. You will have to try both to find out which one is actually your HDMI device.

 

Testing a device is as simple as using:

 

aplay -D hw:0,0 test.wav

 

Where hw:0,0 refers to your hardware detected above with aplay -l.

 

For Alsa playback applications we provide hardware addresses in the form:

 

Quote:
 hw:card#,device#
 

So in my case it is:

 

Quote:
 hw:1,0

 

Setting defaults is the final step. Run the following in a terminal:

 

Quote:
sudo nano /etc/asound.conf

 

I suggest cleaning out this entire file so it is blank then putting the below contents in.

 

 

Quote:

pcm.!default {
    type hw
    card 0

device 0
}

ctl.!default {
    type hw           
    card 0

device 0
}

 

 

Simply replace the card and device numbers with the ones you found above.

 

For instance my config reads:

 

 

Quote:

pcm.!default {
    type hw
    card 1

device 0
}

ctl.!default {
    type hw           
    card 1

device 0
}

 

 

You are done with alsa!

 

 

Turning off pulseaudio:

 

As of 14.04 the version of pulseaudio used is much easier to disable with only a single line needing to be edited.
 

Using the command:
sudo nano /etc/pulse/client.conf

 

Change the autospawn line to read:
autospawn = no

 

That's it. No joke, you are done. Just restart your machine.

 

 

 

Playback!

Setting up your music player to use alsa.

 

There are many options out there for playing back bitperfect audio in linux as far as music players go.


This post by Rizlaw is a great summary, albeit rather outdated. If you have more questions feel free to ask via pm, post a reply, or simply head over to the forums for your specific distro.


Edited by yay101 - 6/21/14 at 6:42am
post #2 of 10
Quote:
 There are several options for audio output in linux. Where windows has kmixer (mixing, lossy) and wasapi (direct control, lossless) linux uses pulseaudio (mixing, lossy) and alsa (direct control, lossless).

 

Could you go into more detail about PulseAudio being "lossy"?  I don't find support of that anywhere.  The closest I got was this post on Computer Audiophile but the maintainer comment that's linked to is dead: http://www.computeraudiophile.com/f11-software/ubuntu-how-achieve-bitperfect-playback-8480/#post107417

 

Quote:

Q. Why does pulseaudio need Alsa installed?

A. Pulseaudio is just a super advanced mixer that can handle any input and output or loop or network stream. Alsa is simply the default output and supports almost all hardware.

 

I get what you're saying that a user can choose to use PulseAudio or ALSA directly, but you may want to make it clear PulseAudio is in fact a layer on top of ALSA and doesn't exist in its stead.  https://en.wikipedia.org/wiki/File:Pulseaudio-diagram.svg

 

Why should someone use PulseAudio at all instead of ALSA's dmix plugin?  Does ALSA's mixing also degrade audio quality?  if the concern is avoiding any software mixing why is switching between PulseAudio and ALSA better than always using ALSA directly and toggling the dmix plugin?  http://www.alsa-project.org/main/index.php/Asoundrc#Software_mixing

 

I think just a little bit more information and the guide will be even more helpful to beginners.

post #3 of 10
Thread Starter 
All of that was left out for the purpose of it not being 30 pages long. I will update it tomorrow with spoiler sections to explain perhaps.

Edit: and about lossy. Anything that is not bit perfect, is by definition lossy as it has lost information. By that reasoning all software mixing is Lossy, the thing we wish to avoid.

Also, as requested. Here is the reasoning behind pulseaudio instead of dmix for instance. Pulseaudio has to be installed anyway. Its not optional, dmix is. Many apps won't even output audio if pulseaudio is not detected as it is their only output method these days. Several video players are guilty of that sadly. I miss the days of plugins and dmix sometimes, but I also see the value of a universal mixer.

There are ways to increase audio quality as well as still use pulseaudio as its entire mixing interface is configured by a single file. The downside of course is still not bit exact audio, but also massive kernel io and CPU limitations. Much like jack.
Edited by yay101 - 1/15/14 at 10:07am
post #4 of 10
Quote:
 Edit: and about lossy. Anything that is not bit perfect, is by definition lossy as it has lost information. By that reasoning all software mixing is Lossy, the thing we wish to avoid.

 

Ok, I get you, thanks.

 

Quote:
Also, as requested. Here is the reasoning behind pulseaudio instead of dmix for instance. Pulseaudio has to be installed anyway. Its not optional, dmix is 

 

As a Slackware user I've never had to install it.  I'm guessing PulseAudio-by-default distros have all of the media/audio players in their repositories compiled to support it, but again I don't want beginners to have the wrong impression.  Even in those PulseAudio-by-default distros I imagine it's possible to get along without it.  If you want to assume that the reader's life will be easier the PulseAudio route then it may be prudent to include a list of popular distros that you know rely on PulseAudio more than others rather than this blanket statement.

post #5 of 10
Thread Starter 
That's a good point, I may add more information soon. The main problem is Pulseaudio is installed by default on a great majority of prepackaged distros. Even a lot of Arch's packages assume pulseaudio is present, and adding a flag for that on arch would be like 5 lines in a pkgbuild. Laziness I guess.
post #6 of 10

Readers may find the script I created useful for yay101 's excellent newbie guide.

 

With a single command, it lists all the hardware addresses for digital output interfaces of any soundcard (inclusing USB DACS) known by alsa, regardless of the existance of pulseaudio.

 

You can read about and download it here:

http://lacocina.nl/audio/detect-alsa-output-capabilities

 

Regards,

Ronald

post #7 of 10
Thread Starter 

That a really cool script ronalde, I am going to rewrite this guide very soon with a long and short version with the short version being "mostly" automated. Recent changes to the gnome stack and the release of the next ubuntu and mint builds coming up mean some things will change,  and possibly more people will shortly be looking for just this.

post #8 of 10
Quote:

Originally Posted by yay101 View Post
 

Q. Why can’t i just remove pulseaudio completely?

A. Most modern desktops have deep requirements for pulseaudio libraries, some only need a single “emulator” type library and pulseaudio is never actually on the machine.

 

I removed the pulseaudio server, and kept the libraries. This is enough to get rid of the mixing and pulseaudio related bugs/problems, but applications that depend on the libraries still run.

post #9 of 10

Finally. THANKS for helping me get this set up!

post #10 of 10
Thread Starter 

Updated for 14.04. As people have issues i will write specific guides for specific setups.

New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Computer Audio
Head-Fi.org › Forums › Equipment Forums › Computer Audio › [GUIDE] NEWB guide to Bit-Perfect Linux audio.