/* CODE.H - DECLARATIONS USED FOR ARITHMETIC ENCODING AND DECODING */

/* The constants defining precisions, and the associated types, may be
   modified to fit the capabilities of the implementation, subject to
   the restriction that Code_bits-Freq_bits be at least two (preferably
   more, for efficient coding). */


/* PRECISION OF CODING VALUES. Coding values are fixed-point binary 
   fractions in the range [0,1), represented as integers scaled by 
   2^Code_bits.  A large value for code_bits will permit larger counts,
   and will also result in more efficient coding. */

#define Code_bits 32			/* Number of bits for code values   */

typedef unsigned code_value;		/* Data type holding code values    */


/* PRECISION OF SYMBOL PROBABILITIES. Symbol probabilities are unnormalized
   counts no greater than Freq_full.  Counts that become larger than this
   are scaled down to satisfy this restriction. */

#define Freq_bits 22			/* Number of bits for frequencies   */
#define Freq_full (1<<Freq_bits)	/* Largest frequency value          */

typedef unsigned freq_value;		/* Data type holding frequencies    */


/* PRECISION OF DIVISION. Division of a code value by a frequency value 
   gives a result of precision (Code_bits-Freq_bits), which must be at
   least two for correct operation (larger differences give smaller code
   size). */

typedef unsigned div_value;		/* Data type for result of division */


/* PROCEDURES. */

void start_encoding (void);
void start_decoding (void);
void encode_symbol  (int, freq_value []);
void encode_bit     (int, freq_value, freq_value);
int  decode_symbol  (freq_value []);
int  decode_bit     (freq_value, freq_value);
void done_encoding  (void);

void start_outputing_bits (void);
void start_inputing_bits (void);
void output_bit (int);
int  input_bit (void);
void done_outputing_bits (void);
