Reputation: 1
I'm trying to stream out and play audio data that comes in from a TCP:port. Data is unsigned 8-bit and the data rate is 11.025KHz.
I have no problem receiving the data, but I need some help with the code to get the audio streaming to work with C# and NAudio.
Upvotes: 0
Views: 371
Reputation: 59
NAudio has BufferedWaveProvider class just for your purpose. You can use it like this:
var bufferedStream = new BufferedWaveProvider(format);
var waveOut = new WaveOut();
waveOut.Init(bufferedStream);
waveOut.Play();
And now you should supply buffered provider with your data (probably in another thread):
var buffer = GetData(); // Here is your code
bufferedStream.AddSamples(buffer, 0, buffer.Length);
Probably you'll want to check whether there is enough data in buffer, otherwise pause playback or something else.
This tutorial explains how it works in NAuduo. And here is an example.
Upvotes: 2