59 lines
1.2 KiB
C#
59 lines
1.2 KiB
C#
using System;
|
|
namespace AudioStreamer.Processors
|
|
{
|
|
public class Echo : BaseAudioProcessor
|
|
{
|
|
Int32 amplification;
|
|
Int16[] delayBuffer;
|
|
int delayPosition;
|
|
|
|
public Echo()
|
|
{
|
|
delayBuffer = new short[0];
|
|
FloatAmplification = 0.8f;
|
|
Delay = 4096;
|
|
}
|
|
|
|
public Echo(int delay)
|
|
{
|
|
delayBuffer = new short[0];
|
|
FloatAmplification = 0.8f;
|
|
Delay = delay;
|
|
}
|
|
|
|
public Int32 Amplification { get { return this.amplification; } set { this.amplification = value; } }
|
|
public float FloatAmplification
|
|
{
|
|
get { return ((float)this.amplification) / 655360f; }
|
|
set { this.amplification = (Int32)(value * 65536.0f); }
|
|
}
|
|
|
|
public int Delay {
|
|
get { return this.delayBuffer.Length; }
|
|
set {
|
|
if (value != delayBuffer.Length){
|
|
lock (this){
|
|
Array.Resize(ref delayBuffer,value);
|
|
delayPosition %= value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override void process(ref short[] samples)
|
|
{
|
|
lock (this){
|
|
|
|
for (int n = 0; n < samples.Length;n++){
|
|
delayBuffer[delayPosition] = (Int16)(((((Int32)delayBuffer[delayPosition]) * this.amplification) >> 16) + samples[n]);
|
|
samples[n] = delayBuffer[delayPosition];
|
|
delayPosition++;
|
|
delayPosition %= delayBuffer.Length;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|