summaryrefslogtreecommitdiff
path: root/servers
diff options
context:
space:
mode:
authorPedro J. Estébanez <pedrojrulez@gmail.com>2020-10-15 01:57:17 +0200
committerPedro J. Estébanez <pedrojrulez@gmail.com>2020-10-15 01:57:17 +0200
commit257ba4a7fb1c76b187b2e0b1903e40d9e1097616 (patch)
treeb8620d3d8eb5b7833f73238f2ae8c51a53c0242f /servers
parentbf37ab52b3ee4b14f235cfa1ea9e48c24c616bb3 (diff)
Fix application of window in FFT
Diffstat (limited to 'servers')
-rw-r--r--servers/audio/effects/audio_effect_spectrum_analyzer.cpp19
1 files changed, 9 insertions, 10 deletions
diff --git a/servers/audio/effects/audio_effect_spectrum_analyzer.cpp b/servers/audio/effects/audio_effect_spectrum_analyzer.cpp
index e744dbf9b0..3f4f11ee8d 100644
--- a/servers/audio/effects/audio_effect_spectrum_analyzer.cpp
+++ b/servers/audio/effects/audio_effect_spectrum_analyzer.cpp
@@ -113,15 +113,15 @@ void AudioEffectSpectrumAnalyzerInstance::process(const AudioFrame *p_src_frames
float *fftw = temporal_fft.ptrw();
for (int i = 0; i < to_fill; i++) { //left and right buffers
- float window = -0.5 * Math::cos(2.0 * Math_PI * (double)i / (double)to_fill) + 0.5;
- fftw[(i + temporal_fft_pos) * 2] = window * p_src_frames[i].l;
- fftw[(i + temporal_fft_pos) * 2 + 1] = 0;
- fftw[(i + temporal_fft_pos + fft_size * 2) * 2] = window * p_src_frames[i].r;
- fftw[(i + temporal_fft_pos + fft_size * 2) * 2 + 1] = 0;
+ float window = -0.5 * Math::cos(2.0 * Math_PI * (double)temporal_fft_pos / (double)fft_size) + 0.5;
+ fftw[temporal_fft_pos * 2] = window * p_src_frames->l;
+ fftw[temporal_fft_pos * 2 + 1] = 0;
+ fftw[(temporal_fft_pos + fft_size * 2) * 2] = window * p_src_frames->r;
+ fftw[(temporal_fft_pos + fft_size * 2) * 2 + 1] = 0;
+ ++p_src_frames;
+ ++temporal_fft_pos;
}
- p_src_frames += to_fill;
- temporal_fft_pos += to_fill;
p_frame_count -= to_fill;
if (temporal_fft_pos == fft_size * 2) {
@@ -134,9 +134,8 @@ void AudioEffectSpectrumAnalyzerInstance::process(const AudioFrame *p_src_frames
for (int i = 0; i < fft_size; i++) {
//abs(vec)/fft_size normalizes each frequency
- float window = 1.0; //-.5 * Math::cos(2. * Math_PI * (double)i / (double)fft_size) + .5;
- hw[i].l = window * Vector2(fftw[i * 2], fftw[i * 2 + 1]).length() / float(fft_size);
- hw[i].r = window * Vector2(fftw[fft_size * 4 + i * 2], fftw[fft_size * 4 + i * 2 + 1]).length() / float(fft_size);
+ hw[i].l = Vector2(fftw[i * 2], fftw[i * 2 + 1]).length() / float(fft_size);
+ hw[i].r = Vector2(fftw[fft_size * 4 + i * 2], fftw[fft_size * 4 + i * 2 + 1]).length() / float(fft_size);
}
fft_pos = next; //swap