예제 #1
0
 /// <summary>
 /// Closes the WAV file
 /// </summary>
 public void Dispose()
 {
     if (writer != null)
     {
         writer.Dispose();
         writer = null;
     }
 }
예제 #2
0
 /// <summary>
 /// Creates a Wave file by reading all the data from a WaveProvider
 /// BEWARE: the WaveProvider MUST return 0 from its Read method when it is finished,
 /// or the Wave File will grow indefinitely.
 /// </summary>
 /// <param name="filename">The filename to use</param>
 /// <param name="sourceProvider">The source WaveProvider</param>
 public static void CreateWaveFile(string filename, IWaveProvider sourceProvider)
 {
     using (var writer = new WaveFileWriter(filename, sourceProvider.WaveFormat))
     {
         long outputLength = 0;
         var buffer = new byte[sourceProvider.WaveFormat.AverageBytesPerSecond * 4];
         while (true)
         {
             int bytesRead = sourceProvider.Read(buffer, 0, buffer.Length);
             if (bytesRead == 0)
             {
                 // end of source provider
                 break;
             }
             outputLength += bytesRead;
             // Write will throw exception if WAV file becomes too large
             writer.Write(buffer, 0, bytesRead);
         }
     }
 }
예제 #3
0
 /// <summary>
 /// Constructs a new WaveRecorder
 /// </summary>
 /// <param name="destination">The location to write the WAV file to</param>
 /// <param name="source">The Source Wave Provider</param>
 public WaveRecorder(IWaveProvider source, string destination)
 {
     this.source = source;
     this.writer = new WaveFileWriter(destination, source.WaveFormat);
 }