• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# UnsafeBuffer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Trig

 static unsafe Trig()
 {
     int length = Trig._mask + 1;
       Trig._sinBuffer = UnsafeBuffer.Create(length, 4);
       Trig._cosBuffer = UnsafeBuffer.Create(length, 4);
       Trig._sinPtr = (float*) (void*) Trig._sinBuffer;
       Trig._cosPtr = (float*) (void*) Trig._cosBuffer;
       Trig._indexScale = (float) length / 6.283185f;
       for (int index = 0; index < length; ++index)
       {
     Trig._sinPtr[index] = (float) Math.Sin(((double) index + 0.5) / (double) length * 6.28318548202515);
     Trig._cosPtr[index] = (float) Math.Cos(((double) index + 0.5) / (double) length * 6.28318548202515);
       }
       float num = 0.0f;
       while ((double) num < 6.28318548202515)
       {
     Trig._sinPtr[(int) ((double) num * (double) Trig._indexScale) & Trig._mask] = (float) Math.Sin((double) num);
     Trig._cosPtr[(int) ((double) num * (double) Trig._indexScale) & Trig._mask] = (float) Math.Cos((double) num);
     num += 1.570796f;
       }
 }
开发者ID:zloiia,项目名称:sdrsrc,代码行数:21,代码来源:Trig.cs


示例17: FftProcessor

        public FftProcessor(int fftSize)
        {            
            _fftSize = fftSize;
            _halfSize = fftSize / 2;
            _overlapSize = (int) Math.Ceiling(_fftSize * OverlapRatio);
            _fftBufferPos = _halfSize;

            _blendFactor = 1.0f / _overlapSize;

            _fftBuffer = UnsafeBuffer.Create(fftSize, sizeof(Complex));
            _fftBufferPtr = (Complex*)_fftBuffer;

            _outOverlapBuffer = UnsafeBuffer.Create(_overlapSize, sizeof(float));
            _outOverlapPtr = (float*) _outOverlapBuffer;

            _overlapBuffer = UnsafeBuffer.Create(fftSize / 2, sizeof(float));
            _overlapBufferPtr = (float*)_overlapBuffer;

            _sampleBuffer = UnsafeBuffer.Create(fftSize, sizeof(float));
            _sampleBufferPtr = (float*)_sampleBuffer;
            _sampleBufferHead = _halfSize;
        }
开发者ID:taozhengbo,项目名称:sdrsharp,代码行数:22,代码来源:FftProcessor.cs


示例18: Resampler

 public unsafe Resampler(double inputSampleRate, double outputSampleRate, int tapsPerPhase = 160, double protectedPassband = 0.45)
 {
     Resampler.DoubleToFraction(outputSampleRate / inputSampleRate, out this._interpolationFactor, out this._decimationFactor);
       this._tapsPerPhase = tapsPerPhase;
       int length = tapsPerPhase * this._interpolationFactor;
       this._firKernelBuffer = UnsafeBuffer.Create(length, 4);
       this._firKernel = (float*) (void*) this._firKernelBuffer;
       double cutoffFrequency = Math.Min(inputSampleRate, outputSampleRate) * protectedPassband;
       float[] numArray = FilterBuilder.MakeLowPassKernel(inputSampleRate * (double) this._interpolationFactor, length - 1, cutoffFrequency, WindowType.BlackmanHarris4);
       fixed (float* numPtr = numArray)
       {
     for (int index = 0; index < numArray.Length; ++index)
     {
       IntPtr num1 = (IntPtr) (numPtr + index);
       double num2 = (double) *(float*) num1 * (double) this._interpolationFactor;
       *(float*) num1 = (float) num2;
     }
     Utils.Memcpy((void*) this._firKernel, (void*) numPtr, length * 4);
       }
       this._firQueueBuffer = UnsafeBuffer.Create(length, 4);
       this._firQueue = (float*) (void*) this._firQueueBuffer;
 }
开发者ID:zloiia,项目名称:sdrsrc,代码行数:22,代码来源:Resampler.cs


示例19: OverlapAddProcessor

 public unsafe OverlapAddProcessor(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._windowBuffer = UnsafeBuffer.Create(this._fftSize, 4);
       this._windowPtr = (float*) (void*) this._windowBuffer;
       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;
       this._overlapBuffer = UnsafeBuffer.Create(this._halfSize, sizeof (Complex));
       this._overlapPtr = (Complex*) (void*) this._overlapBuffer;
       double num = Math.PI / 2.0 / (double) (this._halfSize - 1);
       for (int index = 0; index < this._halfSize; ++index)
       {
     double a = (double) index * num;
     this._windowPtr[index] = (float) Math.Sin(a);
     this._windowPtr[this._fftSize - 1 - index] = this._windowPtr[index];
       }
 }
开发者ID:zloiia,项目名称:sdrsrc,代码行数:23,代码来源:OverlapAddProcessor.cs


示例20: OverlapCrossfadeProcessor

 public unsafe OverlapCrossfadeProcessor(int fftSize, float crossFadingRatio = 0.0f)
 {
     this._fftSize = fftSize;
       this._halfSize = this._fftSize / 2;
       this._crossFadingSize = (int) ((double) this._halfSize * (double) crossFadingRatio);
       this._outputSize = this._halfSize - this._crossFadingSize;
       this._inputPos = this._halfSize + this._crossFadingSize;
       this._queuepBuffer = UnsafeBuffer.Create(this._fftSize, sizeof (Complex));
       this._queuePtr = (Complex*) (void*) this._queuepBuffer;
       this._windowBuffer = UnsafeBuffer.Create(this._crossFadingSize, 4);
       this._windowPtr = (float*) (void*) this._windowBuffer;
       this._fftBuffer = UnsafeBuffer.Create(this._fftSize, sizeof (Complex));
       this._fftPtr = (Complex*) (void*) this._fftBuffer;
       this._outputBuffer = UnsafeBuffer.Create(this._outputSize, sizeof (Complex));
       this._outputPtr = (Complex*) (void*) this._outputBuffer;
       this._crossFadingBuffer = UnsafeBuffer.Create(this._crossFadingSize, sizeof (Complex));
       this._crossFadingPtr = (Complex*) (void*) this._crossFadingBuffer;
       double num = Math.PI / 2.0 / (double) (this._crossFadingSize - 1);
       for (int index = 0; index < this._crossFadingSize; ++index)
       {
     double a = (double) index * num;
     this._windowPtr[index] = (float) Math.Pow(Math.Sin(a), 2.0);
       }
 }
开发者ID:zloiia,项目名称:sdrsrc,代码行数:24,代码来源:OverlapCrossfadeProcessor.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# UnsafeNativeMethods类代码示例发布时间:2022-05-24
下一篇:
C# UnrealTargetPlatform类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap