51 lines
1.2 KiB
C#
51 lines
1.2 KiB
C#
using System;
|
|
namespace AudioStreamer.Processors
|
|
{
|
|
public class FIRFilter : BaseAudioProcessor
|
|
{
|
|
Int32[] amplifications;
|
|
ModuloList<Int16> delay;
|
|
int delayPosition;
|
|
|
|
public FIRFilter(Int32[] amps)
|
|
{
|
|
this.amplifications = amps;
|
|
this.delay = new ModuloList<Int16>(amps.Length);
|
|
}
|
|
public FIRFilter(float[] amps)
|
|
{
|
|
this.amplifications = new Int32[amps.Length];
|
|
this.delay = new ModuloList<Int16>(amps.Length);
|
|
|
|
for (int n = 0; n < amps.Length;n++){
|
|
this.setAmplification(n,amps[n]);
|
|
}
|
|
}
|
|
|
|
public Int32[] Amplifications { get { return this.amplifications; } }
|
|
|
|
public float getAmplification(int n){
|
|
return ((float)this.amplifications[n]) / 65536.0f;
|
|
}
|
|
public void setAmplification(int n, float amp){
|
|
this.amplifications[n] = (Int32)(amp * 65536.0f);
|
|
}
|
|
|
|
|
|
protected override void process(ref short[] samples)
|
|
{
|
|
for (int n = 0; n < samples.Length; n++){
|
|
this.delay[n + delayPosition] = samples[n];
|
|
samples[n] = 0;
|
|
|
|
for (int pa = 0; pa < amplifications.Length; pa++){
|
|
samples[n] += (Int16)((this.amplifications[pa] * delay[delayPosition - pa])>>16);
|
|
}
|
|
}
|
|
|
|
delayPosition += samples.Length;
|
|
delayPosition %= this.amplifications.Length;
|
|
}
|
|
}
|
|
}
|