public void CanAccessSamplesIndividuallyInAMonoFile()
 {
     var ms =  new MemoryStream();
     using (var writer = new WaveFileWriter( new IgnoreDisposeStream(ms), new WaveFormat(8000, 16, 1)))
     {
         writer.WriteSample(0.1f);
         writer.WriteSample(0.2f);
         writer.WriteSample(0.3f);
         writer.WriteSample(0.4f);
     }
     ms.Position = 0;
     using (var reader = new WaveFileForwardOnlyReader(new ForwardOnlyStream(ms)))
     {
         Assert.AreEqual(0.1f, reader.ReadNextSampleFrame()[0], 0.001f);
         Assert.AreEqual(0.2f, reader.ReadNextSampleFrame()[0], 0.001f);
         Assert.AreEqual(0.3f, reader.ReadNextSampleFrame()[0], 0.001f);
         Assert.AreEqual(0.4f, reader.ReadNextSampleFrame()[0], 0.001f);
         Assert.IsNull(reader.ReadNextSampleFrame());
     }
 }
        public void CanAccessSamplesIndividuallyInAStereo24BitFile()
        {
            var ms = new MemoryStream();
            using (var writer = new WaveFileWriter(new IgnoreDisposeStream(ms), new WaveFormat(44100, 24, 2)))
            {
                writer.WriteSample(0.1f);
                writer.WriteSample(0.2f);
                writer.WriteSample(0.3f);
                writer.WriteSample(0.4f);

            }
            ms.Position = 0;
            using (var reader = new WaveFileForwardOnlyReader(new ForwardOnlyStream(ms)))
            {
                var f1 = reader.ReadNextSampleFrame();
                Assert.AreEqual(0.1f, f1[0], 0.0001f);
                Assert.AreEqual(0.2f, f1[1], 0.0001f);
                var f2 = reader.ReadNextSampleFrame();
                Assert.AreEqual(0.3f, f2[0], 0.0001f);
                Assert.AreEqual(0.4f, f2[1], 0.0001f);
                Assert.IsNull(reader.ReadNextSampleFrame());
            }
        }
 public void CanLoadAndReadVariousProblemWavFiles()
 {
     string testDataFolder = @"C:\Users\Mark\Downloads\NAudio";
     if (!Directory.Exists(testDataFolder))
     {
         Assert.Ignore("{0} not found", testDataFolder);
     }
     foreach (string file in Directory.GetFiles(testDataFolder, "*.wav"))
     {
         string wavFile = Path.Combine(testDataFolder, file);
         Debug.WriteLine(String.Format("Opening {0}", wavFile));
         using (var reader = new WaveFileForwardOnlyReader(wavFile))
         {
             byte[] buffer = new byte[reader.WaveFormat.AverageBytesPerSecond];
             int bytesRead;
             int total = 0;
             do
             {
                 bytesRead = reader.Read(buffer, 0, buffer.Length);
                 total += bytesRead;
             } while (bytesRead > 0);
             Debug.WriteLine(String.Format("Read {0} bytes", total));
         }
     }
 }
        public void DisposeOfStreamWhenConstructedFromFilePath()
        {
            string tempFilePath = System.IO.Path.GetTempFileName();
            System.IO.File.WriteAllText(tempFilePath, "Some test content");
            try
            {
                var waveReader = new WaveFileForwardOnlyReader(tempFilePath);

                Assert.Fail("Expected exception System.FormatException was not thrown for file missing a header.");
            }
            catch(FormatException ex)
            {
                Assert.IsNotNull(ex);
            }
            finally
            {
                System.IO.File.Delete(tempFilePath);
            }
        }