Make a DIY digital jukebox

Have you ever wondered what to do with an old computer sitting in a closet collecting dust? Why not create your own digital jukebox! This Do It Yourself (DIY) project will guide you through the steps to do just that with the help of Fedora and open-source software. In this article we will:

  • Explain the concept of real-time processing and why it is necessary in achieving bit-perfect playback
  • Give a step-by-step tutorial in configuring the kernel for real-time processing and optimizing the hardware for audio priority
  • Show you how to install the basic tools required for configuring and displaying your audio device (i.e. sound card, or Digital Audio Converter (DAC))

Before we begin installing and configuring the system we need to go through some basic digital audio theory to understand how the jukebox can achieve optimal sound performance.

DIGITAL AUDIO 101

The kernel must be configured for real-time processing, and top priority given to any audio request to provide crisp playback. This is done to reduce latency – the delay in time when the signal enters the system and is output through the audio device.

It’s best to experience latency with a fun experiment. With a friend in the same room, call their cellphone and talk. Notice the slight delay from the cellphone speaker?

This is because when talking to someone physically beside you, the audio is transmitted in real-time – a straight path from mouth-to-ear. If you’re using a cellphone, your voice (analogue) would first be converted into binary (digital). The signal would then be routed through the towers to the receiving phone. That phone would then convert the digital signal back into analogue for the listener. The processing of this audio causes a delay. This is latency.

The same goes for digital audio. The path that the audio packets travel from the source file to the audio device takes time. When we add layers and filters we add more processing and thus increase latency. This is why for the jukebox we are going to keep it simple and only use ALSA (Audio Linux Sound Architecture).

By eliminating Pulseaudio, or the Jack-Audio-Connection-Kit (JACK), we can keep the processing of audio data to a minimum. By sending the audio data straight to the audio device without additional processing, the path is significantly shortened and allows us to achieve bit-perfect audio.

What is Bit-Perfect?

Bit-perfect audio is the transmission of bits from the audio file (FLAC, MP3, OGG-Vorbis, &c.) to the audio device without altering the bit depth, sample rate, or number of channels. Bit depth refers to the number of bits in each sample: 16-bit, 24-bit, &c. The sample rate is the number of audio samples transmitted per second. For example, Audio CDs have a bit depth of 16-bit and a sample rate of 44.1 kHz, or 44,100 samples per second. High quality audio files have a bit depth of 24-bits per sample with a sample rate of 96 kHz or 192 kHz. Channels consist of: mono (1), stereo (2 – left and right), or surround sound (5.1).

In other words, playing a 24-bit audio file at 96 kHz on an audio device limited to 16-bits at 48 kHz playback is not bit-perfect. This is because the audio software, will have to convert the information, or down-sample the signal, into a format readable by the device during playback. For optimal sound quality it is best to let the audio device take care of re-sampling. This also minimizes the amount of CPU processing, keeping the kernel open for what really matters, transporting the audio information.

PREPARING THE JUKEBOX

Now that the technicalities are out of the way, we can fire up that old computer and start configuring the jukebox. First, download Fedora Server and perform a minimal installation. Enable administrative rights for the user account. If you need help with installing Fedora, consult the Fedora Project’s Documentation site. Once the installation is complete, update the system, install your favourite text editor (we will use nano in the examples), and reboot.

Configuring for Real-Time

Once you’re logged in, type:

sudo nano /etc/security/limits.d/20-audio.conf

This creates a file which dictates the priority of any audio request.

Enter the following in the file:

# Gives top priority to all audio requests
@audio - rtprio 99
# Gives favour to any audio requests
@audio - nice -20
# Allows unlimited memory access
@audio - memlock unlimited

Save the file and exit the editor.

Using these settings are safe because this is a dedicated device with a single purpose. For a desktop or workstation, the above settings can cause system instability. This is why Pulseaudio or JACK for these systems can make a difference.

Next we will add the user account to the audio group so that any audio software the user runs can take advantage of the settings we entered in the 20-audio.conf file. To do this run:

sudo usermod -aG audio user

Remember to replace user with your username.

Next, configure the I/O scheduler to minimize disk latency. The deadline scheduler works best for this task as it guarantees a higher priority for read requests. To see what scheduler the system is using type:

cat /sys/block/sda/queue/scheduler
noop [deadline] cfq

The square-brackets displays the I/O scheduler enabled on the system. If deadline is not in those square-brackets, open the grub configuration file:

sudo nano /etc/default/grub

At the end of the “GRUB_CMDLINE_LINUX” line, just before the end-quotes, type elevator=deadline and save the file.

To apply the GRUB configuration switch the user to root and type:

grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg

for EFI systems, or:

grub2-mkconfig -o /boot/grub2/grub.cfg

for legacy BIOS systems.

Installing the Audio Linux Sound Architecture:

To install ALSA do:

sudo dnf -y install alsa-lib alsa-utils alsa-tools

And reboot the computer.

To view the audio devices Fedora detected on your system type:

cat /proc/asound/cards

This will list the sound cards installed on your system.

0 [HDMI]: HDA-Intel - HDA Intel HDMI
HDA Intel HDMI at 0xf731c000 irq 49
1 [PCH]: HDA-Intel - HDA Intel PCH
HDA Intel PCH at 0xf7318000 irq 48

As you can see in this example, the HDMI (digital stream) is assigned to card0, and PCH (analogue stream) is assigned to card1. USB DACs compatible with Linux will appear in this list.

Congratulations, optimal sound quality is successfully configured. Tune-in to the Fedora Magazine for part two where we will install and configure XMMS2, and finalize the transformation of that old computer into a Digital Jukebox.

Fedora Project community

17 Comments

  1. dowatuwant

    Nice DIY project!
    Next up is figuring out how to do the exact same with Debian-based distros such as Ubuntu and Linux Mint, and accounting for any differences in package downloads and configuration steps.

  2. Jason Gray

    Latency is only an issue when recording, and has no effect in and of it self on the “bit perfectness” of the audio. Even then it only really matters if you’re software monitoring and/or recording on top of backing tracks. You are also incorrect in your assumption that hardware resampling in your DAC is better than software resampling before the hardware. Unless your DAC has DSP capabilities if you don’t resample it in software the driver will… in software, or not at all maybe. Best case you get really crappy resampling, worse case the DAC won’t be able to play the audio at all. If the audio doesn’t match the hardware your best bet is software resampling before the hardware. If you want bit perfect audio rip your CD’s to FLAC’s without oversampling them, get yourself a good 16/44.1 DAC and configure PulseAudio and ALSA for 16/44.1. That way everything that’s 16/44.1 will passthough unmolested and everything else will get resampled to 16/44.1 so your DAC doesn’t choke on it.

    • Hi @Jason.

      I see the oversight in the article where it blurs latency with bit-perfect. The sentence begining with, “By eliminating Pulseaudio…” should be a new paragraph. Thanks for pointing this out and I will ask the editors if we can fix that to avoid confusion for other readers.

      It’s true that latency is a primary concern, and more apparent, with audio recording. However, the ALSA project states that, “latency is inherent when processing audio in the digital domain” (http://www.alsa-project.org/main/index.php/Low_latency_howto). Also, there are different types of audio latency and the Android Developer’s site explains this at https://developer.android.com/ndk/guides/audio/audio-latency.html. On my Fedora desktop I use JACK for RT playback because the settings I described in the article can cause instability with the desktop. With JACK I can hear noticeable improvement in audio playback between 180 ms latency and 9.0 ms latency. For example, the drums in the beginning of Since I’ve Been Loving You, by Led Zeppelin, has more punch and the sound of the instruments are more definitive. I can hear the drumsticks hitting the skin and producing the sound. Using the default Pulseaudio and Rhythmbox, I find these tiny details are lost.

      ALSA, by default, re-samples to 48 kHz if software mixing is enabled in the application (https://wiki.archlinux.org/index.php/Advanced_Linux_Sound_Architecture#High_quality_re-sampling). By sending the information straight to the hardware and bypassing the software mixer, ALSA will direct the audio as-is to the audio device without tainting the source. We cover this in Part Two by configuring the audio player to bypass the software mixer. We also show how users can verify that the samples are sent to the the hardware untainted. To achieve this with a desktop/GUI audio player, check out https://www.head-fi.org/threads/bit-perfect-audio-from-linux.561961/#post_7596268. It may reference some outdated software but the concept and app configuration is still relevant. In the case of Rhythmbox and Pulseaudio, the default audio player and sound server in Fedora Workstation, ALSA will re-sample the audio.

      Most of the DACs I’ve seen have a max resolution and max sample rate stated in their technical specifications and can sample audio at lower rates without having to do any conversion. The KORG DAC (https://www.thomann.de/ie/korg_ds_dac_100m.htm) and this Benchmark DAC 3L (https://benchmarkmedia.com/collections/digital-to-analog-audio-converter/products/benchmark-dac3-l-digital-to-analog-audio-converter#top) are just a couple of examples. If the DAC up-samples the audio, then the process for up-sampling through the software may be redundant. For example, if a user plays audio at 16/44.1 kHz with ALSA/Pulseaudio using the software mixer, then ALSA automatically converts it to 48 kHz. When the stream enters a DAC which automatically converts the audio to 96 kHz, that audio data is again re-sampled.

      The reason I stated in the article that the 20-audio.conf settings are safe is because this is a dedicated machine that only performs one task, playing music. Think of it as transforming the computer into an appliance. Using these settings for a desktop machine will certainly cause instability and I highly recommend against using these settings with such an environment. This is why the article says to perform a minimal installation of Fedora Server. This avoids additional, and unnecessary, software from being installed, and additional processes from being loaded. I have an old MacBook 4,1 that I use as my jukebox. It is configured with these settings and I have not encountered any instability with audio playback. The computer is also running as an NFS-server and I’ve yet to encounter any performance or stability issues.

      Thanks for the feedback. It helped to clarify some technicalities that seem lost in the article.

      • Jason Gray

        Audio output latency = Not important, unless it’s huge. Most off the shelf soundcards are capable of sub 200 ms if not sub 100 ms Audio output latency pretty easily. Unless you notice a delay between user input events and audio output it’s nothing to worry about. Any difference in sound you notice is because you’re not processing the audio with PulseAudio. It has nothing to do with the latency. If anything a little bit of latency is a good thing in a playback system and helps prevent drop outs(distortion, clicks, pops).

        Audio input latency = N/A

        Warmup latency = 1 time cost ideally. Not really a factor, at least not one you can control.

        Touch latency = Also not really user controllable. I’ll heap this into “UI latency”, along with actual application latency, disk latency and so on and so on…

        So you’re Total latency(the time between you physically clicking the mouse and you hearing sound) is really just UI latency + Audio output latency.

        Unless there is something wrong with your system latency isn’t going to be an issue. Even if it is it’ll be a UX issue not a audio quality issue unless you set it to low and get drop outs ofc.

        I don’t upsample audio. I have a decant 16/44.1 DAC. I was explicitly telling you if you want easy good quality audio way just configure both ALSA and PulseAudio for 16/44.1 and DOWNsample everything else.(assuming your audio started as CD’s) as I said that way 16/44.1 passes though unprocessed.

        I worry that you really don’t fully understand what you’re talking about and are going to lead would be users down a long hard road to no benefit. And that most if not all of your precised sound quality gains are confirmation bias. After all you tweaked your system so much, it HAS to sound better…

      • Jason Gray

        If you want to set up a simple “music appliance” then just install and configure mpd and configure ALSA for 16/44.1(assuming again your audio started as CD’s and you didn’t foolishly upsample it when you ripped it) and set it DOWN sample everything else or if all your audio is the same set ALSA to that and forget it. 99% of soundcards support 16/44.1 naively so your soundcard more than likely will not resample it. RT is WAY overkill. A RaspberryPi with a stock kernel can process audio just fine without all those RT tweaks surely your server is more powerful than a Raspberry Pi? What you’re doing by giving real-time priority to audio just for the sake of shaving off a few milliseconds of latency is pointless, and does nothing to improve audio quality, on the contrary what it does is makes everything not audio a 2nd class citizen for no reason.

        • PitDog

          Would love to see some bare bones how-to’s from this writer!

          • Jason Gray

            For a Music Appliance here’s the easy way.
            1. Buy a Raspberry Pi and a USB DAC that fit your budget and needs(there are also DAC HATs).
            2. Download either Volumio or RuneAudio.
            3. Follow their docs/HowTo’s on how to set it up.
            4. Enjoy high quality audio.

  3. Hans Meiser

    Thanks for the explanations!

    I am a bit afraid this is an exercise reinventing the wheel. There is many good GNU audioplayers out there that work well on ARM (raspberry +DAC) and X86_64 hardware (your old PC with sound card).

    One of the distributions I use regularly is Volumio (volumio.org) – and it works like a charm, plug and play. No fiddling around, and you get a bit-perfect audio. (To be fair, I’d like to mention Rune Audio and Moode Audio players as well).

    • Thanks for the comment @Hans. I agree there are other distros/packages that provide an out-of-box experience – Audiophile Linux (http://www.ap-linux.com/) was the first I experimented with. The article was meant to show an in-depth look at some of the configurations used by these distros. An opportunity for the “do-it-yourselfer” Fedora audiophile to tinker and experiment on a rainy-day, starting from the ground up.

      I’m glad you mentioned other distros like Volumio. I looked at their site and found the architectural design they’re using for audio playback very interesting – especially with the implementation of Sox with Jack. It would be great if someone could provide a similar out-of-box experience using Fedora. I hope other readers can take the feedback you’ve provided and build upon the concept of this article with their own project.

      • PitDog

        Shaun you are raising intriguing points but I am surprised you express these tweaks as something for people new to Linux. Regardless I concur with your curiousity about new applicaitions and will check some of these out. But hey, why is there no mention in this thread of Fedora Jam? Maybe I am missing here and should lurk more before posting but it seems that and Ubuntu Studio address a lot of the issues of concern herein by including a veritable Christmas tree of enticing applications which are presumably integrated and tweaked to a decent compromise.

  4. Brian Vaughan

    All you need to do to make an old computer into a “digital jukebox” is plug in some speakers, boot it up with the LiveCD version of Fedora or any Linux distribution, and start the default media player.

    This article went out of its way to make something very easy seem very hard.

    • @Brian: Maybe wait for Part Two to see what the author had in mind for the concept?

    • Jason Gray

      I totally agree. Not to mention the fact that giving audio unlimited memory and the highest priority is not a good idea. Unless you enjoy other application freezing for a slit sec when songs start or a misbehaving audio driver eating all your RAM? It also fails to mention that by default ALSA resamples audio… The default sampling rate I believe is 48000? So unless your audio files are 48000 with the above configuration you will NOT get “bit perfect” audio. You will get fast but questionable quality resampling from ALSA.

    • This is true @Brian, but unfortunately the LiveCDs are not configured for optimal sound quality out-of-the-box. This guide addresses the technicalities of tweaking the system for such quality and is targeted to “do-it-yourselfers” who may be new to Linux, and want to make their own from the ground-up. It gives them an opportunity to learn, the empowerment that they can achieve, and the freedom to configure their system to their liking – all of which makes Linux/Fedora a great kernel/OS. As @Hans mentioned, there are distros that provide such out-of-the-box experience and yield similar results (volumio.org and http://www.ap-linux.com/ are some examples).

      Your comment has struck a splendid idea with regards to the LiveCDs. It would be awesome if someone could take the concepts of this article, improve it, and create a Fedora livecd that provides an out-of-box experience. Or maybe a script that automates the configuration process. Volumio is based off Debian and Audiophile Linux is based off Arch Linux. I think it would be great if the Fedora community had one.

      Thanks for the feedback.

  5. Galaad

    Thanks a lot,
    Can’t wait part 2 🙂 this exactly what i’m waiting for, a bit perfect audio player.
    hope next part will show a nice interface in order to use it easily.

  6. PitDog

    This is making it way too complicated and to now have to wait for part two imposes really just another constraint on the usability of this article which I had bookmarked. But now it is mostly interesting from an academic perspective as my digital jukebox will remain whatever my oldest computer I have not given away to a need person and I am perfectly happy running the various audio players in all the repos of all the linux flavors. When I get back into recording I might do some research but just for playback i don’t want to ruin a computer, any computer hooked up to speakers is inevitably pressed into service for other functions from time to time, such as recording or surfing the web to download more music.

Comments are Closed

The opinions expressed on this website are those of each author, not of the author's employer or of Red Hat. Fedora Magazine aspires to publish all content under a Creative Commons license but may not be able to do so in all cases. You are responsible for ensuring that you have the necessary permission to reuse any work on this site. The Fedora logo is a trademark of Red Hat, Inc. Terms and Conditions