Пример #1
0
        internal int Pack(NVorbis.Ogg.BBuffer Buffer)
        {
            // preamble
            Buffer.Write(0x03, 8);
            Buffer.Write(_vorbis);

            // vendor
            Buffer.Write(_vendor.Length, 32);
            Buffer.Write(_vendor);

            // comments
            Buffer.Write(comments, 32);
            if (comments != 0)
            {
                for (int i = 0; i < comments; i++)
                {
                    if (user_comments[i] != null)
                    {
                        Buffer.Write(comment_lengths[i], 32);
                        Buffer.Write(user_comments[i]);
                    }
                    else
                    {
                        Buffer.Write(0, 32);
                    }
                }
            }
            Buffer.Write(1, 1);
            return(0);
        }
Пример #2
0
        override internal void pack(Object i, NVorbis.Ogg.BBuffer opb)
        {
            InfoFloor1 info = (InfoFloor1)i;

            int count = 0;
            int rangebits;
            int maxposit = info.postlist[1];
            int maxclass = -1;

            /* save out partitions */
            opb.Write(info.Partitions, 5);             /* only 0 to 31 legal */
            for (int j = 0; j < info.Partitions; j++)
            {
                opb.Write(info.Partitionclass[j], 4);                 /* only 0 to 15 legal */
                if (maxclass < info.Partitionclass[j])
                {
                    maxclass = info.Partitionclass[j];
                }
            }

            /* save out partition classes */
            for (int j = 0; j < maxclass + 1; j++)
            {
                opb.Write(info.class_dim[j] - 1, 3);              /* 1 to 8 */
                opb.Write(info.class_subs[j], 2);                 /* 0 to 3 */
                if (info.class_subs[j] != 0)
                {
                    opb.Write(info.class_book[j], 8);
                }
                for (int k = 0; k < (1 << info.class_subs[j]); k++)
                {
                    opb.Write(info.class_subbook[j][k] + 1, 8);
                }
            }

            /* save out the post list */
            opb.Write(info.mult - 1, 2);             /* only 1,2,3,4 legal now */
            opb.Write(Util.ilog2(maxposit), 4);
            rangebits = Util.ilog2(maxposit);

            for (int j = 0, k = 0; j < info.Partitions; j++)
            {
                count += info.class_dim[info.Partitionclass[j]];
                for (; k < count; k++)
                {
                    opb.Write(info.postlist[k + 2], rangebits);
                }
            }
        }
Пример #3
0
        override internal void pack(Object vr, NVorbis.Ogg.BBuffer opb)
        {
            InfoResidue0 info = (InfoResidue0)vr;
            int          acc  = 0;

            opb.Write(info.begin, 24);
            opb.Write(info.end, 24);

            opb.Write(info.grouping - 1, 24);         /* residue vectors to group and
                                                      *  code with a partitioned book */
            opb.Write(info.partitions - 1, 6);        /* possible partition choices */
            opb.Write(info.groupbook, 8);             /* group huffman book */

            /* secondstages is a bitmask; as encoding progresses pass by pass, a
             * bitmask of one indicates this partition class has bits to write
             * this pass */
            for (int j = 0; j < info.partitions; j++)
            {
                int i = info.secondstages[j];
                if (Util.ilog(i) > 3)
                {
                    /* yes, this is a minor hack due to not thinking ahead */
                    opb.Write(i, 3);
                    opb.Write(1, 1);
                    opb.Write((int)(((uint)i) >> 3), 5);
                }
                else
                {
                    opb.Write(i, 4);                     /* trailing zero */
                }
                acc += Util.icount(i);
            }
            for (int j = 0; j < acc; j++)
            {
                opb.Write(info.booklist[j], 8);
            }
        }
Пример #4
0
        override internal void pack(Object i, NVorbis.Ogg.BBuffer opb)
        {
            InfoFloor0 info = (InfoFloor0)i;

            opb.Write(info.order, 8);
            opb.Write(info.rate, 16);
            opb.Write(info.barkmap, 16);
            opb.Write(info.ampbits, 6);
            opb.Write(info.ampdB, 8);
            opb.Write(info.numbooks - 1, 4);
            for (int j = 0; j < info.numbooks; j++)
            {
                opb.Write(info.books[j], 8);
            }
        }
Пример #5
0
        internal int pack(NVorbis.Ogg.BBuffer opb)
        {
            int  i;
            bool ordered = false;

            opb.Write(0x564342, 24);
            opb.Write(dim, 16);
            opb.Write(entries, 24);

            // pack the codewords.  There are two packings; length ordered and
            // length random.  Decide between the two now.

            for (i = 1; i < entries; i++)
            {
                if (lengthlist[i] < lengthlist[i - 1])
                {
                    break;
                }
            }
            if (i == entries)
            {
                ordered = true;
            }

            if (ordered)
            {
                // length ordered.  We only need to say how many codewords of
                // each length.  The actual codewords are generated
                // deterministically

                int count = 0;
                opb.Write(1, 1);                 // ordered
                opb.Write(lengthlist[0] - 1, 5); // 1 to 32

                for (i = 1; i < entries; i++)
                {
                    int _this = lengthlist[i];
                    int _last = lengthlist[i - 1];
                    if (_this > _last)
                    {
                        for (int j = _last; j < _this; j++)
                        {
                            opb.Write(i - count, Util.ilog(entries - count));
                            count = i;
                        }
                    }
                }
                opb.Write(i - count, Util.ilog(entries - count));
            }
            else
            {
                // length random.  Again, we don't code the codeword itself, just
                // the length.  This time, though, we have to encode each length
                opb.Write(0, 1);                 // unordered

                // algortihmic mapping has use for 'unused entries', which we tag
                // here.  The algorithmic mapping happens as usual, but the unused
                // entry has no codeword.
                for (i = 0; i < entries; i++)
                {
                    if (lengthlist[i] == 0)
                    {
                        break;
                    }
                }

                if (i == entries)
                {
                    opb.Write(0, 1);                     // no unused entries
                    for (i = 0; i < entries; i++)
                    {
                        opb.Write(lengthlist[i] - 1, 5);
                    }
                }
                else
                {
                    opb.Write(1, 1);                     // we have unused entries; thus we tag
                    for (i = 0; i < entries; i++)
                    {
                        if (lengthlist[i] == 0)
                        {
                            opb.Write(0, 1);
                        }
                        else
                        {
                            opb.Write(1, 1);
                            opb.Write(lengthlist[i] - 1, 5);
                        }
                    }
                }
            }

            // is the entry number the desired return value, or do we have a
            // mapping? If we have a mapping, what type?
            opb.Write(maptype, 4);
            switch (maptype)
            {
            case 0:
                // no mapping
                break;

            case 1:
            case 2:
                // implicitly populated value mapping
                // explicitly populated value mapping
                if (quantlist == null)
                {
                    // no quantlist?  error
                    return(-1);
                }

                // values that define the dequantization
                opb.Write(q_min, 32);
                opb.Write(q_delta, 32);
                opb.Write(q_quant - 1, 4);
                opb.Write(q_sequencep, 1);
                {
                    int quantvals = 0;
                    switch (maptype)
                    {
                    case 1:
                        // a single column of (c->entries/c->dim) quantized values for
                        // building a full value list algorithmically (square lattice)
                        quantvals = maptype1_quantvals();
                        break;

                    case 2:
                        // every value (c->entries*c->dim total) specified explicitly
                        quantvals = entries * dim;
                        break;
                    }

                    // quantized values
                    for (i = 0; i < quantvals; i++)
                    {
                        opb.Write(Math.Abs(quantlist[i]), q_quant);
                    }
                }
                break;

            default:
                // error case; we don't have any other map types now
                return(-1);
            }
            return(0);
        }
Пример #6
0
        override internal void pack(Info vi, Object imap, NVorbis.Ogg.BBuffer opb)
        {
            InfoMapping0 info = (InfoMapping0)imap;

            /* another 'we meant to do it this way' hack...  up to beta 4, we
             * packed 4 binary zeros here to signify one submapping in use.  We
             * now redefine that to mean four bitflags that indicate use of
             * deeper features; bit0:submappings, bit1:coupling,
             * bit2,3:reserved. This is backward compatable with all actual uses
             * of the beta code. */

            if (info.submaps > 1)
            {
                opb.Write(1, 1);
                opb.Write(info.submaps - 1, 4);
            }
            else
            {
                opb.Write(0, 1);
            }

            if (info.coupling_steps > 0)
            {
                opb.Write(1, 1);
                opb.Write(info.coupling_steps - 1, 8);
                for (int i = 0; i < info.coupling_steps; i++)
                {
                    opb.Write(info.coupling_mag[i], Util.ilog2(vi.Channels));
                    opb.Write(info.coupling_ang[i], Util.ilog2(vi.Channels));
                }
            }
            else
            {
                opb.Write(0, 1);
            }

            opb.Write(0, 2);             /* 2,3:reserved */

            /* we don't write the channel submappings if we only have one... */
            if (info.submaps > 1)
            {
                for (int i = 0; i < vi.Channels; i++)
                {
                    opb.Write(info.chmuxlist[i], 4);
                }
            }
            for (int i = 0; i < info.submaps; i++)
            {
                opb.Write(info.timesubmap[i], 8);
                opb.Write(info.floorsubmap[i], 8);
                opb.Write(info.residuesubmap[i], 8);
            }
        }