示例#1
0
        static void Main(string[] args)
        {
            var parser = new ADTSParser(@"C:\Users\nbasa\Documents\audiodata\sample.aac");

            if (parser.parse() == 0)
            {
                System.Console.WriteLine(parser.IsSingleFs.ToString());
                System.Console.WriteLine(parser.Freq);

                var list = parser.List;
                System.Console.WriteLine(list.Count);
#if false
                double time = 0;
                double tbps = 0;
                foreach (var val in list)
                {
                    int    fs = AdtsFrameInfo.BitAsign2Fs(val.Header.Fs);
                    double t  = 1024.0 / fs;
                    time += t;
                    double bps = val.Header.FrameSize * 8 / t;
                    tbps += bps;
                    System.Console.WriteLine(t.ToString() + "," + time + "," + bps);
                }
                // System.Console.WriteLine(tbps / list.Count);
#endif
                System.Console.WriteLine(parser.Duration);
                System.Console.WriteLine(parser.AvgBps);
            }
            else
            {
                System.Console.WriteLine("parsing error.");
            }
            return;
        }
示例#2
0
        /// <summary>
        /// ストリームパーシング処理本体
        /// </summary>
        /// <param name="br">バイナリ読み込みオブジェクト</param>
        /// <param name="remain">読み取り可能なバイトサイズ</param>
        /// <returns></returns>
        private dynamic parse(BinaryReader br, long remain)
        {
            while (remain > 7)
            {
                // ヘッダー分読み込む
                long   offset = br.BaseStream.Position;
                byte[] b      = br.ReadBytes(7);

                var hdr = new AacAdtsHeader();

                // Sync Header
                if (b[0] != 0xFF && (b[1] & 0xF0) != 0xF0)
                {
                    System.Diagnostics.Debug.WriteLine("error");
                    return(new { Result = 1, Remain = remain });
                }
                // ID
                hdr.ID = ((b[1] & 0x08) == 0x08);
                // Layer, 常に0
                if ((b[1] & 0x06) != 0)
                {
                    System.Diagnostics.Debug.WriteLine("error");
                    return(new { Result = 2, Remain = remain });
                }
                // Protection bit
                hdr.ProtectionBit = ((b[1] & 0x01) == 0x01);

                // Profile
                hdr.Profile = (byte)((b[2] >> 6) & 0x03);
                // Fs
                hdr.Fs = (byte)((b[2] >> 2) & 0x0F);
                // PrivateBit
                hdr.PrivateBit = ((b[2] & 0x02) == 0x02);

                byte tmp = (byte)(b[2] & 0x01);
                tmp       <<= 2;
                tmp        |= (byte)((b[3] >> 6) & 0x3);
                hdr.Channel = tmp;

                // オリジナル
                hdr.Original   = ((b[3] & 0x20) == 0x20);
                hdr.Home       = ((b[3] & 0x10) == 0x10);
                hdr.Copyright  = ((b[3] & 0x08) == 0x08);
                hdr.Icopyright = ((b[3] & 0x04) == 0x04);

                // フレームサイズ
                UInt16 size = (byte)(b[3] & 0x03);
                size        <<= 8;
                size         |= b[4];
                size        <<= 3;
                size         |= (UInt16)(b[5] >> 5);
                hdr.FrameSize = (Int16)size;

                // バッファサイズ
                size           = (byte)(b[5] & 0x1F);
                size         <<= 6;
                size          |= (UInt16)((b[6] >> 2) & 0x3F);
                hdr.BufferSize = (Int16)size;

                // オフセット
                hdr.DBOffset = (byte)(b[6] & 0x03);

                if (!hdr.ProtectionBit)
                {
                    hdr.CRC = br.ReadUInt16();
                }

                // 保存
                AdtsFrameInfo fi = new AdtsFrameInfo(hdr, offset);
                m_List.Add(fi);

                // 移動
                br.BaseStream.Seek(offset + hdr.FrameSize, SeekOrigin.Begin);
                remain -= hdr.FrameSize;
            }
            return(new { Result = 0, Remain = remain });
        }