Hi ppl! ...I have a quick question! ...I am designing an audio effect algorithm; flanger. I am currently working on the problem of interpolation. Now my problem lies here:
If sample rate is 22.4 kHz, I can work out that the current delay will map exactly to any one sample in a 1second buffer by:
SAMPLE_RATE / 1000 - to give number of samples per second.
So: every ms, 22.4 samples are saved. If my delay time is [for example] 5ms, I have:
5 * 22.4 = 112 - this is a whole number! - can take the 112th sample and return!
BUT! If my delay time is 4ms:
4 * 22.4 = 89.6 - not a whole number!
SO, in this case, i need to take an average of the 89th sample and the 90th sample in the buffer!
My problem is this! how can I check to see if the number calculated is a whole number?
Thanks for any help!!! Matt.Code:tmp = currentDelay * (SAMPLE_RATE / 1000); if (tmp = whole number) { /* can simply return the sample at point currentDelay time from current sample! */ /* find where this sample is in the buffer - currentDelay samples from writePtr */ return audioBuffer[pointer - tmp]; } else { /* Have to return the average of the two nearest neighbours - get whole number part */ return(average(audioBuffer[pointer - tmp], audioBuffer[pointer-(tmp+1)])); } /* NOTE: Please - don't say my return statements are false because I am using array wrap around checks in my code! i.e: if (tmp < pointer){ sample is at other end of array! calculate its position! } I just haven't put it here because it would be about 10 lines longer!!! */