public BufferedFFT(int bufferSize, int fftSize, ILoudnessWeighting weighting = null) { this.bufferSize = bufferSize; this.fftSize = fftSize; this.LoudnessWeighting = weighting != null ? weighting : new NullWeighting(fftSize / 4); ringBuffer = new RingBuffer <float>(bufferSize); fft = new FFT(fftSize); }
public void CopyTo(float[] dest, int offset, int count, int stride, ILoudnessWeighting weighting) { int max = count; if (max > size / 2) { max = size / 2; } if (weighting.Size < max) { throw new ArgumentOutOfRangeException("Weighting not large enough"); } int desti = offset; for (int i = 0; i < max; i++) { float freq = (float)i / (float)((size / 2) - 1); dest[desti] = (float)(Math.Sqrt(fftTempComplex[i].X * fftTempComplex[i].X + fftTempComplex[i].Y * fftTempComplex[i].Y) * weighting[freq]); desti += stride; } }
/// <summary> /// Creates a buffered FFT sized to generate the given output. /// /// FFT is made twice the size of the output buffer, because we discard all frequencies above the Nyquist rate. /// The ring buffer is made twice the size of the FFT (so 4 times the size of the output). /// /// </summary> /// <param name="outputSize"></param> /// <param name="weighting"></param> public BufferedFFT(int outputSize, ILoudnessWeighting weighting = null) : this(outputSize * 4, outputSize * 2, weighting) { }