示例#1
0
        static void WriteFmtChunk(RiffWriter writer, AudioInfo audioInfo, int bytesPerSample)
        {
            Contract.Requires(writer != null);
            Contract.Requires(audioInfo != null);
            Contract.Requires(bytesPerSample > 0);

            writer.BeginChunk("fmt ", 16);
            writer.Write((ushort)1);
            writer.Write((ushort)audioInfo.Channels);
            writer.Write((uint)audioInfo.SampleRate);
            writer.Write((uint)(bytesPerSample * audioInfo.Channels * audioInfo.SampleRate));
            writer.Write((ushort)(bytesPerSample * audioInfo.Channels));
            writer.Write((ushort)audioInfo.BitsPerSample);
            writer.FinishChunk();
        }
示例#2
0
        public void Initialize(Stream stream, AudioInfo audioInfo, MetadataDictionary metadata, SettingsDictionary settings)
        {
            Contract.Ensures(_writer != null);
            Contract.Ensures(_writer.BaseStream == stream);
            Contract.Ensures(_channels == audioInfo.Channels);
            Contract.Ensures(_bytesPerSample > 0);
            Contract.Ensures(_multiplier > 0);

            _writer         = new RiffWriter(stream, "WAVE");
            _channels       = audioInfo.Channels;
            _bytesPerSample = (int)Math.Ceiling(audioInfo.BitsPerSample / (double)8);
            _multiplier     = (float)Math.Pow(2, audioInfo.BitsPerSample - 1);

            _writer.Initialize();
            WriteFmtChunk(_writer, audioInfo, _bytesPerSample);
            _writer.BeginChunk("data");
        }