Beispiel #1
0
        override internal Object look(DspState vd, InfoMode mi, Object i)
        {
            float      scale;
            Info       vi   = vd.vi;
            InfoFloor0 info = (InfoFloor0)i;
            LookFloor0 look = new LookFloor0();

            look.m  = info.order;
            look.n  = vi.blocksizes[mi.blockflag] / 2;
            look.ln = info.barkmap;
            look.vi = info;
            look.lpclook.init(look.ln, look.m);

            // we choose a scaling constant so that:
            scale = look.ln / toBARK((float)(info.rate / 2.0f));

            // the mapping from a linear scale to a smaller bark scale is
            // straightforward.  We do *not* make sure that the linear mapping
            // does not skip bark-scale bins; the decoder simply skips them and
            // the encoder may do what it wishes in filling them.  They're
            // necessary in some mapping combinations to keep the scale spacing
            // accurate
            look.linearmap = new int[look.n];
            for (int j = 0; j < look.n; j++)
            {
                int val = (int)Math.Floor(toBARK((float)((info.rate / 2.0f) / look.n * j)) * scale);                 // bark numbers represent band edges
                if (val >= look.ln)
                {
                    val = look.ln;                     // guard against the approximation
                }
                look.linearmap[j] = val;
            }
            return(look);
        }
Beispiel #2
0
        override internal Object inverse1(Block vb, Object i, Object memo)
        {
            LookFloor0 look = (LookFloor0)i;
            InfoFloor0 info = look.vi;

            float[] lsp = null;
            if (memo is float[])
            {
                lsp = (float[])memo;
            }

            int ampraw = vb.opb.Read(info.ampbits);

            if (ampraw > 0)
            {             // also handles the -1 out of data case
                int   maxval  = (1 << info.ampbits) - 1;
                float amp     = (float)ampraw / maxval * info.ampdB;
                int   booknum = vb.opb.Read(Util.ilog(info.numbooks));

                if (booknum != -1 && booknum < info.numbooks)
                {
                    CodeBook b    = vb.vd.fullbooks[info.books[booknum]];
                    float    last = 0.0f;

                    if (lsp == null || lsp.Length < look.m + 1)
                    {
                        lsp = new float[look.m + 1];
                    }
                    else
                    {
                        for (int j = 0; j < lsp.Length; j++)
                        {
                            lsp[j] = 0.0f;
                        }
                    }

                    for (int j = 0; j < look.m; j += b.dim)
                    {
                        if (b.decodev_set(lsp, j, vb.opb, b.dim) == -1)
                        {
                            return(null);
                        }
                    }

                    for (int j = 0; j < look.m;)
                    {
                        for (int k = 0; k < b.dim; k++, j++)
                        {
                            lsp[j] += last;
                        }
                        last = lsp[j - 1];
                    }
                    lsp[look.m] = amp;
                    return(lsp);
                }
            }
            return(null);
        }
Beispiel #3
0
        internal static void lpc_to_curve(float[] curve, float[] lpc, float amp, LookFloor0 l,
			String name, int frameno)
        {
            // l->m+1 must be less than l->ln, but guard in case we get a bad stream
            float[] lcurve = new float[Math.Max(l.ln * 2, l.m * 2 + 2)];

            if (amp == 0)
            {
                for (int j = 0; j < l.n; j++)
                    curve[j] = 0.0f;
                return;
            }
            l.lpclook.lpc_to_curve(lcurve, lpc, amp);

            for (int i = 0; i < l.n; i++)
                curve[i] = lcurve[l.linearmap[i]];
        }
Beispiel #4
0
        override internal int inverse2(Block vb, Object i, Object memo, float[] Out)
        {
            LookFloor0 look = (LookFloor0)i;
            InfoFloor0 info = look.vi;

            if (memo != null)
            {
                float[] lsp = (float[])memo;
                float   amp = lsp[look.m];

                Lsp.lsp_to_curve(Out, look.linearmap, look.n, look.ln, lsp, look.m, amp, info.ampdB);
                return(1);
            }
            for (int j = 0; j < look.n; j++)
            {
                Out[j] = 0.0f;
            }
            return(0);
        }
Beispiel #5
0
        static internal void lpc_to_curve(float[] curve, float[] lpc, float amp, LookFloor0 l,
                                          String name, int frameno)
        {
            // l->m+1 must be less than l->ln, but guard in case we get a bad stream
            float[] lcurve = new float[Math.Max(l.ln * 2, l.m * 2 + 2)];

            if (amp == 0)
            {
                for (int j = 0; j < l.n; j++)
                {
                    curve[j] = 0.0f;
                }
                return;
            }
            l.lpclook.lpc_to_curve(lcurve, lpc, amp);

            for (int i = 0; i < l.n; i++)
            {
                curve[i] = lcurve[l.linearmap[i]];
            }
        }
Beispiel #6
0
        internal override Object look(DspState vd, InfoMode mi, Object i)
        {
            float scale;
            Info vi = vd.vi;
            InfoFloor0 info = (InfoFloor0)i;
            LookFloor0 look = new LookFloor0();
            look.m = info.order;
            look.n = vi.blocksizes[mi.blockflag] / 2;
            look.ln = info.barkmap;
            look.vi = info;
            look.lpclook.init(look.ln, look.m);

            // we choose a scaling constant so that:
            scale = look.ln / toBARK((float)(info.rate / 2.0f));

            // the mapping from a linear scale to a smaller bark scale is
            // straightforward.  We do *not* make sure that the linear mapping
            // does not skip bark-scale bins; the decoder simply skips them and
            // the encoder may do what it wishes in filling them.  They're
            // necessary in some mapping combinations to keep the scale spacing
            // accurate
            look.linearmap = new int[look.n];
            for (int j = 0; j < look.n; j++)
            {
                int val = (int)Math.Floor(toBARK((float)((info.rate / 2.0f) / look.n * j)) * scale); // bark numbers represent band edges
                if (val >= look.ln)
                    val = look.ln; // guard against the approximation
                look.linearmap[j] = val;
            }
            return look;
        }
Beispiel #7
0
        internal int inverse(Block vb, Object i, float[] Out)
        {
            //System.err.println("Floor0.inverse "+i.getClass()+"]");
            LookFloor0 look   = (LookFloor0)i;
            InfoFloor0 info   = look.vi;
            int        ampraw = vb.opb.Read(info.ampbits);

            if (ampraw > 0)
            {             // also handles the -1 out of data case
                int   maxval  = (1 << info.ampbits) - 1;
                float amp     = (float)ampraw / maxval * info.ampdB;
                int   booknum = vb.opb.Read(Util.ilog(info.numbooks));

                if (booknum != -1 && booknum < info.numbooks)
                {
                    lock (this)
                    {
                        if (lsp == null || lsp.Length < look.m)
                        {
                            lsp = new float[look.m];
                        }
                        else
                        {
                            for (int j = 0; j < look.m; j++)
                            {
                                lsp[j] = 0.0f;
                            }
                        }

                        CodeBook b    = vb.vd.fullbooks[info.books[booknum]];
                        float    last = 0.0f;

                        for (int j = 0; j < look.m; j++)
                        {
                            Out[j] = 0.0f;
                        }

                        for (int j = 0; j < look.m; j += b.dim)
                        {
                            if (b.decodevs(lsp, j, vb.opb, 1, -1) == -1)
                            {
                                for (int k = 0; k < look.n; k++)
                                {
                                    Out[k] = 0.0f;
                                }
                                return(0);
                            }
                        }
                        for (int j = 0; j < look.m;)
                        {
                            for (int k = 0; k < b.dim; k++, j++)
                            {
                                lsp[j] += last;
                            }
                            last = lsp[j - 1];
                        }
                        // take the coefficients back to a spectral envelope curve
                        Lsp.lsp_to_curve(Out, look.linearmap, look.n, look.ln, lsp, look.m,
                                         amp, info.ampdB);

                        return(1);
                    }
                }
            }
            return(0);
        }