Exemplo n.º 1
0
        /// <summary>
        /// This reads the format section
        /// </summary>
        void ReadFmt()
        {
            var pos = binaryReader.BaseStream.Position;

            // The audio format is given here
            AudioFormat = binaryReader.ReadUInt16();
            // Get the parameters that we'll use to decode the audio file
            // note: some of these parameters aren't stored here; with the internal
            // Vorbis format, the extra header has those
            NumChannels    = binaryReader.ReadUInt16();
            SampleRate     = binaryReader.ReadUInt32();
            AvgBytesPerSec = binaryReader.ReadUInt32();
            BlockAlign     = binaryReader.ReadUInt16();
            BitsPerSample  = binaryReader.ReadUInt16();
            var extraSize = binaryReader.ReadUInt16();

            // There is maybe some extra stuff, but I'm going to ignore them unless
            // we have no choice
            if (2 == AudioFormat)
            {
                // IMA Wave format
                return;
            }
            if (0xffff != AudioFormat)
            {
                // This is a format that we don't support.  (Most likely it is a
                // format not supported on Vector.
                throw new System.Exception("Unsupported audio format");
            }

            // This is a Vorbis style audio, get information
            binaryReader.BaseStream.Position = pos + 0x18;
            numSamples = binaryReader.ReadUInt32();
            binaryReader.BaseStream.Position = pos + 0x18 + 0x10;
            setup_ofs = binaryReader.ReadUInt32();
            audio_ofs = binaryReader.ReadUInt32();
            binaryReader.BaseStream.Position = pos + 0x18 + 0x28;
            var blocksize_1_exp = binaryReader.ReadByte();
            var blocksize_0_exp = binaryReader.ReadByte();

            transcoder             = new  Vorbis(blocksize_0_exp, blocksize_1_exp);
            transcoder.NumChannels = NumChannels;
            transcoder.SampleRate  = SampleRate;
        }