Exemple #1
0
 public static Complex FromAngleFast(float angle)
 {
     return(Trig.SinCos(angle));
 }
Exemple #2
0
 public float ArgumentFast()
 {
     return(Trig.Atan2(Imag, Real));
 }
Exemple #3
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;
                    }
                }
            }
        }
Exemple #4
0
 public float ArgumentFast()
 {
     return(Trig.Atan2(this.Imag, this.Real));
 }
        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
        }