opus/tests/laplace-test.c
Timothy B. Terriberry ef2e650592 Add coarse energy entropy model tuning.
This tunes the entropy model for coarse energy introduced in commit
 c1c40a76.
It uses a constant set of parameters, tuned from about an hour and a
 half of randomly selected test data encoded for each frame size,
 prediction type (inter/intra), and band number.
These will be slightly sub-optimal for different frame sizes, but
 should be better than what we were using.

For inter, this saves an average of 2.8, 5.2, 7.1, and 6.7 bits/frame
 for frame sizes of 120, 240, 480, and 960, respectively.
For intra, this saves an average of 1.5, 3.0, 4.5, and 5.3 bits/frame
 (for the same frame sizes, respectively).
2010-11-09 17:54:41 +08:00

71 lines
1.5 KiB
C

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include "laplace.h"
#define CELT_C
#include "../libcelt/stack_alloc.h"
#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 ec_laplace_get_start_freq(int decay)
{
celt_uint32 ft = 32768 - LAPLACE_MINP*(2*LAPLACE_NMIN+1);
int fs = (ft*(16384-decay))/(16384+decay);
return fs+LAPLACE_MINP;
}
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];
ALLOC_STACK;
ptr = malloc(DATA_SIZE);
ec_byte_writeinit_buffer(&buf, ptr, DATA_SIZE);
//ec_byte_writeinit(&buf);
ec_enc_init(&enc,&buf);
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;
}
for (i=0;i<10000;i++)
ec_laplace_encode(&enc, &val[i],
ec_laplace_get_start_freq(decay[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,
ec_laplace_get_start_freq(decay[i]), decay[i]);
if (d != val[i])
{
fprintf (stderr, "Got %d instead of %d\n", d, val[i]);
ret = 1;
}
}
return ret;
}