Exemplo n.º 1
0
        public sealed override void Quant(float[] lsp, float[] qlsp, int order, Bits bits)
        {
            float[] array = new float[20];
            for (int i = 0; i < order; i++)
            {
                qlsp[i] = lsp[i];
            }
            array[0]         = 1f / (qlsp[1] - qlsp[0]);
            array[order - 1] = 1f / (qlsp[order - 1] - qlsp[order - 2]);
            for (int i = 1; i < order - 1; i++)
            {
                float num  = 1f / ((0.15f + qlsp[i] - qlsp[i - 1]) * (0.15f + qlsp[i] - qlsp[i - 1]));
                float num2 = 1f / ((0.15f + qlsp[i + 1] - qlsp[i]) * (0.15f + qlsp[i + 1] - qlsp[i]));
                array[i] = ((num <= num2) ? num2 : num);
            }
            for (int i = 0; i < order; i++)
            {
                qlsp[i] -= new float?((float)(0.25 * (double)i + 0.25)).Value;
            }
            for (int i = 0; i < order; i++)
            {
                qlsp[i] *= 256f;
            }
            int data = LspQuant.Lsp_quant(qlsp, 0, Codebook_Constants.cdbk_nb, 64, order);

            bits.Pack(data, 6);
            for (int i = 0; i < order; i++)
            {
                qlsp[i] *= 2f;
            }
            data = LspQuant.Lsp_weight_quant(qlsp, 0, array, 0, Codebook_Constants.cdbk_nb_low1, 64, 5);
            bits.Pack(data, 6);
            for (int i = 0; i < 5; i++)
            {
                qlsp[i] *= 2f;
            }
            data = LspQuant.Lsp_weight_quant(qlsp, 0, array, 0, Codebook_Constants.cdbk_nb_low2, 64, 5);
            bits.Pack(data, 6);
            data = LspQuant.Lsp_weight_quant(qlsp, 5, array, 5, Codebook_Constants.cdbk_nb_high1, 64, 5);
            bits.Pack(data, 6);
            for (int i = 5; i < 10; i++)
            {
                qlsp[i] *= 2f;
            }
            data = LspQuant.Lsp_weight_quant(qlsp, 5, array, 5, Codebook_Constants.cdbk_nb_high2, 64, 5);
            bits.Pack(data, 6);
            for (int i = 0; i < order; i++)
            {
                qlsp[i] *= new float?((float)0.00097656).Value;
            }
            for (int i = 0; i < order; i++)
            {
                qlsp[i] = lsp[i] - qlsp[i];
            }
        }
Exemplo n.º 2
0
        public sealed override void Quant(float[] lsp, float[] qlsp, int order, Bits bits)
        {
            float[] array = new float[20];
            for (int i = 0; i < order; i++)
            {
                qlsp[i] = lsp[i];
            }
            array[0]         = 1f / (qlsp[1] - qlsp[0]);
            array[order - 1] = 1f / (qlsp[order - 1] - qlsp[order - 2]);
            for (int i = 1; i < order - 1; i++)
            {
                array[i] = Math.Max(1f / (qlsp[i] - qlsp[i - 1]), 1f / (qlsp[i + 1] - qlsp[i]));
            }
            for (int i = 0; i < order; i++)
            {
                qlsp[i] -= 0.3125f * (float)i + 0.75f;
            }
            for (int i = 0; i < order; i++)
            {
                qlsp[i] *= 256f;
            }
            int data = LspQuant.Lsp_quant(qlsp, 0, Codebook_Constants.high_lsp_cdbk, 64, order);

            bits.Pack(data, 6);
            for (int i = 0; i < order; i++)
            {
                qlsp[i] *= 2f;
            }
            data = LspQuant.Lsp_weight_quant(qlsp, 0, array, 0, Codebook_Constants.high_lsp_cdbk2, 64, order);
            bits.Pack(data, 6);
            for (int i = 0; i < order; i++)
            {
                qlsp[i] *= 0.0019531f;
            }
            for (int i = 0; i < order; i++)
            {
                qlsp[i] = lsp[i] - qlsp[i];
            }
        }