private unsafe void ReceiveSamples_sync()
        {
            lms_stream_meta_t meta = new lms_stream_meta_t();

            meta.timestamp          = 0;
            meta.flushPartialPacket = false;
            meta.waitForTimestamp   = false;

            while (_isStreaming)
            {
                if (_iqBuffer == null || _iqBuffer.Length != _readLength)
                {
                    _iqBuffer = UnsafeBuffer.Create((int)_readLength, sizeof(Complex));
                    _iqPtr    = (Complex *)_iqBuffer;
                    Thread.Sleep(100);
                }

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

                var ptrIq = _iqPtr;

                if (test_signal)
                {
                    SineWaveWithNoise(ptrIq, _readLength, phase_accumulator1, sine_freq1);
                    phase_accumulator1 = CosineWaveWithNoise(ptrIq, _readLength, phase_accumulator1, sine_freq1);
                }
                else
                {
                    NativeMethods.LMS_RecvStream(_stream, _samplesPtr, _readLength, ref meta, SampleTimeoutMs);

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

                ComplexSamplesAvailable(_iqPtr, _iqBuffer.Length);
            }

            NativeMethods.LMS_StopStream(_stream);
            Close();
        }
Beispiel #2
0
        private unsafe void ReceiveSamples_sync()
        {
            lms_stream_meta_t meta = new lms_stream_meta_t();

            meta.timestamp          = 0;
            meta.flushPartialPacket = false;
            meta.waitForTimestamp   = false;

            while (_isStreaming)
            {
                if (_iqBuffer == null || _iqBuffer.Length != _readLength)
                {
                    _iqBuffer = UnsafeBuffer.Create((int)_readLength, sizeof(Complex));
                    _iqPtr    = (Complex *)_iqBuffer;
                    Thread.Sleep(100);
                }

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

                dataMutex.WaitOne();
                NativeMethods.LMS_RecvStream(_stream, _samplesPtr, _readLength, ref meta, SampleTimeoutMs);
                dataMutex.ReleaseMutex();

                var ptrIq = _iqPtr;

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

                ComplexSamplesAvailable(_iqPtr, _iqBuffer.Length);
            }

            NativeMethods.LMS_StopStream(_stream);
            Close();
        }
 public static unsafe extern int LMS_RecvStream(IntPtr stream, void *samples, uint sample_count, ref lms_stream_meta_t meta, uint timeout_ms);
 public static unsafe extern int LMS_SendStream(IntPtr stream, void *samples, UInt64 sample_count,
                                                ref lms_stream_meta_t meta, UInt64 timeout_ms);