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

How to perform simultaneous playback and recording using NAudio?

Jan 5, 2015 at 6:03 PM
Dear NAudio community,

I'm a novice when in comes to computer audio, and have not worked with NAudio before, but it looks like it might be a fit for an application I need to develop. I'm hoping that the community can offer some help.

The key is simultaneously playing back some predefined tone through an output on the card and recording from an input to the card. Some type of high-quality 24-bit 48 kHz or better sound card would perform the following:
  1. Create some number of seconds of a test waveform. For example, a 200 Hz sine wave at 600 Volts RMS that runs for 1 second. (I understand that the output level would need to be measured/calibrated, and is only going to provide some % of whatever full scale is).
  2. Play that waveform to one (or both) channels of a sound card (selectable before the test is run).
  3. After some short amount of settling delay (programmable in milliseconds), record from one (or both) inputs of a sound card.
  4. Note that the recording needs to be going on while the playback is still occurring.
  5. Save the recorded data and pass it to something external (like a MATLAB program) for further analysis, and/or do other mathematical manipulations of the playback and recorded data, such as taking a ratio, multiplying by a scaling factor, etc.
  6. The GUI needs to be "easy to use", streamlined, slick, and modern, and using Visual Studio with C# is a likely approach.
The MATLAB portion and other math manipulations aren't the worrisome part for me. I’m trying to find a way to simultaneously play back a signal and record a response on the same sound card.

How can simultaneous playback and recording using the same sound card be done in NAudio? Can you point me to any specific examples for reference?

Since I am new to all of this, is there a preferred type of driver/interface to the sound card? For example, I've seen several references that state that if ASIO is available, you should use it, but they really don't explain why. I know there are many other interface types out there, including WASAPI, WDM-KS, DirectSound, and perhaps others, but I do not know the strengths and weaknesses of each yet. So if I have a choice with NAudio, what driver/interface should I use, and why?

Thanks in advance for your help!

Scott
Jan 9, 2015 at 9:44 AM
Hi,

I have almost the same question and i'm also novice on this topic.

I have an audio stream that will be consumed by "something" (like a speech engine) and I'd like to also write the stream to a file.

I don't know if NAudio has a magical double stream ?

Jp
Jan 9, 2015 at 1:44 PM
Thanks Jp,

I have not received any other responses, which is very disappointing. I'm hoping that your added interest will encourage someone in the group to help answer our common questions.

As an aside, I have also been looking at PortAudio, which apparently can playback and record simultaneously, but the examples are not terribly enlightening, and I have not received much help from their mailing list, either.

Will let you know if I get any other information to work with.

Kind regards,

Scott

Jan 9, 2015 at 10:02 PM
Hi Scott,

you can do most of those things with NAudio. The SignalGenerator class can make the sounds you want. MonoToStereo convertors will allow you to choose which side the audio should be played through. WaveIn can record from the soundcard. Here's a post from my blog on how to record the audio you are playing back:
http://www.markheath.net/post/how-to-record-and-play-audio-at-same

Hope this points you in the right direction

Mark