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

48 lines
826 B
C#

namespace SDRSharp.Radio
{
public struct DcRemover
{
private float _average;
private float _ratio;
public float Offset => this._average;
public DcRemover(float ratio)
{
this._ratio = ratio;
this._average = 0f;
}
public void Init(float ratio)
{
this._ratio = ratio;
this._average = 0f;
}
public unsafe void Process(float* buffer, int length)
{
for (int i = 0; i < length; i++)
{
this._average += this._ratio * (buffer[i] - this._average);
buffer[i] -= this._average;
}
}
public unsafe void ProcessInterleaved(float* buffer, int length)
{
length *= 2;
for (int i = 0; i < length; i += 2)
{
this._average += this._ratio * (buffer[i] - this._average);
buffer[i] -= this._average;
}
}
public void Reset()
{
this._average = 0f;
}
}
}