Arithmetic coding tutorial code  1
AC
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes | Static Protected Attributes
AC::Base Class Reference

#include <arith_code.hh>

Inheritance diagram for AC::Base:
Inheritance graph
[legend]

Public Member Functions

unsigned int number_input_bits ()
 number of bits inserted in the state More...
 
unsigned int number_input_symbols ()
 number of symbols inserted in the state More...
 
unsigned int number_output_bits ()
 number of bits extracted from the state More...
 
unsigned int number_output_symbols ()
 number of symbols extracted from the state More...
 
void print_state ()
 print the internal state More...
 
interval_t S_interval ()
 return the S_interval More...
 
interval_t B_interval ()
 return the B_interval More...
 
int output_bit ()
 outputs one bit from the state, if available, else -1 More...
 
void output_bits (output_callback_t out)
 outputs multiple bits, returns them using a callback (if not null; else they are lost) More...
 
void frequencies2cumulative_frequencies ()
 if the output callback is used in decoding, then the "cumulative_frequencies" and "max_symbol" must be used; "cumulative_frequencies" may be updated from "frequencies" using this call, that wraps freq2cum_freq() More...
 

Data Fields

const char * prefix
 name of the class, for printing More...
 
FILE * verbose_stream = stdout
 
F_tcumulative_frequencies = NULL
 if the output callback is used in decoding, then the "cumulative_frequencies" and "max_symbol" must be updated after each symbol is decoded, with the correct frequencies for the next symbol More...
 
I_t max_symbol = -1
 if the output callback is used in decoding, then the "cumulative_frequencies" and "max_symbol" must be updated after each symbol is decoded, with the correct frequencies for the next symbol More...
 
F_tfrequencies = NULL
 if the output callback is used in decoding, then the "cumulative_frequencies" and "max_symbol" must be used; these may be derived from a table of frequencies, that may be stored here More...
 
void * callback_data = NULL
 

Protected Member Functions

void doubleit ()
 
void doublehi ()
 
void doublelow ()
 
void doublecen ()
 
I_t separ_low_high (int symb, const F_t *cum_freq)
 divides Slow - Shigh in subintervals : returns the beginning of each interval; note that intervals are in reverse order wrt symbols, that is, symb=0 gives the rightmost subinterval, symb=max_symbols-1 is the leftmost More...
 
int resize_pull_one_bit ()
 returns 0 , 1 or -1 if no bit can be pulled at this moment ; resize S-interval and B-interval accordingly More...
 
I_t interval_right (int symb, const F_t *cum_freq)
 right extreme of a S-sub-interval ; note that symbols start from 0 here More...
 
I_t interval_left (int symb, const F_t *cum_freq)
 left extreme of a S-sub-interval More...
 
void push_symbol (int symb, const F_t *cum_freq)
 put symbol in S-interval by splitting it and choosing a subinterval, proportional to the frequencies More...
 
void push_bit (int bit)
 put bit in B-interval More...
 
 Base ()
 

Protected Attributes

unsigned int bitsToFollow
 
int virtual_bit
 
const I_t One = 1
 
const I_t Top = (One << AC_representation_bitsize)
 representation of 1 More...
 
const I_t Qtr = (One << (AC_representation_bitsize-2))
 representation of 1/4 More...
 
const I_t QtrMinus = (One << (AC_representation_bitsize-2)) - One
 representation of point preceding 1/4 More...
 
const I_t Half = (Qtr*2)
 Representation of 3/4. More...
 
const I_t ThreeQtr = (Qtr*3)
 representation of 3/4 More...
 
F_t const cum_freq_uniform8 [9] = { 8 , 7 , 6 , 5, 4 , 3 , 2 , 1 , 0 }
 cumulative tables of 8 equidistributed symbols More...
 
F_t const * cum_freq_flush = cum_freq_uniform8
 special cumulative table used for flushing More...
 
I_t Slow
 S-interval left extreme. More...
 
I_t Shigh
 S-interval right extreme (included in the interval) More...
 
long_I_t Srange
 S-interval width. More...
 
I_t Blow
 B-interval left extreme. More...
 
I_t Bhigh
 B-interval right extreme. More...
 
unsigned int significant_bits
 significant bits (used in the decoder) More...
 
unsigned int n_in_bits
 number of bits inserted in the state More...
 
unsigned int n_in_symbs
 number of symbols inserted in the state More...
 
unsigned int n_zooms
 number of zooms More...
 
unsigned int n_out_bits
 number of bits extracted from the state More...
 
unsigned int n_out_symbs
 number of symbols extracted from the state More...
 

Static Protected Attributes

static const int n_symbols_flush = 8
 how many symbols in the special cumulative table used for flushing More...
 

Detailed Description

! base class ; should not be used; contains the logic common to encoder and decoder

Constructor & Destructor Documentation

◆ Base()

AC::Base::Base ( )
protected

Member Function Documentation

◆ B_interval()

interval_t AC::Base::B_interval ( )

return the B_interval

◆ doublecen()

void AC::Base::doublecen ( )
protected

◆ doublehi()

void AC::Base::doublehi ( )
protected

◆ doubleit()

void AC::Base::doubleit ( )
protected

◆ doublelow()

void AC::Base::doublelow ( )
protected

◆ frequencies2cumulative_frequencies()

void AC::Base::frequencies2cumulative_frequencies ( )

if the output callback is used in decoding, then the "cumulative_frequencies" and "max_symbol" must be used; "cumulative_frequencies" may be updated from "frequencies" using this call, that wraps freq2cum_freq()

◆ interval_left()

I_t AC::Base::interval_left ( int  symb,
const F_t cum_freq 
)
protected

left extreme of a S-sub-interval

◆ interval_right()

I_t AC::Base::interval_right ( int  symb,
const F_t cum_freq 
)
protected

right extreme of a S-sub-interval ; note that symbols start from 0 here

◆ number_input_bits()

unsigned int AC::Base::number_input_bits ( )

number of bits inserted in the state

◆ number_input_symbols()

unsigned int AC::Base::number_input_symbols ( )

number of symbols inserted in the state

◆ number_output_bits()

unsigned int AC::Base::number_output_bits ( )

number of bits extracted from the state

◆ number_output_symbols()

unsigned int AC::Base::number_output_symbols ( )

number of symbols extracted from the state

◆ output_bit()

int AC::Base::output_bit ( )

outputs one bit from the state, if available, else -1

◆ output_bits()

void AC::Base::output_bits ( output_callback_t  out)

outputs multiple bits, returns them using a callback (if not null; else they are lost)

◆ print_state()

void AC::Base::print_state ( )

print the internal state

◆ push_bit()

void AC::Base::push_bit ( int  bit)
protected

put bit in B-interval

◆ push_symbol()

void AC::Base::push_symbol ( int  symb,
const F_t cum_freq 
)
protected

put symbol in S-interval by splitting it and choosing a subinterval, proportional to the frequencies

◆ resize_pull_one_bit()

int AC::Base::resize_pull_one_bit ( )
protected

returns 0 , 1 or -1 if no bit can be pulled at this moment ; resize S-interval and B-interval accordingly

◆ S_interval()

interval_t AC::Base::S_interval ( )

return the S_interval

◆ separ_low_high()

I_t AC::Base::separ_low_high ( int  symb,
const F_t cum_freq 
)
protected

divides Slow - Shigh in subintervals : returns the beginning of each interval; note that intervals are in reverse order wrt symbols, that is, symb=0 gives the rightmost subinterval, symb=max_symbols-1 is the leftmost

Field Documentation

◆ Bhigh

I_t AC::Base::Bhigh
protected

B-interval right extreme.

◆ bitsToFollow

unsigned int AC::Base::bitsToFollow
protected

◆ Blow

I_t AC::Base::Blow
protected

B-interval left extreme.

◆ callback_data

void* AC::Base::callback_data = NULL

a pointer to data that the callbacks receive as second argument (it is initialized with a pointer to the class)

◆ cum_freq_flush

F_t const* AC::Base::cum_freq_flush = cum_freq_uniform8
protected

special cumulative table used for flushing

◆ cum_freq_uniform8

F_t const AC::Base::cum_freq_uniform8[9] = { 8 , 7 , 6 , 5, 4 , 3 , 2 , 1 , 0 }
protected

cumulative tables of 8 equidistributed symbols

◆ cumulative_frequencies

F_t* AC::Base::cumulative_frequencies = NULL

if the output callback is used in decoding, then the "cumulative_frequencies" and "max_symbol" must be updated after each symbol is decoded, with the correct frequencies for the next symbol

◆ frequencies

F_t* AC::Base::frequencies = NULL

if the output callback is used in decoding, then the "cumulative_frequencies" and "max_symbol" must be used; these may be derived from a table of frequencies, that may be stored here

◆ Half

const I_t AC::Base::Half = (Qtr*2)
protected

Representation of 3/4.

◆ max_symbol

I_t AC::Base::max_symbol = -1

if the output callback is used in decoding, then the "cumulative_frequencies" and "max_symbol" must be updated after each symbol is decoded, with the correct frequencies for the next symbol

◆ n_in_bits

unsigned int AC::Base::n_in_bits
protected

number of bits inserted in the state

◆ n_in_symbs

unsigned int AC::Base::n_in_symbs
protected

number of symbols inserted in the state

◆ n_out_bits

unsigned int AC::Base::n_out_bits
protected

number of bits extracted from the state

◆ n_out_symbs

unsigned int AC::Base::n_out_symbs
protected

number of symbols extracted from the state

◆ n_symbols_flush

const int AC::Base::n_symbols_flush = 8
staticprotected

how many symbols in the special cumulative table used for flushing

◆ n_zooms

unsigned int AC::Base::n_zooms
protected

number of zooms

◆ One

const I_t AC::Base::One = 1
protected

◆ prefix

const char* AC::Base::prefix

name of the class, for printing

◆ Qtr

const I_t AC::Base::Qtr = (One << (AC_representation_bitsize-2))
protected

representation of 1/4

◆ QtrMinus

const I_t AC::Base::QtrMinus = (One << (AC_representation_bitsize-2)) - One
protected

representation of point preceding 1/4

◆ Shigh

I_t AC::Base::Shigh
protected

S-interval right extreme (included in the interval)

◆ significant_bits

unsigned int AC::Base::significant_bits
protected

significant bits (used in the decoder)

◆ Slow

I_t AC::Base::Slow
protected

S-interval left extreme.

◆ Srange

long_I_t AC::Base::Srange
protected

S-interval width.

◆ ThreeQtr

const I_t AC::Base::ThreeQtr = (Qtr*3)
protected

representation of 3/4

◆ Top

const I_t AC::Base::Top = (One << AC_representation_bitsize)
protected

representation of 1

◆ verbose_stream

FILE* AC::Base::verbose_stream = stdout

stream where verbose output will be printed (verbose output may be enabled by defining the AC_verbose macro)

◆ virtual_bit

int AC::Base::virtual_bit
protected

The documentation for this class was generated from the following files: