mirror of
https://github.com/SDRSharpR/SDRSharper.git
synced 2026-01-04 07:29:55 +01:00
71 lines
1.4 KiB
C#
71 lines
1.4 KiB
C#
using System;
|
|
|
|
namespace SDRSharp.Radio
|
|
{
|
|
public sealed class IQFirFilter
|
|
{
|
|
private readonly bool _isMultiThteaded;
|
|
|
|
private readonly FirFilter _rFilter;
|
|
|
|
private readonly FirFilter _iFilter;
|
|
|
|
private readonly SharpEvent _event;
|
|
|
|
public IQFirFilter(float[] coefficients)
|
|
: this(coefficients, false, 1)
|
|
{
|
|
}
|
|
|
|
public IQFirFilter(float[] coefficients, bool isMultiThteaded, int decimationFactor)
|
|
{
|
|
this._rFilter = new FirFilter(coefficients, decimationFactor);
|
|
this._iFilter = new FirFilter(coefficients, decimationFactor);
|
|
this._isMultiThteaded = isMultiThteaded;
|
|
if (this._isMultiThteaded)
|
|
{
|
|
this._event = new SharpEvent(false);
|
|
}
|
|
}
|
|
|
|
~IQFirFilter()
|
|
{
|
|
this.Dispose();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
this._rFilter.Dispose();
|
|
this._iFilter.Dispose();
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
public unsafe void Process(Complex* iq, int length)
|
|
{
|
|
if (this._isMultiThteaded)
|
|
{
|
|
DSPThreadPool.QueueUserWorkItem(delegate
|
|
{
|
|
this._rFilter.ProcessInterleaved((float*)iq, length);
|
|
this._event.Set();
|
|
});
|
|
}
|
|
else
|
|
{
|
|
this._rFilter.ProcessInterleaved((float*)iq, length);
|
|
}
|
|
this._iFilter.ProcessInterleaved((float*)((byte*)iq + 4), length);
|
|
if (this._isMultiThteaded)
|
|
{
|
|
this._event.WaitOne();
|
|
}
|
|
}
|
|
|
|
public void SetCoefficients(float[] coefficients)
|
|
{
|
|
this._rFilter.SetCoefficients(coefficients);
|
|
this._iFilter.SetCoefficients(coefficients);
|
|
}
|
|
}
|
|
}
|