Exemplo n.º 1
0
        public unsafe void Configure(double sampleRate, int decimationStageCount)
        {
            int num = (int)Math.Pow(2.0, (double)decimationStageCount);

            if (this._sampleRate != sampleRate || this._audioDecimationFactor != num)
            {
                this._sampleRate        = sampleRate;
                this._pilotFilterBuffer = UnsafeBuffer.Create(sizeof(IirFilter));
                this._pilotFilter       = (IirFilter *)(void *)this._pilotFilterBuffer;
                this._pilotFilter->Init(IirFilterType.BandPass, 19000.0, this._sampleRate, 500);
                this._pll->SampleRate       = (float)this._sampleRate;
                this._pll->DefaultFrequency = 19000f;
                this._pll->Range            = 20f;
                this._pll->Bandwidth        = 10f;
                this._pll->Zeta             = 0.707f;
                this._pll->PhaseAdjM        = StereoDecoder._pllPhaseAdjM;
                this._pll->PhaseAdjB        = StereoDecoder._pllPhaseAdjB;
                this._pll->LockTime         = 0.5f;
                this._pll->LockThreshold    = 1f;
                double  num2         = sampleRate / (double)num;
                float[] coefficients = FilterBuilder.MakeBandPassKernel(num2, 250, 20.0, 16000.0, WindowType.BlackmanHarris4);
                this._channelAFilter  = new FirFilter(coefficients, 1);
                this._channelBFilter  = new FirFilter(coefficients, 1);
                this._deemphasisAlpha = (float)(1.0 - Math.Exp(-1.0 / (num2 * (double)StereoDecoder._deemphasisTime)));
                this._deemphasisAvgL  = 0f;
                this._deemphasisAvgR  = 0f;
            }
            if (this._channelADecimator != null && this._channelBDecimator != null && this._audioDecimationFactor == num)
            {
                return;
            }
            this._channelADecimator     = new FloatDecimator(decimationStageCount);
            this._channelBDecimator     = new FloatDecimator(decimationStageCount);
            this._audioDecimationFactor = num;
        }
Exemplo n.º 2
0
        private void InitFilters()
        {
            int cutoff1 = 0;
            int cutoff2 = 10000;
            var iqBW    = _bandwidth / 2;
            int iqOrder = _actualDetectorType == DetectorType.WFM ? 60 : _filterOrder;

            var coeffs = FilterBuilder.MakeLowPassKernel(_sampleRate / (1 << _baseBandDecimationStageCount), iqOrder, iqBW, _windowType);

            if (_iqFilter == null || _decimationModeHasChanged)
            {
                _iqFilter = new IQFirFilter(coeffs, _actualDetectorType == DetectorType.WFM, 1);
            }
            else
            {
                _iqFilter.SetCoefficients(coeffs);
            }

            switch (_actualDetectorType)
            {
            case DetectorType.AM:
                cutoff1 = MinBCAudioFrequency;
                cutoff2 = Math.Min(_bandwidth / 2, MaxBCAudioFrequency);
                break;

            case DetectorType.CW:
                cutoff1 = Math.Abs(_cwToneShift) - _bandwidth / 2;
                cutoff2 = Math.Abs(_cwToneShift) + _bandwidth / 2;
                break;

            case DetectorType.USB:
            case DetectorType.LSB:
                cutoff1 = MinSSBAudioFrequency;
                cutoff2 = _bandwidth;
                break;

            case DetectorType.DSB:
                cutoff1 = MinSSBAudioFrequency;
                cutoff2 = _bandwidth / 2;
                break;

            case DetectorType.NFM:
                cutoff1 = MinNFMAudioFrequency;
                cutoff2 = _bandwidth / 2;
                break;
            }

            coeffs = FilterBuilder.MakeBandPassKernel(_sampleRate / (1 << (_baseBandDecimationStageCount + _audioDecimationStageCount)), _filterOrder, cutoff1, cutoff2, _windowType);
            _audioFilter.SetCoefficients(coeffs);
        }
Exemplo n.º 3
0
        public void Configure(double sampleRate, int decimationStageCount)
        {
            _audioDecimationFactor = (int)Math.Pow(2.0, decimationStageCount);

            if (_sampleRate != sampleRate)
            {
                _sampleRate = sampleRate;

                _pilotFilterBuffer = UnsafeBuffer.Create(sizeof(IirFilter));
                _pilotFilter       = (IirFilter *)_pilotFilterBuffer;
                _pilotFilter->Init(IirFilterType.BandPass, DefaultPilotFrequency, _sampleRate, 500);


                _pll->SampleRate       = (float)_sampleRate;
                _pll->DefaultFrequency = DefaultPilotFrequency;
                _pll->Range            = PllRange;
                _pll->Bandwidth        = PllBandwith;
                _pll->Zeta             = PllZeta;
                _pll->PhaseAdjM        = _pllPhaseAdjM;
                _pll->PhaseAdjB        = _pllPhaseAdjB;
                _pll->LockTime         = PllLockTime;
                _pll->LockThreshold    = PllThreshold;

                var outputSampleRate = sampleRate / _audioDecimationFactor;
                var coefficients     = FilterBuilder.MakeBandPassKernel(outputSampleRate, 250, Vfo.MinBCAudioFrequency, Vfo.MaxBCAudioFrequency, WindowType.BlackmanHarris4);
                _channelAFilter = new FirFilter(coefficients, 1);
                _channelBFilter = new FirFilter(coefficients, 1);

                _deemphasisAlpha = (float)(1.0 - Math.Exp(-1.0 / (outputSampleRate * _deemphasisTime)));
                _deemphasisAvgL  = 0;
                _deemphasisAvgR  = 0;
            }

            if (_channelADecimator == null || _channelBDecimator == null || decimationStageCount != _channelADecimator.StageCount)
            {
                _channelADecimator = new FloatDecimator(decimationStageCount);
                _channelBDecimator = new FloatDecimator(decimationStageCount);
            }
        }
Exemplo n.º 4
0
        private void initFilters()
        {
            int num         = this._bandwidth / 2;
            int filterOrder = (this._actualDetectorType == DetectorType.WFM) ? 60 : this._filterOrder;

            float[] coefficients = FilterBuilder.MakeLowPassKernel(this._sampleRate / Math.Pow(2.0, (double)this._baseBandDecimationStageCount), filterOrder, (double)num, this._windowType);
            if (this._realIqFilter == null)
            {
                this._realIqFilter = new IQFirFilter(coefficients, this._actualDetectorType == DetectorType.WFM, 1);
            }
            else
            {
                this._realIqFilter.SetCoefficients(coefficients);
            }
            if (this._cpxIqFilter == null)
            {
                this._cpxIqFilter = new CpxFirFilter(coefficients);
            }
            else
            {
                this._cpxIqFilter.SetCoefficients(coefficients);
            }
            this._envFilter.MakeCoefficients(this._sampleRate / Math.Pow(2.0, (double)this._envelopeDecimationStageCount), 6000, num, this._windowType, false);
            if (this._notch >= 0)
            {
                this._notchFilter[this._notch].MakeCoefficients(this._sampleRate / Math.Pow(2.0, (double)this._baseBandDecimationStageCount), this._notchFrequency, this._notchWidth, this._windowType, true);
                this._notch = -1;
            }
            int num2 = 0;
            int num3 = 10000;

            switch (this._actualDetectorType)
            {
            case DetectorType.AM:
            case DetectorType.SAM:
                num2 = 20;
                num3 = Math.Min(this._bandwidth / 2, 16000);
                break;

            case DetectorType.CW:
                num2 = this._cwToneShift - this._bandwidth / 2;
                num3 = this._cwToneShift + this._bandwidth / 2;
                break;

            case DetectorType.LSB:
            case DetectorType.USB:
                num2 = 400;
                num3 = this._bandwidth;
                break;

            case DetectorType.DSB:
                num2 = 400;
                num3 = this._bandwidth / 2;
                break;

            case DetectorType.NFM:
                num2 = 300;
                num3 = this._bandwidth / 2;
                break;
            }
            coefficients = FilterBuilder.MakeBandPassKernel(this._sampleRate / Math.Pow(2.0, (double)(this._baseBandDecimationStageCount + this._audioDecimationStageCount)), this._filterOrder, (double)num2, (double)num3, this._windowType);
            this._audioFilter.SetCoefficients(coefficients);
            this._rFilter.SetCoefficients(coefficients);
            this._lFilter.SetCoefficients(coefficients);
        }
Exemplo n.º 5
0
 public static float[] MakeStopBandKernel(double sampleRate, int filterOrder, int cutoff1, int cutoff2, WindowType windowType)
 {
     return(FilterBuilder.InvertSpectrum(FilterBuilder.MakeBandPassKernel(sampleRate, filterOrder, (double)cutoff1, (double)cutoff2, windowType)));
 }