/// <summary> /// Calculates a normalization offset for the current window function. Every window function leads to /// a different FFT result peak value, and since the peak value of each windowed FFT means 0dB, this /// offset can be used to adjust the calculated dB values. /// </summary> private void CalculateWindowFunctionNormalizationOffset() { if (windowFunction == null) { windowFunctionNormalizationDecibelOffset = 0; } else { SineGeneratorStream sine = new SineGeneratorStream(1024, 16, new TimeSpan(0, 0, 1)); float[] input = new float[WindowSize]; float[] output = new float[input.Length / 2]; WindowFunction wf = WindowUtil.GetFunction(windowFunction.Type, input.Length); sine.Read(input, 0, input.Length); wf.Apply(input); fft.Forward(input); int maxIndex = FFTUtil.Results(input, output); float maxValue = output[maxIndex]; windowFunctionNormalizationDecibelOffset = 1f - maxValue; } }
public void Apply(float[] values, int valuesOffset) { WindowUtil.Apply(values, valuesOffset, window); }