[PATCH] Fix apodization functions
Martijn van Beurden
mvanb1 at gmail.com
Fri Aug 1 10:36:49 PDT 2014
The bartlett, bartlett_hann and triangle functions were broken.
Especially bartlett and bartlett_hann produced bad results,
worse than using a rectangular window. They have been fixed and
should now be according to the textbook definition
---
src/libFLAC/window.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/libFLAC/window.c b/src/libFLAC/window.c
index b873368..f6cd505 100644
--- a/src/libFLAC/window.c
+++ b/src/libFLAC/window.c
@@ -58,7 +58,7 @@ void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L)
for (n = 0; n <= L/2-1; n++)
window[n] = 2.0f * n / (float)N;
for (; n <= N; n++)
- window[n] = 2.0f - 2.0f * (N-n) / (float)N;
+ window[n] = 2.0f - 2.0f * n / (float)N;
}
}
@@ -68,7 +68,7 @@ void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L)
FLAC__int32 n;
for (n = 0; n < L; n++)
- window[n] = (FLAC__real)(0.62f - 0.48f * fabs((float)n/(float)N+0.5f) + 0.38f * cos(2.0f * M_PI * ((float)n/(float)N+0.5f)));
+ window[n] = (FLAC__real)(0.62f - 0.48f * fabs((float)n/(float)N-0.5f) - 0.38f * cos(2.0f * M_PI * ((float)n/(float)N)));
}
void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L)
@@ -173,16 +173,16 @@ void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L)
FLAC__int32 n;
if (L & 1) {
- for (n = 1; n <= L+1/2; n++)
+ for (n = 1; n <= (L+1)/2; n++)
window[n-1] = 2.0f * n / ((float)L + 1.0f);
for (; n <= L; n++)
- window[n-1] = - (float)(2 * (L - n + 1)) / ((float)L + 1.0f);
+ window[n-1] = (float)(2 * (L - n + 1)) / ((float)L + 1.0f);
}
else {
for (n = 1; n <= L/2; n++)
- window[n-1] = 2.0f * n / (float)L;
+ window[n-1] = 2.0f * n / ((float)L + 1.0f);
for (; n <= L; n++)
- window[n-1] = ((float)(2 * (L - n)) + 1.0f) / (float)L;
+ window[n-1] = (float)(2 * (L - n + 1)) / ((float)L + 1.0f);
}
}
--
1.9.1
--------------060708000208010508080005--
More information about the flac-dev
mailing list