I use this function to combine two wav files
public static void Concatenate(string outputFile, ArrayList sourceFiles) { byte[] buffer = new byte[1024]; WaveFileWriter waveFileWriter = null; try { foreach (string sourceFile in sourceFiles) { using (WaveFileReader reader = new WaveFileReader(sourceFile)) { if (waveFileWriter == null) { // first time in create new Writer waveFileWriter = new WaveFileWriter(outputFile, reader.WaveFormat); } else { if (!reader.WaveFormat.Equals(waveFileWriter.WaveFormat)) { //throw new InvalidOperationException("Can't concatenate WAV Files that don't share the same format"); } } int read; while ((read = reader.Read(buffer, 0, buffer.Length)) > 0) { waveFileWriter.WriteData(buffer, 0, read); } } } } catch (Exception ex) { } finally { if (waveFileWriter != null) { waveFileWriter.Dispose(); } } }
But this function joins the second wav file after the first end of wav.

I really want to join the second wav file 2 milliseconds before the end of wav.

Is there a way to do this using NAudio or using some other library?
source share