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); }
public void SelectDevice() { this.CloseDevice(); this._device = new CyCaptureDevice(); this._device.Frequency = this._frequency; this._gui.Device = this._device; this._device.SamplesAvailable += new SamplesAvailableDelegate(this.captDevice_SamplesAvailable); this._device.SampleRateChanged += new EventHandler(this.captDevice_SampleRateChanged); }
private void CloseDevice() { if (this._device == null) { return; } this._device.Stop(); this._device.SamplesAvailable -= new SamplesAvailableDelegate(this.captDevice_SamplesAvailable); this._device.SampleRateChanged -= new EventHandler(this.captDevice_SampleRateChanged); this._device.Dispose(); this._device = (CyCaptureDevice)null; }