Hi,

I was doing some speed and compression comparisons with various apodization/windowing functions, and found out that the definitions for the bartlett and bartlett_hann window in the FLAC codebase have been wrong since their introduction. The attached patch fixes that.

Furthermore, I found some peculiar behaviour of the gauss apodization that seems to expose bug. Using different windows does usually not change the encoding speed (only the number of them), but when I use -A gauss(0,05) (or gauss(0.05), it's locale-specific), the encoding time doubles. It seems to be when using STDDEV parameters between 0.1 and 0.01. This is also the case when using FLAC 1.3.0.

I used gprof to check and it seems that the time spend in the function FLAC__lpc_compute_autocorrelation_intrin_sse_lag_16 increases 20-fold while the number of calls stays the same. Could this be a bug?
>From a320e46330b1bc96453aef9240485ebef6f72246 Mon Sep 17 00:00:00 2001
From: Martijn van Beurden <mva...@gmail.com>
Date: Fri, 1 Aug 2014 19:36:49 +0200
Subject: [PATCH] Fix apodization functions

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

_______________________________________________
flac-dev mailing list
flac-dev@xiph.org
http://lists.xiph.org/mailman/listinfo/flac-dev

Reply via email to