Make a DIY digital jukebox: Part 2

Welcome to Part 2 of a DIY digital jukebox project. Part 1 of this project addressed how to tweak the system to provide optimal audio performance. With a minimal installation of Fedora Server, the system focused on doing one thing: playing audio. The article covered how to configure audio processing with real-time priority and enhanced disk response time with the I/O scheduler to aid with audio data delivery from the hard drive. It also touched on what bit-perfect playback is, why it’s essential to maintain the purity of the audio source, and how to avoid tainting that data on its way to the hardware. All these contribute to achieving that crisp sound demanded by audiophiles.

This guide provides “do-it-yourselfers” who may be audiophiles and new to Linux the resources and collective information to build their own audio transport system from scratch. Part 2 completes the transformation from computer to appliance. You’ll learn how to:

  1. Install common open-source codecs like FLAC and Ogg-Vorbis from the official Fedora repository
  2. Install and configure the XMMS2 software
  3. Configure XMMS2 systemd service and open TCP ports via Firewalld
  4. Connect the client to the digital jukebox
  5. Test for bit-accurate playback via the command-line

Installing the codecs

To play your audio files you must install some codecs. This article only covers popular, open-source codecs available in the official Fedora repository. To install non-free or legally encumbered codecs, you’ll need to use third-party repositories.

To play FLAC, Vorbis and MP3 files, run this command using sudo:

sudo dnf install flac vorbis libmad

Installing the XMMS2 server software

For server/client software you’ll use XMMS2 (X-Platform Music Multiplexing System 2). XMMS2 is a framework built specifically for audio processing. XMMS2 is modular by design and has a variety of plugins to expand its capabilities. These plugins apply to audio transport, decoders, effects, output, and importing and exporting playlists. For the sake of simplicity, and to avoid additional processing, you won’t install any plugins in this article.

To install the XMMS2 server software, and allow the jukebox to broadcast for discovery on the local network, run this command:

sudo dnf install xmms2 avahi

When the installation is complete, run:

xmms2d &

This command executes the XMMS2 daemon and creates the configuration files in the user’s home directory. Some errors may appear, but that’s OK since you still need to configure the player. For now, press Enter to return to the shell prompt. Now run the command:

xmms2

The xmms2> prompt appears. XMMS2 is a sophisticated piece of software, and to go through all the commands is beyond the scope of this article. To learn more, type help at the prompt, or consult the man pages. To exit the prompt type:

exit

Finally, reboot the computer.

Configuring XMMS2

Now comes the fun part of the project: tweaking the configuration files for XMMS2. You’ll also create a systemd service file to start the XMMS2 daemon on boot and open ports that allow client access.

First, you need the IP address of the jukebox. To determine that, run this command:

nmcli

Below is an example of results:

ens3: connected to ens3 "Red Hat Virtio network device"
ethernet (virtio_net), 52:54:00:8B:D5:A1, hw, mtu 1500
ip4 default inet4 10.0.0.210/24
inet6 fe80::34fa:a011:f20e:c0a2/64

Note the numbers beside inet4. The IP address in the above example is 10.0.0.210. This is what you need to configure the XMMS2 server for client connectivity. Now run:

cat /proc/asound/cards

This command displays a list of audio hardware connected and recognized by the system. In the example from Part 1 you saw:

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

If you have a Linux-compatible USB DAC it is listed here. The examples in this article use PCH (or card1). Now type:

cat /proc/asound/card1/pcm0p/info

You should get something similar to the following:

card: 1
device: 0
subdevice: 0
stream: PLAYBACK
id: ALC3234 Analog
name: ALC3234 Analog
subname: 
subdevice #0
class: 0s
ubclass: 0
subdevices_count: 1
subdevices_avail: 0

Note the numbers beside card and device.  You need this information for the next step when you configure ALSA to process the audio straight to the hardware.

XMMS2 configuration files

To open the XMMS2 configuration file, run:

nano ~/.config/xmms2/xmms2.conf

Find this line:

<section name="alsa">

<property name=”device”> is set to default. You want to change that to direct the audio straight to the hardware. Remove default and enter: hw:x,y (where x is the card number and y is the device number).

Next, change the mixer property to Master, and mixer_dev to hw:x (again where x is the card number). Your file should look similar to the example below:

<section name="alsa">
     <property name="device">hw:1,0</property>
     <property name="mixer">Master</property>
     <property name="mixer_dev">hw:1</property>
     <property name="mixer_index">0</property>
</section>

Scroll down to <section name=”clients”>. The entry for watch_dirs property is empty. Here, add the path to the directory that contains the music files. Remember to enter the directory path for your music.

<section name="clients">
     <section name="mlibupdater">
          <property name="watch_dirs">/home/sassam/Music/</property>
     </section>
</section>

Next, configure <section name=”core”>. Look for the ipsocket property, and remove the unix:///tmp/xmms… entry and enter a TCP port 6600 for your system:

<property name="ipcsocket">tcp://10.0.0.210:6600</property>

Remember to replace 10.0.0.210 with your IP address. The section should look similar to the example below:

<section name="core">
     <property name="ipcsocket">tcp://10.0.0.210:6600</property>
     <property name="logtsfmt">%H:%M:%S </property>
     <property name="shutdownpath">/home/sassam/.config/xmms2/shutdown.d</property> 
     <property name="startuppath">/home/sassam/.config/xmms2/startup.d</property>
</section>

The last setting to configure is the output section. Change the plugin property from pulse to alsa.

<section name="output">
     <property name="buffersize">32768</property>
     <property name="flush_on_pause">1</property>
     <property name="plugin">alsa</property>
</section>

Be careful if you edit the buffersize property. If it’s set too low you may encounter playback issues. This example keeps the defaults, but feel free to experiment. Save the file and exit.

Creating the XMMS2 systemd service

Edit a new service file using sudo:

sudo nano /etc/systemd/system/xmms2d.service

In the file enter:

[Unit]
Description=XMMS2 Service
After=NetworkManager.service

[Service]
ExecStart=/bin/bash -c "sleep 3; /usr/bin/xmms2d --yes-run-as-root --conf=/home/sassam/.config/xmms2/xmms2.conf"

[Install]
WantedBy=multi-user.target

Save the file and exit. To enable the service on boot, and in this session, enter:

sudo systemctl daemon-reload; sudo systemctl enable --now xmms2d.service

Now, open port 6600 in your firewall, to allow the XMMS2 client access to the system over your local area network:

sudo firewall-cmd --permanent --add-port 6600/tcp; firewall-cmd --reload

Success! Your digital jukebox is fully configured. You can adjust the volume on the server-side with:

alsamixer

The XMMS2 Client

The client used is GXMMS2, available in the Fedora repository. GXMMS2 is a simple client with a small window that allows users to control audio playback on the XMMS2 server. To install GXMMS2 on your Fedora desktop, open the terminal and enter:

sudo dnf install gxmms2

When the installation is complete, open the GXMMS2 program to create the client configuration file. To edit the file, go back into the Terminal and enter:

nano ~/.config/xmms2/clients/gxmms2.conf

Here, set AutoReconnect to yes, and change the IPCPath to the socket path you entered in the server configuration file above. For example:

AutoReconnect=yes
IPCPath=tcp://10.0.0.210:6600

Again, remember to use the IP address of your digital jukebox. Feel free to go through the configuration file and adjust the settings to your liking. Then save the file, exit the editor, and close the GXMMS2 window.

Re-open GXMMS2, click the Open playlist editor button, then click the MLib Browser tab. A list of your audio files appears. Double-click the artist, then double-click the album. GXMMS2 displays a list of songs. Highlight the songs you want to add the playlist and click the Add button, or double-click the song. Click the Playlist tab, then double-click on a song to start playing.

Testing for Bit-Perfect Playback

Now let’s check for bit-perfect playback. Go back to your server and at the shell prompt enter:

cat /proc/asound/card1/pcm0p/sub0/hw_params

Remember to use the card number you configured in the xmms2.conf file. For the song playing in the above screencast, the following information is shown:

access: RW_INTERLEAVED
format: S16_LE
subformat: STD
channels: 2
rate: 44100 (44100/1)
period_size: 735
buffer_size: 22050

This shows the playback format is 16-bit using two channels with a sample rate of 44100. The software is not resampling and playback is identical to the audio file, and bit-perfect playback has been achieved. Remember, if you try to play an audio format beyond the resolution of your audio device, like a 24-bit FLAC file on a 16-bit DAC/soundcard, you may get unstable, or no, playback. To play these files you can configure ALSA/XMMS2 for software mixing, or install and configure a sound server like Pulseaudio or JACK to resample the audio information. However, bit-perfect playback will be lost.

Congratulations! You have successfully created your own digital jukebox optimized for sound quality. What was once old is now new again thanks to Fedora and open source software.

This article touched upon some of the fundamentals of digital audio. Readers and audiophiles looking to refine their systems, and improve upon the information provided, can find more details from the sites below. Some of the referenced software may be outdated, but the concepts are still relevant.

ALSA Project:

https://wiki.archlinux.org/index.php/Advanced_Linux_Sound_Architecture#High_quality_re-sampling

http://www.ap-linux.com/documentation/playing-audio/

24bit96 | high res audio and hd music:

Dynobot’s Computer Audio – https://sites.google.com/site/computeraudioorg/setting-up-alsa

https://www.head-fi.org/threads/bit-perfect-audio-from-linux.561961/#post_7596268

[PDF] Real-Time Audio Servers on BSD Unix Derivatives – https://jyx.jyu.fi/dspace/bitstream/handle/123456789/12485/URN_NBN_fi_jyu-2005243.pdf 

XMMS2 Man Page – https://www.gsp.com/cgi-bin/man.cgi?section=1&topic=xmms2

Using Software

2 Comments

  1. PitDog

    Hi Shaun, just wondering which of the various steps are advisable if we are just trying to optimize sound on a general purpose computer as opposed to a dedicated jukebox computer. I first installed Redhat in 2000, so I am still new to Linux and don’t know for instance if the uninstallations which seem to accompany certain codec additions {in some variants of Linux, at least) are harmful. I notice ubuntu studio has two boot options, a low latency and a regular boot option and wonder if this option can be configured on Fedora or even installed by default in Jam. Thanks.

    • Hi Pitdog,

      For a general-purpose computer I would recommend the Jack Audio Connection Kit. I use Jack and Qjackctl on my main desktop when I’m testing for audio quality. You can install both these packages with dnf. They are available on Fedora Jam by default. You can tweak Jack in the Qjackctl application and play around with the settings to fit the capabilities of your hardware. The great thing about this application is it calculates and displays the latency depending on your settings. Most sites I’ve seen say that ~10 ms latency is really good, however you can try to go lower. Just remember that if uou go too low you will get xruns (skips and stutters). There’s a great beginner’s guide at http://libremusicproduction.com/articles/demystifying-jack-–-beginners-guide-getting-started-jack, and you can find more details at http://jackaudio.org.

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