I am looking for a simple (pseudo)code that spectrum-inverse a sampled audio signal. Ideally C++
The code should support different sample rates (16/32/48KHz).
I am looking for a simple (pseudo)code that spectrum-inverse a sampled audio signal. Ideally C++
The code should support different sample rates (16/32/48KHz).
In order to get something that has the same type of temporal structure as the original, you need to
Since it's an audio signal, it doesn't much matter that the phases will be all messed up. You can't generally hear them anyway. Except for the flipping part, ARSS does the spectrogram creation and sound resynthesis.
Otherwise, you can just take a FFT, invert the amplitudes of the components, and take the inverse FFT. But that will be essentially nonsensical, as it will completely scramble the temporal structure of the sound as well as the frequency structure.
Mixing the signal by Fs/2
will swap high frequencies and low frequencies - think of rotating the spectrum around the unit circle by half a turn. You can achieve this rotation by multiplying every other sample by -1.
Mixing by Fs/2
is equivalent to mixing by exp(j*pi*n)
. If x
is the input and y
the output,
y[n] = x[n] * exp(j*pi*n) = x[n] * [cos(pi*n) + j*sin(pi*n)]
This simplifies easily because sin(pi*n)
is 0, and cos(pi*n)
is alternating 1,-1.