[sdiy] Update - OT - Linear interpolation in C

Tom Wiltshire tom at electricdruid.net
Wed Feb 2 16:09:14 CET 2011


On 2 Feb 2011, at 14:19, Olivier Gillet wrote:

>> I thought some of you might be interested to see how I solved the fixed-point maths / linear interpolation problem I asked about the other day. Basically I followed the advice I got here, and put an assembly routine in to do the interp, which is then called from the C.
>> 
>> It goes in its own source file ("assembly.s") and looks like this:
>> 
>> ; Declare the functions as global so they're visible to C code
>> .global _Lerp
> 
> The advantage of using inline assembly directly in the C code is that
> you can get rid of the overhead of a function call - so there'll
> probably less shuffling of data between registers which are useless
> and only due to the fact that you must explicitly allocate registers
> in assembly. I'm saying that without having seen the generated
> assembly code, but my gut feeling with tiny embedded platforms is
> "flatten things as early as possible in the compile/link/run" chain,
> and having small chunks of assembly linked rather than inlined is one
> phase too late to me.


I agree, Olivier.

This way is tidy, though, which counts for a lot. Secondly, this is an LFO, so I'm not as pushed for time as usual for this kind of thing. If it was an audio oscillator I'd be trying to reduce it as much as I could - in fact, I'd probably have done it all in assembly. But in this case, a 48KHz sample rate at 16-bit is going to be easily good enough (an LFO with a better-than-CD-quality sample rate?!) and 48KHz gives me enough cycles not to worry about one function call overhead.

T.


More information about the Synth-diy mailing list