Fix crashes with VBR for short duration frames and very low bitrates. This may, howev...
[opus.git] / tests / laplace-test.c
index 69ab4f2..417f4e1 100644 (file)
@@ -5,23 +5,43 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include "laplace.h"
+#define CELT_C 
+#include "../libcelt/stack_alloc.h"
 
-int main()
+#include "../libcelt/rangeenc.c"
+#include "../libcelt/rangedec.c"
+#include "../libcelt/entenc.c"
+#include "../libcelt/entdec.c"
+#include "../libcelt/entcode.c"
+#include "../libcelt/laplace.c"
+
+#define DATA_SIZE 40000
+
+int main(void)
 {
    int i;
+   int ret = 0;
    ec_enc enc;
    ec_dec dec;
    ec_byte_buffer buf;
+   unsigned char *ptr;
    int val[10000], decay[10000];
-   ec_byte_writeinit(&buf);
+   ALLOC_STACK;
+   ptr = malloc(DATA_SIZE);
+   ec_byte_writeinit_buffer(&buf, ptr, DATA_SIZE);
+   //ec_byte_writeinit(&buf);
    ec_enc_init(&enc,&buf);
    
-   for (i=0;i<10000;i++)
+   val[0] = 3; decay[0] = 6000;
+   val[1] = 0; decay[1] = 5800;
+   val[2] = -1; decay[2] = 5600;
+   for (i=3;i<10000;i++)
    {
       val[i] = rand()%15-7;
       decay[i] = rand()%11000+5000;
-      ec_laplace_encode(&enc, val[i], decay[i]);      
    }
+   for (i=0;i<10000;i++)
+      ec_laplace_encode(&enc, &val[i], decay[i]);      
       
    ec_enc_done(&enc);
 
@@ -32,9 +52,11 @@ int main()
    {
       int d = ec_laplace_decode(&dec, decay[i]);
       if (d != val[i])
+      {
          fprintf (stderr, "Got %d instead of %d\n", d, val[i]);
+         ret = 1;
+      }
    }
    
-   ec_byte_writeclear(&buf);
-   return 0;
+   return ret;
 }