Fixing integer overflow in wave file I have this recording from my DAW that showed a strange form of distortion: the signal clipped at many places, but instead of simply being clipped (loss of information), somehow the integer value of the signal overflowed and has been stored in the file. It resulted in worse-sounding distortion, but the information is still there, as a mirrored image in the opposite side of the signal.
This is plainly evident when looking at the waveform. You can clearly tell when the signal clips because the rest of the wave is visible between the peaks. 
How should I approach fixing this file? I am very comfortable with SOX, ffmpeg, the C language, SuperCollider and various other tools.
What you have there is &quot;wrap around&quot; and a bad case at that.
It's easy enough to fix though. Let's call your samples $x[n]$ and your max amplitude $x_{max}$, so your signal is currently bounded to $[-x_{max},+x_{max}]$
Go through the waveform sample by sample. Whenever you see a jump that's larger than your max amplitude, add or subtract twice the max amplitude to bring it back to where it was.
Something like
for (i = 1; i&lt;n; i++)
{
   sampleDiff = x[i]-x[i-1];
   if (sampleDiff &gt; xmax) { x[i] = x[i] - 2*xmax; }
   if (sampleDiff &lt; -xmax) { x[i] = x[i] + 2*xmax;}
}

Make sure you are using a data type that accommodate a data range of at least  $[-2x_{max},+2x_{max}]$, which is quite likely NOT the original data type. Also make sure you don't start in a &quot;wrapped&quot; region, i.e. x[0] needs to be good