ref: e38c7c18f77ba03e4f3c18c6de5cc4cbb17dcdf3
parent: 8143be30263bfa23276e4a7e9c5b2428b455174e
author: Jean-Marc Valin <[email protected]>
date: Fri Dec 7 12:10:14 EST 2007
Energy is now Laplace-encoded (very poorly for now)
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -397,11 +397,11 @@
ec_byte_readinit(&buf,data,len);
ec_dec_init(&dec,&buf);
- /* Get band energies */
- unquant_energy(st->mode, bandE, st->oldBandE, &dec);
-
/* Get the pitch index */
pitch_index = ec_dec_uint(&dec, MAX_PERIOD-(B+1)*N);;
+
+ /* Get band energies */
+ unquant_energy(st->mode, bandE, st->oldBandE, &dec);
/* Pitch MDCT */
compute_mdcts(&st->mdct_lookup, st->window, st->out_mem+pitch_index, P, N, B);
--- a/libcelt/quant_bands.c
+++ b/libcelt/quant_bands.c
@@ -31,10 +31,9 @@
#include "quant_bands.h"
+#include "laplace.h"
#include <math.h>
-int dummy_qi[100];
-
void quant_energy(CELTMode *m, float *eBands, float *oldEBands, ec_enc *enc)
{
int i;
@@ -51,11 +50,14 @@
res = .25f*(i+3.f);
//res = 1;
qi = (int)floor(.5+(x-pred-prev)/res);
- dummy_qi[i] = qi;
+ /*if (qi > 40)
+ qi = 40;
+ if (qi < -40)
+ qi = -40;*/
+ ec_laplace_encode(enc, qi, 15000);
q = qi*res;
//printf("%f %f ", pred+prev+q, x);
- //printf("%d ", qi);
//printf("%f ", x-pred-prev);
oldEBands[i] = pred+prev+q;
@@ -79,9 +81,8 @@
float pred = .7*oldEBands[i];
res = .25f*(i+3.f);
- qi = dummy_qi[i];
+ qi = ec_laplace_decode(dec, 15000);
q = qi*res;
-
//printf("%f %f ", pred+prev+q, x);
//printf("%d ", qi);
//printf("%f ", x-pred-prev);
@@ -92,4 +93,5 @@
eBands[i] = 0;
prev = (prev + .5*q);
}
+ //printf ("\n");
}
--- a/libentcode/Makefile.am
+++ b/libentcode/Makefile.am
@@ -7,4 +7,4 @@
ectest_SOURCES = ectest.c
ectest_LDADD = $(top_builddir)/libentcode/libentcode.la
noinst_HEADERS = bitrdec.h bitree.h bitrenc.h ecintrin.h entcode.h entdec.h \
- entenc.h mfrngcod.h probdec.h probenc.h probmod.h
+ entenc.h laplace.h mfrngcod.h probdec.h probenc.h probmod.h
--- a/libentcode/laplace.c
+++ b/libentcode/laplace.c
@@ -33,7 +33,7 @@
#include "entdec.h"
#include <stdio.h>
-int ec_laplace_get_total(int decay)
+static int ec_laplace_get_total(int decay)
{
return (1<<30)/((1<<14) - decay) - (1<<15) + 1;
}
@@ -52,8 +52,17 @@
fs = 1<<15;
for (i=0;i<value;i++)
{
+ int tmp_l, tmp_s;
+ tmp_l = fl;
+ tmp_s = fs;
fl += fs*2;
fs = (fs*decay)>>14;
+ if (fs == 0)
+ {
+ fs = tmp_s;
+ fl = tmp_l;
+ break;
+ }
}
if (fl < 0)
fl = 0;