public unsafe void MakeCoefficients(double sampleRate, int frequency, int width, WindowType window, bool stopBand = true) { int order = this._order; if (sampleRate < 30000.0 || width > 600) { order = 400; } if (sampleRate < 3000.0 || width > 6000) { order = 200; } this._width = width; this._frequency = frequency; int num = this._frequency - this._width / 2; int num2 = this._frequency + this._width / 2; int num3 = (int)Math.Max((double)(-this._fftLen / 2), (double)(num * this._fftLen) / sampleRate); int num4 = (int)Math.Min((double)(this._fftLen / 2), (double)(num2 * this._fftLen) / sampleRate); num3 = -num3; if (num3 < 0) { num3 += this._fftLen; } num4 = -num4; if (num4 < 0) { num4 += this._fftLen; } Complex[] fftBuf = this._fftBuf; fixed (Complex* buffer = fftBuf) { int num5 = (!stopBand) ? 1 : 0; int num6 = stopBand ? 1 : 0; for (int i = 0; i < this._fftLen; this._fftBuf[i].Imag = 0f, i++) { if (num3 < this._fftLen / 2 && num4 >= this._fftLen / 2) { this._fftBuf[i].Real = (float)((i < num3 || i > num4) ? num5 : num6); continue; } ref Complex val = ref this._fftBuf[i]; if (num3 <= num4 && i >= num3 && i <= num4) { goto IL_0171; } if (num4 < num3 && i >= num4 && i < num3) { goto IL_0171; } int num7 = num6; goto IL_0173; IL_0171: num7 = num5; goto IL_0173; IL_0173: val.Real = (float)num7; } Fourier.BackwardTransform(buffer, this._fftLen); }
public unsafe void Process(Complex *buffer, int length) { int i = 0; int j = 0; for (; i < length; i++) { this._fftBufferPtr[this._fftBufferPos++] = buffer[i]; if (this._fftBufferPos == this._fftSize) { int num = this._halfSize; int num2 = 0; while (num < this._fftSize) { this._overlapBufferPtr[num2] = this._fftBufferPtr[num]; num++; num2++; } for (; j < length; j++) { if (this._sampleBufferHead == this._sampleBufferTail) { break; } buffer[j] = this._sampleBufferPtr[this._sampleBufferTail]; this._sampleBufferTail = (this._sampleBufferTail + 1 & this._fftSize - 1); } Fourier.ForwardTransform(this._fftBufferPtr, this._fftSize, false); this.ProcessFft(this._fftBufferPtr, this._fftSize); Fourier.BackwardTransform(this._fftBufferPtr, this._fftSize); int num3 = 0; int num4 = this._halfSize - this._overlapSize; while (num3 < this._halfSize) { if (num3 < this._overlapSize) { float num5 = (float)num3 * this._blendFactor; Complex.Mul(ref this._sampleBufferPtr[this._sampleBufferHead], this._fftBufferPtr[num4], num5); Complex.Mul(ref this._tmp, this._outOverlapPtr[num3], 1f - num5); Complex.Add(ref this._sampleBufferPtr[this._sampleBufferHead], this._tmp); } else { this._sampleBufferPtr[this._sampleBufferHead] = this._fftBufferPtr[num4]; } this._sampleBufferHead = (this._sampleBufferHead + 1 & this._fftSize - 1); num3++; num4++; } int num6 = 0; int num7 = this._fftSize - this._overlapSize; while (num6 < this._overlapSize) { this._outOverlapPtr[num6] = this._fftBufferPtr[num7]; num6++; num7++; } for (int k = 0; k < this._halfSize; k++) { this._fftBufferPtr[k] = this._overlapBufferPtr[k]; } this._fftBufferPos = this._halfSize; } } for (; j < length; j++) { if (this._sampleBufferHead == this._sampleBufferTail) { break; } buffer[j] = this._sampleBufferPtr[this._sampleBufferTail]; this._sampleBufferTail = (this._sampleBufferTail + 1 & this._fftSize - 1); } }