public SampleAggregator(int fftLength) { if (!IsPowerOfTwo(fftLength)) { throw new ArgumentException("FFT Length must be a power of two"); } m = (int) Math.Log(fftLength, 2.0); this.fftLength = fftLength; fftBuffer = new Complex[fftLength]; fftArgs = new FftEventArgs(fftBuffer); }
public SampleAggregator(int fftLength) { if (!IsPowerOfTwo(fftLength)) { throw new ArgumentException("FFT Length must be a power of two"); } m = (int)Math.Log(fftLength, 2.0); this.fftLength = fftLength; fftBuffer = new Complex[fftLength]; fftArgs = new FftEventArgs(fftBuffer); }
private void FftCalculated(object sender, FftEventArgs e) { if (_lines == 0) return; lock (SpectrumData) { int x; var b0 = 0; SpectrumData.Clear(); for (x = 0; x < _lines; x++) { float peak = 0; var b1 = (int) Math.Pow(2, x*10.0/(_lines - 1)); if (b1 > 2047) b1 = 2047; if (b1 <= b0) b1 = b0 + 1; for (; b0 < b1; b0++) if (peak < e.Result[1 + b0].X) peak = e.Result[1 + b0].X; var y = (int) (Math.Sqrt(peak)*3*255 - 4); if (y > 255) y = 255; if (y < 0) y = 0; SpectrumData.Add((byte) y); } } }