There was an unpleasant but VERY infrequent glitch in PICYCLE, and it was related to rapid shifting between MIP maps, and it just got fixed.

The wavetable filtering had previously been done in the time domain, by progressively filtering the signal at each octave to kill high frequency energy. This was all well and good, but my implementation requires that to avoid glitching, I need to ensure that there is a positive-moving zero transition at location zero in the wavetable, at all octaves. And with arbitrary signals that condition couldn't be guaranteed, hence the occasional glitch.

BUT - if I assume that all the psychoacoustic stuff I have ever read is right, and that human hearing is phase-insensitive (and please, feel free to all shoot me down at once) then an FFT-based fix can be used.

a) Take the source wave.

b) FFT it.

c) For each frequency bin

d) take the magnitude of the real and imaginary frequency components and stick it in the real part

e) Zero out the imaginary part.

f) Inverse FFT it to get the waveform back

So in effect I have just phase-aligned all the frequency components of the wave by killing the cos component.

Then I get three effects at once.

Firstly, I get easy MIPping - by progressively zeroing out bins then performing the inverse FFT, I get a bandlimited wave at each octave.

Secondly, since everything is a sin I will have a positive zero transition at phase=0.0.

Thirdly, via some deep FFT magic that I can't explain in maths but that I intuitively get, as it is associated with the behaviour of phase-aligned sine waves, suddenly some kind of 'complex conjugate' effect appears in the time domain, and I get an outgoing waveform that is symmetrical but inverted around the phase=0.5 point.

So after FFT then inverse FFT the outgoing wave is visibly different to the incoming, but only in phase, there is no DC bias because I punch that out to zero, and as if by magic the wave immediately before the phase=0 transition is symmetrical with the wave after the phase=0.0 transition, at all octaves, so the zero transition is well-behaved and is always located exactly at phase=0.0.

Phew.

My synthetic waves - square and saw and triangle, and the 'formant' things with buckets of harmonics - all come through unmodified but bandlimited, which is in fact not surprising as they are already of that 'complex conjugate' mirrored / symmetrical shape. Interestingly, having checked the veracity of that previous statement, I now discover that the 'formant' shapes do get slightly mangled / translated - they were like this -

and are now like this -

Same same but different. Fascinating, Jim. And the amplitude difference between these is something that I have now fixed.

$64,000 question - does it sound the same? I don't actually have an A/B test that will let me determine that yet, but it really, really sounds similar. And frankly my dear, I don't give a damn, as the FFT method is the only one that will let me fix the problem. Hence it has to stay.

The key thing is that the desired effect happens - no more clicks. In fact, it sounds ACE.

For your visual pleasure here's Caitlin going 'Aah', top version with FFT processing, bottom version with time-domain filtering. Comparing the differences is interesting. The downward-moving zero transition is not at phase = 0.5 in the time-domain filtered version, due to the asymmetry in the first and second halves of the wave. In fact in the original there is a whole zero-crossing pair in the first half of the waveform that doesn't appear in the second - the first half has less area below the curve than the second has area above the curve, so there is a DC bias, and under progressive filtering in the time domain the zero transition I need to make it click-free will move away from 0.0, and this one will click.

They really don't look the same, but they have all the same frequency compenents, albeit phase-shifted relative to each other.

I repeat - fascinating, eh?