private WaveStream CreateInputStream(string fileName) { WaveChannel32 inputStream; if (fileName.EndsWith(".wav")) { WaveStream readerStream = new WaveFileReader(fileName); if (readerStream.WaveFormat.Encoding != WaveFormatEncoding.Pcm) { readerStream = WaveFormatConversionStream.CreatePcmStream(readerStream); readerStream = new BlockAlignReductionStream(readerStream); } if (readerStream.WaveFormat.BitsPerSample != 16) { var format = new WaveFormat(readerStream.WaveFormat.SampleRate, 16, readerStream.WaveFormat.Channels); readerStream = new WaveFormatConversionStream(format, readerStream); } inputStream = new WaveChannel32(readerStream); } else if (fileName.EndsWith(".mp3")) { WaveStream mp3Reader = new Mp3FileReader(fileName); //WaveStream pcmStream = WaveFormatConversionStream.CreatePcmStream(mp3Reader); //WaveStream blockAlignedStream = new BlockAlignReductionStream(mp3Reader); inputStream = new WaveChannel32(mp3Reader); } else { throw new InvalidOperationException("Unsupported extension"); } // we are not going into a mixer so we don't need to zero pad //((WaveChannel32)inputStream).PadWithZeroes = false; volumeStream = inputStream; var meteringStream = new MeteringStream(inputStream, inputStream.WaveFormat.SampleRate / 10); meteringStream.StreamVolume += new EventHandler <StreamVolumeEventArgs>(meteringStream_StreamVolume); return(meteringStream); }
private WaveStream CreateInputStream(string fileName) { WaveChannel32 inputStream; if (fileName.EndsWith(".wav")) { WaveStream readerStream = new WaveFileReader(fileName); if (readerStream.WaveFormat.Encoding != WaveFormatEncoding.Pcm) { readerStream = WaveFormatConversionStream.CreatePcmStream(readerStream); readerStream = new BlockAlignReductionStream(readerStream); } if (readerStream.WaveFormat.BitsPerSample != 16) { var format = new WaveFormat(readerStream.WaveFormat.SampleRate, 16, readerStream.WaveFormat.Channels); readerStream = new WaveFormatConversionStream(format, readerStream); } inputStream = new WaveChannel32(readerStream); } else if (fileName.EndsWith(".mp3")) { WaveStream mp3Reader = new Mp3FileReader(fileName); //WaveStream pcmStream = WaveFormatConversionStream.CreatePcmStream(mp3Reader); //WaveStream blockAlignedStream = new BlockAlignReductionStream(mp3Reader); inputStream = new WaveChannel32(mp3Reader); } else { throw new InvalidOperationException("Unsupported extension"); } // we are not going into a mixer so we don't need to zero pad //((WaveChannel32)inputStream).PadWithZeroes = false; volumeStream = inputStream; var meteringStream = new MeteringStream(inputStream, inputStream.WaveFormat.SampleRate / 10); meteringStream.StreamVolume += new EventHandler<StreamVolumeEventArgs>(meteringStream_StreamVolume); return meteringStream; }