SDRSharper/SDRSharper.Radio/SDRSharp.Radio/IQDecimator.cs
SDRSharpR c07e6e6034 SDRSharper (SDRSharp Remake) Full Source (VS2017)
SDRSharper (SDRSharp Remake) Full Source (VS2017)
2018-03-26 14:02:05 -07:00

57 lines
1.6 KiB
C#

namespace SDRSharp.Radio
{
public sealed class IQDecimator
{
private readonly bool _isMultithreaded;
private readonly FloatDecimator _rDecimator;
private readonly FloatDecimator _iDecimator;
private readonly SharpEvent _event = new SharpEvent(false);
public int StageCount => this._rDecimator.StageCount;
public IQDecimator(int stageCount, double samplerate, bool useFastFilters, bool isMultithreaded)
{
this._isMultithreaded = (Utils.ProcessorCount > 1);
int threadCount = (!this._isMultithreaded) ? 1 : (Utils.ProcessorCount / 2);
DecimationFilterType filterType = (!useFastFilters) ? DecimationFilterType.Baseband : DecimationFilterType.Fast;
this._rDecimator = new FloatDecimator(stageCount, samplerate, filterType, threadCount);
this._iDecimator = new FloatDecimator(stageCount, samplerate, filterType, threadCount);
}
public IQDecimator(int stageCount, double samplerate, bool useFastFilters)
: this(stageCount, samplerate, useFastFilters, false)
{
}
public IQDecimator(int stageCount, double samplerate)
: this(stageCount, samplerate, false)
{
}
public unsafe void Process(Complex* buffer, int length)
{
float* buffer2 = (float*)((byte*)buffer + 4);
if (this._isMultithreaded)
{
DSPThreadPool.QueueUserWorkItem(delegate
{
this._rDecimator.ProcessInterleaved((float*)buffer, length);
this._event.Set();
});
}
else
{
this._rDecimator.ProcessInterleaved((float*)buffer, length);
}
this._iDecimator.ProcessInterleaved(buffer2, length);
if (this._isMultithreaded)
{
this._event.WaitOne();
}
}
}
}