public void FinalizeFile() { long pos = underlyingStream.Position; WavHeaderUtil.UpdateLength(underlyingStream, (int)(pos - WavHeaderUtil.HEADER_LENGTH)); underlyingStream.Position = pos; }
public static bool IdentifyWavFile(string path, out WavFileInfo info) { bool ok; byte[] header = new byte[WavHeaderUtil.HEADER_LENGTH]; using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read)) { fs.Read(header, 0, WavHeaderUtil.HEADER_LENGTH); ok = WavHeaderUtil.ParseWavHeader(header, out info); } return(ok); }
public WavFileReader(Stream underlyingStream, int bufferSize = 16384) : base(underlyingStream) { //Read WAV header byte[] header = new byte[WavHeaderUtil.HEADER_LENGTH]; underlyingStream.Read(header, 0, WavHeaderUtil.HEADER_LENGTH); if (!WavHeaderUtil.ParseWavHeader(header, out info)) { throw new Exception("This is not a valid WAV header."); } //Create wrapper reader = new StreamSampleReader(underlyingStream, Format, SampleRate, WavHeaderUtil.HEADER_LENGTH, Channels, bufferSize); }
public WavFileWriter(Stream underlyingStream, int sampleRate, short channels, SampleFormat format, int bufferSize) : base(underlyingStream) { //Create wrapper writer = new StreamSampleWriter(underlyingStream, format, sampleRate, WavHeaderUtil.HEADER_LENGTH, channels, bufferSize); //Create info info = new WavFileInfo { bitsPerSample = writer.BitsPerSample, channels = channels, sampleRate = sampleRate }; //Write header byte[] header = WavHeaderUtil.CreateHeader(info); underlyingStream.Position = 0; underlyingStream.Write(header, 0, header.Length); }