Our team member Andy has written a step-by-step guide how to use the HiFiBerry DAC together with Volumio for music playback. Have a look at it!
A reader asked why I created a separate DSP board instead of just added analogue inputs and outputs to the Raspberry Pi and do the DSP processing in software on the Raspberry Pi CPU. I never though about this option, but they might be interesting.
Independent from the processing power of the Raspberry CPU (we will come to this later), one problem is the operating system. The OS does not have realtime capabilities, which means the OS kernel can block every user process as long as it wants. However, this is more a theoretical problem, than a practical one. Using some buffering this will most likely work well. But do not expect delays in the range < 1ms, they will be longer than this!
The CPU is running at 700MHz and can be clocked even up to 1GHz which is way faster than the DSP chip on the HiFiBerry DSP light. This chip runs at 50MHz only. However, clock rate does not say a lot about performance. DSP chips are specially created for the algorithms use in digital signal processing, while a normal CPU is optimized to do most of the tasks reasonably well. Let’s have a look on the Raspberry Pi CPU: The SoC is produced by Broadcom and uses a ARM1176JZ-F core. It is based on the ARMv6 architecture, which is quite old (first CPUs based on this architecture shipped in 2002). One good thing about it is, that it features a floating point numerical co-processor – a VFPv2. It even has a DSP command set. However, the DSP commands are useless for our use, because they work only with 16bit. It would be possible to emulate 32bit operations with it, but the performance will be relatively low. Therefore we will have a look on the floating point unit.
The VFPv2 floating point unit
After having a look at the technical reference manual, it seems, that the floating point unit can process most floating point operations in a single clock cycle. On the Raspberry Pi this would mean a theoretical floating point performance of 1 GFlops. However this is a completely theoretical number. Data has to be transferred between the main memory and the VFP. This means, the practical performance will be much lower. However, it still looks promising.
Simple test in C
Let’s see, what happens if we use s simple C program that runs a floating point multiplication over and over. Out program uses this inner multiplication (both variables are floats). It loops exactly 1,000,000,000 times over this operation.
f1[i] *= f2[i];
We use arrays to make sure to have the least efficient access (from memory to CPU back to memory) to the data. Therefore this is a worst-case scenario. With 1GFlops performance, the program should be finished in 1 second. Let’s see:
[email protected]:~/fp$ time ./ft real 1m9.358s user 1m7.960s sys 0m0.050s
Oops, that’s almost 70 seconds. That would result in a floating point performance of only 14 MFlops. And – yes, we did use the hardware VFP unit, the program was compiled that way.
That’s a lot less than even the simple HiFiBerry DSP light board. With 48kHz sample rate this would result in less than 300 operations per sample. That’s not much.
Now let’s use some code that does not need memory access all the time. It uses only two variables:
f *= g
This should need less memory access.
[email protected]:~/fp$ time ./ft real 0m44.142s user 0m43.340s sys 0m0.010s
It looks better, but the performance is still less than 25MFlops.
It is interesting to see, that even having the simple loop around the operations we used takes about 14 seconds. That means, the floating point performance is a bit better. In the second case it would be a bit more than 30 MFlops.
Conclusion: Using C code, the Raspberry Pi can be used only for simple DSP operations. However, there might be a chance to dramatically improve the performance by using highly optimized assembler code.
- ARMv6 Reference manual
- ARM1176JZF-S™ Technical Reference Manual
- ARM System Developer’s Guide
I started with the programming for the HiFiBerry DSP light. Basically the software uses the program generated by Sigma Studio and writes it to the EEPROM module on the HiFiBerry DSP or directly to the DSP chip. In both cases the code is the same, only the I2C address is different. The software will be open-source, you can have a look at the current version on GitHub. It is not fully functional yet, it is not even an alpha version, but a work-in-progress.
The first software version will be a command-line-only version. There are also plans to have a web interface that you can use from your PC or even your mobile phone. A loudspeaker crossover that can be changed from your mobile phone? Yes, you can do it. Turning room equalization on or off from your mobile phone – you can do this too. Sounds cool? Are you interested to help with the development? Contact me!
You want to simulation the effect of horns and waveguides on a speaker design? Check out the software from Randteam.de. It uses lumped element models for acoustics modeling. This is not a “plug-and-play” software where you simply insert your horn design and click “run”. It will need at least some training, but the results seem to match reality quiet well.
There is a free version that does not allow saving. The commercial version of ABEC2 that is still in work.
In the past I used TurboCAD for loudspeaker designs. Unfortunately my TurboCAD version is extremely old and also does not run on my Mac. Therefore, I was looking for a new CAD software. Sketchup is good for some designs, but has two major problems: It is not designed for the creation of small parts (it is not usable for sub-millimeter resolution) and it does not support boolean operations in 3D (the commercial version does, but not the free version).
After looking at several open source CAD systems I decided to start using FreeCAD. FreeCAD is extremely powerful, it supports even parametric modeling. Unfortunately this also means that you need some time to learn how to use it. FreeCAD is available for Windows, Linux and Mac. Unfortunately, the Mac version is a bit less stable than the Linux and Windows version.
There is another problem for Mac users: You need a third mouse key. MagicPrefs worked well with my Magic Mouse to implement this on MacOS.
Update 16.06.2013: The parametric modeling is extremely powerful if you understand how it works. It makes changes on existing components very easy. Unfortunately the MacOS version of FreeCAD has some stability issues. Therefore save often or use the Linux version in a virtual machine.
If you’re using an DSP for equalization or as crossover (or both), you might have a look at rePhase. This open source tools allows to create filters for all kinds of DSPs, both IIR[ref]infinite impulse response[/ref] and FIR[ref] finite impulse response[/ref] filters.