[xiph-cvs] cvs commit: speex/libspeex quant_lsp.c
Jean-Marc Valin
jm at xiph.org
Wed Oct 8 23:51:04 PDT 2003
jm 03/10/09 02:51:04
Modified: libspeex quant_lsp.c
Log:
fixed-point: LSP quantization cleanup
Revision Changes Path
1.27 +50 -41 speex/libspeex/quant_lsp.c
Index: quant_lsp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/quant_lsp.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- quant_lsp.c 9 Oct 2003 03:54:37 -0000 1.26
+++ quant_lsp.c 9 Oct 2003 06:51:03 -0000 1.27
@@ -99,9 +99,9 @@
static int lsp_weight_quant(spx_word16_t *x, spx_word16_t *weight, signed char *cdbk, int nbVec, int nbDim)
{
int i,j;
- float dist;
+ spx_word32_t dist;
spx_word16_t tmp;
- float best_dist=0;
+ spx_word32_t best_dist=0;
int best_id=0;
signed char *ptr=cdbk;
for (i=0;i<nbVec;i++)
@@ -131,7 +131,6 @@
int id;
/* FIXME: get rid of that static allocation */
spx_word16_t quant_weight[10];
- spx_word16_t nlsp[10];
for (i=0;i<order;i++)
qlsp[i]=lsp[i];
@@ -141,39 +140,41 @@
for (i=0;i<order;i++)
qlsp[i]-=LSP_SCALING*(.25*i+.25);
-#ifdef FIXED_POINT
- for (i=0;i<order;i++)
- nlsp[i]=floor(.5+qlsp[i]*LSP_SCALE);
-#else
+#ifndef FIXED_POINT
for (i=0;i<order;i++)
- nlsp[i] = LSP_SCALE*qlsp[i];
+ qlsp[i] = LSP_SCALE*qlsp[i];
#endif
- id = lsp_quant(nlsp, cdbk_nb, NB_CDBK_SIZE, order);
+ id = lsp_quant(qlsp, cdbk_nb, NB_CDBK_SIZE, order);
speex_bits_pack(bits, id, 6);
for (i=0;i<order;i++)
- nlsp[i]*=2;
+ qlsp[i]*=2;
- id = lsp_weight_quant(nlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
+ id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
speex_bits_pack(bits, id, 6);
for (i=0;i<5;i++)
- nlsp[i]*=2;
+ qlsp[i]*=2;
- id = lsp_weight_quant(nlsp, quant_weight, cdbk_nb_low2, NB_CDBK_SIZE_LOW2, 5);
+ id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low2, NB_CDBK_SIZE_LOW2, 5);
speex_bits_pack(bits, id, 6);
- id = lsp_weight_quant(nlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
+ id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
speex_bits_pack(bits, id, 6);
for (i=5;i<10;i++)
- nlsp[i]*=2;
+ qlsp[i]*=2;
- id = lsp_weight_quant(nlsp+5, quant_weight+5, cdbk_nb_high2, NB_CDBK_SIZE_HIGH2, 5);
+ id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high2, NB_CDBK_SIZE_HIGH2, 5);
speex_bits_pack(bits, id, 6);
+#ifdef FIXED_POINT
for (i=0;i<order;i++)
- qlsp[i]=nlsp[i] * (.00097656/LSP_OVERSCALE);
+ qlsp[i]=PSHR(qlsp[i],2);
+#else
+ for (i=0;i<order;i++)
+ qlsp[i]=qlsp[i] * .00097656;
+#endif
for (i=0;i<order;i++)
qlsp[i]=lsp[i]-qlsp[i];
@@ -213,7 +214,6 @@
int i;
int id;
spx_word16_t quant_weight[10];
- spx_word16_t nlsp[10];
for (i=0;i<order;i++)
qlsp[i]=lsp[i];
@@ -222,27 +222,29 @@
for (i=0;i<order;i++)
qlsp[i]-=LSP_SCALING*(.25*i+.25);
-#ifdef FIXED_POINT
- for (i=0;i<order;i++)
- nlsp[i]=floor(.5+qlsp[i]*LSP_SCALE);
-#else
+#ifndef FIXED_POINT
for (i=0;i<order;i++)
- nlsp[i]=qlsp[i]*LSP_SCALE;
+ qlsp[i]=qlsp[i]*LSP_SCALE;
#endif
- id = lsp_quant(nlsp, cdbk_nb, NB_CDBK_SIZE, order);
+ id = lsp_quant(qlsp, cdbk_nb, NB_CDBK_SIZE, order);
speex_bits_pack(bits, id, 6);
for (i=0;i<order;i++)
- nlsp[i]*=2;
+ qlsp[i]*=2;
- id = lsp_weight_quant(nlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
+ id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
speex_bits_pack(bits, id, 6);
- id = lsp_weight_quant(nlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
+ id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
speex_bits_pack(bits, id, 6);
+#ifdef FIXED_POINT
+ for (i=0;i<order;i++)
+ qlsp[i] = PSHR(qlsp[i],1);
+#else
for (i=0;i<order;i++)
- qlsp[i] = nlsp[i]*(0.0019531/LSP_OVERSCALE);
+ qlsp[i] = qlsp[i]*0.0019531;
+#endif
for (i=0;i<order;i++)
qlsp[i]=lsp[i]-qlsp[i];
@@ -279,7 +281,6 @@
int i;
int id;
spx_word16_t quant_weight[10];
- spx_word16_t nlsp[10];
for (i=0;i<order;i++)
qlsp[i]=lsp[i];
@@ -297,24 +298,26 @@
for (i=0;i<order;i++)
qlsp[i]-=LSP_SCALING*(.3125*i+.75);
-#ifdef FIXED_POINT
- for (i=0;i<order;i++)
- nlsp[i] = floor(.5+qlsp[i]*LSP_SCALE);
-#else
+#ifndef FIXED_POINT
for (i=0;i<order;i++)
- nlsp[i] = qlsp[i]*LSP_SCALE;
+ qlsp[i] = qlsp[i]*LSP_SCALE;
#endif
- id = lsp_quant(nlsp, high_lsp_cdbk, 64, order);
+ id = lsp_quant(qlsp, high_lsp_cdbk, 64, order);
speex_bits_pack(bits, id, 6);
for (i=0;i<order;i++)
- nlsp[i]*=2;
+ qlsp[i]*=2;
- id = lsp_weight_quant(nlsp, quant_weight, high_lsp_cdbk2, 64, order);
+ id = lsp_weight_quant(qlsp, quant_weight, high_lsp_cdbk2, 64, order);
speex_bits_pack(bits, id, 6);
+#ifdef FIXED_POINT
+ for (i=0;i<order;i++)
+ qlsp[i] = PSHR(qlsp[i],1);
+#else
for (i=0;i<order;i++)
- qlsp[i] = nlsp[i]*(0.0019531/LSP_OVERSCALE);
+ qlsp[i] = qlsp[i]*0.0019531;
+#endif
for (i=0;i<order;i++)
qlsp[i]=lsp[i]-qlsp[i];
@@ -349,7 +352,6 @@
int i;
int id;
spx_word16_t quant_weight[10];
- spx_word16_t nlsp[10];
for (i=0;i<order;i++)
qlsp[i]=lsp[i];
@@ -358,8 +360,10 @@
for (i=0;i<order;i++)
qlsp[i]-=LSP_SCALING*(.25*i+.3125);
+#ifndef FIXED_POINT
for (i=0;i<order;i++)
- nlsp[i]=qlsp[i]*LSP_SCALE;
+ qlsp[i] = qlsp[i]*LSP_SCALE;
+#endif
id = lsp_quant(qlsp, cdbk_lsp_vlbr, 512, order);
speex_bits_pack(bits, id, 9);
@@ -370,8 +374,13 @@
id = lsp_weight_quant(qlsp, quant_weight, cdbk_lsp2_vlbr, 16, 10);
speex_bits_pack(bits, id, 4);
+#ifdef FIXED_POINT
for (i=0;i<order;i++)
- qlsp[i]=nlsp[i]*(0.00097655/LSP_OVERSCALE);
+ qlsp[i]=PSHR(qlsp[i],2);
+#else
+ for (i=0;i<order;i++)
+ qlsp[i]=qlsp[i]*0.00097655;
+#endif
for (i=0;i<order;i++)
qlsp[i]=lsp[i]-qlsp[i];
<p><p>--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list