File tree Expand file tree Collapse file tree 1 file changed +5
-6
lines changed
src/AudioTools/AudioLibs/FFT Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -28,12 +28,12 @@ class WindowFunction {
2828 virtual void begin (int samples) {
2929 this ->samples_minus_1 = -1 .0f + samples;
3030 this ->i_samples = samples;
31- this ->i_half_samples = samples / 2 - 1 ;
31+ this ->i_half_samples = samples / 2 ;
3232 }
3333
3434 // / Provides the multipication factor at the indicated position. The result is symetrically mirrored around the center
3535 inline float factor (int idx) {
36- float result = idx < i_half_samples ? factor_internal (idx) : factor_internal (i_samples-idx-1 );
36+ float result = idx <= i_half_samples ? factor_internal (idx) : factor_internal (i_samples-idx-1 );
3737 return result>1 .0f ? 1 .0f : result;
3838 }
3939
@@ -75,9 +75,8 @@ class BufferedWindow : public WindowFunction {
7575 WindowFunction::begin (samples);
7676 if (p_wf->samples () != samples) {
7777 p_wf->begin (samples);
78- len = samples;
79- buffer.resize (len);
80- for (int j = 0 ; j < len; j++) {
78+ buffer.resize (i_half_samples + 1 );
79+ for (int j = 0 ; j <= i_half_samples; j++) {
8180 buffer[j] = p_wf->factor (j);
8281 }
8382 }
@@ -89,7 +88,7 @@ class BufferedWindow : public WindowFunction {
8988 int len;
9089
9190 float factor_internal (int idx) override {
92- if (idx < 0 || idx > len ) return 0.0 ;
91+ if (idx < 0 || idx > i_half_samples ) return 0.0 ;
9392 return buffer[idx];
9493 }
9594};
You can’t perform that action at this time.
0 commit comments