diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-10-15 13:21:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-15 13:21:33 +0200 |
commit | e927f5417040cd17a9df4b918f660fe731e636b0 (patch) | |
tree | 2e6f040df99faa83784e9d1c191c72d6c6763363 /servers | |
parent | d76eb0b491516adbafa4cf0c57f235f7cd0e578f (diff) | |
parent | 257ba4a7fb1c76b187b2e0b1903e40d9e1097616 (diff) |
Merge pull request #42804 from RandomShaper/fix_fft_window
Fix application of window in FFT
Diffstat (limited to 'servers')
-rw-r--r-- | servers/audio/effects/audio_effect_spectrum_analyzer.cpp | 19 |
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 |