示例#1
0
        public void FinalizeFile()
        {
            long pos = underlyingStream.Position;

            WavHeaderUtil.UpdateLength(underlyingStream, (int)(pos - WavHeaderUtil.HEADER_LENGTH));
            underlyingStream.Position = pos;
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }