I have been trying to understand sinc interpolation for a while now and have coded several versions of it.

The problem is, as you might quess, it doesn't work.

I have tested the interpolation code with pure sine wave changing the frequency from 50hz to something bigger like 100hz.

The latest code I have been using is from here viewtopic.php?t=330731#

- Code: Select all
`#define SINC_WIDTH 32`

#define SAMPLES_PER_ZERO_CROSSING 11500

float sincInterp(float playhead, float* input, int sourceLength){

long playheadint = floor(playhead);

double playheadfrac = playhead - playheadint;

double accum = 0.0;

// Loop through every sample we're interested in...

int i;

for(i = -SINC_WIDTH + 1; i < SINC_WIDTH -1; i ++) {

long thissample = playheadint + i;

// HACK: To handle start and end points,

// we just duplicate the start and end samples.

// POSSIBLE FIX: mirror start/end of input?

if(thissample < 0) thissample = 0;

if(thissample >= sourceLength) thissample = sourceLength - 1;

double moo = input[thissample];

float sincindex = fabs(round((i+playheadfrac) * SAMPLES_PER_ZERO_CROSSING));

moo *= sinc(sincindex);

accum += moo;

}

return (float)accum;

}

sinc generation code (copied from somewhere I don't remember)

- Code: Select all
`void make_sinc(){`

int i;

double temp,win_freq,win;

win_freq = PI / SINC_WIDTH / SAMPLES_PER_ZERO_CROSSING;

sinc_table[0] = 1.0;

for (i=1;i<SINC_WIDTH * SAMPLES_PER_ZERO_CROSSING;i++) {

temp = (double) i * PI / SAMPLES_PER_ZERO_CROSSING;

sinc_table[i] = sin(temp) / temp;

win = 0.5 + 0.5 * cos(win_freq * i);

sinc_table[i] *= win;

}

}

sinc is a method where the value is got from a sinc table

- Code: Select all
`...`

temp = fabs(x);

low = temp; /* these are interpolation steps */

delta = temp - low; /* and can be ommited if desired */

return linear_interp(sinc_table[low],sinc_table[low + 1],delta);

...

Using 50hz sine wave with rate = 1.1 the output waveform is like this.

And frequency spectrum like this.

We can clearly see that the interpolation is not perfect. In fact linear interpolation would be much better than this

It doesn't help If I change SINC_WIDTH or SAMPLES_PER_ZERO_CROSSING to bigger values. The quality stays the same.

I'm making some mistake in somewehere but I don't know where.

I don't wan't opinions about I should use some other interpolation methods. I just want to learn why my code doesn't work and after then I can move on and perhaps use some other method for interpolation

I would really appreciate your help