[sdiy] Fwd: OT - Linear interpolation in C

Mikko Helin maohelin at gmail.com
Sun Jan 30 21:16:11 CET 2011


So you have to use throughout your code the dsp.h defined / DSP
Libraries implemented and _builtin_ functions and define your
fractionals like defined in dsp.h

#ifndef fractional
typedef int fractional;
#endif

and intialize them with the Q15 macro in dsp.h

#define Q15(X) ((X < 0.0) ? (int)(32768*(X) - 0.5) : (int)(32767*(X) + 0.5))

Alternatively implement your own DSP libraries or see if other
compliers (IAR, Mikroe) support fractionals.

On MC forums there were discussions on adding native fractional
support to MC C but it's not on top of the list (far from it).

More about dsPIC® Language Tools Libraries here:
http://ww1.microchip.com/downloads/en/devicedoc/51456b.pdf

- Mikko

On Sun, Jan 30, 2011 at 8:43 PM, Mikko Helin <maohelin at gmail.com> wrote:
> I think Microchip C supports 1.15 in _Q15 data type, at least their
> Fixed Point Math Librarty uses this and Q16 (which is 15.16
> fractional) data types.
>
> See:
> http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2680&dDocName=en552208
>
> - Mikko
>
> On Sun, Jan 30, 2011 at 4:10 PM, Tom Wiltshire <tom at electricdruid.net> wrote:
>> The first section (doing the table lookups) is easy, and I've got that working fine in C. It's the second section I'm struggling with. Specifically, I can't see how the C variable types I've got relate to the 1.15 format accumulator usage that I'm used to. I've got a 1.15 integer type in C (signed int), but it is treated as a full range integer (eg 32767 to -32768) rather than as a fractional number from -1 to nearly 1, which is how I use it with the accumlator.



More information about the Synth-diy mailing list