c# - How to join 2 or more .WAV files together programmatically? -


i need ability join 2 or more .wav files in 1 .wav file. must programmatically, using c# (3rd-party products not option). know of system.media.soundplayer class, not looking play the .wav, create it.

here's basic wav concatenation function built using naudio. ensure data chunks concatenated (unlike code example in this codeproject article linked in answer). protect against concatenating wav files not share same format.

public static void concatenate(string outputfile, ienumerable<string> 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 don't share same format");                     }                 }                  int read;                 while ((read = reader.read(buffer, 0, buffer.length)) > 0)                 {                     wavefilewriter.writedata(buffer, 0, read);                 }             }         }     }         {         if (wavefilewriter != null)         {             wavefilewriter.dispose();         }     }  } 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -