[Ardour-Dev] Hello, some tech talk, etc.
fons at linuxaudio.org
Fri Jul 6 16:24:28 PDT 2012
On Fri, Jul 06, 2012 at 06:58:01PM +0200, Razvan Cojocaru wrote:
> Compilers have come a long way from 1992. And how one's
> used C++ is just as important as for how long one's used it.
> One can pick a small subset of C++ and use only that for
Indeed, and that's what I've been doing for two decades.
And I don't regret that choice.
I *really* wonder if all this concern about programming
'patterns' matters in the end. What makes me write this
is not some dark desire to whip up a debate, but just
something that happened only a few days ago and which
left me with some questions. And if anyone could provide
even a hint to an answer to these I'd be quite happy.
About 15 years ago a wrote a rather complicated piece
of code implementing a phase modulation receiver. The
context is in a sense quite similar to audio app.
Input from the HW is a complex-valued signal sampled
at 1 MHz. Somehere in the [-0.5...+0.5] MHz bandwidth
there is some signal that must be detected, and shifted
to 0 Hz. 'Shifting' means a complex multiplication by
a signal from an oscillator that tracks the signal's
frequency. The classical solution, at least in HW, is
to use a phase locked loop.
The code I wrote 15 years ago uses a quite different
approach, it uses 'open loop' algorithms exclusively.
These have some advantages, and that was the reason
to use them, but this is otherwise irrelevant. The
algorithm I implemented performed phase measurements
on the signal and then used curve fitting (2nd or 3rd
degree) to find the phase trajectory of the signal.
That data was then passed on to a second thread which
used it to 'rotate' the original input signal to zero
This rather complex code (a few thousand lines), takes
something like 4% CPU for the two threads when running
on my home system.
A few days ago, I wrote the same thing (functionally
at least) as a classical PLL. The inner loop over all
samples is something like 20 short lines of C++, maybe
1 percent of the original. Yet executing in the same
environment, it takes 17% CPU. And I don't understand
why - it performs a tiny subset of the calculations
done by the original code.
You may of course say that the difference between 4% and
17% doesn't matter. But it does if you have to run 10
instances, and the original code allows that without any
A world of exhaustive, reliable metadata would be an utopia.
It's also a pipe-dream, founded on self-delusion, nerd hubris
and hysterically inflated market opportunities. (Cory Doctorow)
More information about the Ardour-Dev