Saturday, 7 September 2013

Using Task Parallel Library to write wav & playback at same time?

Using Task Parallel Library to write wav & playback at same time?

I am trying to write an application using NAudio that can record a .wav
file & playback at the same time. I have an event that grabs all the
incoming audio here:
void asioOut_AudioAvailable(object sender, AsioAudioAvailableEventArgs e)
{
if (s == null)
{
s = myList.AcceptSocket();
}
var samples = e.GetAsInterleavedSamples();
}
Inside the event is a method that records the incoming audio:
writer.WriteSamples(samples, 0, samples.Length);
And another method that sends the audio to playback
sendData(samples);
I tried setting up each task in parallel but each task finishes running at
the end of the event.
if (writeWav == null && sendFloatData == null)
{
writeWav = new Task(() => writer.WriteSamples(samples,
0, samples.Length));
sendFloatData = new Task(() => sendData(samples));
writeWav.Start();
sendFloatData.Start();
}
How can I set this up so that each time the event fires, each task
continues separately?

No comments:

Post a Comment