
At the heart of the reference Bryston BDP – 2 audio player cost, for a minute, 156 thousand rubles is a standard motherboard with an Intel Atom processor and an ESI Juli @ PCI sound card. Developers have chosen Debian Linux as the OS for this player. If you have the time and desire, you can assemble a similar digital source from the available hardware, and this article will help you with installing the necessary software and fine-tuning the system parameters.
Introduction
It should be noted that when creating BDP – 2, engineers from Bryston did not bother themselves with the work on the software part: Debian 6.0.1 stock comes in delivery, kernel 2.6.32 without realtime support is offered, almost untouched MPD settings are offered, there are no optimizations at all . The fact is that standard cores have a rather large sound delay (11–20 ms), and this does not allow to work with sound professionally. In a realtime system, this delay is ~ 1 ms, which is already considered an excellent result. Therefore, first we compile the kernel and MPD sound server with RT patches to minimize delays, then set a high-precision event timer, set maximum priorities for devices and processes related to audio transmission, and finally finish tuning the system parameters. In general, let's do what the hi-end should have done.
')
We will consider the example of an ancient company (VIA Epia-MS motherboard, VIA C3 800 MHz percents, 512 MB of RAM, ESI Juli @ PCI sound card) and the Debian 7.1 distribution installed at the minimum, that is, without graphics and unnecessary services. You may have another sound, only we would recommend PCI / PCI-E, since external USB cards may not work correctly with some motherboards.

Experimental computer, the analog part of ESI Juli @ dismantled

For the tests used a digital-to-analog converter Nagra DAC
Compiling RT kernels
RT-patch is designed to support real-time in the core, and not “soft”, but “hard”. The difference lies in the fact that “soft” real-time systems allow a slight excess of the desired execution time, while in “hard” real-time systems, such an excess is unacceptable. The patch is superimposed on the vanilla core, so we put everything needed to compile it and download the core and patch:
# apt-get install kernel-package libncurses5-dev fakeroot build-essential pkg-config wget gcc autoconf git # mkdir kernel && cd $_ # wget bit.ly/149djQn # wget bit.ly/14rDBvQ
Unpack and patch:
# tar xjf linux-3.8.13.tar.bz2 && cd linux-3.8.13 # bzcat ../patch-3.8.13-rt11.patch.bz2 | patch -p1
Then in the menuconfig / nconfig we enable the option Processor type and features -> Preemption Model -> Fully Preemptible Kernel (RT) and build the kernel:
# CONCURENCY_LEVEL=3 fakeroot make-kpkg --initrd --append-to-version=-rt kernel_image kernel_headers
Instead of CONCURENCY_LEVEL = 3, you can put your own number, depending on the number of processor cores + 1.
Install and reboot:
# dpkg -i ../*.deb # reboot

Choosing the right kernel option
MPD preparation
For starters, what is it? Why do we need another player, if there are already enough of them? Actually, MPD is a daemon with a client-server architecture, which opens up quite interesting possibilities, namely:
- Unlike many other graphical players, it does very well without the Xs, so if they fall or are completely absent on the computer, the music will still play;
- this is a client-server application — if desired, it can be controlled from a graphical interface;
- MPD is not only client-server - it is also networked! Consequently, it can be put on a headless server and calmly steer it even from a netbook, even from another computer, even from a smartphone or tablet (iOS / Android).
MPD itself supports many features, including support for FLAC, ALAC, WAV, MP3, OGG, streaming audio playback, gapless playback (playback without pauses) ... you can’t name it all.
Sources are taken from the official site (for the reasons given below, version 0.17.1 is required), then we put the necessary dependencies for the build:
# wget bit.ly/14wxPtj # tar xjvf mpd-0.17.1.tar.bz2 # cd mpd-0.17.1 # apt-get build-dep mpd # apt-get install libcdio-paranoia-dev
After that, you can, in principle, go to the directory and type the autogen command, and then make ... but we will not rush, because otherwise MPD will be compiled with default options, which may not be suitable for us. In addition, you will have to apply the RT patch to the MPD itself, which is designed to improve the sound quality by controlling the priorities of the streams (in vain, did you compile the RT core?). Since the player itself is developing faster than the patch, the MPD version should be exactly 0.17.1. Download the patch and apply it:
# wget bit.ly/10kbsHY -O mpd-rtopt.diff.gz # gunzip -c mpd-rtopt.diff.gz | patch -p1
Now you can choose build options. Of course, this is a matter of taste, but we collected with the following options:
# ./autogen.sh CFLAGS="-O2 -mtune=`uname -m`" --enable-alsa --enable-rtopt --enable-id3 --enable-sqlite --enable-audiofile --enable-flac --enable-cdio-paranoia --enable-lsr --disable-oss --disable-pulse --disable-jack --disable-ipv6 --disable-inotify # make && make install
Consider some options in more detail:
- --enable-alsa - includes ALSA support;
- --enable-rtopt - actually, for the sake of which we patch;
- --enable-id3 - ID3 tag support;
- --enable-sqlite - SQLite support for internal MPD database;
- --enable-audiofile - support for wav files;
- --enable-flac - support for FLAC - compression format without loss of quality;
- --enable-cdio-paranoia - audioCD;
- --enable-lsr - support for changing the sampling rate on the fly;
- --disable-oss - since we will use ALSA, we will not need OSS;
- --disable-pulse, --disable-jack - we also don’t need wrappers around ALSA;
- --disable-ipv6 - if there is no IPv6, why include it?
- --disable-inotify - for less resource consumption.
And now, after successful assembly and installation, let's move on to setting up the audio system.
Initial setup and tuning
Here are the most important parts of the mpd.conf file:
# . music_directory "/var/mpd/music" # - playlist_directory "/var/mpd/plists" # db_file "/var/mpd/mpd_db" # — sticker_file "/var/mpd/sticker_db" log_file "/var/log/mpd.log" # ESI Juli@, SPDIF (Toslink RCA) # — `mpd.conf`. audio_output { # , ALSA type "alsa" # name "ESI Julia SPDIF" # ( aplay -L) device "iec958:CARD=Juli,DEV=0" # bit-perfect playback, , , replay_gain_handler "none" auto_resample "no" auto_channels "no" auto_format "no" # Memory-mapping I/O use_mmap "yes" # priority "FIFO:99" } ... # audio_buffer_size "2048" # buffer_before_play "50%" ... # realtime- MPD — realtime_option { memlock "yes" # locks in-memory stack_reserve "1024" # ( ) heap_reserve "10240" # ( ) main_priority "OTHER:0" player_priority "FIFO:50" decoder_priority "FIFO:47" update_priority "OTHER:0" # }
Optionally (and if MPD was compiled with the appropriate option) you can, for example, enable streaming audio via HTTP - for the latter you need to add the following lines to the config:
audio_output { type "httpd" name "My HTTP Stream" # , vorbis lame encoder "vorbis" port "8000" # quality "5.0" # quality bitrate bitrate "128" # (44,1 , 16 , ) format "44100:16:2" }

Mpd.conf configuration file
It is also necessary to make tuning of the system. First of all, create the file /etc/security/limits.d/mpd with the following content:
@audio - rtprio 99 @audio - memlock unlimited @audio - nice -19
This file almost disables the priority limits for the daemon. Next, you need to change the HPET setting (which is a clock frequency generator and is not used by default on many rather old motherboards). To do this, edit the line in the / etc / default / grub file - at the same time we will add the threadirqs option, which is related to the RT core and will be needed later:
GRUB_CMDLINE_LINUX_DEFAULT="quiet clocksource=hpet threadirqs"
HPET is required for more accurate (in time) signal to the DAC. It would seem that the difference of several micro (and even nano-) seconds when applying the bit stream is so insignificant that you should not pay attention to it ... but no. One bit was delayed, two came ahead of time - and in a high-end stereo system, the difference can be felt by the human ear. With HPET, the likelihood of such a scenario is reduced.
Let's also configure some kernel parameters through sysctl. Open /etc/sysctl.conf in your favorite editor and add the following lines to it:
# , vm.overcommit_memory = 2 vm.overcommit_ratio = 50 vm.swappiness = 10 # HPET dev.hpet.max-user-freq = 2048
In addition to the last parameter, you need to change the same for rtc - but, since it is in sysfs, you will have to write it in rc.local:
echo 2048 > /sys/class/rtc/rtc0/max_user_freq
Put the package rtirq-init. It contains a script that increases the priorities of IRQ streams associated with sound equipment:
# apt-get install rtirq-init
After installation, you may need to edit the / etc / default / rtirq file, namely the list of IRQ streams that will have increased priority:
RTIRQ_NAME_LIST="rtc snd usb i8042"
And finally - if you have a PCI sound card, then you need to maximize the timeout timer (latency timer, which sets the time that the card on the bus can take, if other cards turn to the bus) for it and, accordingly, slightly increase its for other PCI devices. But first you need to know the PCI ID card:
# lspci | grep -i audio
In my case, the ID was 01: 09.0, therefore, to increase the latency timer, we type the commands
# setpci -v -d *:* latency_timer=b0 # setpci -v -s 01:09.0 latency_timer=ff
You can also register these commands in rc.local.

QMPDClient interface

Sonata is another MPD client.
RT patch turns Linux kernel into fully pre-emptive (i.e. with preemptive multitasking)
Health check
In general, you can now start the MPD daemon. Before launching, make sure that the music in the appropriate directory is present and a directory for playlists has been created. If it is scattered in different directories, then you can point at them with symlinks. The command for manual start looks like this:
# mpd /etc/mpd.conf
But how to check the performance? The fact is that even the simplest console client is not included in the MPD source code, like the libmpdclient library, so you can either compile them yourself or install the appropriate package. Since the client does not require the imposition of patches, there is no special reason to bother with the compilation, which means we install the package:
# apt-get install mpc
Before starting, we recommend to look at the settings of the mixer - in Debian 7.1 the sound is disabled by default. Update the MPD database, add all the music to the playlist and start playback:
# mpc update
If everything is normal, then the music should sound. In the case of streaming playback, you also need to check the operation of this stream. We specify the address and port registered in the config. For some players, you must also specify the file mpd.ogg - for example,
192.168.1.5 : 8000 / mpd.ogg.
Remove unnecessary
Well, now you need to clean up the system. In general, you can do it yourself, but there are some subtleties - for example, packages installed with apt-get build-dep cannot be completely removed. So, first we mark the necessary packages for MPD so that they will not be removed by the following command, and only then we remove the packages related to the assembly:
# apt-mark manual libcdio-paranoia1 libavahi-glib1 libcurl3-gnutls libshout3 # apt-get autoremove kernel-package libncurses5-dev fakeroot build-essential pkg-config wget gcc autoconf git # apt-get remove libcdio-paranoia-dev
Then we execute the following three-story command:
# apt-get remove $(apt-cache showsrc "mpd" | grep Build-Depends | perl -p -e 's/(?:[\[(].+?[\])]|Build-Depends:|,|\|)
This command looks frightening, but it does quite a harmless thing - it removes all the packages that were needed to build MPD.
We also delete the MTA - why do we need mail at the audio station?
# apt-get remove exim
In general, you can remove the rest of the packages useless for an audio station yourself. But if you are not sure whether you need, for example, cron or syslog, it is better to simply disable them from the init scripts.
Mounting root FS in RO mode
If you have music on a different storage device than the system, it makes sense to install the root file system in read only mode when downloading. The easiest way to do this is to write the appropriate option in / etc / fstab. However, this will require placing all mutable parts on other sections or removing the programs that generate this data, which is sometimes not entirely simple.
Another way is to use unionfs / aufs / overlayfs — these file systems allow you to combine both RO and RW in one mount point - the latter can be placed in RAM. This technique is used to create live distributions. More information on how to do this can be found on the page .
MPD clients
Are there other clients for MPD? Of course have. Moreover, having multiple clients is one of the features of this daemon. Some of them will describe in more detail.
- Ncmpc is a fairly simple MPD client based on ncurses. Unfortunately, it is not very convenient to work with playlists.
- But another client on ncurses - ncmpcpp is in this sense much more pleasant. It has a search by tags.
- The xfce client, xfmpc, is notable for its minimalism and lack of extra features.
- Another graphical client, Sonata, allows, among other things, to download album covers and lyrics from the Internet and has a large number of settings. For example, it supports work with several MPD servers. True, the settings window is not too intuitive.
- QMPDClient, as the name implies, is a Qt-client and looks like a very powerful player - but not very impressed. Nevertheless, we note the possibility of automatically deleting the already played composition from the playlist.
We should also mention clients for communicators. For Android, there were MPDroid and DroidMPD on Google Play. Which one to choose is a matter of taste; The interface of the second seemed somewhat coarse. For iPhone / iPod, MPoD is popular, for iPad there is a specialized version - MPaD.

The MPDRoid interface is pretty cute.

MPoD: iPhone Client
Around Audio Distributions
There are many distributions for working with sound - from minimalistic, to work exclusively as an audio center without a monitor with network control, to sophisticated ones with a bunch of sequencers and VST plug-ins. All of them, of course, can not be described, but a small overview of the individual does not hurt. And we will start with Voyage MPD.
Voyage MPD is an embeddable distribution based on Debian 7.1. The latest version at the time of this writing contains MPD 0.18, kernel 3.8.13 with the latest ALSA drivers, Meshlium-based web interface, DoP support (DSD over PCM, packaging DSD into PCM frames) is also announced. There is a Voyage MPD Starter Kit that allows you to build an audio station. The cost of a set of 149 dollars, but the sound card is not included.
64 Studio is a distribution kit (again on Debian), positioned as sharpened for creating media content. It has the following features: low-latency core, sequencers such as Rosegarden, Ardour - multitrack sound editor ... However, the distribution has not been updated since 2008.
Ubuntu Studio - as they say, no comment. In fact, the same Ubuntu with XFCE, sharpened by the creation of multimedia content. Nothing special stands out - except for the low-latency kernel and the ability to put a meta package on a regular Ubuntu and turn it into a given distribution.
AV Linux , despite the name, is not an antivirus for Linux, but another distribution for working with audio and video. Of the features, it can be called that it includes not only free software, but also demos of proprietary products such as LinuxDSP and Mixbus.
Results
Linux can be used both as software for audio centers, and as software for professional work with sound. And if the first aspect is even more or less visible (although there are some subtleties here, as one could see from the above), then professional work with sound is so diverse that you will not embrace it in the framework of the book. The article, however, did not pursue such a goal - we just wanted to show that a system can be built on the basis of an ancient company, the sound quality of which will not be inferior to equipment worth thousands of dollars.
Optimal BIOS settings
Here are some BIOS settings that are recommended to be tweaked to improve performance:
- If there is HyperThreading, it is better to disable it.
- Video BIOS shadow is also better off.
- For PCI devices, turn off the PCI Delay Transaction option because it increases latency.
- Disable all unnecessary embedded devices.
First published in the magazine "Hacker" from 08/2013.Publication on Issuu.comSubscribe to "Hacker"

