I have many features which utilize spectrum data from Unity. I now have another native audio library to replace Unity Audio to play music in games.
I got a FFT lib to calculate the input data to get out the magnitudes. But the problem is the data I got and data from Unity. This will cause other features will not work the same way.
To be more specific. When test on file mp3 with 440Hz only.
- with Unity I got value > 0.01 around index 9, 10, 11 (0 is the start0
- with native FFT, I got value around 4, 5, 6
- Of course the value will be difference
I’m not audio engineer, I don’t know how to simulate data like Unity. One big mystery to me is after calculate FFT, only half of array have meaning value. Ex: for 512, I only got 256 useful value. How can Unity fill the full array of 512 samples?
Note: I pre-apply window function the same with Unity to try to reproduce the best result:
memset(_imag, 0, (_fftSize) * sizeof(float));
memcpy(_real, data, (_fftSize) * sizeof(float));
for (size_t i = 0; i < _fftSize; i++) {
_real[i] *= _window[i];
}
ComputeFFTComplex(_real, _imag, _logSize, true);
for (size_t i = 0; i < _fftSize; i++) {
_halfSpectrum[i] = sqrt(_real[i]*_real[i] + _imag[i]*_imag[i]) / _fftSize*2.0f;
}
New contributor