recording while playing (synchronisation problem)

Nov 13, 2011 at 9:05 AM
Edited Nov 13, 2011 at 9:40 AM

I'm using NAudio 1.4 and I want to record a fix duration of microphon input while some audio is playing in the background.

The audio plays some signals (metronom clicks) to which user must react (play a note on an instrument).  Playing and recording is started at the same time.

The problem is that the recorded audio is always "shifted" forward (between 50 and 120 milliseconds) == beginning too early

-> the instrument hits are not sync with the metronom clicks, although the were played excact the same time( the first instrument sound should start at 0 millisec but it starts between 50 and 120 millisec).

-> Therefore this timespan is missing at the end of the file, as I'm recording a fix length. If it was always the same timespan, I could handle it, but it seems to be random (let's assume that the mic input always starts at the same time (i'm currrently simulating the input by just placing the mic before my pc speaker, so basically i'm just recoding the metronom clicks itself...)

The following code (extract) gets executed in one new thread:


wavePlayer.Play(); // wavePlyer is IWavePlayer

// I'm using the (modified) class "AudioRecorder" that is provided in the NAudio Demo:

WaveFileWriter writer = new WaveFileWriter(waveFileName, recordingFormat);
recordingState = RecordingState.Recording;

  Any idea ? How to do accurate  full duplex recording -> keep sync with WaveIn stream and WaveOut stream?



Nov 19, 2011 at 9:32 AM
Edited Nov 19, 2011 at 9:37 AM

simplified: When I' recording (via mic) what my speakers are playing I would expect the first non-zero sound samples in the recorded stream to be approx at position 0 (millisec), but not at 50-100 millisec - Given that playing and recording is started at the same time and that the non-zero sound in the play stream is starting at position 0.