示例#1
0
        public int Read(float *buf, int ofs, int count)
        {
            if (_readEvent != null)
            {
                while (_size == 0 && !_terminated)
                {
                    _readEvent.WaitOne();
                }
                if (_terminated)
                {
                    return(0);
                }
            }

            int result;

            lock (this)
            {
                result = DoPeek(buf, ofs, count);
                DoAdvance(result);
            }

            if (_writeEvent != null)
            {
                _writeEvent.Set();
            }

            return(result);
        }
示例#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();
            }
        }
示例#3
0
        public void Write(float *buf, int ofs, int count)
        {
            if (_writeEvent != null)
            {
                while (_size >= _maxSize && !_terminated)
                {
                    _writeEvent.WaitOne();
                }
                if (_terminated)
                {
                    return;
                }
            }

            lock (this)
            {
                var left = count;
                while (left > 0)
                {
                    int toWrite  = Math.Min(BlockSize - _writePos, left);
                    var block    = GetWBlock();
                    var blockPtr = (float *)block;
                    Utils.Memcpy(blockPtr + _writePos, buf + ofs + count - left, toWrite * sizeof(float));
                    _writePos += toWrite;
                    left      -= toWrite;
                }
                _size += count;
            }

            if (_readEvent != null)
            {
                _readEvent.Set();
            }
        }
示例#4
0
        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();
            }
        }
示例#5
0
        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();
            }
        }
示例#6
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();
                }
            }
        }
示例#7
0
        private void IQObserverThread()
        {
            while (_iqObserverThreadRunning)
            {
                _iqObserverEvent.WaitOne();

                for (var i = 0; i < _iqObservers.Count; i++)
                {
                    if (_iqObservers[i].Enabled)
                    {
                        _iqObservers[i].IQSamplesAvailable(_iqObserverBufferPtr, _iqObserverBuffer.Length);
                    }
                }
            }
        }
示例#8
0
        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
        }