/*
   file rr_testbench.c
   (C) 2003 Yann GUIDON <whygee@f-cpu.org>
   version Sat Dec 27 07:10:47 CET 2003

   Testbench for the Range Reduction encoder/decoder

   compile with
     gcc -o rr rr_testbench.c
   or
     gcc -DPHASING -o rr rr_testbench.c
*/

#include <stdio.h>  /* for printf */

#ifndef PHASING
#include "rr_simple.c"
#else
#include "rr_phasing-in.c"
#endif

/* these data shall not be larger than 24 bits */
unsigned int S[16]={ 0xFFFFFF, 0xFFFFFF, 0xFFFFFF,
         0x30, 0x20, 3, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0};
unsigned int T[16];
unsigned char bitstream[1000];

int main() {

  /******** Encoding ********/

  /* initialize the output stream */
  stream = &bitstream[0];
  stream_length = 0;
  shift_count = 0;
  reservoir = 0;

  encode_RR(16, &S[0]);
  encode_RR( 5, &S[10]);
  encode_RR( 1, &S[8]);
  encode_RR(10, &S[0]);

  printf("\nResult : %d bits\n\n",
      shift_count + (stream_length << 3));  

  /* flush the reservoir */
  if (shift_count > 0)
    stream[stream_length++] = reservoir;

  /******** Decoding ********/

  /* seek to the start */
  stream_length = 0;
  shift_count = 0;
  reservoir = 0;

  decode_RR(16, T);
  decode_RR( 5, T);
  decode_RR( 1, T);
  decode_RR(10, T);

  return 0;
}

