コード例 #1
0
ファイル: Fourier.cs プロジェクト: jamezleedz/SDRSharper
        public unsafe static void ForwardTransformLut(Complex *buffer, int length)
        {
            int     num     = length - 1;
            int     num2    = length / 2;
            Complex complex = default(Complex);

            complex.Real = 0f;
            complex.Imag = 0f;
            Complex c = default(Complex);

            c.Real = 0f;
            c.Imag = 0f;
            int num3 = 0;

            for (int num4 = length; num4 > 1; num4 >>= 1)
            {
                num3++;
            }
            int num5 = num2;

            for (int num4 = 1; num4 < num; num4++)
            {
                if (num4 < num5)
                {
                    complex      = buffer[num5];
                    buffer[num5] = buffer[num4];
                    buffer[num4] = complex;
                }
                int num6;
                for (num6 = num2; num6 <= num5; num6 /= 2)
                {
                    num5 -= num6;
                }
                num5 += num6;
            }
            for (int i = 1; i <= num3; i++)
            {
                int num7 = 1 << i;
                int num8 = num7 / 2;
                int num9 = 16 - i;
                for (num5 = 1; num5 <= num8; num5++)
                {
                    int num10 = num5 - 1;
                    int num11 = num10 << num9;
                    c.Real = Fourier._lr[num11];
                    c.Imag = Fourier._li[num11];
                    for (int num4 = num10; num4 <= num; num4 += num7)
                    {
                        num11 = num4 + num8;
                        Complex.Mul(ref complex, c, buffer[num11]);
                        Complex.Sub(ref buffer[num11], buffer[num4], complex);
                        Complex.Add(ref buffer[num4], complex);
                    }
                }
            }
        }
コード例 #2
0
ファイル: Fourier.cs プロジェクト: jamezleedz/SDRSharper
        public unsafe static void ForwardTransformRot(Complex *buffer, int length)
        {
            int     num  = length - 1;
            int     num2 = length / 2;
            Complex c    = default(Complex);

            c.Real = 0f;
            c.Imag = 0f;
            Complex complex = default(Complex);

            complex.Real = 0f;
            complex.Imag = 0f;
            int num3 = 0;

            for (int num4 = length; num4 > 1; num4 >>= 1)
            {
                num3++;
            }
            int num5 = num2;

            for (int num4 = 1; num4 < num; num4++)
            {
                if (num4 < num5)
                {
                    complex      = buffer[num5];
                    buffer[num5] = buffer[num4];
                    buffer[num4] = complex;
                }
                int num6;
                for (num6 = num2; num6 <= num5; num6 /= 2)
                {
                    num5 -= num6;
                }
                num5 += num6;
            }
            for (int i = 1; i <= num3; i++)
            {
                int    num7 = 1 << i;
                int    num8 = num7 / 2;
                double num9 = 3.1415926535897931 / (double)num8;
                for (num5 = 1; num5 <= num8; num5++)
                {
                    int num10 = num5 - 1;
                    Complex.FromAngle(ref c, num9 * (double)num10);
                    Complex.Conjugate(ref c);
                    for (int num4 = num10; num4 <= num; num4 += num7)
                    {
                        int num11 = num4 + num8;
                        Complex.Mul(ref complex, c, buffer[num11]);
                        Complex.Sub(ref buffer[num11], buffer[num4], complex);
                        Complex.Add(ref buffer[num4], complex);
                    }
                }
            }
        }
コード例 #3
0
 private unsafe void ProcessStandard(Complex *buffer, int length)
 {
     if (this._queueBuffer != null)
     {
         for (int i = 0; i < length; i++)
         {
             Complex *ptr = this._queuePtr + this._offset;
             *        ptr = buffer[i];
             this._acc.Real = 0f;
             this._acc.Imag = 0f;
             int      num  = this._queueSize;
             Complex *ptr2 = ptr;
             Complex *ptr3 = this._coeffPtr;
             if (num >= 4)
             {
                 do
                 {
                     Complex.Mul(ref this._acc, *ptr2, *ptr3);
                     Complex.Mul(ref this._tmp, ptr2[1], ptr3[1]);
                     Complex.Add(ref this._acc, this._tmp);
                     Complex.Mul(ref this._tmp, ptr2[2], ptr3[2]);
                     Complex.Add(ref this._acc, this._tmp);
                     Complex.Mul(ref this._tmp, ptr2[3], ptr3[3]);
                     Complex.Add(ref this._acc, this._tmp);
                     ptr2 += 4;
                     ptr3 += 4;
                 }while ((num -= 4) >= 4);
             }
             while (num-- > 0)
             {
                 ref Complex tmp    = ref this._tmp;
                 Complex *   intPtr = ptr2;
                 ptr2 = intPtr + 1;
                 Complex  c       = *intPtr;
                 Complex *intPtr2 = ptr3;
                 ptr3 = intPtr2 + 1;
                 Complex.Mul(ref tmp, c, *intPtr2);
                 Complex.Add(ref this._acc, this._tmp);
             }
             if (--this._offset < 0)
             {
                 this._offset = this._queueSize * 3;
                 Utils.Memcpy(this._queuePtr + this._offset + 1, this._queuePtr, (this._queueSize - 1) * sizeof(Complex));
             }
             buffer[i] = this._acc;
         }
     }
コード例 #4
0
ファイル: FftProcessor.cs プロジェクト: jamezleedz/SDRSharper
        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);
            }
        }