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

Karaoke scenario

Jun 21, 2011 at 9:27 PM

I am coding a karaoke program with NAudio. My scenario is that when the user starts recording. I'm playing the audio with WaveOut and record the mic with WaveIn simultaneously. When the user stops the recording I'm mixing the two wavs with WaveMixerStream32 at hard-coded WaveFormat of 44100, 16, 1.
It looks like it's working OK but on some machines there is a latency issue. i.e. the mic is recorded some milliseconds behind the instrumental audio. What could cause that behavior?

Jun 21, 2011 at 11:10 PM

NAudio does not operate by default at a low latency. You can adjust the buffer sizes and number of buffers, but if you go too low, there will be dropouts.

Also, you will always need to compensate for the latency when aligning what is recorded with what was played. In other words, the recording is always one buffer length behind the playback.

Jun 22, 2011 at 6:58 PM

I'm recording the instrumental and the voice at two separate files and then mix them. Do I need to align the two files before I mix them with WaveMixerStream32?

Jun 25, 2011 at 6:46 AM

How do you take input from the microphone and play it out of the speakers? Could you say something about how you're doing that?

Jun 26, 2011 at 7:53 PM

I'm recording the input with WaveIn to a wav file and then mix it with the wav from the audio....

Jun 26, 2011 at 7:57 PM

ok, then you will probably need to compensate by the playback latency. Try with multiples of your buffer size, starting with one buffer.

Jun 26, 2011 at 8:18 PM

But I think that the latency differ from one PC to another. How can I detect the amount of latency that I have to compensate?

Jun 26, 2011 at 8:21 PM

The latency is calculated from buffer sizes, which you know. What size buffers are you using on WaveOut and WaveIn? I suspect you are using the defaults which is 100ms buffers. However, old versions of NAudio used 3 buffers, so the effective playback latency was 200ms (two buffers queued while the other one is playing)

Jun 27, 2011 at 9:09 PM

Maybe it is a better idea to change the workflow of my scenario so instead of recording the two streams separately and then mix them, it would be better to mix the wav file and the stream from the mic in real-time. Is it possible?

Jul 1, 2011 at 9:36 PM

that doesn't really change anything, there will always be latency to compensate for because of buffering

Aug 2, 2011 at 8:18 PM

I still can't understand how can I change the latency amount on a particular client machine, so I compensate correctly.