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

Resample with raw data

Feb 20, 2014 at 12:17 PM
Edited Feb 20, 2014 at 12:18 PM
Hi, I juste want to resample but only CreateWaveFile work and i dont want a wave file
bye [] data = From64String("----- string encoded ---");
MemoryStream fs = new MemoryStream(data);
      var baseDir = AppDomain.CurrentDomain.BaseDirectory;

      using (var wfr = new WaveFileReader(fs))
      {
          var outputFormat = new WaveFormat(8000, 16, 1);
          using (var pcmStream = new WaveFormatConversionStream(outputFormat, wfr))
          {
              using (var ms = new MemoryStream())
              {
                  var bytesRead = -1;
                  while (bytesRead != 0)
                  {
                      var buffer = new byte[pcmStream.WaveFormat.AverageBytesPerSecond];
                      bytesRead = pcmStream.Read(buffer, 0, pcmStream.WaveFormat.AverageBytesPerSecond);


                      ms.Write(buffer, 0, bytesRead);
                   }

                   program.WaveHeaderIN(ms.GetBuffer());
                  ms.Position = 0;
                  RawSourceWaveStream RawStram = new RawSourceWaveStream(ms, outputFormat);

                  System.IO.File.WriteAllBytes(@"Desktop\waveConvertBy.wav", ms.GetBuffer());
                  // to make a real wav file...

                  ms.Position = 0;
                  WaveFileWriter.CreateWaveFile(Path.Combine(\Desktop\output.wav"), RawStram);
                  Console.WriteLine("wavefile length: " + RawStram.Length);

              }
          }
      }
ms.getBUffer is not a wav file when i play it. there is another way to put RawSourcewave stream into byte? or memory Stream?
thanks
Feb 27, 2014 at 10:24 PM
I'm not really sure what you're trying to achieve. Use CreateWaveFile to make a WAV file, or just use a FileStream if you only need the raw data.
NAudio WaveStreams never return a WAV header from their Read method, just raw audio.