views:

661

answers:

5

How can I play a sound based on waveform data that my .Net program is generating from user input and mathematical functions? By "waveform data" I am mean SPL values in a fixed interval time-series (probably 44.1 kHz). I presume that this requires some kind of streaming buffer arrangement.

Note, that this has to be live/real-time, so just creating a .wav file and then playing that will not be sufficient. VB.net is preferred, but C# is acceptable also.

Just to clarify: What I am looking for is a simple working code example.

A: 

I think you'll need to use DirectSound (DirectX API) for that. It works off buffers which you could fill with your generate data.

Maybe something like this will help

ongle
+1  A: 

Check out this thread on loading up a DirectSound buffer with arbitrary data and playing it.

Per comment: Yes, I know. You will need to translate the C++ into C# or VB.NET. But, the concept is what's important. You create a secondary DirectSound buffer and then use it to stream over to your primary buffer and play.

JP Alioto
Well that's *not* VB.net or C#. In fact it doesn't look like .Net at all.
RBarryYoung
+4  A: 

You can do this using NAudio. You create a stream that derives from WaveStream and in its overriden Read method, you return your samples which you can generate on the fly. You have control over the size of the buffers used by the soundcard which gives you control over the latency.

Mark Heath
+1  A: 

IrrKlang, BASS.net, NAudio, CLAM, G3D, and others that can do this.

Infro
A: 

Please see http://alvas.net/alvas.audio,tips.aspx#tip32

ava