I've implemented looping of audio samples with a cross fade of 22000 (somewhat arbitrarily chosen) samples. In doing this on a non-pitch shifted sample (so interpolation doesn't need to be accounted for for both parts of the sample), I can hear the cross-fading--it's very smooth, but every single time the loop starts over (after the cross fade ends), there is a tiny click, and I don't know why.
Basically, when the sample position reaches the loopEnd value minus the xfade_length, the crossfading begins. When the sample position reaches the loopEnd value, samplePosition is reassigned to loopStart + xfade_length. I even went so far as to check the actual output data to make sure things look correct:
Sample number of the loop start + xfade sample length: 30946 (when crossfading is over, samplePosition is reset to this number).
Output of the last value in the buffer before looping the sample: -0.00536969
Actual value of the raw 30945th sample (start of loop + xfade length - 1 -- i.e. the last sample before the loop starts over): -0.00537109
Why am I getting a click when the loop starts over when the actual output of the last sample of the crossfade is nearly identical to the actual raw data? The only reason the output of the last sample before the loop is SLIGHTLY different from the actual sample value of the 30945th sample is due to the VERY slight xfade that is still present on the last iteration of the crossfade. Surely the click is not due to this tiny discrepency in data.
Is this some sort of high frequency interference?