Hacking your Linux computer for a better listening experience

No readers like this yet.
music infinity

Opensource.com

In this article, I am going to focus on the hardware, software, and configuration issues that we Linux laptop users must confront in order to really enjoy that wonderful digital music on our hard drives.

Some background

Let's say you have a laptop running a late-model Linux distribution (Fedora, Ubuntu, openSUSE, Arch Linux, Linux Mint, Debian, etc.). In all likelihood, the distribution you installed includes a default application for playing music.

For instance, if you're running the GNOME desktop under Fedora, you probably have Gnome Music installed; if you're running the Unity desktop on Ubuntu, you likely have Rhythmbox in place. Or you might have a favorite player you install on your system that provides you with a set of features you find comfortable or maybe even indispensable.

You probably have some music files organized in your Music folder in your home directory, perhaps by artist then album. You also probably have some headphones or earphones or desktop speakers you use to listen to your music, and to use those you likely plug them into the headphone jack on your laptop.

Assuming all of that is true—and that you aren't plagued by weird configuration issues or unsupported hardware in your laptop—you can enjoy to the music you have put on your computer. And since this isn't an article about troubleshooting hardware/software incompatibilities, nor about "the best Linux music player ever," what more is there to say?

The problem

Well, it turns out that if you take your listening seriously and spend your cash on high-quality music or carefully rip your CDs (or LPs!) to digital, then using the default Linux audio processing chain to play your music leaves something to be desired. This is because your typical modern Linux distribution offers a really complex and general purpose audio processing chain with the goal of taking care of all the various sound-related processing chores that can happen on a modern computer: recording and playing back sounds, sound alerts, mixing, DJing, internet telephony, watching videos (with the sound synchronized to the video), and so on.

You can learn more about this amazingly elaborate audio processing chain in these three articles.

The solution

By focusing on the single task of playing music—and by spending a little bit of money on hardware—we can set up a dedicated music playback environment that ensures the bits in the music file are the bits that get to the digital-to-analog conversion process and thence to your ears, maximizing your opportunity to hear what was originally recorded.

The first thing we need to talk about is Pulse Audio. Chances are, your Linux laptop has this installed and uses it to manage various aspects of the sound recording and playback process. When Pulse Audio first appeared lots of people had lots of problems with it, but these days it seems to work quite well and handles things like mixing the audio stream you've tuned in from your browser with audio alerts and any other important sound events. However, one thing Pulse Audio does that we don't want done is resampling your data to its preferred output resolution.

So, we will take advantage of the Advanced Linux Sound Architecture (ALSA) audio pipeline that most often sits below Pulse Audio. Specifically, we will do this by connecting a second sound card that we will use for music-only purposes. We will send our music directly to ALSA, bypassing Pulse Audio along the way and encouraging Pulse Audio to manage the internal sound card.

This approach—two sound cards, one dedicated to music, the other left to general-purpose audio chores—has some great advantages. First, it meets our goal of having a streamlined and "bit perfect" audio pipeline dedicated to playing music. Second, it means that other sounds still appear in your laptop speakers or on your headphone-out jack, rather than getting mixed into your music. Third, it lets us select hardware developed especially for high-quality music reproduction and that can be selected to complement the electrical characteristics of your headphones or earphones.

Choosing a setup

I'm going to dive right into a concrete example that will provide the basis for understanding all of this. My laptop is a 2013-vintage System76 Gazelle Pro. According to the du utility, I currently have 180Gb of data in the Music folder in my home directory. When I want to listen to this music, I use the Guayadeque music player and I plug a Schiit Fulla digital-to-analog converter and headphone amplifier into one of the USB ports on the laptop. When I am traveling, I use a pair of Shure SE215 in-ear monitors to listen. If I am home, I am more likely to use my trusty AKG K701 headphones. Time to explain some of these choices and mention some alternatives.

Music player

Guayadeque music player screenshot

Why the Guayadeque music player? The main reason is that it can be configured to pass output directly to the ALSA hardware device interface, thereby bypassing things like software mixers and resampling code that has the potential to modify our music in ways that aren't necessary, given that we are dedicating audio hardware to its reproduction.

Besides that important reason, Guayadeque is, in my opinion, a very nice Linux music player. It's fast, it handles my medium-sized music library well, and it has lots of great features. But it's not everyone's cup of tea, and there are alternatives that, while providing a different set of features, also allow the user to send music directly to the ALSA hardware interface. One such is GmusicBrowser; another is QuodLibet. Another interesting choice is mpd; I'll talk about that one in a future article on home music setups.

Digital-to-analog converter

Why the Schiit Fulla digital-to-analog converter? First of all, it plays well with Linux. I have some experience with other digital-to-analog converters and I can claim with certainty that such is not always the case. Second, the Fulla is not terribly expensive at $79 plus shipping. Third, once again my personal experience is that the good people at Schiit make nice, reasonably priced equipment and provide great after-sales service. Fourth, the Fulla handles the music playing chores I want it to manage: it plays music files at the various resolutions and bit rates that occur in my library (from 16-bit 44.1kHz CD-sourced files to 24-bit 96kHz downloads from my favorite vendors). Fifth, it drives both of my headphones well and sounds very good doing so.

Having said that, there are alternatives. A quick search at your favorite online merchant will turn up a wide range of USB-based digital-to-analog converters at various price levels and with various features. One that I own and like in principle, but that has caused me some difficulty depending on the Linux kernel in question, is the AudioQuest DragonFly. I like it because it has a software-controlled analog volume control and because it supports the same wide range of resolution and sample rate as the Fulla. However, it is more expensive and I have had problems with Linux connectivity in some cases. My son has a Fiio product (no longer in production) that plugs into the USB port on his System76 laptop, works fine with Linux, and gives him decent audio, including higher-than-CD quality. Another one that intrigues me is the Geek Out; again more expensive, and I'm not sure about Linux compatibility, but it also supports higher-than-96kHz sampling rates and DSD. Has anyone tried this with Linux?

Which reminds me—if you're trying something that is not known to be compatible with Linux, try to buy it somewhere that will let you make sure it works before you pay. You need 15-30 minutes with the device to make sure of its compatibility. Look in the log files to see if you see any strange errors when you plug the device in or when you start playback. Look in /proc/asound to make sure that files are playing at the resolution and bit rate that you expect. And make sure the gain is correct for your headphones or earphones.

Headphones and earphones

With regard to headphones and earphones, I won't say a lot except that if at all possible, try before buying.

Comfort is important. Also, different people seem to have a different idea of what sounds good when it comes to headphones, which may be related to interactions with the physical structure of the ear. I find both my AKGs and my Shures are very comfortable and sound great. There is some really interesting information on headphones, earphones, amplifiers, and digital-to-analog converters at Inner Fidelity, including test results for those who aren't satisfied with the idea of critical listening. Of course, most headphones are compatible with all Linux distros.

In the end, I suppose lots of people wouldn't notice these differences or wouldn't care if they did. In my case, listening carefully is a key part of my enjoyment of recorded music, and it is facilitated by having good equipment properly configured for the job at hand. My laptop-based system gives me the chance to enjoy my music while I'm working away from home, or at home without bothering the rest of my family. If you love your music, give it a try!

Chris Hermansen portrait Temuco Chile
Seldom without a computer of some sort since graduating from the University of British Columbia in 1978, I have been a full-time Linux user since 2005, a full-time Solaris and SunOS user from 1986 through 2005, and UNIX System V user before that.

31 Comments

I would say that PulseAudio is still a problem, specially in multi user environments and it's not the only application which has multiuser issues, sadly there is quite many developers out there who do not think about multiuser environments, don't test that they application works properly as they sit all alone on their Linux machine.
Another issue is crappy sound hardware as HDA, sadly those who make Linux friendly hardware has jumped on the crap audio hardware train too, I would like to see more bold enough to use audio hardware with hardware mixer.
I still think OSS with SoundBlaster16 was far better than my audio with PulseAudio and HDA.

Martin, thanks for your comment.

It could be useful to others who read this column if you could briefly elaborate on the problems you mention with respect to Pulse in a multi-user environment (or provide a link to such a description), especially if there are known work-arounds.

WIth respect to audio hardware, do you think it's a lack of boldness that keeps manufacturers away from hardware mixers? I wonder if audio hardware is generally seen to be a place to economize...

Anyway, for those seeking good quality results from their music, I don't advocate mixing other sounds into the music stream, whether with hardware or software mixers.

In reply to by Martin (not verified)

In my case I have always one user logged in for each family member, so it's just to switch to your session to continue what you were supposed to do. audio usually works for all users at the beginning, but soon all the other uses except the first logged in are using the dummy device instead and no sound and restarting personal pulseaudio will in most cases not help, you have to see to terminate all pulseaudio and audio using applications.
This ain't just on one system but happen on multiple systems where all audio is handled by pulseaudio.

Sure you don't want to mix things when you are listening to your music, but you may not want to miss that notification either as you are waiting for while you listen, you have the option to mix it or have it like Jolla Phone and stop all other audio to give the notification and let you miss a part of what you are listening to.
When you mix, you have the option to do it in hardware or software and soundcards with a hardware mixer tend to work far better in my experience, but sure computer makers who can't afford to spend 2 cents for a CDRom audio cable, they will not spend a dollar more for better audio either.

In reply to by clhermansen

Martin, thanks for the additional info.

At home, we have a shared computer much like you describe, with logins for five of six family members (the dog does not yet have a login, I am somewhat ashamed to say). Having said that, I don't believe too many of us use that computer for listening to music or watching videos, and so I cannot recall us having the kind of problem you mention with the audio being hogged by one of the users. It sounds frustrating and I bet it happens most often when it's not the sysadmin logged in :-)

I DO remember such a thing happening with CD-ROMs or USB sticks or some such mountable media, at least awhile back.

I get your point about notifications and the like. I guess it all depends on the compromises we are willing to make as individuals to approximate our house full of telephones, doorbells, and record players within the confines of a single computer interface. I guess in my case I don't want the music passing through some kind of mechanism that exists just to let me hear the equivalent of the doorbell or telephone in my headphones; but I can understand that lots of people might prefer to have things work that way. What seems marvellous to me is that we have both options available to us.

As to manufacturers saving costs, I find it weird that many of them present their products as though they had really high-quality audio built in, when in fact they really don't. My System76 Gazelle Pro for instance - and I really, really like System76 and their products - has a "THX" sticker on the wrist-rest, but I can tell you that the sound coming from my laptop's hardware is nothing like the THX in a theatre (even THX home theatre). And I see various computer products with "sound by XXX" where XXX is some well-known manufacturer of quality sound products, but those computer versions of things don't in my experience measure up to the expectations generated by the label. Oh well.

In reply to by Martin (not verified)

It seems to me that most people who are really concerned with high music quality, especially for headphone listening or in a quiet room alone, get a dedicated sound card rather than using Intel's built in 'HDA' audio. That goes double for anyone making recordings.

In reply to by Martin (not verified)

Great article. It's on my list of upgrades to get a really nice sound card. As a Slackware user, I don't have Pulse to contend with, but I'd like the flexibility of an additional card and higher quality. Thanks for the overview!

Great article. You have given me a new appreciation for the beauty of Linux.

I am using vlc. Any comments on this versus the players you favor?

Good question, alciblades!

I just plugged in my Schiit Fulla, installed VLC and took a look at the configuration.

VLC immmediately offered the Schiit on the Audio > Audio Device menu, which seemed like a good sign.

I also took a look at Tools > Preferences > Audio. There I was able to set my audio to pass directly through to Alsa (as well as other options). Below that is a drop-down that allowed me to select the device, which I set to "USB Audio Direct hardware device without any conversions".

There is also a checkbox for "Enable time stretching audio" which sounds to me like some software mixing to make audio match video. I would probably disable that if I were just going to listen to music.

So far so good. Then I selected some high-res music ("Invisible Origins" / Beaten by Them) and pressed play, and good! I had music. I took a look at /proc/asound/Schiit/stream0 and it seemed to me that it was working ok. So I switched to another high-res album ("August and Everything After" / Counting Crows), and minor disaster struck - music started coming out of the laptop speakers rather than the Schiit / headphones.

I fiddled all the settings controls I could and nothing changed, so I closed VLC and then re-opened it, this time on a 96/24 "Highway 61 Revisited" / Bob Dylan, and music again came from the Schiit / headphones. The music also "paused" briefly at one point, which was weird.

So I switched to a 96/24 "My Aim is True" / Elvis Costello, which also played fine through the headphones.

I briefly listened to the same two Costello tracks on Quod Libet through the same hardware settings and didn't notice anything different. However given the problems I found, I would want to dig into the VLC thing further if I were planning to use it more often.

With respect to VLC on its own, I used to use it for watching DVDs and always found it reliable, but from my very limited experience it is not the best tool for browsing and organizing your music. For instance, both Quod Libet and Guayadeque offer tag editing and a more tag-oriented view of the music, rather than the filesystem structure view that seems to me to be VLC's only option. With them you can do things like sort your view by album title or artist without reorganizing your filesystem structure.

I should emphasize that I'm no kind of VLC expert; these are just my barely-informed reactions to trying it out. If you have other info to share, please do!

And thanks for the comment!

In reply to by alcibiades (not verified)

Elementary. If you make changes to VLC preferences, it's best to exit VLC and restart, to get the full effect - it's often not immediate.

In reply to by clhermansen

Thanks for the additional information, Somewhat Reticent!

In reply to by Somewhat Reticent (not verified)

If you change VLC settings, best to exit and restart VLC. That simple.

In reply to by clhermansen

At first, I couldn't understand why you would want 2 streams of music from one source. But after reading the article, I could see why. I am what some call an audiophile as I spent most of my adult career in home automation and 2-channel stereo setups. However, for someone who travels or wants to not disturb everyone, this is a great alternative to having dedicated equipment. Great read!

Thanks for the comment, BJ Maynard!

I hope it's clear now that what I want (and what I have) are two streams of sound - one that carries what I would call mostly junk sound - noisy web sites, sound alerts, that kind of stuff, plus VOIP calls; and one that just carries high quality music.

I should also mention that I don't always have the second (external) DAC plugged into my laptop; I only plug it in when I'm planning to play music, mostly through my headphones. Though last summer I borrowed my daughter's AudioEngine powered speakers to take on a vacation, and that was also a fine combo.

Anyway, I'm delighted that you enjoyed the article! Thanks for the feedback.

In reply to by bmaynard

The article makes a suggestion which is often useful: to use an external digital-to-audio converter which is operating directly on the bit stream from the source rather than by way of the computer's digital volume control and its computer's sound card's analog output.

Most importantly, this can avoid contamination of the analog audio signal by electrical noise from inside the computer. This is commonly audible. The computer's filtering of the analog output to remove ultrasonic components of the analog signal resulting from sampling also may not be of the highest quality, resulting in uneven frequency response, remaining ultrasonic components or analog distortion. Sending the computer's notification beeps and chirps to a different output also can be very useful, especially when broadcasting the programming.

Less importantly, an analog converter can avoid the slight degradation of the digital signal by digital resampling to adjust volume (which the article's author seems to think is most important).

Whether the degradations are actually audible is another question. It will depend on the quality of the audio components of each particular computer. There are many "tweak" audiophiles who claim to hear things which understanding of psychoacoustic limits, confirmed by double-blind testing, show to be inaudible, or in fact don't exist at all. (One claim I've heard of is that bit-identical recordings sound different depending on what hard drive they are played from -- that kind of nonsense.) This is often in connection with promotion of overpriced products.

Whether this is worth the trouble with the need to carry a dongle for a portable computer, is another question. Many people now get their portable audio from a cell phone, and then the dongle is proportionally even more of an inconvenience. The cell phone will need special software to output sigital audio through its USB port.

I have had a variety of experiences. My laptop's audio output is clean but may have some treble roll-off. My tower computer often injects low-level audible grunge into its analog audio output. I drive a rather large sound system from my cell phone's headphone output in a friend's basement where I am working on a project. It sounds great as long as it's connected by wi-fi and the cell phone radio doesn't radiate interference into the amplifier. (Put the phone in airplane mode and turn off "notifications" but then turn on wi-fi.)

The article makes a suggestion which is often useful: to use an external digital-to-audio converter which is operating directly on the bit stream from the source rather than by way of a digital volume control and the computer's sound card's analog output.

Most importantly, this can avoid contamination of the analog audio output signal by electrical noise from inside the computer. Also, the computer's filtering of the analog output to remove ultrasonic components of the analog signal resulting from sampling also may not be of the highest quality, resulting in uneven frequency response, remaining ultrasonic components or analog distortion. Sending the computer's notification beeps and chirps to a different output also can be very useful, especially when broadcasting the programming.

Less importantly, an analog converter can avoid the slight degradation of the digital signal by digital resampling to adjust volume (which the article's author seems to think is most important).

Whether the degradations are actually audible is another question. It will depend on the quality of the audio components of each particular computer. There are many "tweak" audiophiles who claim to hear things which understanding of psychoacoustic limits, confirmed by double-blind testing, show to be inaudible, or in fact don't exist at all. (One claim I've heard of is that bit-identical recordings sound different depending on what hard drive they are played from -- that kind of nonsense.) This is often in connection with promotion of overpriced products.

Whether it is worth the trouble with the need to carry a dongle for a portable computer, is another question. Many people now get their portable audio from a cell phone, and then the dongle is proportionally even more of an inconvenience. The cell phone will need special software to output digital audio through its USB port.

I have had a variety of experiences. My laptop's audio output is clean but may have some treble roll-off. My tower computer often injects low-level audible grunge into its analog audio output. I drive a rather large sound system from my cell phone's headphone output in a friend's basement where I am working on a project. It sounds great as long as it's connected by wi-fi and the cell phone radio doesn't radiate interference into the amplifier. (Put the phone in airplane mode and turn off "notifications" but then turn on wi-fi.)

John S. Allen, thanks for the comments.

I agree with your perspective on noise and general problems with unnecessarily degrading the audio. The inside of a computer is a noisy place and that's just not compatible with generating clean, quiet analog output.

I wouldn't say i think a digital volume control is a bad thing per-se. I just appreciate the use of an analog volume control in a lower-cost and compact device like the DragonFly or Schiit Fulla.

I also like your point about audio on the cell phone. To me, there is a theoretical perfect cell phone accompanying device that provides: 1) a high quality DAC; 2) a bunch of extra storage for more music; and 3) more battery life. In fact I think someone is building such a thing - is it the GeekOut folks?

In reply to by John S. Allen (not verified)

Good article. Do you recommend two sound cards for desktops? If yes, recommendations for internal sound cards?

Thanks for the compliment, Randy.

If you are going to use your computer for general purpose desktop work and to drive your headphones, powered speakers or home stereo, I definitely recommend a second sound card or otherwise dedicated digital-audio converter for the music stream, both because the built-in equipment isn't usually very good and because - in my opinion - it's better not to mix all the other audio going on in your computer onto your music stream; that just downgrades your sound quality in your music stream. However, if you want your audio alerts and VOIP calls going through your home stereo, then by all means use the same sound hardware for everything... nevertheless, it's probably still worth upgrading your audio hardware.

A few years ago I put an ASUS Xonar DX sound card in my main work desktop so that it could handle higher-resolution music data (up to 192KHz / 24 bit). The Xonar DX is not a bad unit; it doesn't cost a ton, it is pretty flexible and the sound quality is decent. Two caveats, though: when it switches to a different sampling rate, through the analog output a fairly noticeable but very brief burst of noise can be heard, which cannot be particularly good for headphones or other downstream equipment; and its S/PDIF output is limited to TOSLINK.

Besides that unit, I have read good things about the higher end Xonar products. There is also an internal sound card called the Juli@ that seems to be oriented to high quality music and liked by the people who review such products professionally.

These days, however, I would probably tend to lean to a USB-connected device. This isn't because I think USB is a better interface than S/PDIF, but because there are always USB ports available and much less often S/PDIF electrical or optical. Also, S/PDIF doesn't seem to be supported for the other digital audio standard, DSD; nor for the super-duper high resolution audio becoming available these days (352.8 and 384 KHz). There is reasonably priced noise filtering gear that can be used to reduce noise issues if those happen to intrude. FInally, there are some good quality USB digital audio converters starting around US$100-150 that I believe provide better audio than any internal sound cards do for similar prices (for example the Schiit Modi 2, the AudioQuest DragonFly). At least from my experience.

I hope this helps! If something's not clear, let me know.

In reply to by Randy (not verified)

Of course, it would be nice to know how to make pulseaudio behave ...

Somewhat Reticent,

From my perspective, for Pulse Audio to "behave", I would prefer to either tell it that it must not manage a certain sound device (and then bypass it through to ALSA) or be able to tell it that it must not resample nor mix nor otherwise mess with a certain sound device. There is a "passthrough" setting in Pulse and that setting MAY permit the latter but I haven't investigated. And of course it may be possible to do the former as well; I just don't know. One day perhaps I'll dig into the matter further.

In reply to by Somewhat Reticent (not verified)

When I have a permanent setup and am interested in high quality audio I generally run the digital output from my motherboard direct into my home theatre amplifier and let it do the digital to analogue conversation, I guess though most laptops can't do this outside hdmi

Simon Lees, thanks for the comment.

I'm not certain my goal of a dedicated high-quality stream for music can be realized that way. Can you configure your HDMI or S/PDIF out from your computer to be dedicated to music, with no mixing of other audio and no resampling?

I realize for some that having all audio coming through a given interface is desirable. But not for me.

In reply to by Simon Lees (not verified)

Im running a Cambridge DacMagic Plus USB DAC with linux for my stereo setup and a Denon DA10 battery powered DAC for my headphones with laptop/android :) As long as a device is USB 2.0 capable (asyncronous transferes) you'll get 24bit 192khz sounds working like a charm :)

esac, thanks for the comment!

Great to hear of your positive experience with these two devices. However I can't be as optimistic as you about "any USB 2.0 capable device" working flawlessly; I really think it's safer to try the device in question if at all possible before buying it, or making sure that the vendor will accept returns if the device proves incompatible.

I probably should have mentioned in my article that reviewing the alsa-users archives over the past year will give some good ideas as to the kinds of problems that arise.

http://www.alsa-project.org/main/index.php/Mailing-lists

In reply to by esac (not verified)

For home audio, I think you have to go a long way to beat a Raspberry Pi coupled with an IQAudIO PiDAC+. Nice clean sound, that appears perfect to my ears.

I think it makes better sense to use a digital audio (S/PDIF) output to an external DAC. Because this is a standard electrical format, there are no operating system compatibility issues so long as the output interface is supported, which it normally is. Most sound cards have the output and many computers intended for multimedia use have it on the system board. Since the output is digital data, the quality of the interface is not very important, so a cheap sound card can be used if it has the necessary output. It works fine with PulseAudio once it is properly configured. The digital volume should be set to 100% output.

The output can be optical fiber or coaxial electrical. Optical is best since it completely isolates the downstream audio system from all of the electrical noise generated by the computer. Coaxial works fine but can have hum and noise problems. Using a USB output also has the hum and noise issue plus it can have timing problems in an multi-tasking environment and the device has to be properly supported by the system.

Gefen makes a nice little DAC for about U$80 although if you are serious about audiophile performance you would want something better. Audio Advisor has a large selection over a wide price range. There are an increasing number of integrated amplifiers available with built-in DAC's from Peachtree Audio, Parasound and others.

Mike Hughes, thank you for your comments.

I have a more recent article oriented toward the "home setup", at

https://opensource.com/life/16/1/how-set-linux-based-music-server-home

if you feel like it, please add this comment there.

A few points in response to your comments:

I too like S/PDIF but it's not generally available on laptops, which was the focus of this article. Conversely, I cannot think of a computer that doesn't have a USB interface or two... Also, for those who want to experiment with DSD, DXD and other formats, it seems that S/PDIF support for those is not a given (or maybe even possible), whereas with USB it is. Also, it seems that USB "asynchronous" transfers can get around the timing issues.

Thanks again!

In reply to by mhhughes

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.