当前位置: 首页>>代码示例>>C#>>正文


C# UnsafeBuffer类代码示例

本文整理汇总了C#中UnsafeBuffer的典型用法代码示例。如果您正苦于以下问题:C# UnsafeBuffer类的具体用法?C# UnsafeBuffer怎么用?C# UnsafeBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


UnsafeBuffer类属于命名空间,在下文中一共展示了UnsafeBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SingleThreadSegmentPool

        public SingleThreadSegmentPool(int segmentCount)
        {
            if (segmentCount < 1024)
            {
                throw new ArgumentException($"SegmentCount must be at least {MinimalSegmentCount}", nameof(segmentCount));
            }

            var segmentStructureOverhead = segmentCount*Segment.Size;
            var segmentData = segmentCount*SegmentSize;

            _buffer = new UnsafeBuffer(segmentData + segmentStructureOverhead);

            var segments = (Segment*) _buffer.RawBytes;
            var data = _buffer.RawBytes + segmentStructureOverhead;

            for (var i = 0; i < segmentCount; i++)
            {
                var s = segments + i;
                var buffer = data + i*SegmentSize;
                var segment = new Segment(buffer, SegmentSize);

                // copy to the memory pointed by s
                Native.MemcpyUnmanaged((byte*) s, (byte*) &segment, Segment.Size);

                Push(s);
            }
        }
开发者ID:Scooletz,项目名称:RampUp,代码行数:27,代码来源:SingleThreadSegmentPool.cs

示例2: WhenAllocatedAndDisposed_ShouldFreeMemory

 public void WhenAllocatedAndDisposed_ShouldFreeMemory()
 {
     using (var buffer = new UnsafeBuffer(short.MaxValue + 1))
     {
         GC.KeepAlive(buffer);
     }
 }
开发者ID:Scooletz,项目名称:RampUp,代码行数:7,代码来源:UnsafeBufferTests.cs

示例3: ProcessSquelch

        private void ProcessSquelch(float* audio, int length)
        {
            if (_squelchThreshold > 0)
            {
                if (_hissBuffer == null || _hissBuffer.Length != length)
                {
                    _hissBuffer = UnsafeBuffer.Create(length, sizeof(float));
                    _hissPtr = (float*) _hissBuffer;
                }

                Utils.Memcpy(_hissPtr, audio, length * sizeof(float));

                _hissFilter.Process(_hissPtr, length);

                for (var i = 0; i < _hissBuffer.Length; i++)
                {
                    var n = (1 - _noiseAveragingRatio) * _noiseLevel + _noiseAveragingRatio * Math.Abs(_hissPtr[i]);
                    if (!float.IsNaN(n))
                    {
                        _noiseLevel = n;
                    }
                    if (_noiseLevel > _noiseThreshold)
                    {
                        audio[i] = 0.0f;
                    }
                }

                _isSquelchOpen = _noiseLevel < _noiseThreshold;
            }
            else
            {
                _isSquelchOpen = true;
            }
        }
开发者ID:taozhengbo,项目名称:sdrsharp,代码行数:34,代码来源:FmDetector.cs

示例4: ComplexFilter

 public unsafe ComplexFilter(Complex[] kernel)
     : base(ComplexFilter.GetFFTSize(kernel.Length))
 {
     this._kernelBuffer = UnsafeBuffer.Create(this.FFTSize, sizeof (Complex));
       this._kernelPtr = (Complex*) (void*) this._kernelBuffer;
       this.SetKernel(kernel);
 }
开发者ID:zloiia,项目名称:sdrsrc,代码行数:7,代码来源:ComplexFilter.cs

示例5: Trig

        static Trig()
        {
            _mask = ~(-1 << ResolutionInBits);
            var sampleCount = _mask + 1;

            _sinBuffer = UnsafeBuffer.Create(sampleCount, sizeof(float));
            _cosBuffer = UnsafeBuffer.Create(sampleCount, sizeof(float));
            _sinPtr = (float*) _sinBuffer;
            _cosPtr = (float*) _cosBuffer;

            const float twoPi = (float) (Math.PI * 2.0);
            const float pi2 = (float) (Math.PI / 2.0);
            _indexScale = sampleCount / twoPi;

            for (var i = 0; i < sampleCount; i++)
            {
                _sinPtr[i] = (float) Math.Sin((i + 0.5f) / sampleCount * twoPi);
                _cosPtr[i] = (float) Math.Cos((i + 0.5f) / sampleCount * twoPi);
            }

            for (var angle = 0.0f; angle < twoPi; angle += pi2)
            {
                _sinPtr[(int) (angle * _indexScale) & _mask] = (float) Math.Sin(angle);
                _cosPtr[(int) (angle * _indexScale) & _mask] = (float) Math.Cos(angle);
            }
        }
开发者ID:taozhengbo,项目名称:sdrsharp,代码行数:26,代码来源:Trig.cs

示例6: NoiseFilter

 public unsafe NoiseFilter(int fftSize = 4096)
     : base(fftSize)
 {
     this._gainBuffer1 = UnsafeBuffer.Create(fftSize, 4);
       this._gainPtr1 = (float*) (void*) this._gainBuffer1;
       this._gainBuffer2 = UnsafeBuffer.Create(fftSize, 4);
       this._gainPtr2 = (float*) (void*) this._gainBuffer2;
 }
开发者ID:zloiia,项目名称:sdrsrc,代码行数:8,代码来源:NoiseFilter.cs

示例7: Dispose

 public unsafe void Dispose()
 {
     this._coeffBuffer = (UnsafeBuffer) null;
       this._queueBuffer = (UnsafeBuffer) null;
       this._coeffPtr = (float*) null;
       this._queuePtr = (float*) null;
       GC.SuppressFinalize((object) this);
 }
开发者ID:zloiia,项目名称:sdrsrc,代码行数:8,代码来源:FirFilter.cs

示例8: RdsDecoder

 public unsafe RdsDecoder()
 {
     this._pllBuffer = UnsafeBuffer.Create(sizeof (Pll));
       this._pll = (Pll*) (void*) this._pllBuffer;
       this._oscBuffer = UnsafeBuffer.Create(sizeof (Oscillator));
       this._osc = (Oscillator*) (void*) this._oscBuffer;
       this._syncFilterBuffer = UnsafeBuffer.Create(sizeof (IirFilter));
       this._syncFilter = (IirFilter*) (void*) this._syncFilterBuffer;
       this._bitDecoder = new RdsDetectorBank();
       this._bitDecoder.FrameAvailable += new RdsFrameAvailableDelegate(this.FrameAvailableHandler);
 }
开发者ID:zloiia,项目名称:sdrsrc,代码行数:11,代码来源:RdsDecoder.cs

示例9: RdsDecoder

        public RdsDecoder()
        {
            _pllBuffer = UnsafeBuffer.Create(sizeof(Pll));
            _pll = (Pll*) _pllBuffer;

            _oscBuffer = UnsafeBuffer.Create(sizeof(Oscillator));
            _osc = (Oscillator*) _oscBuffer;

            _syncFilterBuffer = UnsafeBuffer.Create(sizeof(IirFilter));
            _syncFilter = (IirFilter*) _syncFilterBuffer;
        }
开发者ID:taozhengbo,项目名称:sdrsharp,代码行数:11,代码来源:RdsDecoder.cs

示例10: IQBalancer

 public unsafe IQBalancer()
 {
     this._dcRemoverIBuffer = UnsafeBuffer.Create(sizeof (DcRemover));
       this._dcRemoverI = (DcRemover*) (void*) this._dcRemoverIBuffer;
       this._dcRemoverI->Init(1E-05f);
       this._dcRemoverQBuffer = UnsafeBuffer.Create(sizeof (DcRemover));
       this._dcRemoverQ = (DcRemover*) (void*) this._dcRemoverQBuffer;
       this._dcRemoverQ->Init(1E-05f);
       this._windowBuffer = UnsafeBuffer.Create((Array) FilterBuilder.MakeWindow(WindowType.Hamming, 1024));
       this._windowPtr = (float*) (void*) this._windowBuffer;
       this._isMultithreaded = Environment.ProcessorCount > 1;
 }
开发者ID:zloiia,项目名称:sdrsrc,代码行数:12,代码来源:IQBalancer.cs

示例11: NoiseFilter

        public NoiseFilter(int fftSize)
            : base(fftSize)
        {
            _gainBuffer = UnsafeBuffer.Create(fftSize, sizeof(float));
            _gainPtr = (float*) _gainBuffer;

            _smoothedGainBuffer = UnsafeBuffer.Create(fftSize, sizeof(float));
            _smoothedGainPtr = (float*) _smoothedGainBuffer;

            _powerBuffer = UnsafeBuffer.Create(fftSize, sizeof(float));
            _powerPtr = (float*) _powerBuffer;
        }
开发者ID:taozhengbo,项目名称:sdrsharp,代码行数:12,代码来源:NoiseFilter.cs

示例12: OverlapSaveProcessor

 public unsafe OverlapSaveProcessor(int fftSize)
 {
     this._fftSize = fftSize;
       this._halfSize = this._fftSize / 2;
       this._inputPos = this._halfSize;
       this._queuepBuffer = UnsafeBuffer.Create(this._fftSize, sizeof (Complex));
       this._queuePtr = (Complex*) (void*) this._queuepBuffer;
       this._fftBuffer = UnsafeBuffer.Create(this._fftSize, sizeof (Complex));
       this._fftPtr = (Complex*) (void*) this._fftBuffer;
       this._outputBuffer = UnsafeBuffer.Create(this._halfSize, sizeof (Complex));
       this._outputPtr = (Complex*) (void*) this._outputBuffer;
 }
开发者ID:zloiia,项目名称:sdrsrc,代码行数:12,代码来源:OverlapSaveProcessor.cs

示例13: IQBalancer

 public IQBalancer()
 {
     _dcRemoverIBuffer = UnsafeBuffer.Create(sizeof(DcRemover));
     _dcRemoverI = (DcRemover*) _dcRemoverIBuffer;
     _dcRemoverI->Init(DcTimeConst);
     _dcRemoverQBuffer = UnsafeBuffer.Create(sizeof(DcRemover));
     _dcRemoverQ = (DcRemover*) _dcRemoverQBuffer;
     _dcRemoverQ->Init(DcTimeConst);
     var window = FilterBuilder.MakeWindow(WindowType.Hamming, FFTBins);
     _windowBuffer = UnsafeBuffer.Create(window);
     _windowPtr = (float*) _windowBuffer;
     _isMultithreaded = Environment.ProcessorCount > 1;
 }
开发者ID:Sir-Loin,项目名称:sdrsharp_experimental,代码行数:13,代码来源:IQBalancer.cs

示例14: ProcessMono

        private void ProcessMono(float* baseBand, float* interleavedStereo, int length)
        {
            #region Prepare buffer

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

            #endregion

            #region Decimate L+R

            Utils.Memcpy(_channelAPtr, baseBand, length * sizeof(float));
            _channelADecimator.Process(_channelAPtr, length);

            #endregion

            #region Filter L+R

            length /= _audioDecimationFactor;
            _channelAFilter.Process(_channelAPtr, length);

            #endregion

            #region Process deemphasis

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

            #endregion

            #region Fill output buffer

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

            #endregion
        }
开发者ID:taozhengbo,项目名称:sdrsharp,代码行数:47,代码来源:StereoDecoder.cs

示例15: Resampler

 public Resampler(double inputSampleRate, double outputSampleRate, int taps)
 {
     DoubleToFraction(outputSampleRate / inputSampleRate, out _interpolationFactor, out _decimationFactor);
     var filterLenght = (int) (500.0 / 32000 * inputSampleRate) / _interpolationFactor * _interpolationFactor;
     _tapsPerPhase = filterLenght / _interpolationFactor;
     _firKernelBuffer = UnsafeBuffer.Create(filterLenght, sizeof(float));
     _firKernel = (float*) _firKernelBuffer;
     var cutoff = Math.Min(inputSampleRate, outputSampleRate) * ProtectedPassband;
     var kernel = FilterBuilder.MakeLowPassKernel(inputSampleRate * _interpolationFactor, filterLenght - 1, cutoff, WindowType.BlackmanHarris4);
     fixed (float* ptr = kernel)
     {
         for (var i = 0; i < kernel.Length; i++)
         {
             ptr[i] *= _interpolationFactor;
         }
         Utils.Memcpy(_firKernel, ptr, filterLenght * sizeof(float));
     }
     _firQueueBuffer = UnsafeBuffer.Create(filterLenght, sizeof(float));
     _firQueue = (float*) _firQueueBuffer;
 }
开发者ID:taozhengbo,项目名称:sdrsharp_experimental,代码行数:20,代码来源:Resampler.cs


注:本文中的UnsafeBuffer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。