Beispiel #1
0
int test4 (void)
{
  SchroBuffer *buffer = schro_buffer_new_and_alloc (100);
  SchroPack *pack;
  SchroUnpack unpack;
  int i;
  int16_t x;
  int ok = 1;


  for(i=-1000;i<1000;i++){
    pack = schro_pack_new ();
    schro_pack_encode_init (pack, buffer);
    schro_pack_encode_sint (pack, i);
    schro_pack_flush(pack);
    schro_pack_free (pack);

    schro_unpack_init_with_data (&unpack, buffer->data, buffer->length, 1);
    schro_unpack_decode_sint_s16 (&x, &unpack, 1);

    if (i != x) {
      printf("%d %d %c\n", i, x, (i==x)?' ':'x');
      ok = 0;
    }
  }

  schro_buffer_unref (buffer);

  return ok;
}
Beispiel #2
0
int
check (int n, int freq)
{
  SchroBuffer *buffer;
  OilProfile prof;
  double ave, std;
  int x;
  int y;

  buffer = schro_buffer_new_and_alloc (100000);

  encode(buffer, n, freq);

  print_speed();

  x = decode(buffer, n, &prof, 0);
  oil_profile_get_ave_std (&prof, &ave, &std);
  printf("orig %d,%d: %g (%g) %d\n", n, freq, ave, std, x);

  x = decode(buffer, n, &prof, 1);
  oil_profile_get_ave_std (&prof, &ave, &std);
  printf("ref  %d,%d: %g (%g) %d\n", n, freq, ave, std, x);

  y = decode(buffer, n, &prof, 2);
  oil_profile_get_ave_std (&prof, &ave, &std);
  printf("test %d,%d: %g (%g) %d\n", n, freq, ave, std, y);
  if (x != y) {
    printf("BROKEN\n");
  }

  schro_buffer_unref (buffer);

  return 0;
}
Beispiel #3
0
int
main (int argc, char *argv[])
{
    int i;
    SchroBuffer *buffer = schro_buffer_new_and_alloc (300);
    SchroBits *bits;
    int value;
    int fail = 0;
    int n;

    schro_init();

    srand(time(NULL));

    bits = schro_bits_new();

    printf("unsigned int\n");
    schro_bits_encode_init (bits, buffer);
    for(i=0; i<N; i++) {
        ref[i] = rand() & 0x7;
        schro_bits_encode_uint(bits,ref[i]);
    }
    schro_bits_flush (bits);
    n = schro_bits_get_offset (bits);
    schro_bits_free (bits);

    bits = schro_bits_new();
    schro_bits_decode_init (bits, buffer);
    for(i=0; i<N; i++) {
        value = schro_bits_decode_uint (bits);
        if (value != ref[i]) {
            printf("decode failed (%d != %d) at offset %d\n", value, ref[i], i);
            fail = 1;
        }
    }

    printf("signed int\n");
    schro_bits_encode_init (bits, buffer);
    for(i=0; i<N; i++) {
        ref[i] = (rand() & 0xf) - 8;
        schro_bits_encode_sint (bits,ref[i]);
    }
    schro_bits_flush (bits);
    n = schro_bits_get_offset (bits);
    schro_bits_free (bits);

    bits = schro_bits_new();
    schro_bits_decode_init (bits, buffer);
    for(i=0; i<N; i++) {
        value = schro_bits_decode_sint (bits);
        if (value != ref[i]) {
            printf("decode failed (%d != %d) at offset %d\n", value, ref[i], i);
            fail = 1;
        }
    }

    return fail;
}
Beispiel #4
0
int
main (int argc, char *argv[])
{
  int i;
  SchroBuffer *buffer = schro_buffer_new_and_alloc (100);
  SchroBits *bits;
  int value;
  int fail = 0;
  int n;

  schro_init();

  printf("unsigned int\n");
  for(i=0;i<21;i++) {
    bits = schro_bits_new();
    schro_bits_encode_init (bits, buffer);
    schro_bits_encode_uint(bits,i);
    schro_bits_flush (bits);
    n = schro_bits_get_offset (bits);
    schro_bits_free (bits);

    bits = schro_bits_new();
    schro_bits_decode_init (bits, buffer);
    printf("%3d:", i);
    dump_bits (bits, n);
    value = schro_bits_decode_uint (bits);
    if (value != i) {
      printf("decode failed (%d != %d)\n", value, i);
      fail = 1;
    }
    schro_bits_free (bits);
  }
  printf("\n");

  printf("signed int\n");
  for(i=-5;i<6;i++) {
    bits = schro_bits_new();
    schro_bits_encode_init (bits, buffer);
    schro_bits_encode_sint(bits,i);
    schro_bits_flush (bits);
    n = schro_bits_get_offset (bits);
    schro_bits_free (bits);

    bits = schro_bits_new();
    schro_bits_decode_init (bits, buffer);
    printf("%3d:", i);
    dump_bits (bits, n);
    value = schro_bits_decode_sint (bits);
    if (value != i) {
      printf("decode failed (%d != %d)\n", value, i);
      fail = 1;
    }
    schro_bits_free (bits);
  }
  printf("\n");

  return fail;
}
Beispiel #5
0
int test1 (void)
{
  SchroBuffer *buffer = schro_buffer_new_and_alloc (100);
  SchroPack *pack;
  SchroUnpack unpack;
  int i;
  int ref[800];
  int x;
  int guard;

  for(i=0;i<800;i++){
    ref[i] = rand()&1;
  }
  guard = rand()&1;

  pack = schro_pack_new ();
  schro_pack_encode_init (pack, buffer);
  for(i=0;i<800;i++){
    schro_pack_encode_bit (pack, ref[i]);
  }
  schro_pack_flush(pack);
  schro_pack_free (pack);


  schro_unpack_init_with_data (&unpack, buffer->data, buffer->length, guard);

  for(i=0;i<800;i++){
    x = schro_unpack_decode_bit (&unpack);
    if (x != ref[i]) {
      printf("test1 failed at bit %d\n", i);
      schro_unpack_dump(&unpack);
      return 0;
    }
  }
  for(i=0;i<100;i++){
    x = schro_unpack_decode_bit (&unpack);
    if (x != guard) {
      printf("test1 failed at guard bit %d\n", i);
      schro_unpack_dump(&unpack);
      return 0;
    }
  }

  schro_buffer_unref (buffer);

  return 1;
}
Beispiel #6
0
int test2 (void)
{
  SchroBuffer *buffer = schro_buffer_new_and_alloc (1000);
  SchroPack *pack;
  SchroUnpack unpack;
  int i;
  int ref[100];
  int x;
  int n_bytes;

  memset (buffer->data, 0, 1000);
  for(i=0;i<100;i++){
    ref[i] = rand()&0xff;
  }

  pack = schro_pack_new ();
  schro_pack_encode_init (pack, buffer);
  for(i=0;i<100;i++){
    schro_pack_encode_uint (pack, ref[i]);
  }
  schro_pack_flush(pack);
  n_bytes = schro_pack_get_offset (pack);
  schro_pack_free (pack);


  schro_unpack_init_with_data (&unpack, buffer->data, n_bytes, 1);

  for(i=0;i<100;i++){
    x = schro_unpack_decode_uint (&unpack);
    if (x != ref[i]) {
      printf("test2 failed at symbol %d (%d should be %d)\n", i, x, ref[i]);
      schro_unpack_dump(&unpack);
      return 0;
    }
  }

  schro_buffer_unref (buffer);

  return 1;
}
static SchroBuffer *schro_buffer_of_ogg_packet(ogg_packet *op)
{
    SchroBuffer *buffer = schro_buffer_new_and_alloc(op->bytes);
    memcpy(buffer->data, op->packet, op->bytes);
    return buffer;
}
Beispiel #8
0
int test3 (void)
{
  SchroBuffer *buffer = schro_buffer_new_and_alloc (1000);
  SchroPack *pack;
  SchroUnpack unpack;
  SchroUnpack unpack2;
  int i;
  int ref[100];
  int x;
  int n_bytes;
  int n_bits = 0;
  int n_bits2 = 0;

  memset (buffer->data, 0, 1000);
  for(i=0;i<100;i++){
    ref[i] = (rand()&0xff) - 128;
  }

  pack = schro_pack_new ();
  schro_pack_encode_init (pack, buffer);
  n_bits = 0;
  for(i=0;i<50;i++){
    schro_pack_encode_sint (pack, ref[i]);
    n_bits += schro_pack_estimate_sint (ref[i]);
  }
  n_bits2 = 0;
  for(i=50;i<100;i++){
    schro_pack_encode_sint (pack, ref[i]);
    n_bits2 += schro_pack_estimate_sint (ref[i]);
  }
  schro_pack_flush(pack);
  n_bytes = schro_pack_get_offset (pack);
  schro_pack_free (pack);


  schro_unpack_init_with_data (&unpack, buffer->data, n_bytes, 1);
  schro_unpack_copy (&unpack2, &unpack);

  schro_unpack_limit_bits_remaining (&unpack, n_bits);
  for(i=0;i<50;i++){
    x = schro_unpack_decode_sint (&unpack);
    if (x != ref[i]) {
      SCHRO_ERROR("test3 failed at symbol %d (%d should be %d)", i, x, ref[i]);
      schro_unpack_dump(&unpack);
      return 0;
    }
  }
  for(i=0;i<10;i++){
    x = schro_unpack_decode_sint (&unpack);
    if (x != 0) {
      SCHRO_ERROR("test3 failed at symbol %d (%d should be 0)", i, x);
      schro_unpack_dump(&unpack);
      return 0;
    }
  }

  schro_unpack_skip_bits (&unpack2, n_bits);
  schro_unpack_limit_bits_remaining (&unpack2, n_bits2);
  for(i=50;i<100;i++){
    x = schro_unpack_decode_sint (&unpack2);
    if (x != ref[i]) {
      SCHRO_ERROR("test3 failed at symbol %d (%d should be %d)", i, x, ref[i]);
      schro_unpack_dump(&unpack2);
      return 0;
    }
  }
  for(i=0;i<10;i++){
    x = schro_unpack_decode_sint (&unpack2);
    if (x != 0) {
      SCHRO_ERROR("test3 failed at symbol %d (%d should be 0)", i, x);
      schro_unpack_dump(&unpack2);
      return 0;
    }
  }

  schro_buffer_unref (buffer);

  return 1;
}