ref: 2875f6bf8d24dbce0e736d2c521791e218d13875
parent: a5431bfb090b3b3d31744265a86a1d8684c1e34d
author: Jean-Marc Valin <[email protected]>
date: Sat Jan 5 08:32:32 EST 2008
Now using 8 bands for the pitch gain, with a 128-entry codebook.
--- a/libcelt/Makefile.am
+++ b/libcelt/Makefile.am
@@ -17,7 +17,7 @@
libcelt_la_LDFLAGS = -version-info @CELT_LT_CURRENT@:@CELT_LT_REVISION@:@CELT_LT_AGE@
noinst_HEADERS = arch.h bands.h celt.h cwrs.h fftwrap.h mdct.h modes.h \
- os_support.h pitch.h psy.h quant_bands.h quant_pitch.h smallft.h vq.h
+ os_support.h pgain_table.h pitch.h psy.h quant_bands.h quant_pitch.h smallft.h vq.h
noinst_PROGRAMS = testcelt
testcelt_SOURCES = testcelt.c
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -170,13 +170,21 @@
//gain = Sxy/(2*(pbank[i+1]-pbank[i]));
//if (i<3)
//gain *= 1+.02*gain;
- if (gain > .90)
- gain = .90;
- if (gain < 0.0)
- gain = 0.0;
-
+ if (gain > 1.f)
+ gain = 1.f;
+ if (gain < 0.0f)
+ gain = 0.0f;
+ /* We need to be a bit conservative, otherwise residual doesn't quantise well */
+ gain *= .9f;
gains[i] = gain;
+ //printf ("%f ", 1-sqrt(1-gain*gain));
}
+ /*if(rand()%10==0)
+ {
+ for (i=0;i<m->nbPBands;i++)
+ printf ("%f ", 1-sqrt(1-gains[i]*gains[i]));
+ printf ("\n");
+ }*/
for (i=B*pBands[m->nbPBands];i<B*pBands[m->nbPBands+1];i++)
P[i] = 0;
}
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -32,12 +32,12 @@
#include "modes.h"
#define NBANDS 18
-#define PBANDS 5
+#define PBANDS 8
#define PITCH_END 37
#define NBANDS128 15
-#define PBANDS128 5
-#define PITCH_END128 36
+#define PBANDS128 8
+#define PITCH_END128 45
static const float means[15] = {
14.8621, 12.6918, 10.2978, 9.5862, 10.3784,
@@ -58,25 +58,28 @@
};
const int qbank0[NBANDS +2] = {0, 2, 4, 6, 8, 10, 12, 14, 16, 19, 22, 26, 31, 37, 45, 56, 71, 91, 116, 128};
-const int pbank0[PBANDS +2] = {0, 4, 8, 12, 19, PITCH_END, 128};
-const int qpulses0[NBANDS ] = {7, 5, 5, 4, 4, 3, 3, 2, 3, 2, 2, 2, 2, 0, 0, 0, 0, 0};
+const int pbank0[PBANDS +2] = {0, 2, 4, 6, 8, 12, 19, 31, PITCH_END, 128};
+//const int pbank0[PBANDS +2] = {0, 4, 8, 12, 19, PITCH_END, 128};
+const int qpulses0[NBANDS ] = {7, 5, 5, 4, 4, 3, 3, 2, 3, 2, 2, 2, 2, 1, 0, 0, 0, 0};
//const int qpulses0[NBANDS ] = {7, 5, 5, 5, 4, 4, 3, 3, 3, 3, 4, 3, 3, -2, 0, 0, 0, 0};
const int qbank1[NBANDS128+2] = {0, 2, 4, 6, 8, 12, 16, 20, 24, 28, 36, 44, 52, 68, 84, 116, 128};
-const int qpulses1[NBANDS128] = {7, 5, 5, 5, 4, 5, 4, 5, 5, 4, -2, 0, 0, 0, 0};
+const int qpulses1[NBANDS128] = {7, 5, 5, 5, 4, 5, 4, 5, 5, 4, 2, 0, 0, 0, 0};
const int qpulses2[NBANDS128] = {28,24,20,16,24,20, 18, 12, 10, 10,-7, -4, 0, 0, 0};
const int qpulses2s[NBANDS128] ={38,30,24,20,24,20, 18, 16, 14, 20,-20,-14, -8, -8, -5};
-const int pbank1[PBANDS128+2] = {0, 4, 8, 12, 20, PITCH_END128, 128};
+const int pbank1[PBANDS128+2] = {0, 2, 4, 6, 8, 12, 20, 28, PITCH_END128, 128};
+//const int pbank1[PBANDS128+2] = {0, 4, 8, 12, 20, PITCH_END128, 128};
#define NBANDS256 15
-#define PBANDS256 5
-#define PITCH_END256 72
+#define PBANDS256 8
+#define PITCH_END256 88
const int qbank3[NBANDS256+2] = {0, 4, 8, 12, 16, 24, 32, 40, 48, 56, 72, 88, 104, 126, 168, 232, 256};
-const int pbank3[PBANDS256+2] = {0, 8, 16, 24, 40, PITCH_END256, 256};
+//const int pbank3[PBANDS256+2] = {0, 8, 16, 24, 40, PITCH_END256, 256};
+const int pbank3[PBANDS256+2] = {0, 4, 8, 12, 16, 24, 40, 56, PITCH_END128, 128};
const CELTMode mode0 = {
128, /**< overlap */
--- a/libcelt/quant_pitch.c
+++ b/libcelt/quant_pitch.c
@@ -30,7 +30,9 @@
*/
#include "quant_pitch.h"
-
+#include <math.h>
+#include "pgain_table.h"
+
static const float cdbk_pitch[]={ 0.00826816, 0.00646836, 0.00520978, 0.00632398, 0.0108199 ,
0.723347, 0.0985132, 0.630212, 0.0546661, 0.0246779 ,
0.802152, 0.759963, 0.453441, 0.384415, 0.0625198 ,
@@ -93,6 +95,7 @@
{
int i, id;
float g2[len];
+#if 0
for (i=0;i<len;i++)
g2[i] = gains[i]*gains[i];
id = vq_index(g2, cdbk_pitch, len, 32);
@@ -99,12 +102,31 @@
ec_enc_uint(enc, id, 32);
for (i=0;i<len;i++)
gains[i] = sqrt(cdbk_pitch[id*len+i]);
+#else
+ //for (i=0;i<len;i++) printf ("%f ", gains[i]);printf ("\n");
+ for (i=0;i<len;i++)
+ g2[i] = 1-sqrt(1-gains[i]*gains[i]);
+ id = vq_index(g2, pgain_table, len, 128);
+ ec_enc_uint(enc, id, 128);
+ //for (i=0;i<len;i++) printf ("%f ", pgain_table[id*len+i]);printf ("\n");
+ for (i=0;i<len;i++)
+ gains[i] = (sqrt(1-(1-pgain_table[id*len+i])*(1-pgain_table[id*len+i])));
+ //for (i=0;i<len;i++) printf ("%f ", g2[i]);printf ("\n");
+ //for (i=0;i<len;i++) printf ("%f ", gains[i]);printf ("\n");
+ //printf ("\n");
+#endif
}
void unquant_pitch(float *gains, int len, ec_dec *dec)
{
int i, id;
+#if 0
id = ec_dec_uint(dec, 32);
for (i=0;i<len;i++)
gains[i] = sqrt(cdbk_pitch[id*len+i]);
+#else
+ id = ec_dec_uint(dec, 128);
+ for (i=0;i<len;i++)
+ gains[i] = (sqrt(1-(1-pgain_table[id*len+i])*(1-pgain_table[id*len+i])));
+#endif
}