Пример #1
0
        internal override 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);
            }
        }
Пример #2
0
        // also responsible for range checking
        internal override Object unpack(Info vi, NVorbis.Ogg.BBuffer opb)
        {
            InfoMapping0 info = new InfoMapping0();

            if (opb.Read(1) != 0)
            {
                info.submaps = opb.Read(4) + 1;
            }
            else
            {
                info.submaps = 1;
            }

            if (opb.Read(1) != 0)
            {
                info.coupling_steps = opb.Read(8) + 1;

                for (int i = 0; i < info.coupling_steps; i++)
                {
                    int testM = info.coupling_mag[i] = opb.Read(Util.ilog2(vi.Channels));
                    int testA = info.coupling_ang[i] = opb.Read(Util.ilog2(vi.Channels));

                    if (testM < 0 || testA < 0 || testM == testA || testM >= vi.Channels
                        || testA >= vi.Channels)
                    {
                        //goto err_out;
                        info.free();
                        return (null);
                    }
                }
            }

            if (opb.Read(2) > 0)
            { /* 2,3:reserved */
                info.free();
                return (null);
            }

            if (info.submaps > 1)
            {
                for (int i = 0; i < vi.Channels; i++)
                {
                    info.chmuxlist[i] = opb.Read(4);
                    if (info.chmuxlist[i] >= info.submaps)
                    {
                        info.free();
                        return (null);
                    }
                }
            }

            for (int i = 0; i < info.submaps; i++)
            {
                info.timesubmap[i] = opb.Read(8);
                if (info.timesubmap[i] >= vi.Times)
                {
                    info.free();
                    return (null);
                }
                info.floorsubmap[i] = opb.Read(8);
                if (info.floorsubmap[i] >= vi.floors)
                {
                    info.free();
                    return (null);
                }
                info.residuesubmap[i] = opb.Read(8);
                if (info.residuesubmap[i] >= vi.residues)
                {
                    info.free();
                    return (null);
                }
            }
            return info;
        }
Пример #3
0
        // Analysis side code, but directly related to blocking.  Thus it's
        // here and not in analysis.c (which is for analysis transforms only).
        // The init is here because some of it is shared
        int init(Info vi, bool encp)
        {
            this.vi = vi;
            modebits = Util.ilog2(vi.Modes);

            transform[0] = new Object[VI_TRANSFORMB];
            transform[1] = new Object[VI_TRANSFORMB];

            // MDCT is tranform 0

            transform[0][0] = new Mdct();
            transform[1][0] = new Mdct();
            ((Mdct)transform[0][0]).Init(vi.blocksizes[0]);
            ((Mdct)transform[1][0]).Init(vi.blocksizes[1]);

            _window[0][0][0] = new float[VI_WINDOWB][];
            _window[0][0][1] = _window[0][0][0];
            _window[0][1][0] = _window[0][0][0];
            _window[0][1][1] = _window[0][0][0];
            _window[1][0][0] = new float[VI_WINDOWB][];
            _window[1][0][1] = new float[VI_WINDOWB][];
            _window[1][1][0] = new float[VI_WINDOWB][];
            _window[1][1][1] = new float[VI_WINDOWB][];

            for (int i = 0; i < VI_WINDOWB; i++)
            {
                _window[0][0][0][i] = window(i, vi.blocksizes[0], vi.blocksizes[0] / 2,
                    vi.blocksizes[0] / 2);
                _window[1][0][0][i] = window(i, vi.blocksizes[1], vi.blocksizes[0] / 2,
                    vi.blocksizes[0] / 2);
                _window[1][0][1][i] = window(i, vi.blocksizes[1], vi.blocksizes[0] / 2,
                    vi.blocksizes[1] / 2);
                _window[1][1][0][i] = window(i, vi.blocksizes[1], vi.blocksizes[1] / 2,
                    vi.blocksizes[0] / 2);
                _window[1][1][1][i] = window(i, vi.blocksizes[1], vi.blocksizes[1] / 2,
                    vi.blocksizes[1] / 2);
            }

            fullbooks = new CodeBook[vi.Books];
            for (int i = 0; i < vi.Books; i++)
            {
                fullbooks[i] = new CodeBook();
                fullbooks[i].init_decode(vi.BookParam[i]);
            }

            // initialize the storage vectors to a decent size greater than the
            // minimum

            pcm_storage = 8192; // we'll assume later that we have
            // a minimum of twice the blocksize of
            // accumulated samples in analysis
            pcm = new float[vi.Channels][];
            {
                for (int i = 0; i < vi.Channels; i++)
                {
                    pcm[i] = new float[pcm_storage];
                }
            }

            // all 1 (large block) or 0 (small block)
            // explicitly set for the sake of clarity
            lW = 0; // previous window size
            W = 0; // current window size

            // all vector indexes; multiples of samples_per_envelope_step
            centerW = vi.blocksizes[1] / 2;

            pcm_current = centerW;

            // initialize all the mapping/backend lookups
            mode = new Object[vi.Modes];
            for (int i = 0; i < vi.Modes; i++)
            {
                int mapnum = vi.ModeParam[i].mapping;
                int maptype = vi.map_type[mapnum];
                mode[i] = FuncMapping.mapping_P[maptype].look(this, vi.ModeParam[i],
                    vi.MapParam[mapnum]);
            }
            return (0);
        }
Пример #4
0
 internal abstract Object unpack(Info vi, NVorbis.Ogg.BBuffer opb);
Пример #5
0
 DspState(Info vi)
 {
     //this();
     init(vi, false);
     // Adjust centerW to allow an easier mechanism for determining output
     pcm_returned = centerW;
     centerW -= vi.blocksizes[W] / 4 + vi.blocksizes[lW] / 4;
     granulepos = -1;
     sequence = -1;
 }
Пример #6
0
 public int synthesis_init(Info vi)
 {
     init(vi, false);
     // Adjust centerW to allow an easier mechanism for determining output
     pcm_returned = centerW;
     centerW -= vi.blocksizes[W] / 4 + vi.blocksizes[lW] / 4;
     granulepos = -1;
     sequence = -1;
     return (0);
 }
Пример #7
0
        override internal Object unpack(Info vi, NVorbis.Ogg.BBuffer opb)
        {
            int        count = 0, maxclass = -1, rangebits;
            InfoFloor1 info = new InfoFloor1();

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

            /* read partition classes */
            for (int j = 0; j < maxclass + 1; j++)
            {
                info.class_dim[j]  = opb.Read(3) + 1;             /* 1 to 8 */
                info.class_subs[j] = opb.Read(2);                 /* 0,1,2,3 bits */
                if (info.class_subs[j] < 0)
                {
                    info.free();
                    return(null);
                }
                if (info.class_subs[j] != 0)
                {
                    info.class_book[j] = opb.Read(8);
                }
                if (info.class_book[j] < 0 || info.class_book[j] >= vi.Books)
                {
                    info.free();
                    return(null);
                }
                for (int k = 0; k < (1 << info.class_subs[j]); k++)
                {
                    info.class_subbook[j][k] = opb.Read(8) - 1;
                    if (info.class_subbook[j][k] < -1 || info.class_subbook[j][k] >= vi.Books)
                    {
                        info.free();
                        return(null);
                    }
                }
            }

            /* read the post list */
            info.mult = opb.Read(2) + 1;             /* only 1,2,3,4 legal now */
            rangebits = opb.Read(4);

            for (int j = 0, k = 0; j < info.Partitions; j++)
            {
                count += info.class_dim[info.Partitionclass[j]];
                for (; k < count; k++)
                {
                    int t = info.postlist[k + 2] = opb.Read(rangebits);
                    if (t < 0 || t >= (1 << rangebits))
                    {
                        info.free();
                        return(null);
                    }
                }
            }
            info.postlist[0] = 0;
            info.postlist[1] = 1 << rangebits;

            return(info);
        }
Пример #8
0
        internal override Object unpack(Info vi, NVorbis.Ogg.BBuffer opb)
        {
            int acc = 0;
            InfoResidue0 info = new InfoResidue0();
            info.begin = opb.Read(24);
            info.end = opb.Read(24);
            info.grouping = opb.Read(24) + 1;
            info.partitions = opb.Read(6) + 1;
            info.groupbook = opb.Read(8);

            for (int j = 0; j < info.partitions; j++)
            {
                int cascade = opb.Read(3);
                if (opb.Read(1) != 0)
                {
                    cascade |= (opb.Read(5) << 3);
                }
                info.secondstages[j] = cascade;
                acc += Util.icount(cascade);
            }

            for (int j = 0; j < acc; j++)
            {
                info.booklist[j] = opb.Read(8);
            }

            if (info.groupbook >= vi.Books)
            {
                free_info(info);
                return (null);
            }

            for (int j = 0; j < acc; j++)
            {
                if (info.booklist[j] >= vi.Books)
                {
                    free_info(info);
                    return (null);
                }
            }
            return (info);
        }
Пример #9
0
		abstract internal Object unpack(Info vi, NVorbis.Ogg.BBuffer opb);
Пример #10
0
 internal override Object unpack(Info vi, NVorbis.Ogg.BBuffer opb)
 {
     return "";
 }
Пример #11
0
        internal override Object unpack(Info vi, NVorbis.Ogg.BBuffer opb)
        {
            int count = 0, maxclass = -1, rangebits;
            InfoFloor1 info = new InfoFloor1();

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

            /* read partition classes */
            for (int j = 0; j < maxclass + 1; j++)
            {
                info.class_dim[j] = opb.Read(3) + 1; /* 1 to 8 */
                info.class_subs[j] = opb.Read(2); /* 0,1,2,3 bits */
                if (info.class_subs[j] < 0)
                {
                    info.free();
                    return (null);
                }
                if (info.class_subs[j] != 0)
                {
                    info.class_book[j] = opb.Read(8);
                }
                if (info.class_book[j] < 0 || info.class_book[j] >= vi.Books)
                {
                    info.free();
                    return (null);
                }
                for (int k = 0; k < (1 << info.class_subs[j]); k++)
                {
                    info.class_subbook[j][k] = opb.Read(8) - 1;
                    if (info.class_subbook[j][k] < -1 || info.class_subbook[j][k] >= vi.Books)
                    {
                        info.free();
                        return (null);
                    }
                }
            }

            /* read the post list */
            info.mult = opb.Read(2) + 1; /* only 1,2,3,4 legal now */
            rangebits = opb.Read(4);

            for (int j = 0, k = 0; j < info.Partitions; j++)
            {
                count += info.class_dim[info.Partitionclass[j]];
                for (; k < count; k++)
                {
                    int t = info.postlist[k + 2] = opb.Read(rangebits);
                    if (t < 0 || t >= (1 << rangebits))
                    {
                        info.free();
                        return (null);
                    }
                }
            }
            info.postlist[0] = 0;
            info.postlist[1] = 1 << rangebits;

            return (info);
        }
Пример #12
0
        internal override Object unpack(Info vi, NVorbis.Ogg.BBuffer opb)
        {
            InfoFloor0 info = new InfoFloor0();
            info.order = opb.Read(8);
            info.rate = opb.Read(16);
            info.barkmap = opb.Read(16);
            info.ampbits = opb.Read(6);
            info.ampdB = opb.Read(8);
            info.numbooks = opb.Read(4) + 1;

            if ((info.order < 1) || (info.rate < 1) || (info.barkmap < 1) || (info.numbooks < 1))
            {
                return (null);
            }

            for (int j = 0; j < info.numbooks; j++)
            {
                info.books[j] = opb.Read(8);
                if (info.books[j] < 0 || info.books[j] >= vi.Books)
                {
                    return (null);
                }
            }
            return (info);
        }
Пример #13
0
 internal abstract Object unpack(Info info, NVorbis.Ogg.BBuffer buffer);
Пример #14
0
 internal abstract void pack(Info info, Object imap, NVorbis.Ogg.BBuffer buffer);
Пример #15
0
        private void DecodeInit()
        {
            convbuffer = new byte[convsize]; // take 8k out of the data segment, not the stack
            SyncState = new SyncState(); // sync and verify incoming physical bitstream
            StreamState = new StreamState(); // take physical pages, weld into a logical stream of packets
            Page = new Page(); // one Ogg bitstream page.  Vorbis packets are inside
            Packet = new Packet(); // one raw packet of data for decode

            Info = new Info(); // struct that stores all the static vorbis bitstream settings
            Comment = new Comment(); // struct that stores all the bitstream user comments
            DspState = new DspState(); // central working state for the packet->PCM decoder
            Block = new Block(DspState); // local working space for packet->PCM decode
            bytes = 0;
        }