[flac-dev] Fix and question apodization functions

lvqcl
Sat, 02 Aug 2014 03:58:00 -0000

Martijn van Beurden wrote:

> 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.

How it affects compression ratio?


> 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?

<http://en.wikipedia.org/wiki/Denormal_number#Performance_issues> ?

Try something like this:

void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const
FLAC__real stddev)
{
	static const double anti_denormal = 0.88817841970012523233890533447266e-15; /*
2e-50 */
	const FLAC__int32 N = L - 1;
	const double N2 = (double)N / 2.;
	FLAC__int32 n;

	for (n = 0; n <= N; n++) {
		const double k = ((double)n - N2) / (stddev * N2);
		window[n] = (FLAC__real)exp(-0.5f * k * k);
		window[n] += anti_denormal;
		window[n] -= anti_denormal;
	}
}