views:

355

answers:

3

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?

A: 

See the answers to this question, in particular you might find Jacob's answer useful.

Winston Smith
I'm not sure how well those responses will translate to my Silverlight app since they seem to be aimed toward managed DirectX or unmanaged libraries - both of which are not available in my context. I'm hoping to find some more "raw" computation examples. Those responses may help though - I'll take a look.
Mike Hodnick
A: 

puhh this is math , isn´t it ;-) So I guess its System.Math and read this free book

Ren Hoek
Ren - could you try to put that file on a "better" free upload site like http://drop.io? the uploaded.to link is nagging me with wait times and the file never downloads.
Mike Hodnick
sorry it´s no upload from me, from this sitehttp://freebooksource.com/blogroll/engineering-technology/signal-analysis-wavelets-filter-banks-time-frequency-transforms-and-applications/
Ren Hoek
A: 

Ah, this is what I'm looking for:

http://stackoverflow.com/questions/344343/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.

Mike Hodnick