1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.

    Dismiss Notice

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

Discussion in 'Computer Audio' started by yay101, Jan 15, 2014.
  1. yay101
    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.


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

    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:
      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:

    The output on my machine is:
    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.
    For Alsa playback applications we provide hardware addresses in the form:

    So in my case it is:
    Setting defaults is the final step. Run the following in a terminal:
    I suggest cleaning out this entire file so it is blank then putting the below contents in.
    Simply replace the card and device numbers with the ones you found above.
    For instance my config reads:
    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:
    Change the autospawn line to read:
    That's it. No joke, you are done. Just restart your machine.
    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.

    drdiem, touramalli and aroldan like this.
  2. cheapous
    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
    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.
  3. yay101
    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.
  4. cheapous
    Ok, I get you, thanks.

    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.
  5. yay101
    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.
  6. ronalde
    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:
  7. yay101
    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.
  8. stv014
    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.

  9. runagt2
    Finally. THANKS for helping me get this set up!
  10. yay101
    Updated for 14.10. Still works fine for 14.04.
  11. aug_aug
    Great guide thanks!
  12. touramalli
    I know it's an outdated thread but being a guide I think it will be good to maintain it updated.
    I'm using Ubuntu 16.04 with gnome and if I specify the device in ctl.!default I can't change the volume or even open alsamixer. Deleting only this line works like it suppose to do.
    This extension (https://extensions.gnome.org/extension/835/alsa-mixer/) adds an icon in the top bar. With alsa the notifications don't work but I don't really care, the are useless after all.
    If you want to adjust the volume with your keyboard, the commands are:
    To check if it works, when you're playing something open a terminal and execute:
    You have to change the card number according with your devices and you can open the file with a text editor if you want.
    Edit: With that config I can't play html5 videos in Firefox but I found a solution:
    With these options you'll be using dmix but what I do is having it commented in the same file, and using it when I have to. Or you can do the opposite if you don't listen to music 24/7 like I do.
  13. noknok23
    the guide worked for me on arch with mpd. Super clear, thanks a lot. I think being able to change the volume digitally defeat the purpose of bitperfect but maybe i am wrong
    Last edited: Feb 26, 2018
  14. yay101
    You are correct noknok23, changing the volume digitally does defeat the purpose of bit perfect audio as it by definition has to do modifications to the stream to adjust the volume and calculate the new bits.

    HOWEVER the difference may very well be inaudible right down to less than half volume (when playing back 16bit padded to 24 or 32).

    It's person choice really, I like my bits as they are in the record all the way to the DAC. Others are welcome to disagree.
  15. drdiem
    Thanks so much for the guide @yay101!

    I'd assumed that setting Pulseaudio autospawn to no (last step in your guide) would disable it entirely, however (on my setup at least), it simply prevents it spawning on KDE Plasma startup and hogging all the soundcards; it still wakes up whenever an app specifically wants to use it.

    This was the last piece in the puzzle for me, because I wanted to retain the convenience of Pulseaudio for most stuff (web browsing, system sounds, watching movies in VLC etc.) whilst retaining pure ALSA-only bitperfect playback in gmusicbrowser. Whilst I'm not playing music, all sound is mixed via Pulseaudio, then when I want bitperfect playback I disable my USB DAC in Pulseaudio Volume Control, and gmusicbrowser can hog it and set any sampling rate the DAC can support. Volume is then managed only via the slider in gmusicbrowser.

    For those who're on this path, here's a few other tidbits I've picked up along the way that are of interest:

    - As per the current ALSA documentation, I do not have any ASLA configuration files at all; no ~/.asoundrc nor /etc/asound.conf file whatsoever. Instead, I configured gmusicbrowser according to Rizlaw's guide and ALSA does a perfect job of passing audio to the DAC without any further configuration.
    - Pulseaudio defaults to 48kHz internally and will up- or down-sample all other streams to that rate in order to mix them. That frequency was chosen since a. it is the DVD native rate and b. it divides well for other common rates (except 44.1, natch).
    - For reference, my setup is Gentoo linux with gmusicbrowser, KDE Plasma 5, Pulseaudio 12.2 and ALSA 1.1.6

    Thanks again @yay101!!

Share This Page