DIY HD Desktop Audio! Cubietruck 384kHz Sinc Upsampling Audio Player

Cubietruck 384 kHz upsampling desktop player

Why do you need this?

After building my high end sinc upsampling audio player computer, I was searching for a new use for my proof-of-concept Cubietruck player. I was originally using this with pulseaudio and the optical output to allow 96kHz medium quality sinc upsampling from flac. This used about 70% of one processor core. However, further experimentation has revealed improvements which allow a dramatic cpu usage reduction. The board is limited to 96kHz output, but by combining with a relatively inexpensive USB DAC, we can now get up to 384kHz! So why do you need it?

  • 384 kHz sinc upsampling using the Secret Rabbit Code Best Sinc Interpolator upsampling algorithm.
  • In other words, fantastic audio quality!
  • You do not need to buy your music collection again as HD audio files. Flac and sinc upsampling is (imho) pretty well indistinguishable from commercial HD recordings, especially when both are upsampled to 384kHz.
  • Up to 2TB of hdd storage for loads of lovely flac files.
  • No significant operational noise; only the hard drive is audible. My one is very quiet, much quieter than a 3TB 3.5 inch drive (both WD reds).
  • Use this at work – have your music collection in excellent quality where you spend a lot of your time.
  • It’s cheap! Well in Hi-Fi terms at least.
  • Have the satisfaction of building your own system that is able to do things some of the best systems cannot.

A Little Theory (skip if you don’t like this sort of thing)

cubietruck + ifi nano dacSo why do I think you don’t need to buy HD audio files? Have a read of my Secret Rabbit Code article, but fundamentally, as an audiophile who has tried these techniques within the context of a high end system (that includes vinyl), experimentation has shown me that sinc upsampling is the solution to harsh CD sound. Best of all, it works from your existing CD collection.

In a nutshell, Shannon’s sampling theorem states that you can recreate all frequencies by sampling at over twice the highest frequency. So why is it that CD still sounds harsh? Why do higher frequency instruments like cymbals sound worse than lower frequency instruments? My guess as to the answer is that just because there is enough information to mathematically determine what the frequencies should be, doesn’t mean that players actually do it. There seems to be a relationship between the number of samples used to represent a frequency and the harshness of that frequency.

One thing to bear in mind is that the sample rate tells you how many numbers (samples) are used to represent the continuously changing waveform and not the audio frequencies present in the music. To explain:

  • All audio is stacks of sine waves of different frequencies (Fourier Analysis). A musical instrument outputs a bucket load of frequencies for each note played. If the high frequencies are distorted, it will affect the tone of the whole instrument.
  • The sample rate of CD is 44,100 per second. This system upsamples to 384,000 samples per second.
  • A 3kHz note (around the most sensitive frequency for humans), sampled at 384,000 samples per sec would have 128 samples for each period of it’s sine wave compared to around 15 samples for CD.
  • A sample is a recording of the amplitude of the sine wave at an instant in time. In music, amplitudes change continuously as they are a function of the displacement of air molecules, which cannot jump instantly from place to place. So samples, by their nature, need some form of processing to get back to continuously varying analogue waveforms.

Technically, I believe it may be the low pass filter at the end of the signal chain in the DAC that could be the main culprit in sound quality degradation, but I’ve not done any scientific measurement of this. I think it would be a great thing to study. It is this that is supposed to change the stepped output of the sampled wave into a smooth signal suitable for listening to.

The solution seems to be a computational problem – my understanding is that the sinc algorithm is the theoretical best for determining what the curve going through the actual samples originally was. This should be uniquely determinable according to Shannon. By taking the upsampled values from that curve, they would be more representative of the original signal. At the highest quality setting used here, the processor uses well over 100,000 input samples to determine the curve for each output sample.

What do you need for this desktop player?

Here’s a picture of an example set up:


The components are:

  • The front end: In the picture, I’m using an android phone with mpdroid. In a work setup, I use a laptop with gmpc, which is what I will talk about here.
  • The player: this is the Cubietruck I have previously written about. It boots from a 1TB hard drive and runs Lubuntu as a headless server. The drive is a 2.5 inch notebook drive which must be purchased separately.
  • A power supply: I bought a reasonable multi-voltage power supply with lots of adapters that can give a decent amount of current. This allows an external USB HDD to be attached for occasional file copying.
  • A network: to communicate between the front end and the player. I’m using a TP-Link TL-WR710N wireless router as it also has a single wired network connection and is quite inexpensive. I understand a network switch could be used instead, but I didn’t go down that path.
  • A 384kHz DAC: this project really came about because I came across the iFi nano DAC. This is a versatile unit that can be powered from an internal battery or USB. There is a lot of tech here for the money. It was a bit of a gamble to see if the Cubietruck could handle this sample rate, but it worked out fine!
  • Some Headphones: the photo shows some AKG 490NC noise cancelling headphones. These are pretty good for air travel, but something in the Cubietruck makes a buzzing in the right ear when the noise cancelling is engaged. I recommend using good headphones of at least this level (probably not noise cancelling), otherwise the investment in the rest of the system won’t be evident.

The power supply and the wireless router can be hidden away somewhere.

Network Access

I connected my laptop over WiFi to the router and then navigated in a browser to the network address for the admin page, which will be something like dependent on your home network. The default admin userid and password is given in the documents:

tplink main statusFrom here you should change the admin and the network passwords. The local network may conflict with other networks and the idea is to keep it just for use with the player. Let’s change it to a more unusual number using the Network, LAN option:

tplink lan settings

To keep the network discreet, we can lower the transmission power using Wireless, Advanced:tplink low powerIn normal use, the router is connected directly to the Cubietruck by a cable so that you don’t have to configure the network without having a GUI, since the Cubietruck is running in headless mode. The laptop providing the front end must connect wirelessly. This is fine in my office environment as the laptop’s main network connection is wired.


P1020940I really like that this DAC is so flexible and low powered. It can do loads of sampling rates up to 384kHz for a budget price. There is an iFi micro iDSD model that can do an extraordinary 768kHz, but it is more than double the price and a lot bigger. This sampling rate wouldn’t be any use with the Cubietruck as the processor is not powerful enough.

It is a very small unit (roughly 10 x 7 x 3 cm) and together with the Cubietruck, they make a very compact desktop system. The DAC’s packaging is excellent and it comes with a number of accessories: RCA cables, USB cable (shown) and a couple of thick elastic bands that I’m not quite sure what they are for. Could they be to attach the unit to something else? If so, what? A phone? The tiny manual does not elaborate.

The DAC supports DSD audio, so all I need now is a way to convert PCM to DSD in software on Linux using mpd. Anyone know of anything? It also does DXD, which I’d never encountered before googling the wikipedia article.

There are RCA and optical S/PDIF outputs as well as a powerful headphone socket, but the input must be USB. This is not a problem as the other common input types are limited to lower sample rates. Testing using other DACs has convinced me that USB is at least as good as any other digital connection types. If you want 384kHz, it has to be USB.

The only downside I’ve found so far is that the volume control can be a bit crackly at low volume.

Cubietruck Configuration

To install and configure Lubuntu & mpd see my previous article.

When you plug the DAC into the Cubietruck using the supplied USB cable, there should be a little flicker of the orange LED showing some CPU activity and then the device should automatically show up when you interrogate for the available sound devices using aplay -l:

aplay-lFrom this, we can determine the mapping between cards and audio devices:

  • Card 0: The analogue headphone socket on the Cubietruck
  • Card 1: The S/PDIF optical out on the Cubietruck
  • Card 2: the iFi nano DAC over USB.

Here is a minimal /etc/mpd.conf file used to configure mpd. Normally this has lots of comments in it, but I’m just including the bare values here for reference:

music_directory                 "/home/linaro/Music/playable" 
playlist_directory              "/var/lib/mpd/playlists" 
db_file                         "/var/lib/mpd/tag_cache" 
log_file                        "/var/log/mpd/mpd.log" 
pid_file                        "/var/run/mpd/pid" 
state_file                      "/var/lib/mpd/state" 
sticker_file                    "/var/lib/mpd/sticker.sql" 
password                        "1111@read,add,control,admin" 
user                            "mpd" 
bind_to_address                 "" 
port                            "6600" 
log_level                       "default" 
gapless_mp3_playback            "yes" 
auto_update                     "yes" 
input { 
        plugin                  "curl" 
audio_output { 
        type                    "alsa" 
        name                    "ALSA iFi Best Sinc 384/32" 
        device                  "hw:2,0"                        # optional 
        format                  "384000:32:2"                   # optional 
        samplerate_converter    "Best Sinc Interpolator"        # best-sinc-interpolator 
        mixer_type              "software"                      # to allow volume controls 
audio_output { 
        type                    "alsa" 
        name                    "ALSA iFi Best Sinc 192/32" 
        device                  "hw:2,0"                        # optional 
        format                  "192000:32:2"                   # optional 
        samplerate_converter    "Best Sinc Interpolator"        # best-sinc-interpolator 
        mixer_type              "software"                      # to allow volume controls


audio_output { 
        type                    "alsa" 
        name                    "ALSA iFi Best Sinc 96/32" 
        device                  "hw:2,0"                        # optional 
        format                  "96000:32:2"                    # optional 
        samplerate_converter    "Best Sinc Interpolator"        # best-sinc-interpolator 
        mixer_type              "software"                      # to allow volume controls 

audio_output { 
        type                    "alsa" 
        name                    "ALSA iFi CD 44.1/16" 
        device                  "hw:2,0"                        # optional 
        format                  "44100:16:2"                    # optional 
        samplerate_converter    "Best Sinc Interpolator"        # best-sinc-interpolator 
        mixer_type              "software"                      # to allow volume controls 

audio_output { 
        type                    "alsa" 
        name                    "ALSA headphone Best Sinc 96/16" 
        device                  "hw:0,0"                        # optional 
        format                  "96000:16:2"                    # optional 
        samplerate_converter    "Best Sinc Interpolator"        # best-sinc-interpolator 
        mixer_type              "software"                      # to allow volume controls 

audio_output { 
        type                    "pulse" 
        name                    "Pulseaudio Optical Output" 
        sink                    "alsa_output.platform-sunxi-sndspdif.0.analog-stereo"   # optional 

filesystem_charset              "UTF-8" 
id3v1_encoding                  "UTF-8"

This creates an mpd configuration with:

  • Outputs for a set of sample rates from CD to 384 kHz through the iFi DAC using alsa (Advanced Linux Sound Architecture)
  • A 96/16 analogue output to headphones on the Cubietruck via the onboard DAC
  • An optical output using whatever parameters are set up in pulseaudio
  • The server must reside at IP address, port 6600
  • The process runs under userid mpd and clients must connect using an authenticating PIN of 1111.

If this works correctly (sudo service mpd start), you should find a single core cpu going into the 90% range when you play music:

topHere we can see that mpd is using 92.9% of a core. The priority is also marked as rt. This stands for Real Time and improves the sound quality along with making the audio less likely to be interrupted by other processes. I set this up by adding this command to my .bashrc:

alias rtmpd='sudo chrt -f -p 99 $(pidof mpd)'

Then I can just run rtmpd when I need to, especially after manually refreshing the mpd service to pick up changes to the configuration file (sudo service mpd restart). It would probably be a good idea to put it in the system startup somewhere as well.

The breakthrough to allow 384kHz upsampling using the highest quality algorithm on limited hardware is to avoid using pulseaudio and go to alsa directly. Pulseaudio is a plug-in (kind of within alsa) that has audio manipulation and routing capabilities. By not using it, the amount of processing is reduced.

The mpd manual says that you can use 0 for the samplerate_converter in alsa output configurations to get the best sinc converter, but in the past I was not able to get this to work and therefore had to use pulseaudio. The trick is merely that this can also be set using the full string “Best Sinc Interpolator”. Check man mpd.conf for more information.

If we want to see what format the device is currently playing, use cat /proc/asound/card2/pcm0p/sub0/hw_params:

hw_paramsWe can see the Cubietruck is operating at 384kHz and 32 bits. Most definitely the source material is not at this level, so in conjunction with the high processor utilisation, we can conclude the upsampling is doing something (I already set the output to use in the player).

Turning off the lightsP1020939

The LEDs can be a bit glaring on the desk. They can be turned off with a relatively easy script from here. The article says it all! Thanks to the author. This leaves the one orange CPU0 light still going, which is not very intrusive and helps to show when there’s something going on.

If you want to turn this off as well, you can add the following lines to the start case statement:

echo 0 &> /sys/class/leds/orange:ph20:led2/brightness
echo "Switching off Orange LED"

and these to the stop statement:

echo 1 &> /sys/class/leds/orange:ph20:led2/brightness
echo "Switching on Orange LED"

However, after experimenting, I preferred this one left on – as did the originator of the script.

Desktop Configuration

serveroptions1gmpc connectionAs in this previous article, I’m using gmpc as the front end. The image above shows the audio outputs that result from the previous mpd configuration.

To configure the player to access mpd, you just need to go to Music->Preferences and set up the connection to be something like in the image to the right. Remember to use the PIN that you set up in the mpd.conf.

Near the top of the article, I showed mpdroid as the front end. I don’t normally use this as I can only use one wireless network at one time on the phone and I prefer to use a network that’s connected to the internet :).

Copying Audio

P1020935Various methods can be used to copy audio onto the Cubietruck. Firstly, over a network – this can be the local wireless, or plugging the Cubietruck back into a wired ethernet, say at home. I typically use utilities such as scp or rsync with this.

Alternatively, an external USB drive can be used. I have a 2TB portable drive that I can load up at home and then use rsync to copy files over. You have to set up a mount point in /etc/fstab. When I load the drive up at home, I use this entry:

UUID=<from blkid command> /mnt/My_Passport ntfs errors=remount-ro,nobootwait,uid=1000,gid=1000,dmask=077,fmask=137 0 1

Then you can use sudo mount -a to mount the drive at the location specified above.

To copy audio, go to the location you would like to copy it to and use something like:

rsync -avz --no-p --no-o /mnt/My_Passport/Music/ . 2> errors

You can use the –delete parameter to delete entries at the destination if you have reorganised things, but this can be very destructive if you have not specified the directories quite right. To check in advance, use the –dry-run option to print a list of what it would do rather than actually doing it.

The benefit of rsync over scp is that, if you get it right, will only copy the file changes since the previous copy rather than doing every file each time.

Sometimes you can get errors in copying which are obscured by status messages, so this version of the command puts them into a separate file for later browsing. These are typically things to do with unsupported characters in file names. The solution is generally to rename the files to avoid those names. You can keep the metadata the same so that your music player can still see the original characters.

If you do rename the files in the source directories, just use the rsync command again and only these files should be copied.


P1020934P1020933At some point, I’d quite like to replace the HDD with a 2TB drive so that I could store more music. Then this would become a semi-portable equivalent of my home system.

Adding new software or performing updates must be done by connecting the Cubietruck back to an ethernet network as it has no internet connection when running over it’s own local wireless network.

The Cubietruck and iFi nano DAC is a quite satisfying combination. One core running almost flat out can handle the best quality upsampling algorithm at the highest sample rate of the DAC without the audio skipping. It may be that if you try and go from lower quality (mp3) or a format that takes more effort to uncompress, that the system would struggle to handle it. You would then need to use one of the lower sample rates, which is what I do if I am listening and simultaneously copying audio to the hard disk.

How does it sound? Well pretty amazing really. Using the external DAC means the music is not limited to 16 bit, 96kHz. Again the benefit of sync upsampling is that the harsh tone of CD is removed, instruments sound more natural, especially high pitched instruments. Further improvements could be had with a better DAC, but it would only make the system more expensive, and most likely, take up more space.

Engaging the battery in the DAC (turn it on with no USB cable attached) gives a noticeable improvement. The tone is softer, the instruments are better placed and there could even be a lower noise floor making everything sound a bit clearer. Another easy improvement would be to buy better headphones. I’m sure the system could handle them.

I gave a demo to a colleague who thought he wouldn’t be able to hear any difference but he was impressed at how musical it sounded as well as immediately noticing the “out of head” spatial positioning of instruments.

The DAC is able to do DSD, but I don’t know of any way to use this. Does anyone know of any software PCM to DSD converters that would work with mpd?

Finally, thanks for reading and I’d be very interested to hear anybody else’s experience with sinc upsampling. Has anyone else reconfigured their Hi-Fi to use this as a primary source?


%d bloggers like this: