コード例 #1
0
 private unsafe void OverlapSave()
 {
     Utils.Memcpy(this._fftPtr, this._queuePtr, this._fftSize * sizeof(Complex));
     Fourier.ForwardTransform(this._fftPtr, this._fftSize, false);
     this.ProcessFft(this._fftPtr, this._fftSize);
     Fourier.InverseTransform(this._fftPtr, this._fftSize);
     Utils.Memcpy(this._outputPtr, this._fftPtr + this._halfSize, this._halfSize * sizeof(Complex));
     Utils.Memcpy(this._queuePtr, this._queuePtr + this._halfSize, this._halfSize * sizeof(Complex));
 }
コード例 #2
0
 private unsafe void OverlapAdd()
 {
     for (int i = 0; i < this._fftSize; i++)
     {
         this._fftPtr[i] = this._queuePtr[i] * this._windowPtr[i];
     }
     Fourier.ForwardTransform(this._fftPtr, this._fftSize, false);
     this.ProcessFft(this._fftPtr, this._fftSize);
     Fourier.InverseTransform(this._fftPtr, this._fftSize);
     for (int j = 0; j < this._halfSize; j++)
     {
         this._outputPtr[j] = this._overlapPtr[j] * this._windowPtr[this._halfSize + j] + this._fftPtr[j] * this._windowPtr[j];
     }
     Utils.Memcpy(this._overlapPtr, this._fftPtr + this._halfSize, this._halfSize * sizeof(Complex));
     Utils.Memcpy(this._queuePtr, this._queuePtr + this._halfSize, this._halfSize * sizeof(Complex));
 }
コード例 #3
0
        private unsafe void OverlapAdd()
        {
            Utils.Memcpy(this._fftPtr, this._queuePtr, this._fftSize * sizeof(Complex));
            Fourier.ForwardTransform(this._fftPtr, this._fftSize, false);
            this.ProcessFft(this._fftPtr, this._fftSize);
            Fourier.InverseTransform(this._fftPtr, this._fftSize);
            Complex *ptr = this._fftPtr + this._fftSize / 2;
            float    num = 1f / (float)(this._outputSize - 1);

            for (int i = 0; i < this._outputSize; i++)
            {
                float num2 = num * (float)i;
                this._outputPtr[i] = this._overlapPtr[i] * (1f - num2) + ptr[i] * num2;
            }
            Utils.Memmove(this._overlapPtr, ptr + this._outputSize, this._outputSize * sizeof(Complex));
            Utils.Memmove(this._queuePtr, this._queuePtr + this._outputSize, (this._fftSize - this._outputSize) * sizeof(Complex));
        }
コード例 #4
0
        private unsafe void OverlapCrossfade()
        {
            Utils.Memcpy(this._fftPtr, this._queuePtr, this._fftSize * sizeof(Complex));
            Fourier.ForwardTransform(this._fftPtr, this._fftSize, false);
            this.ProcessFft(this._fftPtr, this._fftSize);
            Fourier.InverseTransform(this._fftPtr, this._fftSize);
            int num  = 0;
            int num2 = this._crossFadingSize - 1;
            int num3 = this._halfSize;

            while (num < this._crossFadingSize)
            {
                this._outputPtr[num] = this._fftPtr[num3] * this._windowPtr[num] + this._crossFadingPtr[num] * this._windowPtr[num2];
                num++;
                num2--;
                num3++;
            }
            Utils.Memcpy(this._outputPtr + this._crossFadingSize, this._fftPtr + this._halfSize + this._crossFadingSize, (this._outputSize - this._crossFadingSize) * sizeof(Complex));
            Utils.Memcpy(this._crossFadingPtr, this._fftPtr + this._halfSize + this._outputSize, this._crossFadingSize * sizeof(Complex));
            Utils.Memcpy(this._queuePtr, this._queuePtr + this._outputSize, (this._fftSize - this._outputSize) * sizeof(Complex));
        }
コード例 #5
0
        public void Process(Complex *buffer, int length)
        {
            var inOffset  = 0;
            var outOffset = 0;

            while (inOffset < length)
            {
                _fftBufferPtr[_fftBufferPos++] = buffer[inOffset];

                if (_fftBufferPos == _fftSize)
                {
                    for (int i = _halfSize, j = 0; i < _fftSize; i++, j++)
                    {
                        _overlapBufferPtr[j] = _fftBufferPtr[i];
                    }

                    while (outOffset < length && _sampleBufferHead != _sampleBufferTail)
                    {
                        buffer[outOffset] = _sampleBufferPtr[_sampleBufferTail];
                        _sampleBufferTail = (_sampleBufferTail + 1) & (_fftSize - 1);
                        outOffset++;
                    }

                    Fourier.ForwardTransform(_fftBufferPtr, _fftSize, false);

                    ProcessFft(_fftBufferPtr, _fftSize);

                    Fourier.InverseTransform(_fftBufferPtr, _fftSize);

                    for (int i = 0, j = _halfSize - _overlapSize; i < _halfSize; i++, j++)
                    {
                        if (i < _overlapSize)
                        {
                            var alpha = i * _blendFactor;
                            _sampleBufferPtr[_sampleBufferHead] = alpha * _fftBufferPtr[j] + (1.0f - alpha) * _outOverlapPtr[i];
                        }
                        else
                        {
                            _sampleBufferPtr[_sampleBufferHead] = _fftBufferPtr[j];
                        }

                        _sampleBufferHead = (_sampleBufferHead + 1) & (_fftSize - 1);
                    }

                    for (int i = 0, j = _fftSize - _overlapSize; i < _overlapSize; i++, j++)
                    {
                        _outOverlapPtr[i] = _fftBufferPtr[j];
                    }

                    for (var i = 0; i < _halfSize; i++)
                    {
                        _fftBufferPtr[i] = _overlapBufferPtr[i];
                    }
                    _fftBufferPos = _halfSize;
                }

                inOffset++;
            }

            while (outOffset < length && _sampleBufferHead != _sampleBufferTail)
            {
                buffer[outOffset] = _sampleBufferPtr[_sampleBufferTail];
                _sampleBufferTail = (_sampleBufferTail + 1) & (_fftSize - 1);
                outOffset++;
            }
        }