예제 #1
0
    update_model(AcModel acm, int sym)
    {
        int i;

        if (acm.getCFreq(0) == Max_frequency)
        {
            int cum = 0;

            acm.setCFreq(acm.getNSym(), 0);
            for (i = acm.getNSym() - 1; i >= 0; i--)
            {
                acm.setFreq(i, (acm.getFreq(i) + 1) / 2);
                cum += acm.getFreq(i);
                acm.setCFreq(i, cum);
            }
        }

        acm.setFreq(sym, acm.getFreq(sym) + 1);
        for (i = sym; i >= 0; i--)
        {
            acm.setCFreq(i, acm.getCFreq(i) + 1);
        }

        return;
    }
예제 #2
0
    encode_symbol(AcModel acm, int sym)
    {
        int range;

        range = (high - low) + 1;
        high  = low + (range * acm.getCFreq(sym)) / acm.getCFreq(0) - 1;
        low   = low + (range * acm.getCFreq(sym + 1)) / acm.getCFreq(0);

        for (;;)
        {
            if (high < Half)
            {
                bit_plus_follow(0);
            }
            else if (low >= Half)
            {
                bit_plus_follow(1);
                low  -= Half;
                high -= Half;
            }
            else if (low >= First_qtr && high < Third_qtr)
            {
                fbits += 1;
                low   -= First_qtr;
                high  -= First_qtr;
            }
            else
            {
                break;
            }
            low  = 2 * low;
            high = 2 * high + 1;
        }

        if (acm.getAdapt() == 1)
        {
            update_model(acm, sym);
        }

        return;
    }