Playing from a stream

Sep 20, 2009 at 9:35 PM
Edited Sep 20, 2009 at 9:43 PM

Using the WaveInStream, I'm capturing data from the microphone, if I were to package up this data and send it across a network, what's the best way to play it at the other end? I can't find any class which accepts a MemoryStream and plays it (or a stream, or byte array).

Editor
Sep 23, 2009 at 9:20 PM

Please see:

http://stackoverflow.com/questions/184683/play-audio-from-a-stream-using-c

Sep 24, 2009 at 1:25 PM

That technique needs to know the complete length of the stream though, I want to receive the data and start playing it even as I'm receiving more.

Should I maybe have a buffer of 1 second (however many bytes that is) and play that buffer when it's full, which would work so long as latency was less than one second, I believe.

Coordinator
Sep 24, 2009 at 3:09 PM

There is no need to know the length in advance. I would create a derived class from WaveStream that in its Read method returned buffered audio received over the network. If you have run out of data you can either return a zeroed out buffer, or return 0 bytes if you want playback to stop.

The example on stackoverflow shows it stopping when Position >= Length, but there is no reason for that to be the case.

Mark

Sep 24, 2009 at 3:21 PM

Ahh ok, apologies for my terminal stupidity about all this, I've never done any kind of audio programming before :/

 

Thanks very much!