This project has moved and is read-only. For the latest updates, please go here.

Read and Write Same Wave File

Oct 18, 2012 at 9:37 AM

Hi All

Just starting out with NAudio and wondering if some people can point me in the right direction for being able to record audio from a sound card line input - to wave file, while simultaneously being able to play back that same file (maybe minutes later) through the sound card speaker out. 

I've seen many examples of writing to memory and immediately playing back the sound through the speakers, however, I want to write to disk, and then play back the wave file (while it is still recording)... 

Basically a time delay program...

Any pointers would be greatly appreciated...


Oct 19, 2012 at 3:06 PM

I have written code that can do this, but it is not easy. A valid WAV file includes the length of the data chunk early on, but since the length is unknown, you'll need custom reader code. I also found that appending to a file on one thread while reading from it on another is fraught with difficulty. I ended up creating a long blank WAV file, and have one thread overwriting the samples in it while another played back from it. You might find it easier not to use a WAV file at all, and just have a raw PCM audio data file.