Esempio n. 1
0
        public override void WriteHeader(string comment)
        {
            OggPageHeader pageHeader = new OggPageHeader(OggPageHeader.HEADER_TYPE_BOS, 0, streamSerialNumber, pageCount++, 0, 1, new byte[1] {
                80
            });

            byte[] pageHeaderData = pageHeader.BuildData();


            SpeexHeader speexHeader = new SpeexHeader(sampleRate, mode, channels, vbr, bitRate, nframes);

            byte[] speexHeaderData = speexHeader.BuildData();

            int chksum = OggCrc2.checksum(0, pageHeaderData, 0, pageHeaderData.Length);

            chksum = OggCrc2.checksum(chksum, speexHeaderData, 0, speexHeaderData.Length);
            LittleEndian.WriteInt(pageHeaderData, 22, chksum);

            //Misc.ShowBytes(pageHeaderData, 0, pageHeaderData.Length);
            //Misc.ShowBytes(speexHeaderData, 0, speexHeaderData.Length);

            stream.Write(pageHeaderData, 0, pageHeaderData.Length);
            stream.Write(speexHeaderData, 0, speexHeaderData.Length);

            //Console.WriteLine("write page header:" + pageHeaderData.Length);
            //Console.WriteLine("write speex header:" + speexHeaderData.Length);
            //comment
            pageHeader = new OggPageHeader(OggPageHeader.HEADER_TYPE_NORMAL, 0, streamSerialNumber, pageCount++, 0, 1, new byte[1] {
                (byte)(comment.Length + 8)
            });
            pageHeaderData  = pageHeader.BuildData();
            speexHeaderData = new byte[comment.Length + 8];
            LittleEndian.WriteInt(speexHeaderData, 0, comment.Length);
            LittleEndian.WriteString(speexHeaderData, 4, comment);
            LittleEndian.WriteInt(speexHeaderData, 4 + comment.Length, 0);
            chksum = OggCrc2.checksum(0, pageHeaderData, 0, pageHeaderData.Length);
            chksum = OggCrc2.checksum(chksum, speexHeaderData, 0, speexHeaderData.Length);
            LittleEndian.WriteInt(pageHeaderData, 22, chksum);
            stream.Write(pageHeaderData, 0, pageHeaderData.Length);
            stream.Write(speexHeaderData, 0, speexHeaderData.Length);

            //Misc.ShowBytes(pageHeaderData, 0, pageHeaderData.Length);
            //Misc.ShowBytes(speexHeaderData, 0, speexHeaderData.Length);
            //Console.WriteLine("write page header:" + pageHeaderData.Length);
            //Console.WriteLine("write speex comment:" + speexHeaderData.Length);
        }
Esempio n. 2
0
        private void Flush(bool eos)
        {
            OggPageHeader pageHeader = new OggPageHeader((eos ? OggPageHeader.HEADER_TYPE_EOS : OggPageHeader.HEADER_TYPE_NORMAL), granulepos, streamSerialNumber, pageCount++, 0, packetCount, headerBuffer);

            byte[] pageHeaderData = pageHeader.BuildData();
            int    chksum         = OggCrc2.checksum(0, pageHeaderData, 0, pageHeaderData.Length);

            chksum = OggCrc2.checksum(chksum, dataBuffer, 0, dataBufferPtr);
            LittleEndian.WriteInt(pageHeaderData, 22, chksum);
            stream.Write(pageHeaderData, 0, pageHeaderData.Length);
            stream.Write(dataBuffer, 0, dataBufferPtr);
            packetDataSize += dataBufferPtr;

            dataBufferPtr   = 0;
            headerBufferPtr = 0;
            packetCount     = 0;
            if (eos)
            {
                Console.WriteLine("total write " + packetDataSize + " packet data int byte");
            }
        }