ref: 9caa3346c4693604a53e96f4b737096d6414f677
parent: 9a0bba183ce20157ec4e421ef74c6f2605082df4
author: Jean-Marc Valin <[email protected]>
date: Wed Feb 20 10:00:26 EST 2008
Testcase for laplace encoder
--- a/libcelt/bitree.c
+++ b/libcelt/bitree.c
@@ -70,36 +70,3 @@
}
#endif
-#if 0
-#include <stdio.h>
-/*Simple regression test code.
- Compile with bitrenc.c and bitrdec.c as well.*/
-
-static void ec_bitree_print(unsigned *_this,int _sz){
- int i;
- for(i=0;i<_sz;i++)printf("%3i%c",_this[i],i+1<_sz?' ':'\n');
-}
-
-int main(void){
- unsigned t[16]={0,8,4,9,2,10,5,11,1,12,6,13,3,14,7,15};
- int fl;
- int s;
- int i;
- ec_bitree_print(t,16);
- ec_bitree_from_counts(t,16);
- ec_bitree_print(t,16);
- for(i=0;i<=16;i++)printf("%3i%c",ec_bitree_get_cumul(t,i),i<16?' ':'\n');
- for(i=0;i<t[15];i++){
- s=ec_bitree_find_and_update(t,16,16,i,&fl,0);
- printf("%3i: %i %3i\n",i,s,fl);
- }
- for(i=0;i<16;i++){
- s=ec_bitree_find_and_update(t,16,ec_bitree_get_cumul(t,i),&fl,100);
- ec_bitree_to_counts(t,16,16);
- ec_bitree_print(t,16);
- ec_bitree_from_counts(t,16);
- ec_bitree_update(t,16,s,-100);
- }
- return 0;
-}
-#endif
--- a/libcelt/laplace.c
+++ b/libcelt/laplace.c
@@ -33,8 +33,7 @@
#include "config.h"
#endif
-#include "entenc.h"
-#include "entdec.h"
+#include "laplace.h"
static int ec_laplace_get_total(int decay)
{
@@ -110,43 +109,4 @@
return val;
}
-#if 0
-#include <stdio.h>
-int main()
-{
- int val;
- ec_enc enc;
- ec_dec dec;
- ec_byte_buffer buf;
-
- ec_byte_writeinit(&buf);
- ec_enc_init(&enc,&buf);
-
- ec_laplace_encode(&enc, 9, 10000);
- ec_laplace_encode(&enc, -5, 12000);
- ec_laplace_encode(&enc, -2, 9000);
- ec_laplace_encode(&enc, 20, 15000);
- ec_laplace_encode(&enc, 2, 900);
-
- ec_enc_done(&enc);
-
- ec_byte_readinit(&buf,ec_byte_get_buffer(&buf),ec_byte_bytes(&buf));
- ec_dec_init(&dec,&buf);
-
- val = ec_laplace_decode(&dec, 10000);
- printf ("dec: %d\n", val);
- val = ec_laplace_decode(&dec, 12000);
- printf ("dec: %d\n", val);
- val = ec_laplace_decode(&dec, 9000);
- printf ("dec: %d\n", val);
- val = ec_laplace_decode(&dec, 15000);
- printf ("dec: %d\n", val);
- val = ec_laplace_decode(&dec, 900);
- printf ("dec: %d\n", val);
-
-
- ec_byte_writeclear(&buf);
- return 0;
-}
-#endif
--- a/libcelt/laplace.h
+++ b/libcelt/laplace.h
@@ -29,6 +29,8 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "entenc.h"
+#include "entdec.h"
void ec_laplace_encode(ec_enc *enc, int value, int decay);
--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -284,45 +284,3 @@
}
}
-#if 0
-int main()
-{
- int i;
- printf ("log(128) = %d\n", EC_ILOG(128));
- for(i=1;i<2000000000;i+=1738)
- {
- printf ("%d %d\n", i, log2_frac(i, 10));
- }
- return 0;
-}
-#endif
-#if 0
-int main()
-{
- int i;
- int offsets[18] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- int bits[18] = {10, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 10, 8, 9, 10, 11, 6, 7};
- int bits1[18] = {8, 7, 7, 6, 6, 6, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5};
- int bits2[18] = {15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15};
- int bank[20] = {0, 4, 8, 12, 16, 20, 24, 28, 32, 38, 44, 52, 62, 74, 90,112,142,182, 232,256};
- int pulses[18];
- struct alloc_data alloc;
-
- alloc_init(&alloc, celt_mode0);
- int b;
- //b = vec_bits2pulses(&alloc, bank, bits, pulses, 18);
- //printf ("total: %d bits\n", b);
- //for (i=0;i<18;i++)
- // printf ("%d ", pulses[i]);
- //printf ("\n");
- //b = interp_bits2pulses(&alloc, bits1, bits2, 162, pulses, 18);
- b = compute_allocation(&alloc, offsets, 190, pulses);
- printf ("total: %d bits\n", b);
- for (i=0;i<18;i++)
- printf ("%d ", pulses[i]);
- printf ("\n");
-
- alloc_clear(&alloc);
- return 0;
-}
-#endif
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,9 +1,9 @@
INCLUDES = -I$(top_srcdir)/libcelt
METASOURCES = AUTO
-TESTS = type-test ectest cwrs32-test cwrs64-test real-fft-test dft-test
+TESTS = type-test ectest cwrs32-test cwrs64-test real-fft-test dft-test laplace-test
-noinst_PROGRAMS = type-test ectest cwrs32-test cwrs64-test real-fft-test dft-test
+noinst_PROGRAMS = type-test ectest cwrs32-test cwrs64-test real-fft-test dft-test laplace-test
type_test_SOURCES = type-test.c
ectest_SOURCES = ectest.c
@@ -11,5 +11,6 @@
cwrs64_test_SOURCES = cwrs64-test.c
real_fft_test_SOURCES = real-fft-test.c
dft_test_SOURCES = dft-test.c
+laplace_test_SOURCES = laplace-test.c
LDADD = $(top_builddir)/libcelt/libcelt.la
--- /dev/null
+++ b/tests/laplace-test.c
@@ -1,0 +1,40 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "laplace.h"
+
+int main()
+{
+ int i;
+ ec_enc enc;
+ ec_dec dec;
+ ec_byte_buffer buf;
+ int val[10000], decay[10000];
+ ec_byte_writeinit(&buf);
+ ec_enc_init(&enc,&buf);
+
+ for (i=0;i<10000;i++)
+ {
+ val[i] = rand()%15-7;
+ decay[i] = rand()%11000+5000;
+ ec_laplace_encode(&enc, val[i], decay[i]);
+ }
+
+ ec_enc_done(&enc);
+
+ ec_byte_readinit(&buf,ec_byte_get_buffer(&buf),ec_byte_bytes(&buf));
+ ec_dec_init(&dec,&buf);
+
+ for (i=0;i<10000;i++)
+ {
+ int d = ec_laplace_decode(&dec, decay[i]);
+ if (d != val[i])
+ fprintf (stderr, "Got %d instead of %d\n", d, val[i]);
+ }
+
+ ec_byte_writeclear(&buf);
+ return 0;
+}