Search code examples
c#silverlightaudiosynthesis

How to implement a band-pass filter in c# / Silverlight


How would I go about implementing a band-pass filter in c#? I'm using a custom MediaStreamSource in Silverlight and am using additive synthesis to produce sound. My audio stream is a continuous stream of int16 shorts:

//over-simplified example:
short sample = oscillator.GetNextSample();
memoryStream.WriteByte((byte)(sample & 0xFF));
memoryStream.WriteByte((byte)(sample >> 8));

...where "sample" is a function of a sine calculation (or some other complex combination of waveforms) ranging from short.MinValue to short.MaxValue.

I have no idea where to start with a band-pass filter. How would I go about implementing it?


Solution

  • Ah, this is what I'm looking for:

    Low pass filter software?

    I haven't tried it yet, but that is the raw calculation example I was hoping to find. It looks like I'll need to revise that code to work with Int16's instead of doubles, and it also looks like I have a lot of dirty work ahead of me for defining the particular constants/coefficients I'll need, but it should get me started in the right direction.