/*
 * Copyright (c) 1997-2005 Alexandros Eleftheriadis and Danny Hong.
 * 
 * This file is part of Flavor, developed at Columbia University
 * (www.ee.columbia.edu/flavor).
 *
 * Flavor is free software; you can redistribute it and/or modify
 * it under the terms of the Flavor Artistic License as described in
 * the file COPYING.txt. 
 *
 */

/*
 * Authors:
 * Danny Hong <danny@ee.columbia.edu>
 *
 */


/* 
 * The binary arithmetic coder described in 
 * @ARTICLE{
 * AUTHOR  = {Pennebaker, W. B. and et al.},
 * TITLE   = {An Overview of the Basic Principles of the Q-Coder Adaptive Binary Arithmetic Coder},
 * JOURNAL = {IBM J. Res. Develop.},
 * VOLUME  = {32},
 * PAGES   = {717--726},
 * YEAR    = {1988},
 *
 */


const int rTblQ[30]    = {0x0AC1,0x0A81,0x0A01,0x0901,0x0701,0x0681,0x0601,0x0501,0x0481,0x0441,
                          0x0381,0x0301,0x02C1,0x0281,0x0241,0x0181,0x0121,0x00E1,0x00A1,0x0071,
                          0x0059,0x0053,0x0027,0x0017,0x0013,0x000B,0x0007,0x0005,0x0003,0x0001};
const int iTblQ[30][2] = { {0,1},   {0,2},   {1,3},   {2,4},   {3,5},   {4,6},   {5,7},   {5,8},   {6,9},  {7,10},
                          {8,11},  {9,12}, {10,13}, {11,14}, {12,15}, {13,16}, {14,17}, {15,18}, {16,19}, {17,20},
                         {18,21}, {19,22}, {20,23}, {21,24}, {21,25}, {23,26}, {23,27}, {25,28}, {25,28}, {27,29} };

bac QCoder { 
    "prec",     12,             // 12-bit precision
    "ooc",      2,              // No multiplicative operation --> fast BAC
    "soc",      1,              // MPS over LPS
    "norm",     0x1000,         // Renormalize whenever R < 0x1000 
    "bs",       {8,1,4},        // Stuff one 0 bit after eight 1 bits; use 4 spacer bits
    "init",     0x1000,         // Init: R=0x1000 
    "rtable",   {30,1,"rTblQ"}, // The rTbl table contains possible R values for the LPS 
    "nexti",    "iTblQ",        // The iTbl table contains probability transition rules
    "trans",    1               // Apply transition after renormalization
}