public void Process(Complex *iq, int length)
        {
            var ptr = (float *)iq;

            if (_isMultiThteaded)
            {
                DSPThreadPool.QueueUserWorkItem(
                    delegate
                {
                    _rFilter.ProcessInterleaved(ptr, length);
                    _event.Set();
                });
            }
            else
            {
                _rFilter.ProcessInterleaved(ptr, length);
            }

            _iFilter.ProcessInterleaved(ptr + 1, length);

            if (_isMultiThteaded)
            {
                _event.WaitOne();
            }
        }
Exemple #2
0
        public void Process(Complex *buffer, int length)
        {
            var rPtr = (float *)buffer;
            var iPtr = rPtr + 1;

            if (_isMultithreaded)
            {
                DSPThreadPool.QueueUserWorkItem(
                    delegate
                {
                    _rDecimator.ProcessInterleaved(rPtr, length);
                    _event.Set();
                });
            }
            else
            {
                _rDecimator.ProcessInterleaved(rPtr, length);
            }

            _iDecimator.ProcessInterleaved(iPtr, length);

            if (_isMultithreaded)
            {
                _event.WaitOne();
            }
        }
        private void RemoveDC(Complex *iq, int length)
        {
            var iPtr = (float *)iq;
            var qPtr = iPtr + 1;

            if (_isMultithreaded)
            {
                DSPThreadPool.QueueUserWorkItem(
                    delegate
                {
                    // I branch
                    _dcRemoverI->ProcessInterleaved(iPtr, length);
                    _event.Set();
                });
            }
            else
            {
                // I branch
                _dcRemoverI->ProcessInterleaved(iPtr, length);
            }

            // Q branch
            _dcRemoverQ->ProcessInterleaved(qPtr, length);

            if (_isMultithreaded)
            {
                _event.WaitOne();
            }
        }
Exemple #4
0
 public unsafe void Process(Complex *buffer, int length)
 {
     if (this._isMultithreaded)
     {
         this._completedCount = 0;
         for (int i = 1; i < this._phaseCount; i++)
         {
             DSPThreadPool.QueueUserWorkItem(delegate(object parameter)
             {
                 int num2 = (int)parameter;
                 this._oscillators[num2].Mix(buffer, length, num2, this._phaseCount);
                 Interlocked.Increment(ref this._completedCount);
                 this._event.Set();
             }, i);
         }
         this._oscillators->Mix(buffer, length, 0, this._phaseCount);
         if (this._phaseCount > 1)
         {
             Interlocked.Increment(ref this._completedCount);
             while (this._completedCount < this._phaseCount)
             {
                 this._event.WaitOne();
             }
         }
     }
     else
     {
         for (int j = 1; j < this._phaseCount; j++)
         {
             int num = j;
             this._oscillators[num].Mix(buffer, length, num, this._phaseCount);
         }
         this._oscillators->Mix(buffer, length, 0, this._phaseCount);
     }
 }
Exemple #5
0
        public void Process(Complex *buffer, int length)
        {
            _completedCount = 0;

            for (var i = 1; i < _phaseCount; i++)
            {
                DSPThreadPool.QueueUserWorkItem(
                    parameter =>
                {
                    var index = (int)parameter;
                    _oscillators[index].Mix(buffer, length, index, _phaseCount);
                    Interlocked.Increment(ref _completedCount);
                    _event.Set();
                }, i);
            }

            _oscillators[0].Mix(buffer, length, 0, _phaseCount);

            if (_phaseCount > 1)
            {
                Interlocked.Increment(ref _completedCount);

                while (_completedCount < _phaseCount)
                {
                    _event.WaitOne();
                }
            }
        }
Exemple #6
0
 public unsafe void Process(Complex *iq, int length)
 {
     if (this._isMultiThteaded)
     {
         DSPThreadPool.QueueUserWorkItem(delegate
         {
             this._rFilter.ProcessInterleaved((float *)iq, length);
             this._event.Set();
         });
     }
     else
     {
         this._rFilter.ProcessInterleaved((float *)iq, length);
     }
     this._iFilter.ProcessInterleaved((float *)((byte *)iq + 4), length);
     if (this._isMultiThteaded)
     {
         this._event.WaitOne();
     }
 }
Exemple #7
0
        private unsafe void remDC(Complex *iq, int length)
        {
            float *buffer = (float *)((byte *)iq + 4);

            if (this._isMultithreaded)
            {
                DSPThreadPool.QueueUserWorkItem(delegate
                {
                    this._dcRemoverI->ProcessInterleaved((float *)iq, length);
                    this._event.Set();
                });
            }
            else
            {
                this._dcRemoverI->ProcessInterleaved((float *)iq, length);
            }
            this._dcRemoverQ->ProcessInterleaved(buffer, length);
            if (this._isMultithreaded)
            {
                this._event.WaitOne();
            }
        }
Exemple #8
0
        private unsafe void ProcessStereo(float *baseBand, float *interleavedStereo, int length)
        {
            if (this._channelABuffer == null || this._channelABuffer.Length != length)
            {
                this._channelABuffer = UnsafeBuffer.Create(length, 4);
                this._channelAPtr    = (float *)(void *)this._channelABuffer;
            }
            if (this._channelBBuffer == null || this._channelBBuffer.Length != length)
            {
                this._channelBBuffer = UnsafeBuffer.Create(length, 4);
                this._channelBPtr    = (float *)(void *)this._channelBBuffer;
            }
            int audioLength = length / this._audioDecimationFactor;

            if (this._isMultiThreaded)
            {
                DSPThreadPool.QueueUserWorkItem(delegate
                {
                    Utils.Memcpy(this._channelAPtr, baseBand, length * 4);
                    this._channelADecimator.Process(this._channelAPtr, length);
                    if (this._useFilter)
                    {
                        this._channelAFilter.Process(this._channelAPtr, audioLength);
                    }
                    this._event.Set();
                });
            }
            else
            {
                Utils.Memcpy(this._channelAPtr, baseBand, length * 4);
                this._channelADecimator.Process(this._channelAPtr, length);
                if (this._useFilter)
                {
                    this._channelAFilter.Process(this._channelAPtr, audioLength);
                }
            }
            for (int i = 0; i < length; i++)
            {
                float sample = this._pilotFilter->Process(baseBand[i]);
                this._pll->Process(sample);
                this._channelBPtr[i] = baseBand[i] * Trig.Sin((float)((double)this._pll->AdjustedPhase * 2.0));
            }
            if (!this._pll->IsLocked)
            {
                if (this._isMultiThreaded)
                {
                    this._event.WaitOne();
                }
                if (this._useFilter)
                {
                    for (int j = 0; j < audioLength; j++)
                    {
                        this._deemphasisAvgL += this._deemphasisAlpha * (this._channelAPtr[j] - this._deemphasisAvgL);
                        this._channelAPtr[j]  = this._deemphasisAvgL;
                    }
                }
                for (int k = 0; k < audioLength; k++)
                {
                    interleavedStereo[k * 2 + 1] = (interleavedStereo[k * 2] = this._channelAPtr[k] * 0.2f);
                }
            }
            else
            {
                this._channelBDecimator.Process(this._channelBPtr, length);
                if (this._useFilter)
                {
                    this._channelBFilter.Process(this._channelBPtr, audioLength);
                }
                if (this._isMultiThreaded)
                {
                    this._event.WaitOne();
                }
                for (int l = 0; l < audioLength; l++)
                {
                    float num  = this._channelAPtr[l];
                    float num2 = 2f * this._channelBPtr[l];
                    interleavedStereo[l * 2]     = (num + num2) * 0.2f;
                    interleavedStereo[l * 2 + 1] = (num - num2) * 0.2f;
                }
                if (this._useFilter)
                {
                    for (int m = 0; m < audioLength; m++)
                    {
                        this._deemphasisAvgL        += this._deemphasisAlpha * (interleavedStereo[m * 2] - this._deemphasisAvgL);
                        interleavedStereo[m * 2]     = this._deemphasisAvgL;
                        this._deemphasisAvgR        += this._deemphasisAlpha * (interleavedStereo[m * 2 + 1] - this._deemphasisAvgR);
                        interleavedStereo[m * 2 + 1] = this._deemphasisAvgR;
                    }
                }
            }
        }
        private void ProcessStereo(float *baseBand, float *interleavedStereo, int length)
        {
            #region Prepare L+R buffer

            if (_channelABuffer == null || _channelABuffer.Length != length)
            {
                _channelABuffer = UnsafeBuffer.Create(length, sizeof(float));
                _channelAPtr    = (float *)_channelABuffer;
            }

            #endregion

            #region Prepare L-R buffer

            if (_channelBBuffer == null || _channelBBuffer.Length != length)
            {
                _channelBBuffer = UnsafeBuffer.Create(length, sizeof(float));
                _channelBPtr    = (float *)_channelBBuffer;
            }

            #endregion

            #region Decimate and filter L+R

            var audioLength = length / _audioDecimationFactor;

            if (_isMultiThreaded)
            {
                DSPThreadPool.QueueUserWorkItem(
                    delegate
                {
                    Utils.Memcpy(_channelAPtr, baseBand, length * sizeof(float));
                    _channelADecimator.Process(_channelAPtr, length);
                    _channelAFilter.Process(_channelAPtr, audioLength);
                    _event.Set();
                });
            }
            else
            {
                Utils.Memcpy(_channelAPtr, baseBand, length * sizeof(float));
                _channelADecimator.Process(_channelAPtr, length);
                _channelAFilter.Process(_channelAPtr, audioLength);
            }

            #endregion

            #region Demodulate L-R

            for (var i = 0; i < length; i++)
            {
                var pilot = _pilotFilter->Process(baseBand[i]);
                _pll->Process(pilot);
                _channelBPtr[i] = baseBand[i] * Trig.Sin((float)(_pll->AdjustedPhase * 2.0));
            }

            if (!_pll->IsLocked)
            {
                if (_isMultiThreaded)
                {
                    _event.WaitOne();
                }

                #region Process mono deemphasis

                for (var i = 0; i < audioLength; i++)
                {
                    _deemphasisAvgL += _deemphasisAlpha * (_channelAPtr[i] - _deemphasisAvgL);
                    _channelAPtr[i]  = _deemphasisAvgL;
                }

                #endregion

                #region Fill output buffer with mono

                for (var i = 0; i < audioLength; i++)
                {
                    var sample = _channelAPtr[i] * AudioGain;
                    interleavedStereo[i * 2]     = sample;
                    interleavedStereo[i * 2 + 1] = sample;
                }

                #endregion

                return;
            }

            #endregion

            #region Decimate and filter L-R

            _channelBDecimator.Process(_channelBPtr, length);
            _channelBFilter.Process(_channelBPtr, audioLength);

            #endregion

            #region Recover L and R audio channels

            if (_isMultiThreaded)
            {
                _event.WaitOne();
            }

            for (var i = 0; i < audioLength; i++)
            {
                var a = _channelAPtr[i];
                var b = 2f * _channelBPtr[i];
                interleavedStereo[i * 2]     = (a + b) * AudioGain;
                interleavedStereo[i * 2 + 1] = (a - b) * AudioGain;
            }

            #endregion

            #region Process deemphasis

            for (var i = 0; i < audioLength; i++)
            {
                _deemphasisAvgL         += _deemphasisAlpha * (interleavedStereo[i * 2] - _deemphasisAvgL);
                interleavedStereo[i * 2] = _deemphasisAvgL;

                _deemphasisAvgR += _deemphasisAlpha * (interleavedStereo[i * 2 + 1] - _deemphasisAvgR);
                interleavedStereo[i * 2 + 1] = _deemphasisAvgR;
            }

            #endregion
        }