예제 #1
0
        public unsafe int Process(byte *compressed, int compressedCount, short *outBuffer, int outBufferCount)
        {
            //Allocate memory for our info struct
            UnsafeBuffer       infoP = UnsafeBuffer.Create(1, sizeof(NeAACDecFrameInfo));
            NeAACDecFrameInfo *info  = (NeAACDecFrameInfo *)infoP;

            //Process
            short *data = NeAACDecDecode(ctx, (IntPtr)infoP.Address, compressed, compressedCount);

            //Read what we need from the struct and then clean up
            int error   = info->error;
            int samples = info->samples;

            infoP.Dispose();
            info = null;

            //Validate that there were no errors
            if (error > 0)
            {
                throw new Exception($"FAAD reported an error while decoding: " + NeAACDecGetErrorMessageManaged(info->error));
            }

            //Validate we have space to copy
            if (samples > outBufferCount)
            {
                throw new Exception($"Output buffer was not large enough for the number of incoming samples, {info->samples}!");
            }

            //Copy
            Utils.Memcpy(outBuffer, data, samples * sizeof(short));

            return(samples);
        }
예제 #2
0
        private unsafe void ReceiveSamples_sync()
        {
            while (_isStreaming)
            {
                if (_iqBuffer == null || _iqBuffer.Length != _readLength)
                {
                    _iqBuffer = UnsafeBuffer.Create((int)_readLength, sizeof(Complex));
                    _iqPtr    = (Complex *)_iqBuffer;
                }

                if (_samplesBuffer == null || _samplesBuffer.Length != (2 * _readLength))
                {
                    _samplesBuffer = UnsafeBuffer.Create((int)(2 * _readLength), sizeof(float));
                    _samplesPtr    = (float *)_samplesBuffer;
                }

                NativeMethods.LMS_RecvStream(_stream, _samplesPtr, _readLength, IntPtr.Zero, SampleTimeoutMs);

                var ptrIq = _iqPtr;

                for (int i = 0; i < _readLength; i++)
                {
                    ptrIq->Real = _samplesPtr[i * 2];
                    ptrIq->Imag = _samplesPtr[i * 2 + 1];
                    ptrIq++;
                }

                ComplexSamplesAvailable(_iqPtr, _iqBuffer.Length);
            }
        }
예제 #3
0
        /*
         * Allocate and initialize the trellis object
         *
         * Initialization consists of generating the outputs and output value of a
         * given state. Due to trellis symmetry, only one of the transition paths
         * is used by the butterfly operation in the forward recursion, so only one
         * set of N outputs is required per state variable.
         */
        static vtrellis generate_trellis(lte_conv_code code)
        {
            vtrellis trellis;
            short *  o;

            int ns   = NUM_STATES(code.k);
            int olen = (code.n == 2) ? 2 : 4;

            trellis               = new vtrellis();
            trellis.num_states    = ns;
            trellis.sumsBuffer    = UnsafeBuffer.Create(ns, sizeof(short));
            trellis.sums          = (short *)trellis.sumsBuffer;
            trellis.outputsBuffer = UnsafeBuffer.Create(ns * olen, sizeof(short));
            trellis.outputs       = (short *)trellis.outputsBuffer;
            trellis.valsBuffer    = UnsafeBuffer.Create(ns, sizeof(sbyte));
            trellis.vals          = (sbyte *)trellis.valsBuffer;

            /* Populate the trellis state objects */
            for (int i = 0; i < ns; i++)
            {
                o = &trellis.outputs[olen * i];

                if (code.rgen != 0)
                {
                    gen_rec_state_info(code, &trellis.vals[i], i, o);
                }
                else
                {
                    gen_state_info(code, &trellis.vals[i], i, o);
                }
            }

            return(trellis);
        }
예제 #4
0
        public MainWindow()
        {
            InitializeComponent();

            _fftSpectrum    = UnsafeBuffer.Create(_fftBins, sizeof(float));
            _fftSpectrumPtr = (float *)_fftSpectrum;
        }
예제 #5
0
        public AudioResource(SpectrumVideoDemodConfig config, CanvasContext ctx)
        {
            //Set
            this.label = config.label;

            //Get demodulator
            switch (config.demodType)
            {
            case "WBFM": demodulator = new WbFmDemodulator(); break;

            default: throw new Exception("Unknown demodulator type.");
            }

            //Make buffers
            bufferSize            = ctx.BufferSize;
            generalBuffer         = UnsafeBuffer.Create(ctx.BufferSize, out generalBufferComplexPtr);
            generalBufferFloatPtr = (float *)generalBufferComplexPtr;
            audioABuffer          = UnsafeBuffer.Create(ctx.BufferSize, out audioABufferPtr);
            audioBBuffer          = UnsafeBuffer.Create(ctx.BufferSize, out audioBBufferPtr);

            //Init audio
            demodDecimator = ComplexDecimator.CalculateDecimator(ctx.DecimatedSampleRate, config.demodBandwidth, 20, config.demodBandwidth * 0.05f, out float demodSampleRate);
            float actualAudioRate = demodulator.Configure(ctx.BufferSize, demodSampleRate, config.outputSampleRate);

            audioResampler = new ArbitraryStereoResampler(actualAudioRate, config.outputSampleRate, ctx.BufferSize);

            //Create output
            output = ctx.OutputProvider.GetAudioOutput(config.outputFilename, config.outputSampleRate, bufferSize);
        }
        private static int HackRFSamplesAvailable(hackrf_transfer *ptr)
        {
            sbyte *buf = ptr->buffer;
            int    len = ptr->buffer_length;
            IntPtr ctx = ptr->rx_ctx;

            var gcHandle = GCHandle.FromIntPtr(ctx);

            if (!gcHandle.IsAllocated)
            {
                return(-1);
            }
            var instance = (HackRFDevice)gcHandle.Target;

            var sampleCount = (int)len / 2;

            if (instance._iqBuffer == null || instance._iqBuffer.Length != sampleCount)
            {
                instance._iqBuffer = UnsafeBuffer.Create(sampleCount, sizeof(Complex));
                instance._iqPtr    = (Complex *)instance._iqBuffer;
            }

            var ptrIq = instance._iqPtr;

            for (var i = 0; i < sampleCount; i++)
            {
                ptrIq->Imag = _lutPtr[*buf++];
                ptrIq->Real = _lutPtr[*buf++];
                ptrIq++;
            }

            instance.ComplexSamplesAvailable(instance._iqPtr, instance._iqBuffer.Length);
            return(0);
        }
예제 #7
0
        private unsafe static void SdrIqSamplesAvailable(short *buf, uint len, IntPtr ctx)
        {
            GCHandle gCHandle = GCHandle.FromIntPtr(ctx);

            if (gCHandle.IsAllocated)
            {
                SdrIqDevice sdrIqDevice = (SdrIqDevice)gCHandle.Target;
                int         num         = (int)len / 2;
                if (sdrIqDevice._iqBuffer == null || sdrIqDevice._iqBuffer.Length != num)
                {
                    sdrIqDevice._iqBuffer = UnsafeBuffer.Create(num, sizeof(Complex));
                    sdrIqDevice._iqPtr    = (Complex *)(void *)sdrIqDevice._iqBuffer;
                }
                Complex *ptr = sdrIqDevice._iqPtr;
                for (int i = 0; i < num; i++)
                {
                    Complex *intPtr  = ptr;
                    float *  lut     = SdrIqDevice._lut16;
                    short *  intPtr2 = buf;
                    buf          = intPtr2 + 1;
                    intPtr->Imag = lut[*intPtr2 + 32768];
                    Complex *intPtr3 = ptr;
                    float *  lut2    = SdrIqDevice._lut16;
                    short *  intPtr4 = buf;
                    buf           = intPtr4 + 1;
                    intPtr3->Real = lut2[*intPtr4 + 32768];
                    ptr++;
                }
                sdrIqDevice.ComplexSamplesAvailable(sdrIqDevice._iqPtr, sdrIqDevice._iqBuffer.Length);
            }
        }
예제 #8
0
        public void Configure(float sampleRate, int bufferSize)
        {
            //Complain if too low
            if (sampleRate < BAUD_RATE)
            {
                throw new Exception($"The sample rate specified, {sampleRate}, is too low to be useful. Must be >= {BAUD_RATE}.");
            }

            //Create parts
            fmDemod = new FmBasebandDemodulator();
            fmDemod.Configure(bufferSize, sampleRate);
            amDemod          = new AmBasebandDemodulator();
            osc              = new Oscillator(sampleRate, -2400);
            symbolsPerSample = BAUD_RATE / sampleRate;

            //Make filter
            var filterBuilder = new LowPassFilterBuilder(sampleRate, 2080)
                                .SetAutomaticTapCount(200)
                                .SetWindow();

            filter = RealFirFilter.CreateFirFilter(filterBuilder);

            //Create buffer
            buffer?.Dispose();
            buffer = UnsafeBuffer.Create(bufferSize, out bufferPtr);
        }
예제 #9
0
        private unsafe void SdrSamplesAvailable(object sender, CaptureEventArgs e)
        {
            /*GCHandle gcHandle = this._gcHandle;
             * if (!gcHandle.IsAllocated)
             * return;*/
            //CyCaptureDevice target = (CyCaptureDevice) gcHandle.Target;
            CyCaptureDevice target = this;
            int             length = (int)e.BytesCaptures;

            if (target._iqBuffer == null || target._iqBuffer.Length != length)
            {
                target._iqBuffer = UnsafeBuffer.Create(length, sizeof(Complex));
                target._iqPtr    = (Complex *)(void *)target._iqBuffer;
            }
            float    iavg  = target._iavg;
            float    qavg  = target._qavg;
            float    alpha = target._alpha;
            Complex *iqPtr = target._iqPtr;

            for (int index = 0; index < length; index++)
            {
                //iqPtr->Real = CyCaptureDevice._lutPtr[*buf++];
                //iqPtr->Imag = CyCaptureDevice._lutPtr[*buf++];
                iqPtr->Real  = captureDevice.ResultBuffer[index];
                iqPtr->Imag  = captureDevice.ResultBuffer[index];
                iavg        += alpha * (iqPtr->Real - iavg);
                qavg        += alpha * (iqPtr->Imag - qavg);
                iqPtr->Real -= iavg;
                iqPtr->Imag -= qavg;
                ++iqPtr;
            }
            target._iavg = iavg;
            target._qavg = qavg;
            target.ComplexSamplesAvailable(target._iqPtr, target._iqBuffer.Length);
        }
예제 #10
0
        public void Read(Complex *iqBuffer, int length)
        {
            if (_temp == null || _temp.Length != _blockAlign * length)
            {
                _temp       = new byte[_blockAlign * length];
                _tempBuffer = UnsafeBuffer.Create(_temp);
                _tempPtr    = (byte *)_tempBuffer;
            }
            var pos  = 0;
            var size = _tempBuffer.Length;

            while (pos < size)
            {
                int toget = size - pos;
                int got   = _stream.Read(_temp, pos, toget);
                if (got < toget)
                {
                    _stream.Position = _dataPos; // loop if the file ends
                }
                if (got <= 0)
                {
                    break;
                }
                pos += got;
            }
            FillIQ(iqBuffer, length);
        }
예제 #11
0
        protected override void RedrawView()
        {
            //Save or rerender buffer
            if (backgroundBuffer == null || backgroundBuffer.Length != Width * Height)
            {
                backgroundBuffer?.Dispose();
                backgroundBuffer = UnsafeBuffer.Create(Width * Height, out backgroundBufferPtr);
                byte *bufferPtr = (byte *)GetPixelPointer(0, 0);
                for (int i = 0; i < Width * Height * 4; i++)
                {
                    bufferPtr[i] /= 2;
                }
                Utils.Memcpy(backgroundBufferPtr, GetPixelPointer(0, 0), Width * Height * sizeof(DisplayPixel));
            }
            else
            {
                Utils.Memcpy(GetPixelPointer(0, 0), backgroundBufferPtr, Width * Height * sizeof(DisplayPixel));
            }

            //Calculate offsets
            int y = (Height - WINDOW_HEIGHT) / 2;
            int x = (Width - WINDOW_WIDTH) / 2;

            //Draw background
            UtilFill(DisplayPixel.BLACK, x, y, WINDOW_WIDTH, WINDOW_HEIGHT);
            UtilFill(DisplayPixel.RED, x, y + 40, WINDOW_WIDTH, 1);
            UtilOutline(DisplayPixel.RED, x, y, WINDOW_WIDTH, WINDOW_HEIGHT, 1);

            //Draw text
            FontStore.SYSTEM_REGULAR_15.RenderPretty(GetOffsetContext(x + WINDOW_PADDING, y), title.ToCharArray(), DisplayPixel.RED, AlignHorizontal.Left, AlignVertical.Center, WINDOW_WIDTH - WINDOW_PADDING - WINDOW_PADDING, 40);
            FontStore.SYSTEM_REGULAR_15.RenderPretty(GetOffsetContext(x + WINDOW_PADDING, y + 42 + WINDOW_PADDING), message.ToCharArray(), DisplayPixel.WHITE, AlignHorizontal.Left, AlignVertical.Top, WINDOW_WIDTH - WINDOW_PADDING - WINDOW_PADDING, WINDOW_HEIGHT - WINDOW_PADDING - 42);
        }
예제 #12
0
        private unsafe static void RtlSdrSamplesAvailable(byte *buf, uint len, IntPtr ctx)
        {
            GCHandle gCHandle = GCHandle.FromIntPtr(ctx);

            if (gCHandle.IsAllocated)
            {
                RtlDevice rtlDevice = (RtlDevice)gCHandle.Target;
                int       num       = (int)len / 2;
                if (rtlDevice._iqBuffer == null || rtlDevice._iqBuffer.Length != num)
                {
                    rtlDevice._iqBuffer = UnsafeBuffer.Create(num, sizeof(Complex));
                    rtlDevice._iqPtr    = (Complex *)(void *)rtlDevice._iqBuffer;
                }
                Complex *ptr = rtlDevice._iqPtr;
                for (int i = 0; i < num; i++)
                {
                    Complex *intPtr  = ptr;
                    byte *   intPtr2 = buf;
                    buf          = intPtr2 + 1;
                    intPtr->Imag = (float)(*intPtr2 - 128) * 0.0078125f;
                    Complex *intPtr3 = ptr;
                    byte *   intPtr4 = buf;
                    buf           = intPtr4 + 1;
                    intPtr3->Real = (float)(*intPtr4 - 128) * 0.0078125f;
                    ptr++;
                }
                rtlDevice.ComplexSamplesAvailable(rtlDevice._iqPtr, rtlDevice._iqBuffer.Length);
            }
        }
예제 #13
0
        private void InternalConfigure()
        {
            //Dispose of old buffer if needed
            imageBuffer?.Dispose();

            //Get size
            canvasHeight = Height;
            canvasWidth  = Width;

            //Resize canvas
            canvas.Width  = canvasWidth;
            canvas.Height = canvasHeight;

            //Make new buffer
            imageBuffer = UnsafeBuffer.Create(canvasWidth * canvasHeight, out imageBufferPtr);

            //Apply
            if (canvasWidth > 0 && canvasHeight > 0)
            {
                canvas.Image = new Bitmap(canvasWidth, canvasHeight, canvasWidth * sizeof(UnsafeColor), System.Drawing.Imaging.PixelFormat.Format32bppArgb, (IntPtr)imageBufferPtr);
            }

            //Run configure
            Configure(canvasWidth, canvasHeight);
        }
예제 #14
0
        private void RecieveSamples()
        {
            var recBuffer       = new byte[BufferSize];
            var recUnsafeBuffer = UnsafeBuffer.Create(recBuffer);
            var recPtr          = (byte *)recUnsafeBuffer;

            m_iqBuffer    = UnsafeBuffer.Create(BufferSize / 2, sizeof(Complex));
            m_iqBufferPtr = (Complex *)m_iqBuffer;
            var offs = 0;

            while (m_socket != null && m_socket.Connected)
            {
                try
                {
                    var bytesRec   = m_socket.Receive(recBuffer, offs, BufferSize - offs, SocketFlags.None);
                    var totalBytes = offs + bytesRec;
                    offs = totalBytes % 2;                     //Need to correctly handle the hypothetical case where we somehow get an odd number of bytes
                    ProcessSamples(recPtr, totalBytes - offs); //This might work.
                    if (offs == 1)
                    {
                        recPtr[0] = recPtr[totalBytes - 1];
                    }
                }
                catch
                {
                    Close();
                    break;
                }
            }
            this.m_iqBuffer.Dispose();
            this.m_iqBuffer    = null;
            this.m_iqBufferPtr = null;
            GC.KeepAlive(recUnsafeBuffer);
        }
예제 #15
0
        public void AddScaledFrame(float *ptr, int width)
        {
            //Ensure
            if (width != Width)
            {
                return;
            }

            //If the array size is incorrect, create
            if (fftBuffer == null || fftBuffer.Length - 2 != width)
            {
                fftBuffer?.Dispose();
                fftBuffer = UnsafeBuffer.Create(width + 2, sizeof(int));
                fftPtr    = ((float *)fftBuffer) + 1;
            }

            //Copy FFT frame
            Utils.Memcpy(fftPtr, ptr, Width * sizeof(float));

            //Convert and fill padding
            for (int i = 0; i < Width; i++)
            {
                fftPtr[i] = ((Math.Abs(fftPtr[i]) + fftOffset) / fftRange) * Height;
            }
            fftPtr[-1]    = fftPtr[0];
            fftPtr[Width] = fftPtr[Width - 1];

            //Invalidate
            Invalidate();
        }
예제 #16
0
 public unsafe PhyLevel()
 {
     this._tempBuffer    = UnsafeBuffer.Create(BurstLength * 2, sizeof(byte));
     this._tempBufferPtr = (byte *)(void *)this._tempBuffer;
     this._outBuffer     = UnsafeBuffer.Create(BurstLength, sizeof(byte));
     this._outBufferPtr  = (byte *)(void *)this._outBuffer;
 }
예제 #17
0
        private static void RtlSdrSamplesAvailable(byte *buf, uint len, IntPtr ctx)
        {
            var gcHandle = GCHandle.FromIntPtr(ctx);

            if (!gcHandle.IsAllocated)
            {
                return;
            }
            var instance = (RtlDevice)gcHandle.Target;

            var sampleCount = (int)len / 2;

            if (instance._iqBuffer == null || instance._iqBuffer.Length != sampleCount)
            {
                instance._iqBuffer = UnsafeBuffer.Create(sampleCount, sizeof(Complex));
                instance._iqPtr    = (Complex *)instance._iqBuffer;
            }

            var ptr = instance._iqPtr;

            for (var i = 0; i < sampleCount; i++)
            {
                ptr->Imag = _lutPtr[*buf++];
                ptr->Real = _lutPtr[*buf++];
                ptr++;
            }

            instance.ComplexSamplesAvailable(instance._iqPtr, instance._iqBuffer.Length);
        }
예제 #18
0
        public LibUSBAsyncTransfer(IntPtr device, byte endpoint, int bufferSize)
        {
            //Configure
            this.device     = device;
            this.bufferSize = bufferSize;

            //Create buffer
            buffer = UnsafeBuffer.Create(bufferSize, out bufferPtr);

            //Allocate transfer
            transfer = (LibUSBTransfer *)LibUSBNative.libusb_alloc_transfer(0);

            //Get the GCHandle for ourself
            handle = GCHandle.Alloc(this);

            //Populate transfer (same as libusb_fill_bulk_transfer)
            transfer->dev_handle = device;
            transfer->endpoint   = endpoint;
            transfer->type       = LibUSBTransferType.LIBUSB_TRANSFER_TYPE_BULK;
            transfer->timeout    = 0;
            transfer->buffer     = bufferPtr;
            transfer->length     = bufferSize;
            transfer->user_data  = (IntPtr)handle;
            transfer->callback   = Marshal.GetFunctionPointerForDelegate(TransferCallbackDelegate);
        }
예제 #19
0
파일: Program.cs 프로젝트: zillant/RF
        static void Main(string[] args)
        {
            if (_rxBuffer == null)
            {
                _rxBuffer    = UnsafeBuffer.Create((int)SampleRate, sizeof(Complex));
                _rxBufferPtr = (Complex *)_rxBuffer;
            }
            Controller    = new HackRF_Controller();
            Console.Title = "HackRF Samples View";
            Console.ReadKey();



            Controller.SampleRate = SampleRate;
            Controller.Frequency  = 100000000;

            Controller.VGAGain = 40;
            Controller.LNAGain = 24;


            //if (TxMode)
            //{
            //    //FileStream fs = new FileStream(filename, FileMode.Open);
            //    byte[] array = new byte[fs.Length];
            //    fs.Read(array, 0, array.Length);
            //    sbyte[] iqArray = Array.ConvertAll(array, b => unchecked((sbyte)b));
            //    // TO DO Convert iqArray To ComplexFifoStream
            //    Controller.StartTx();
            //}

            while (true)
            {
                Controller.SamplesAvailable += Controller_SamplesAvailable;
            }
        }
        private static void SdrIqSamplesAvailable(short *buf, uint len, IntPtr ctx)
        {
            var gcHandle = GCHandle.FromIntPtr(ctx);

            if (!gcHandle.IsAllocated)
            {
                return;
            }
            var instance = (SdrIqDevice)gcHandle.Target;

            var sampleCount = (int)len / 2;

            if (instance._iqBuffer == null || instance._iqBuffer.Length != sampleCount)
            {
                instance._iqBuffer = UnsafeBuffer.Create(sampleCount, sizeof(Complex));
                instance._iqPtr    = (Complex *)instance._iqBuffer;
            }

            var output = instance._iqPtr;

            for (var i = 0; i < sampleCount; i++)
            {
                output->Imag = _lut16[*buf++ + 32768];
                output->Real = _lut16[*buf++ + 32768];
                output++;
            }

            instance.ComplexSamplesAvailable(instance._iqPtr, instance._iqBuffer.Length);
        }
예제 #21
0
        public unsafe void MakeLog(byte[] srcPtr, int length, long fMin, long fMax)
        {
            if (this._tmpBuf == null || this._tmpBuf.Length != length)
            {
                if (this._tmpBuf != null)
                {
                    this._tmpBuf.Dispose();
                }
                this._tmpBuf = UnsafeBuffer.Create(length, 1);
                this._tmpPtr = (byte *)(void *)this._tmpBuf;
            }
            if (this._frBuf == null || this._frBuf.Length != length)
            {
                if (this._frBuf != null)
                {
                    this._frBuf.Dispose();
                }
                this._frBuf = UnsafeBuffer.Create(length, 8);
                this._frPtr = (long *)(void *)this._frBuf;
                this._fMax  = -1f;
            }
            if (this._fMin != (float)fMin || this._fMax != (float)fMax)
            {
                this._fMin = (float)fMin;
                this._fMax = (float)fMax;
                double num  = Math.Log10((double)fMin);
                double num2 = Math.Log10((double)fMax);
                double num3 = (num2 - num) / (double)length;
                for (int i = 0; i < length; i++)
                {
                    this._frPtr[i] = Convert.ToInt32(Math.Pow(10.0, num + (double)i * num3));
                }
            }
            long num4 = 0L;
            long num5 = 0L;
            int  num6 = 0;
            int  num7 = 0;

            for (int j = 0; j < length; j++)
            {
                num4 = ((num5 <= 0) ? ((j == 0) ? (*this._frPtr) : Convert.ToInt32(Math.Sqrt((double)(this._frPtr[j] * this._frPtr[j - 1])))) : num5);
                num5 = ((j == length - 1) ? this._frPtr[length - 1] : Convert.ToInt32(Math.Sqrt((double)(this._frPtr[j] * this._frPtr[j + 1]))));
                num6 = ((num7 <= 0) ? Math.Min((int)(num4 * length / fMax), length - 1) : num7);
                num7 = Math.Min((int)(num5 * length / fMax), length - 1);
                if (num7 > num6)
                {
                    num6++;
                }
                this._tmpPtr[j] = 0;
                for (int k = num6; k <= num7; k++)
                {
                    this._tmpPtr[j] = Math.Max(this._tmpPtr[j], srcPtr[k]);
                }
            }
            for (int l = 0; l < length; l++)
            {
                srcPtr[l] = this._tmpPtr[l];
            }
        }
예제 #22
0
파일: Frame.cs 프로젝트: Roman-Port/LibSDR
 public Frame()
 {
     bufferB  = UnsafeBuffer.Create(MAX_PDU_LEN, out buffer);
     pduB     = UnsafeBuffer.Create2D(MAX_PROGRAMS, 0x10000, out pdu);
     psd_bufB = UnsafeBuffer.Create2D(MAX_PROGRAMS, MAX_AAS_LEN, out psd_buf);
     psd_idxB = UnsafeBuffer.Create(MAX_PROGRAMS, out psd_idx);
     ccc_bufB = UnsafeBuffer.Create(CCM_BUF_LEN, out ccc_buf);
 }
예제 #23
0
 public unsafe ComplexFilter(Complex[] kernel)
     : base(ComplexFilter.GetFFTSize(kernel.Length))
 {
     this._actualKernelLength = kernel.Length;
     this._kernelBuffer       = UnsafeBuffer.Create(base.FFTSize, sizeof(Complex));
     this._kernelPtr          = (Complex *)(void *)this._kernelBuffer;
     this.SetKernel(kernel);
 }
예제 #24
0
        public AptImageDecoder(int width = 2080)
        {
            //Set
            this.width = width;

            //Make buffers
            frameBuffer = UnsafeBuffer.Create(width, out framePtr);
        }
예제 #25
0
        private unsafe void ReceiveSamples_sync()
        {
            int status = 0;

            while (_isStreaming)
            {
                uint cur_len, new_len;
                lock (syncLock)
                {
                    cur_len = new_len = _readLength;
                }
                if (_iqBuffer == null || _iqBuffer.Length != cur_len)
                {
                    _iqBuffer = UnsafeBuffer.Create((int)cur_len, sizeof(Complex));
                    _iqPtr    = (Complex *)_iqBuffer;
                }
                if (_samplesBuffer == null || _samplesBuffer.Length != (2 * cur_len))
                {
                    _samplesBuffer = UnsafeBuffer.Create((int)(2 * cur_len), sizeof(Int16));
                    _samplesPtr    = (Int16 *)_samplesBuffer;
                }
                if ((status = NativeMethods.bladerf_sync_config(_dev, bladerf_module.BLADERF_MODULE_RX, bladerf_format.BLADERF_FORMAT_SC16_Q11, NumBuffers, cur_len, NumBuffers / 2, SampleTimeoutMs)) != 0)
                {
                    _isStreaming = false;
                }
                while (status == 0 && cur_len == new_len)
                {
                    try
                    {
                        status = NativeMethods.bladerf_sync_rx(_dev, _samplesPtr, cur_len, IntPtr.Zero, SampleTimeoutMs);
                        if (status != 0)
                        {
                            throw new ApplicationException(String.Format("bladerf_rx() error. {0}", NativeMethods.bladerf_strerror(status)));
                        }
                        var ptrIq     = _iqPtr;
                        var ptrSample = _samplesPtr;
                        for (int i = 0; i < cur_len; i++)
                        {
                            ptrIq->Imag = _lutPtr[*ptrSample & 0x0fff];
                            ptrSample++;
                            ptrIq->Real = _lutPtr[*ptrSample & 0x0fff];
                            ptrSample++;
                            ptrIq++;
                        }
                        ComplexSamplesAvailable(_iqPtr, _iqBuffer.Length);
                    }
                    catch
                    {
                        break;
                    }
                    lock (syncLock)
                    {
                        new_len = _readLength;
                    }
                }
            }
        }
예제 #26
0
 public MacLevel()
 {
     for (int i = 0; i < 4; i++)
     {
         _fragmentsHeader[i] = new ReceivedData();
         _tempBuffers[i]     = UnsafeBuffer.Create(4096, sizeof(byte));
         _tempBuffersPtr[i]  = (byte *)_tempBuffers[i];
     }
 }
        private void SendDemodMagic(byte page, ushort offset, uint length, byte[] magic)
        {
            UnsafeBuffer data    = UnsafeBuffer.Create(magic);
            byte *       dataPtr = (byte *)data;

            NativeMethods.RTK_Demod_Byte_Write(page, offset, length, dataPtr);

            data.Dispose();
        }
        private void SendSYSMagic(ushort offset, uint length, byte[] magic)
        {
            UnsafeBuffer data    = UnsafeBuffer.Create(magic);
            byte *       dataPtr = (byte *)data;

            NativeMethods.RTK_SYS_Byte_Write(offset, length, dataPtr);

            data.Dispose();
        }
예제 #29
0
        public SnrCalculator()
        {
            //Create FFT
            fft = new FFTInstance(SNR_FFT_SIZE);

            //Create buffers
            buffer      = UnsafeBuffer.Create(SNR_BUFFER_SIZE, out bufferPtr);
            powerBuffer = UnsafeBuffer.Create(SNR_FFT_SIZE_HALF, out powerBufferPtr);
        }
예제 #30
0
 public unsafe NoiseFilter(int fftSize = 4096)
     : base(fftSize, 0.2f)
 {
     this._gainBuffer         = UnsafeBuffer.Create(fftSize, 4);
     this._gainPtr            = (float *)(void *)this._gainBuffer;
     this._smoothedGainBuffer = UnsafeBuffer.Create(fftSize, 4);
     this._smoothedGainPtr    = (float *)(void *)this._smoothedGainBuffer;
     this._powerBuffer        = UnsafeBuffer.Create(fftSize, 4);
     this._powerPtr           = (float *)(void *)this._powerBuffer;
 }