コード例 #1
0
        public MSF.AudioBlock ParseAudioBlock(int offset, Stream _stream)
        {
            _stream.Seek(offset, SeekOrigin.Begin);
            byte[]         tmp = new byte[4];
            MSF.AudioBlock ab  = new MSF.AudioBlock();
            _stream.Read(tmp, 0, 1);
            ab.AudioFrameNum          = (uint)BitTools.MaskBits(tmp, 0, 8);
            ab.AudioBlockHeaderLength = ab.AudioFrameNum * 5 + 1;

            uint addr = (uint)offset + ab.AudioBlockHeaderLength + CRC_Size;

            for (int i = 0; i < ab.AudioFrameNum; i++)
            {
                //读音频参数集
                MSF.AudioBlock.AudioFrame f = new MSF.AudioBlock.AudioFrame();
                _stream.Read(tmp, 0, 2);
                f.RelativeStartAddr = addr;
                f.Length            = (uint)BitTools.MaskBits(tmp, 0, 16);
                // skip 音频流编号 和 保留
                _stream.Seek(1, SeekOrigin.Current);

                // 读相对时间
                _stream.Read(tmp, 0, 2);
                f.RelativeTime = BitTools.MaskBits(tmp, 0, 16) * timeUint;

                // copy 音频流
                //f._as = BitTools.CopyToNewStream(_stream, (long)f.RelativeStartAddr, (int)f.Length);
                BitTools.CopyFromStreamToBytesArray(_stream, (long)f.RelativeStartAddr, (int)f.Length, ref f._data);

                ab.aFrames.Add(f);
                //下一段音频地址
                addr += f.Length;
            }
            return(ab);
        }
コード例 #2
0
ファイル: CmmbDemux.cs プロジェクト: yspxman/CMTVDemo
        public MSF.AudioBlock ParseAudioBlock(int offset, Stream _stream)
        {
            _stream.Seek(offset, SeekOrigin.Begin);
            byte[] tmp = new byte[4];
            MSF.AudioBlock ab = new MSF.AudioBlock();
            _stream.Read(tmp, 0, 1);
            ab.AudioFrameNum = (uint)BitTools.MaskBits(tmp, 0, 8);
            ab.AudioBlockHeaderLength = ab.AudioFrameNum * 5 +1;

            uint addr = (uint)offset + ab.AudioBlockHeaderLength + CRC_Size;
            for (int i = 0; i < ab.AudioFrameNum; i++)
            {
                //读音频参数集
                MSF.AudioBlock.AudioFrame f = new MSF.AudioBlock.AudioFrame();
                _stream.Read(tmp, 0, 2);
                f.RelativeStartAddr = addr;
                f.Length = (uint)BitTools.MaskBits(tmp, 0, 16);
                // skip 音频流编号 和 保留
                _stream.Seek(1, SeekOrigin.Current);

                // 读相对时间
                _stream.Read(tmp, 0, 2);
                f.RelativeTime = BitTools.MaskBits(tmp, 0, 16) * timeUint;

                // copy 音频流
                //f._as = BitTools.CopyToNewStream(_stream, (long)f.RelativeStartAddr, (int)f.Length);
                BitTools.CopyFromStreamToBytesArray(_stream, (long)f.RelativeStartAddr, (int)f.Length, ref f._data);

                ab.aFrames.Add(f);
                //下一段音频地址
                addr += f.Length;
            }
            return ab;
        }