Thanks for the quick reply, Mark, I've got this working now. For the benefit of anyone else reading this, here's how I did it:
I declared a class-level WaveFileWriter object named "writer" in my SineWaveProvider32 class. I then added a new method to the class:
/// <summary>
/// Start recording audio to the specified .wav file
/// </summary>
/// <param name="filename"></param>
public void StartRecording(string filename)
{
writer = new NAudio.Wave.WaveFileWriter(filename, this.WaveFormat);
}
This gets called from my form and tells it to instantiate the writer and set its filename. Make sure to call this after first calling the SetWaveFormat method.
Then in the Read method, I added the following code, just after the end of the for() loop:
// Do we have a writer object?
if (writer != null)
{
// Yes, so write the samples we've just added to the file
writer.WriteSamples(buffer, 0, sampleCount);
// Have we reached the termination point?
if (sample > 20000)
{
// Yes, so dispose of and remove the writer
writer.Dispose();
writer = null;
}
}
This stops after generating ~20,000 samples, of course the dispose section can be adjusted to terminate under whatever circumstances are needed.
I'm having a huge amount of fun playing with NAudio, by the way, thank you so much for creating it!
Best regards,
Adam.