Commit 9caa3346 authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Testcase for laplace encoder

parent 9a0bba18
......@@ -70,36 +70,3 @@ void ec_bitree_halve(unsigned *_this,int _sz,int _split){
}
#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
......@@ -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 @@ int ec_laplace_decode(ec_dec *dec, int decay)
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
......@@ -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);
......
......@@ -284,45 +284,3 @@ int compute_allocation(const CELTMode *m, int *offsets, int total, int *pulses)
}
}
#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
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 @@ cwrs32_test_SOURCES = cwrs32-test.c
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
#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;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment