Help me fix errors and inefficiencies in clip fix

The clip fix effect needs improvement.

This rewrite got rid of an unused variable and an assignment in an inner loop that had no effect, and combines some repeated code into a function, and rewrites some of that for more clarity.

Besides which, I believe there was a mistake in the math. Each clipping is repaired by computing the cubic determined by two values and two slopes at the boundaries of the clipping. I believe the values for those slopes were chosen mistakenly. The slope of the chord connecting the values at start and end should be subtracted from the values of “d1” and “d2”. I need someone, who knows how to differentiate a polynomial, to check my math.

I also need to devise a convincing test case demonstrating the improvement in the calculation. Someone else might have an idea.

Besides this there are other problems I have not attempted to address. Finding the clips might be made faster with snd-trigger. There is also the problem that the sound is divided into blocks of 10000 samples, and clips too near block boundaries or spanning them do not get repaired. Steve mentioned that he wrote a fix for that problem somewhere – if so, I won’t try to duplicate efforts.
clipfix.ny (4.58 KB)