Sound (Linux) Computing
There has been a growing trend for people to base playing music (and video) on a home computer. Like many serious audio enthusiasts my initial reaction to this was cautious. At first I tended to regard computers as fit only for people happy to play low bitrate mp3 files of poor pop music. But as things developed I decided it was time I tried this out for myself to see what might be possible. However I decided to take an unusual approach...
In practice I have used computers for my daily work for many years. Yet I’ve hardly ever used either Windows or Mac. This may seem surprising to many people with personal computers. But my own introduction to computing was on large ‘mainframe’ machine like the ICL1900 series, long before anyone had a ‘personal computer’. From my perspective it didn’t surprise me when Keith Howard and others reported that there are all kinds of snags with using operating systems like Windows. Because I’ve used UNIX and Linux in the past it made me wonder, “What about Linux?”. Might that be an easier or better option for audio?
If you are unfamiliar with Linux, its advantage is that it is ‘free’ in that anyone who wishes can download and install it with no charge. Unlike commercial systems you can even make copies and give them to your friends to try out. It is also ‘open’ in that if you are interested in computer programming you can tinker with it and change details to suit your own requirements. There are also a variety of ‘distros’ (distributions) each with their own advantages (and drawbacks). These days you can also do what linux fans call a ‘live CD’ tryout. This means you can run it on a Windows computer and play with it without having to remove Windows. Then if you didn’t like it, you can just take out the CD, reboot, and you are back to Windows.
I had an old laptop with Windows XP on it that had been sitting in the corner. Looking on the web it seemed that the most popular form of Linux for ‘newbies’ at the moment is Ubuntu. So I downloaded the data and tried to install this onto the laptop. Alas, this didn’t work because the machine is very old and simply doesn’t have enough RAM to allow Ubuntu to install. However there is a variation called Xubuntu, so I tried that, and was successful. I then had a working Xubuntu Linux computer. In fact, although Ubuntu is designed to have a desktop that behaves in a way that helps Windows users, I decided I actually prefered Xubuntu as it behaves more like earlier Linux systems I’ve used.
One of the advantages of (X)ubuntu for people who haven’t tried Linux before is that it is realtively easy to use, and to install software via the net. This is all without any charge, so you can help yourself to what items of software take your fancy. I therefore installed the packages which allow me to play various kinds of soundfile format and did some experiments. I had no trouble playing various files but for test purposes I generated some CD Audio format waveforms as tracks on a CD. Figure 1 shows the spectra for two examples. One is a 0dBFS (peak) 1kHz sinusoid that is dithered. The other is a -20dBFS dithered 3kHz sinusoid. Note that the spectra I plot all show values that are 3dB less than peak value because the scale shows average power, not peak. Figure 1 was obtained by analysing the test waveforms on the CD, so represents the source. An ideal player should produce spectra which are indistinguishable from those shown in Figure 1.
The old laptop has a digital (spdif or IEC958) coaxial output and a ‘headphone’ output. The results shown in Figure 2 illustrate what I obtained from the laptop via its digital output. These results aren’t perfect. You can see some distortion components at levels around -110dBFS and below. However these correspond to less than 0·001% distortion, so are unlikely to be a worry in practice. I was quite surprised that an old laptop would do this well using a fairly cheap and cheerful internal soundcard system that was never designed for serious audio output. However there were three drawbacks with the laptop (apart from it having a dud battery I’ve never replaced!).
The first problem is illustrated by Figure 3. This shows the result of playing the 0dBFS 1kHz signal via the analogue ‘headphone’ output. The result is clearly being grossly distorted by clipping. The signal is seriously overloading the laptop’s analogue circuits. The computer software ‘sound mixer’ did allow me to turn down the internal gain to avoid this. Alas, this gave me no way to reduce the analogue gain level without also turning down the digital output gain as well. Dropping the signal level did avoid the problem, but reducing the internal gain settings for the computer soundcard would lose resolution which isn’t a very good idea. So I simply left the internal gain set at 0dB (100%), used the spdif output, and ignored the fact that the headphone output I wasn’t using was being clipped.
The second problem was more irritating. This is that the laptop’s audio system insisted that all sound data sampled at 44.1ksamples/sec (e.g. CD Audio) was resampled to 48ks/sec before it emerged from the laptop! This applied to the digital output shown in Figure 2. This needless conversion may well be the reason for the unwanted distortion. The good news is that, although irritating, the level of distortion produced was very low, so may well be ‘harmless’. However it does seem idiotic for the computer system to insist on blindly converting 44.1 into 48 before it will feed out the digital data to you!
The final snag with the laptop was that it is very noisy. The cooling fans in the machine, and in its power supply made far too much racket to make using it for listening to music a comfortable experience. This alone ruled it out for my own purposes, even though the digital output might be good enough to use. I therefore decided to try a modern machine, built to be silent in operation. For this I chose a Shuttle XPC SD11G5. These are designed to be very quiet. No fans in the power supply, and only a large slow-speed one in the actual computer. I chose to use a 60GB solid-state ‘hard disc’, not a conventional disc. This avoids any whirring or chattering from a hard disc. Finally I also decided to disconnect the cooling fan for the CPU.
This last step is potentially risky as it may mean the CPU can overheat. However the Pentium M in the machine can ‘throttle down’ if it becomes too hot – i.e. its clock speed reduces to lower the power it draws. The basic audio playing I wanted to do should not be a very demanding task, so I suspect this would not arise in practice. To check, though, I used some monitoring programs that showed me the temperatures of the CPU and internal devices, and the level of CPU activity. Using these over some hours confirmed that, for my uses, the system never got excessively hot. So I continued to use the machine with no fan at all. Please note, though, that if you try this you might have problems with some other machine or if you wish to use it for tasks that demand more processing power!
The new computer had an optical spdif output, so I used that to repeat my previous tests. The results were very dissapointing as you can see from the examples shown in Figure4. Note this is from a digital output. The cause of the problem is that soundcard system in this machine also insisted on blindly convering any 44.1 ks/sec source material into 48ks/sec. Alas it did this very badly compared to my old laptop. Looking at Figure 4 you can see a forest of distortion components at much higher levels than in previous examples. The spectrum for the 3kHz tone is the give-away about what is going wrong. If the problem were old-fashioned nonlinearity you’d expect the distortion to show up at 6kHz, 9kHz,... etc. But we also see a large distortion component at about 900Hz. The reason for this can be understood by noting that 48,000 - 44,100 = 3900, and 3900 - 3000 = 900. So the 900Hz distortion component appears here because the 3kHz test tone is revealing the poor linearity of the sample-rate conversion. The outcome is bad news – anharmonic distortion of over 0·3% for a -20dBFS 3kHz tone, and even higher levels of distortion for higher signal frequencies or lower signal levels! Virtually useless for any serious audio listening.
At this point I had a 9 year old laptop that was too noisy but gave output that could be said to be ‘adequate but not perfect’, and a nice new – totally silent – machine that messed up the digital sound samples before I could use them. Not a very satisfactory choice. I did experiment with software settings, and also installed different versions of the Xubuntu/Ubuntu linux operating system, but I was unable to find anything that caused the machine to simply provide 44.1ks/sec when that was the sampling rate of the source material being played. So I changed tack and decided that the internal soundcard was useless for my purposes. I contacted Cambridge Audio They said that their DACMagic should work OK with Linux. So I gave a DACMagic a try.
I connected the DACMagic to the Shuttle computer via USB and experimented. For whatever reason I was unable to get any sound using Xubuntu. But Cambridge audio said they had it working with Ubuntu, so I then tried that. Success!!
The DACMagic provides one USB input, plus two spdif optical/coax inputs. It also provides spdif optical and coax outputs which ‘pass though’ what it is receiving in case you want to feed this to another device. Figure 5 shows the output I was able to obtain from the digital outputs of the DACMagic when it was playing my CD Audio test tracks via USB from the Shuttle computer. The spectra are essentially a textbook example of good behaviour. No sign of any distortions. These results are indistinguishable from the source as illustrated in Figure 1. To check this I played the test tracks, recorded the data stream emerging from the DACMagic spdif output and then compared this on a sample-by-sample value basis with the test track. The results were bit-identical. This is clearly much better than I’d managed with either of the internal soundcards. The DACMagic also automatically detected and switched sampling rate. When I played 44.1 ks/sec materials the 44.1 LED on the DACMagic lit. When the source material was 48ks/sec, the 48 LED lit. The sound data wasn’t being fiddled about with on its way to the DAC.
To obtain the above I followed the instructions that Cambridge Audio gave to me. In Ubuntu you open up the System>Preferences>Sound submenu, then select the “C Media USB Headphone Set USB Audio (OSS)” option for the ‘Sound Events’, ‘Music and Movies’, and ‘Audio Conferencing’. Beside each of these is a test button. Click on this and you should then hear a test tone if things are working correctly. Having done this I could play audio CDs in the optical drive, listen to mp3 files, etc, and the DACMagic would be able to play with the correct sampling rate. With the audio gain set to ‘100%’ I found that LPCM formats like CD Audio would provide bit-perfect streams to the DACMagic.
Figure 6 shows the results I could obtain from the analogue output of the DACMagic when playing my test tones. These do show some distortion products. But they are at very low levels and correspond to around 0·001% for a loud signal.
So does Linux compete with Windows or MacOS on a computer system intended for domestic sound reproduction? My view is that the answer is “Yes, but with some words of caution!” The main problem is akin to the one with other operating systems. That you may have to choose your soundcard with care, or on the advice of someone who has already obtained a working system. An advantage of Linux is that there are a variety of ‘distros’ (distribution versions) and you can experiment with them. That said, I’d suggest Ubuntu is probably the best starting place if you’ve never used Linux before.
From my experiments the Cambridge Audio DACMagic is well worth considering if you want a good ‘soundcard’ for a Linux machine. It works, and has some advantages. One is that the LEDs tell you if the data is actually coming though at the correct sampling rate. The other is that it is quite flexible since it has digital outputs and other inputs. That makes it easier to tie into your existing audio system.
I am probably biassed by my personal experiences in that I prefer the way UNIX/Linux works. I like the ‘open’ approach. So I guess I’d tend to prefer the ‘experiment and DIY’ approach, anyway. The internal soundcard in my Shuttle XPC wasn’t very co-operative with Ubuntu, but the DACMagic did work like,... erm, magic, and was easy to get working well. And, as with my laptop, linux often works neatly on machines regarded as ‘too old’ for Windows use. So I plan to continue to use Linux for audio purposes where a computer is handy. If you are happy to experiment, then maybe you can also give it a try.
7th Jun 2009