shithub: opus

Download patch

ref: 5e9f7fc31db7336ce8c5946a4e3edaf4392af097
parent: 817220e91d67215ed3d21ef683f5b605fed12544
author: Gregory Maxwell <[email protected]>
date: Sun Aug 7 18:42:56 EDT 2011

Unit tests for bitexact_cos() and bitexact_log2tan().

--- a/libcelt/tests/mathops-test.c
+++ b/libcelt/tests/mathops-test.c
@@ -3,7 +3,12 @@
 #endif
 
 #include "mathops.c"
+#include "entenc.c"
+#include "entdec.c"
 #include "entcode.c"
+#include "bands.c"
+#include "vq.c"
+#include "cwrs.c"
 #include <stdio.h>
 #include <math.h>
 
@@ -57,6 +62,59 @@
    }
 }
 
+void testbitexactcos(void)
+{
+   int i;
+   opus_int32 min_d,max_d,last,chk;
+   chk=max_d=0;
+   last=min_d=32767;
+   for(i=0;i<16385;i++)
+   {
+      opus_int32 d;
+      opus_int32 q=bitexact_cos(i);
+      chk ^= q*i;
+      d = last - q;
+      if (d>max_d)max_d=d;
+      if (d<min_d)min_d=d;
+      last = q;
+   }
+   if ((chk!=91017006)||(max_d!=5)||(min_d!=0)||(bitexact_cos(0)!=32767)||
+       (bitexact_cos(16384)!=1)||(bitexact_cos(8192)!=23171))
+   {
+      fprintf (stderr, "bitexact_cos failed\n");
+      ret = 1;
+   }
+}
+
+void testbitexactlog2tan(void)
+{
+   int i,fail;
+   opus_int32 min_d,max_d,last,chk;
+   fail=chk=max_d=0;
+   last=min_d=30690;
+   for(i=0;i<8193;i++)
+   {
+      opus_int32 d;
+      opus_int32 mid=bitexact_cos(i);
+      opus_int32 side=bitexact_cos(16384-i);
+      opus_int32 q=bitexact_log2tan(mid,side);
+      chk ^= q*i;
+      d = last - q;
+      if (q!=-1*bitexact_log2tan(side,mid))
+        fail = 1;
+      if (d>max_d)max_d=d;
+      if (d<min_d)min_d=d;
+      last = q;
+   }
+   if ((chk!=16578548)||(max_d!=3219)||(min_d!=-2)||fail||
+       (bitexact_log2tan(32767,1)!=30690)||(bitexact_log2tan(30274,12540)!=2611)||
+       (bitexact_log2tan(23171,23171)!=0))
+   {
+      fprintf (stderr, "bitexact_log2tan failed\n");
+      ret = 1;
+   }
+}
+
 #ifndef FIXED_POINT
 void testlog2(void)
 {
@@ -160,6 +218,8 @@
 
 int main(void)
 {
+   testbitexactcos();
+   testbitexactlog2tan();
    testdiv();
    testsqrt();
    testlog2();