I am trying to calculate the multiscale spectral loss between two FFT spectrums, yet I fail miserably.
I am not sure that .pvcalc2 is the best function here, but none of the PV_ Ugens seem to be able to do the job.
~mel_win_sizes = [128, 256, 1024, 2048];
(
x = {
var src, sines, mssl, inFFT, targetFFT;
src = SoundIn.ar(0);
sines = Mix(8.collect{
var freq = 50.exprand(4950);
var amp = 0.1.rrand(1).ampdb.linlin(-65, 1.0, 0.0, 1.0);
SinOsc.ar(freq) * AmpComp.kr(freq) * amp * 0.1});
inFFT = FFT(LocalBuf(2048), src, 0.25, 1);
targetFFT = FFT(LocalBuf(2048), sines, 0.25, 1);
mssl = inFFT.pvcalc2(targetFFT, {| magnitudes1, phases1, magnitudes2, phases2 |
4.collect{|n|
var magDiff, frobDiff, logAbsDist, inFrobNorm;
magDiff = magnitudes1[0..(~mel_win_sizes[n] - 1)] - magnitudes2[0..(~mel_win_sizes[n] - 1)];
frobDiff = magDiff.squared.sum.sqrt;
logAbsDist = magDiff.abs.sum.log;
inFrobNorm = magnitudes1.squared.sum.sqrt;
(frobDiff / inFrobNorm) + logAbsDist;
}
}.sum);
mssl.poll;
[sines, src]
}.play;
)