Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/speex.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libspeex/Makefile.am5
-rw-r--r--libspeex/cb_search.c96
-rw-r--r--libspeex/exc_gains_table.c256
-rw-r--r--libspeex/exc_table.c192
-rw-r--r--libspeex/testenc.c20
5 files changed, 487 insertions, 82 deletions
diff --git a/libspeex/Makefile.am b/libspeex/Makefile.am
index d992d66..10c676f 100644
--- a/libspeex/Makefile.am
+++ b/libspeex/Makefile.am
@@ -1,6 +1,6 @@
## Process this file with automake to produce Makefile.in. -*-Makefile-*-
-# $Id: Makefile.am,v 1.8 2002/03/07 21:55:22 jmvalin Exp $
+# $Id: Makefile.am,v 1.9 2002/03/11 18:34:06 jmvalin Exp $
# Disable automatic dependency tracking if using other tools than gcc and gmake
#AUTOMAKE_OPTIONS = no-dependencies
@@ -20,7 +20,8 @@ libspeex_la_SOURCES = speex.c \
filters.c \
bits.c \
modes.c \
- exc_table.c
+ exc_table.c \
+ exc_gains_table.c
include_HEADERS = speex.h \
bits.h \
diff --git a/libspeex/cb_search.c b/libspeex/cb_search.c
index 1f151ac..ee3245d 100644
--- a/libspeex/cb_search.c
+++ b/libspeex/cb_search.c
@@ -33,8 +33,11 @@
#include <cb_search.h>
#include "filters.h"
#include <math.h>
+#include <stdio.h>
+#define EXC_CB_SIZE 128
#define min(a,b) ((a) < (b) ? (a) : (b))
+extern float exc_gains_table[128][5];
/*---------------------------------------------------------------------------*\
@@ -143,12 +146,13 @@ float *exc
)
{
int i,j;
- float resp[64][8], E[64];
+ float resp[EXC_CB_SIZE][8], E[EXC_CB_SIZE], Ee[EXC_CB_SIZE];
float t[40], r[40], e[40];
float gains[5];
+ int ind[5];
for (i=0;i<40;i++)
t[i]=target[i];
- for (i=0;i<64;i++)
+ for (i=0;i<EXC_CB_SIZE;i++)
{
residue_zero(codebook[i], awk1, resp[i], 8, p);
syn_filt_zero(resp[i], ak, resp[i], 8, p);
@@ -156,15 +160,20 @@ float *exc
E[i]=0;
for(j=0;j<8;j++)
E[i]+=resp[i][j]*resp[i][j];
+ Ee[i]=0;
+ for(j=0;j<8;j++)
+ Ee[i]+=codebook[i][j]*codebook[i][j];
+
}
for (i=0;i<5;i++)
{
- int best_index;
- float corr, best_gain, score, best_score=-1;
- for (j=0;j<64;j++)
+ int best_index=0;
+ float g, corr, best_gain=0, score, best_score=-1;
+ for (j=0;j<EXC_CB_SIZE;j++)
{
corr=xcorr(resp[j],t+8*i,8);
score=corr*corr/(.001+E[j]);
+ g = corr/(.001+E[j]);
if (score>best_score)
{
best_index=j;
@@ -172,24 +181,28 @@ float *exc
best_gain=corr/(.001+E[j]);
}
}
-
+ ind[i]=best_index;
+ gains[i]=best_gain*Ee[ind[i]];
if (1) { /* Simulating scalar quantization of the gain*/
float sign=1;
printf("before: %f\n", best_gain);
if (best_gain<0)
+ {
sign=-1;
- best_gain = abs(best_gain)+.1;
+ }
+ best_gain = fabs(best_gain)+.1;
best_gain = log(best_gain);
if (best_gain>8)
best_gain=8;
if (best_gain<0)
best_gain=0;
- /*best_gain=.25*rint(4*best_gain);*/
+ /*best_gain=.125*floor(8*best_gain+.5);*/
best_gain=.25*floor(4*best_gain+.5);
best_gain=sign*exp(best_gain);
+ if (fabs(best_gain)<1.01)
+ best_gain=0;
printf("after: %f\n", best_gain);
}
- gains[i]=best_gain;
printf ("search: %d %f %f %f\n", best_index, best_gain, best_gain*best_gain*E[best_index], best_score);
for (j=0;j<40;j++)
@@ -203,13 +216,70 @@ float *exc
t[j]-=r[j];
/*FIXME: Should move that out of the loop if we are to vector-quantize the gains*/
- for (j=0;j<40;j++)
- exc[j]+=e[j];
+ /*for (j=0;j<40;j++)
+ exc[j]+=e[j];*/
}
- for (i=0;i<5;i++)
+ {
+ int best_vq_index=0, max_index;
+ float max_gain=0, log_max, min_dist=0, sign[5];
+
+ for (i=0;i<5;i++)
+ {
+ if (gains[i]<0)
+ {
+ gains[i]=-gains[i];
+ sign[i]=-1;
+ } else {
+ sign[i]=1;
+ }
+ }
+ for (i=0;i<5;i++)
+ if (gains[i]>max_gain)
+ max_gain=gains[i];
+ log_max=log(max_gain+1);
+ max_index = (int)(floor(.5+log_max-3));
+ if (max_index>7)
+ max_index=7;
+ if (max_index<0)
+ max_index=0;
+ max_gain=1/exp(max_index+3.0);
+ for (i=0;i<5;i++)
+ gains[i]*=max_gain;
+
+ if (max_index>2)
+ {
+ for (i=0;i<5;i++)
+ printf ("%f ", gains[i]);
+ printf ("cbgains: \n");
+ }
+ /*Vector quantize gains[i]*/
+ for (i=0;i<256;i++)
+ {
+ float dist=0;
+ for (j=0;j<5;j++)
+ dist += (exc_gains_table[i][j]-gains[j])*(exc_gains_table[i][j]-gains[j]);
+ if (i==0 || dist<min_dist)
+ {
+ min_dist=dist;
+ best_vq_index=i;
+ }
+ }
+ printf ("best_gains_vq_index %d %f %d\n", best_vq_index, min_dist, max_index);
+#if 1
+ for (i=0;i<5;i++)
+ gains[i]= sign[i]*exc_gains_table[best_vq_index][i]/max_gain/(Ee[ind[i]]+.001);
+#else
+ for (i=0;i<5;i++)
+ gains[i]= sign[i]*gains[i]/max_gain/(Ee[ind[i]]+.001);
+#endif
+ for (i=0;i<5;i++)
+ for (j=0;j<8;j++)
+ exc[8*i+j]+=gains[i]*codebook[ind[i]][j];
+ }
+ /*for (i=0;i<5;i++)
printf ("%f ", gains[i]);
- printf ("cbgains: \n");
+ printf ("cbgains: \n");*/
/*TODO: Perform joint optimization of gains and quantization with prediction*/
for (i=0;i<40;i++)
diff --git a/libspeex/exc_gains_table.c b/libspeex/exc_gains_table.c
new file mode 100644
index 0000000..2e333b9
--- /dev/null
+++ b/libspeex/exc_gains_table.c
@@ -0,0 +1,256 @@
+float exc_gains_table[256][5] ={{0,0,0,0,0},
+{0.972275,0.402021,0.401929,0.800834,0.604032},
+{0.521341,0.482969,1.30015,1.34672,0.515598},
+{0.704136,0.254923,0.225597,0.415044,0.237654},
+{0.118532,0.108211,0.109704,0.214159,1.19587},
+{0.953394,1.35646,0.73601,0.449876,0.37701},
+{0.963726,1.14754,0.602996,1.3777,1.33},
+{0.162504,0.137945,0.137239,0.169084,0.713126},
+{0.214615,0.694716,0.250157,0.217016,0.217004},
+{0.578935,1.3047,1.45514,0.591551,0.577459},
+{0.201417,0.191737,0.21526,0.713748,0.534357},
+{0.604835,0.353747,0.950318,0.577202,0.396275},
+{0.226098,0.218205,0.309687,1.34379,0.776054},
+{0.550915,0.635746,0.728705,0.409734,1.45305},
+{0.617468,0.808439,0.467973,0.712037,1.35797},
+{0.354373,0.635841,0.327349,0.564778,0.634233},
+{0.262291,0.24096,0.269297,0.878703,0.846369},
+{0.28283,0.272303,0.523589,0.71841,0.2801},
+{1.08446,0.799391,0.34672,0.451512,0.573106},
+{0.770633,1.19025,0.574476,0.906406,0.924732},
+{0.527886,0.712326,0.529878,0.527529,0.368671},
+{0.55169,0.461453,0.633219,1.04547,1.00062},
+{0.911447,0.416008,0.304148,0.419643,0.310092},
+{0.944921,0.627332,0.591817,0.875507,1.13378},
+{0.723674,0.253275,0.226479,0.235247,0.459685},
+{0.356184,0.654919,0.56119,0.330236,0.659618},
+{0.640447,0.784999,1.39964,0.507196,0.740835},
+{1.37257,0.909719,1.4253,1.35887,0.766594},
+{0.993756,0.368664,0.690089,0.599319,0.44539},
+{0.459005,0.430932,0.70052,0.507022,0.308046},
+{1.35867,0.877721,0.593717,0.917338,0.960946},
+{0.416514,1.39948,0.646887,0.363254,0.355859},
+{0.461567,0.436086,0.433055,1.36922,1.37312},
+{0.515051,0.701988,0.27593,0.258721,0.227499},
+{0.743553,1.35648,0.519104,0.460778,0.79189},
+{1.13341,0.488553,0.876964,0.538191,1.18897},
+{0.477589,0.87371,0.947462,0.855027,0.846926},
+{1.15928,0.477267,0.460651,0.800718,0.897817},
+{0.633649,1.05231,0.916455,0.509586,0.408965},
+{1.42703,0.547723,1.31581,0.90651,0.674567},
+{0.721091,0.332845,0.305928,0.526756,0.518563},
+{0.985646,1.19475,1.27664,0.712838,1.41057},
+{0.526615,0.514881,1.30318,0.457125,1.25301},
+{0.972529,0.700516,1.01761,1.42166,0.748644},
+{0.781448,1.21869,0.346365,0.348731,0.330229},
+{0.356117,0.357101,0.29171,0.325432,1.40351},
+{0.665768,0.576301,0.293516,0.465485,0.321017},
+{1.405,1.21953,0.579994,0.825537,1.34119},
+{1.00666,1.15496,0.446585,0.775017,0.4598},
+{0.935681,1.35373,0.937677,0.660844,0.81937},
+{1.40872,1.32346,0.919368,0.548001,0.999682},
+{1.12925,0.318703,0.294389,0.357727,0.613218},
+{1.41962,0.849738,1.04838,0.534462,1.37598},
+{1.46394,0.741556,0.399826,0.427772,0.426526},
+{0.947719,0.384231,0.420101,1.2868,0.523767},
+{0.726275,0.885338,1.31427,0.889976,1.0509},
+{0.718514,0.31327,0.240932,0.27535,0.750046},
+{1.32024,1.40172,0.932446,1.32921,1.45059},
+{0.511618,0.887083,0.564702,1.24288,1.21622},
+{0.344737,0.338843,0.725848,0.303817,0.469897},
+{0.680904,0.577025,0.308699,0.273644,0.559625},
+{1.40113,0.854853,0.549732,1.41536,0.949144},
+{0.66197,0.763205,0.857623,0.579795,0.692197},
+{0.287785,0.950849,0.745611,0.39432,0.355838},
+{0.997249,1.10924,0.880485,0.913087,1.06778},
+{0.318554,0.697328,0.527362,0.26532,0.265273},
+{0.570326,1.12066,0.446756,0.420497,1.17891},
+{1.37359,0.543468,0.871405,1.37365,0.572593},
+{0.423868,0.981704,0.510652,1.20006,0.419747},
+{0.473503,0.380938,0.657541,0.976714,0.382061},
+{1.42241,0.99629,0.486159,0.9234,0.498345},
+{0.380047,0.933421,1.33968,0.495083,0.377593},
+{1.33858,1.38662,1.07671,0.521677,0.551401},
+{0.525712,0.566488,0.608423,0.610011,0.712988},
+{1.3264,1.36154,1.34812,1.35304,0.689819},
+{0.328145,0.515172,0.293175,0.743057,0.340295},
+{0.179465,0.193377,0.704852,0.271414,0.21437},
+{1.01473,0.966375,0.443888,0.664939,1.05215},
+{0.313297,0.259347,0.240959,0.248981,1.01725},
+{0.51173,1.03144,0.814328,0.397627,0.88187},
+{0.403561,0.437586,1.36324,1.04097,1.24388},
+{1.11891,0.779818,1.35237,0.66367,0.9601},
+{0.695845,0.215196,0.174613,0.156823,0.164481},
+{0.694936,0.475279,0.82149,0.367273,0.659572},
+{1.00446,0.65876,0.688924,0.535484,0.775218},
+{0.488051,0.394564,0.412371,0.401268,0.709179},
+{0.419085,0.932623,0.39922,0.681645,0.344296},
+{1.38096,0.469823,0.767079,1.07721,1.09368},
+{0.858307,0.599978,1.34487,0.747092,1.41773},
+{0.867299,0.813551,0.438826,0.769831,0.685497},
+{0.676983,0.541416,0.917202,1.00752,0.716101},
+{0.509423,0.511131,0.888426,0.85971,1.33703},
+{0.233598,0.210134,0.269673,1.01355,0.400707},
+{0.531641,0.683755,0.491125,1.35098,0.708454},
+{1.04524,0.798053,0.471229,1.38981,0.562417},
+{0.570377,1.29303,1.30446,0.509441,1.11081},
+{0.731226,0.479167,0.367961,0.592231,0.863689},
+{0.719602,0.273401,0.4243,0.241497,0.235092},
+{1.39416,0.870226,0.496218,0.434202,1.05746},
+{1.18606,0.641133,0.334742,0.254625,0.261298},
+{0.318896,0.636718,0.458728,0.980523,0.599414},
+{0.581572,1.38305,0.956477,1.00986,0.847895},
+{0.944455,0.951589,1.10851,0.933021,0.637479},
+{1.41789,0.544071,0.415516,1.00899,0.548907},
+{0.310431,0.482505,0.24913,0.25783,0.734969},
+{1.42007,0.573146,0.504549,0.545169,1.41059},
+{0.394208,1.00389,0.771047,0.783679,0.479258},
+{1.39133,0.348961,0.284455,0.278966,0.283467},
+{0.755718,0.774018,0.728182,0.749738,0.933789},
+{1.00362,0.637714,1.01352,0.975032,1.00686},
+{0.35057,0.943689,0.278791,0.26342,0.244554},
+{1.38077,0.988684,0.782604,1.12476,1.42002},
+{0.932468,0.763109,1.45482,1.01663,0.577551},
+{0.50868,0.958474,0.51353,0.46611,0.637675},
+{0.240751,0.21715,0.215419,0.442746,0.724527},
+{0.845799,0.708941,0.261522,0.235763,0.236392},
+{0.70726,0.32005,0.536322,0.538214,0.294454},
+{0.883629,0.429025,0.747476,1.04414,0.432173},
+{0.459398,1.44193,1.01607,0.596322,0.529043},
+{0.759138,0.599769,0.754105,0.682876,0.419982},
+{0.746836,0.413024,0.359393,0.334954,1.40898},
+{0.774368,1.43343,1.12543,1.24132,1.32189},
+{1.33443,1.19093,1.44996,0.71621,0.863739},
+{0.593881,0.977409,0.936586,0.749974,1.30699},
+{1.02393,0.600096,1.416,1.33026,1.05845},
+{0.810553,0.262657,0.298729,0.77788,0.292396},
+{1.42747,0.460729,0.39096,0.463481,0.797837},
+{1.04254,0.824864,0.836904,0.799879,1.43965},
+{1.39711,0.481567,0.78444,0.798873,0.520114},
+{0.773335,0.483008,1.13145,0.585621,0.827946},
+{0.364525,0.412386,0.873931,0.831505,0.766241},
+{1.31611,1.41568,1.07089,0.822162,1.40385},
+{0.721388,0.551004,0.511029,0.480886,0.518742},
+{0.750012,1.32407,1.40478,1.41808,0.727873},
+{0.244528,0.300501,1.41808,0.583474,0.40588},
+{0.556924,0.808786,0.296311,0.384897,0.817433},
+{0.629217,0.660837,0.370047,0.679343,0.567673},
+{0.94669,0.542862,0.595309,1.39103,1.08608},
+{1.34439,1.38548,0.785918,0.872008,0.536333},
+{0.722287,0.560385,0.502034,0.26883,0.268874},
+{0.264549,0.286265,1.04868,0.340979,0.313366},
+{1.14687,0.958048,0.797669,0.759675,0.751111},
+{1.16042,1.42116,0.578728,0.993924,0.919367},
+{0.275215,0.265237,0.433743,0.284551,0.70771},
+{0.724508,0.684652,0.537697,0.389112,0.785042},
+{0.461,1.04549,1.31324,1.03516,0.523672},
+{0.449075,0.230555,0.220253,0.239218,0.714746},
+{1.07101,0.494466,1.43273,0.505434,0.557922},
+{0.651872,1.40048,0.629312,0.877823,0.478932},
+{0.314476,0.519758,0.944989,0.761632,0.344989},
+{0.586573,1.41873,0.818594,0.688533,1.2816},
+{0.614926,0.340379,0.663732,0.655486,0.578881},
+{1.39413,1.38174,0.870428,1.36998,1.01329},
+{0.427563,0.410732,1.01906,1.37567,1.00929},
+{1.1838,1.09413,0.845674,1.35539,0.729601},
+{0.928725,0.912421,0.948423,0.530318,1.00982},
+{0.716725,0.376622,0.300712,1.04899,0.989422},
+{0.342032,0.611919,0.768187,0.534886,0.536425},
+{0.977419,0.818639,0.484332,0.41841,1.37715},
+{1.4191,0.934955,0.98809,0.963722,0.497427},
+{0.443494,0.357365,0.356933,1.28602,0.380011},
+{1.03689,0.58904,0.593161,0.361587,0.487857},
+{0.62685,0.747246,0.921829,1.33748,0.421531},
+{0.734763,0.992225,0.963457,1.3243,1.40383},
+{0.717794,0.950892,0.57157,0.651529,0.401774},
+{1.35902,0.777653,1.12951,1.43847,1.29577},
+{0.826427,0.984049,0.785996,0.85149,0.597338},
+{0.324075,0.321327,0.499794,0.696533,0.633254},
+{0.699647,0.447185,0.233461,0.207025,0.23467},
+{1.26334,1.39869,0.482715,0.470843,0.736274},
+{0.512698,0.394565,0.406443,0.702691,1.36402},
+{0.34558,0.630122,0.956569,0.321373,0.277504},
+{0.983792,0.30269,0.212727,0.208796,0.215945},
+{1.35273,0.898547,0.886606,0.458719,0.428321},
+{0.914928,1.41073,1.23423,0.975644,0.51781},
+{1.42053,0.786283,1.00712,0.68441,0.883851},
+{0.747769,0.527418,0.703172,0.475628,1.12847},
+{1.32767,0.621679,1.2657,0.925819,1.39837},
+{0.219846,0.228227,0.777264,0.578013,0.388584},
+{1.03874,0.597391,0.388152,0.335099,0.987358},
+{0.626982,0.679977,0.644919,0.897948,0.605773},
+{1.10456,0.94846,0.479339,0.350068,0.289616},
+{0.515314,0.303562,0.281381,0.649247,0.686618},
+{0.734309,0.867893,0.362538,0.37835,0.4413},
+{1.09491,0.393134,0.391774,0.53094,1.30489},
+{0.600756,0.648178,0.722097,0.351113,0.407224},
+{0.4166,0.55147,0.939187,0.452547,0.998761},
+{0.695608,0.31667,0.542135,0.309059,0.491431},
+{0.481968,0.255664,0.730779,0.283866,0.249101},
+{1.24082,0.428159,0.371111,0.639324,0.35982},
+{0.290883,0.30027,0.99396,1.11201,0.398157},
+{1.08646,1.33951,0.638558,0.443313,1.28855},
+{0.899274,1.00716,1.41022,1.33737,1.41783},
+{0.553161,0.540097,1.42208,0.788474,0.398309},
+{0.813856,0.5877,0.992087,1.2488,1.38826},
+{0.750852,0.834514,0.788686,1.16453,0.945668},
+{0.974239,0.693244,0.617397,1.07156,0.707945},
+{0.5439,0.362043,0.598631,0.696378,0.962958},
+{0.698133,1.0455,0.731779,1.2708,0.65881},
+{1.41689,0.489073,0.635876,0.362636,0.338296},
+{0.981828,0.750206,1.06633,0.548349,0.549096},
+{0.954791,0.999911,0.656373,0.395426,0.738605},
+{1.37216,1.25162,0.484418,0.406661,0.34539},
+{0.417482,0.71854,1.03127,0.380905,0.581106},
+{0.524725,0.395229,0.650851,1.41219,0.698916},
+{0.429885,0.75674,0.558314,0.623743,0.99586},
+{0.381661,0.738759,0.312966,0.276511,0.482497},
+{0.392806,0.398552,0.565697,0.352257,0.999441},
+{0.447778,0.258217,0.241994,0.717681,0.297136},
+{0.798993,0.312859,0.588746,0.384457,0.789491},
+{1.00102,0.510132,1.08458,0.930362,0.423518},
+{0.404631,0.684262,0.340142,0.347804,1.12451},
+{0.58875,0.967233,0.610624,0.290556,0.298476},
+{1.35833,0.566374,0.84081,0.424704,0.798814},
+{1.31321,0.627276,0.518045,1.31765,1.39693},
+{1.38743,1.39732,1.1704,0.981091,0.976433},
+{1.11735,0.742696,0.627347,0.727904,0.413121},
+{1.01093,1.06099,1.15139,1.2511,1.01169},
+{0.427703,1.35269,0.36702,0.45199,0.570128},
+{0.837854,0.394956,0.76466,0.331732,0.295262},
+{0.909378,0.446163,0.794585,0.749216,0.786094},
+{0.344702,0.365015,0.329708,0.534921,0.961224},
+{0.38143,0.565635,0.597605,0.721197,0.41132},
+{0.875823,0.637858,0.404223,0.616252,0.324219},
+{0.397054,0.310093,0.746364,0.395879,0.711295},
+{0.264863,0.709984,0.401995,0.483187,0.318389},
+{0.507365,0.949016,1.27131,1.31729,0.93577},
+{0.550813,0.474785,1.3982,0.939911,0.833863},
+{0.712924,0.642765,0.371228,0.984357,0.380933},
+{0.899557,1.38033,1.38934,0.951007,0.986719},
+{0.60779,1.38202,0.713324,1.40317,0.835878},
+{0.852823,0.555799,0.549014,0.979552,1.47657},
+{1.36425,0.910603,1.31872,0.54743,0.477595},
+{1.41767,1.02304,1.3707,0.999278,1.30434},
+{0.576644,0.718734,1.05559,0.77462,0.471096},
+{0.698486,0.326327,0.310007,0.328323,1.07483},
+{0.550321,0.683533,0.395586,0.866495,0.904941},
+{0.794335,1.28904,0.584979,0.897343,1.44688},
+{0.683199,0.450746,1.23226,0.393307,0.377747},
+{0.242492,0.221403,0.299403,0.899992,1.28587},
+{0.877685,1.16576,1.27928,0.492245,0.497385},
+{1.04409,0.323209,0.465109,0.271362,0.300315},
+{1.37676,0.922592,1.00164,1.07654,0.89126},
+{0.496613,1.0732,0.482346,0.837521,0.751919},
+{0.169335,0.15668,0.203705,0.704017,0.251349},
+{0.567055,0.36419,0.40251,0.940086,0.600358},
+{1.15268,0.40942,1.01592,0.395888,0.384224},
+{0.262308,1.12019,0.408302,0.354161,0.32845},
+{1.43401,0.960675,0.575018,0.56046,0.68297},
+{0.565376,0.412315,0.408686,0.705626,0.376174},
+{0.91057,0.840437,0.807628,0.361432,0.34532},
+{0.928957,0.468982,0.355533,0.357671,0.653643},
+{0.248598,0.470228,0.704381,0.295403,0.241939},
+{1.33813,1.38385,1.40354,1.39387,1.31256},
+{1.11846,1.35294,0.568821,1.38766,0.550317},
+{0.315756,0.332599,1.18161,0.580827,0.694064}};
diff --git a/libspeex/exc_table.c b/libspeex/exc_table.c
index 6ae24bf..006f816 100644
--- a/libspeex/exc_table.c
+++ b/libspeex/exc_table.c
@@ -1,64 +1,128 @@
-float exc_table[64][8] = {{-1.04159,1.21534,0.0281572,0.567357,-0.66105,0.917141,-0.44328,0.644215},
-{2.14338,-0.724956,-0.243856,0.0636575,0.051804,-0.0366771,0.277851,0.0973481},
-{0.689252,-0.0152788,0.0669421,0.6023,-1.23989,-0.454837,1.50022,0.387449},
-{-0.655571,-0.28521,1.32617,0.833705,-0.876822,0.231166,0.878329,-0.172353},
-{1.56631,1.21942,0.487014,0.112435,-0.399279,-0.521386,-0.351448,0.247221},
-{0.681692,-0.551779,0.437978,-0.382249,0.616708,0.68908,-1.47909,1.10475},
-{-1.24841,0.670471,0.137208,0.489972,1.01366,0.587233,0.681082,-0.681514},
-{0.690688,-0.756335,0.775508,0.178926,-0.797518,1.39874,-0.958312,0.48669},
-{0.0736325,0.563406,-0.374662,1.00672,-1.22035,0.873397,0.854658,-0.733435},
-{1.2404,0.125571,0.202958,-1.46055,0.943786,0.112168,0.523025,-0.122483},
-{-0.312712,-0.264677,0.510043,1.46644,1.14451,-0.0998857,-0.692069,-0.0233302},
-{0.281634,-0.271152,0.194237,0.235868,0.945309,1.42704,-0.26301,-1.02114},
-{0.261912,1.41646,-1.15821,-0.263153,0.994369,-0.144499,0.515897,-0.428628},
-{-0.495821,0.798849,0.383719,-1.00158,1.36995,-0.762316,0.784773,-0.0896762},
-{0.476335,0.29456,0.104288,0.0255712,-0.0095248,0.274596,1.49057,-1.46249},
-{0.125313,0.0868791,0.0358873,0.357145,-0.544518,0.895025,-1.26285,1.62109},
-{0.126897,0.313613,-0.756072,1.75117,-0.952912,0.119785,-0.0697364,0.628111},
-{1.10276,-0.980415,-0.416322,1.38715,-0.0291589,-0.669674,0.49797,0.376363},
-{-0.0167108,0.672873,-0.64257,0.133314,1.01199,-1.46729,1.05946,0.320406},
-{0.1257,0.800025,1.20711,-0.5645,-1.00903,-0.356976,0.467638,1.05267},
-{1.14128,1.02441,-0.584344,-0.8726,-0.41885,0.114374,0.691641,0.916212},
-{-0.022079,0.1634,0.992857,-0.974776,-0.177774,1.37748,-0.912142,0.627073},
-{-0.172577,1.09201,-0.0479552,-1.1333,1.04384,0.647798,-0.790628,0.533184},
-{0.0223689,-0.927858,1.79641,-0.442921,-0.260088,0.338522,-0.210261,0.80733},
-{1.16543,-0.831543,0.0314858,1.16987,-0.961704,0.687389,0.308519,-0.469408},
-{1.15331,-1.17282,0.685973,-0.338185,1.00024,-0.644017,-0.126828,0.779918},
-{-0.141278,0.254503,-0.274451,0.196185,-0.299476,-0.341986,0.772743,2.04174},
-{0.509146,-0.122004,0.900112,-0.469538,-1.11347,1.35141,0.557897,-0.411944},
-{0.293851,0.994832,-1.11123,0.405403,0.313717,0.518397,-1.05291,1.03034},
-{0.112151,-0.130469,0.55345,-0.564969,0.823356,-1.30379,0.573645,1.387},
-{1.20244,1.24831,1.36317,1.41022,1.38998,1.36448,1.28507,1.1929},
-{1.54916,-0.0432367,-0.190724,-0.53311,-0.147609,1.38607,-0.658561,0.129495},
-{-0.279107,1.51921,-1.28467,0.926618,-0.375457,0.412457,0.102877,0.0269284},
-{1.03453,-1.26679,1.10359,0.0725896,-0.196979,-0.270971,0.969828,-0.177658},
-{-0.200594,0.246468,0.381804,-0.235524,0.133145,-0.862605,1.98216,-0.236907},
-{-1.35127,0.587961,1.3321,-0.178175,0.319357,-0.303824,0.099813,0.754535},
-{0.45814,1.09232,1.21856,0.832085,0.258844,-0.183363,-0.615538,-0.699842},
-{-0.090229,0.0868827,0.409788,-0.352685,0.530318,-0.220869,-0.985997,1.94863},
-{-0.828624,1.43615,-0.511756,0.687363,0.0400852,-0.61435,1.07193,-0.282428},
-{1.31246,-1.51496,0.653514,0.427736,-0.304515,0.428299,-0.442741,0.613971},
-{0.374916,0.312996,-0.802911,1.2433,-0.179408,-0.640173,1.34948,-0.641773},
-{1.23106,-1.09148,1.18843,-0.919555,0.344335,0.503526,-0.246095,0.218774},
-{0.0365025,-0.654073,0.969715,1.00994,-0.520716,-0.574648,-0.257959,1.36526},
-{0.445859,1.28031,-0.45128,-0.717641,-0.0283588,1.35575,0.111841,-0.634202},
-{0.535436,0.595257,-1.44207,1.02815,0.624512,-0.82565,0.241634,0.481186},
-{-0.461299,0.734322,1.24596,-1.37214,0.147082,0.654636,0.416385,-0.212952},
-{0.894284,-0.366136,0.0767162,-0.0555811,1.20647,-1.06341,1.06868,-0.515867},
-{0.336375,0.430788,-0.554035,0.848724,-1.03638,1.48748,-0.744741,0.332997},
-{1.36569,0.377193,-1.35813,0.961464,-0.235192,0.396929,0.107201,-0.332525},
-{-0.537131,-0.996903,-0.214434,0.81525,0.987716,0.889586,0.721483,0.615579},
-{-0.325722,0.0916103,0.279179,1.05899,0.0228423,-1.51322,0.845647,0.757875},
-{-0.46886,1.5701,0.253309,-0.511086,-0.752487,0.289817,1.10434,-0.125427},
-{0.847028,-0.298864,-1.14845,-0.197791,0.234586,0.933259,1.26716,0.171616},
-{0.0795572,-0.212621,1.0749,-1.35585,1.13205,-0.02539,-0.501638,0.872285},
-{-0.840241,1.67483,-0.377716,-0.252819,0.660874,-0.493493,-0.0227003,0.806073},
-{1.21971,-0.542819,0.496746,-0.577628,-0.266686,0.256195,-0.347802,1.69556},
-{0.545959,-0.343555,0.504532,0.674489,-1.68592,0.794496,0.0466908,0.770471},
-{0.344366,-0.648986,1.37931,-0.924877,0.955779,-0.634533,0.746397,-0.134892},
-{0.921527,-0.254106,-0.509001,0.602565,0.589816,-0.868366,-0.474392,1.53031},
-{-0.254479,-0.302833,0.0283111,-0.725651,0.275966,1.22451,1.13252,1.20505},
-{1.32048,-0.00804473,-0.999356,-0.0684118,1.3133,0.239322,-0.585385,0.183382},
-{0.0945416,0.418628,-0.342742,-0.437575,1.70389,-0.795247,-0.449866,0.942269},
-{0,0,0,0,0,0,0,0},
-{1.34164,-0.56087,-0.574784,0.94598,-0.454148,0.619891,-0.828585,0.901291}};
+float exc_table[128][8]={{0,0,0,0,0,0,0,0},
+{-0.519148,-0.383215,0.492778,1.4744,0.677986,-1.30348,0.654883,0.272205},
+{0.235487,1.08995,1.1888,-0.454432,-0.873275,-0.72557,0.127527,1.19132},
+{1.31407,-0.12346,-1.6954,1.12853,0.223931,0.316261,0.0103814,0.00687301},
+{2.02206,-0.221238,-0.709228,0.133388,-0.0665108,0.644046,-0.811408,0.624665},
+{-0.211276,1.64339,-0.628985,-1.14044,1.20664,-0.0699504,-0.0975374,0.408862},
+{-0.225241,1.53847,-1.06719,0.295573,-0.476,1.40531,-0.221542,-0.0712951},
+{-0.0777728,0.263831,-0.390129,1.28144,-0.732307,-1.00018,1.65573,0.0192973},
+{-0.253542,-0.607609,1.56792,-0.386332,0.712034,-1.17144,0.449069,0.902173},
+{0.457305,0.159654,0.964737,-1.48001,-0.124851,1.56212,-0.270539,-0.1115},
+{-0.535583,1.2753,0.82763,-0.511839,-1.21468,0.387945,1.14347,-0.037292},
+{0.658727,0.0951354,-0.91433,1.84221,-1.15651,0.11608,0.457493,-0.0696827},
+{-0.171123,-0.640259,1.98106,-0.538926,-0.702949,0.224473,0.146852,0.907132},
+{1.23847,-0.735588,-0.458715,1.33074,-1.02485,0.564821,-0.481561,0.815328},
+{0.638468,-0.482913,0.360224,1.06189,-1.1122,-0.0272128,1.46374,-0.803822},
+{0.142921,0.427225,0.0114741,0.403792,-0.712144,1.23426,1.06859,-1.48582},
+{0.206021,-0.025427,0.000886086,-0.300349,1.40432,-1.41072,-0.148592,1.4734},
+{0.290391,0.85017,0.246852,0.238577,0.987514,0.876865,-0.322982,-1.54234},
+{1.28185,-0.721373,-0.790936,0.761936,0.591477,-0.541731,-0.440675,1.36101},
+{-0.44707,1.65442,-0.103376,-0.715018,0.227665,-0.744212,1.38073,-0.0216128},
+{1.58882,0.3999,-0.836505,-0.38793,-0.076672,1.06949,0.541261,-0.846127},
+{-1.2514,1.17783,0.00721583,0.998346,-0.964169,0.884813,0.160821,0.188163},
+{0.032151,-1.41618,0.323532,-0.251319,0.415093,1.07904,0.576218,1.22169},
+{-0.14934,1.22495,-0.244964,-0.327759,0.212238,1.15037,-1.46728,0.81144},
+{0.0865305,0.447683,-0.253781,-0.475941,1.57808,-1.48456,1.00947,0.0725317},
+{1.187,-0.692426,-0.160248,0.402956,0.659311,-1.36626,1.23888,0.053066},
+{0.938144,-1.24477,-0.0266074,1.63676,-0.41681,-0.560181,0.552124,0.311536},
+{1.19399,0.845415,-0.296021,0.395652,-0.957363,-0.11966,-0.533361,1.44858},
+{0.607339,-1.11686,0.895028,0.658016,-0.347789,-0.814287,0.0185571,1.52623},
+{1.34549,-0.393902,1.01,-1.15699,-0.63963,0.346319,0.362357,0.948321},
+{-0.644387,0.734053,0.336477,-0.812896,1.00561,-0.128355,-0.940326,1.59094},
+{-1.49306,0.66011,1.21486,0.115235,0.0322791,-0.66451,0.408269,0.971429},
+{0.431509,-0.655904,0.787717,-0.591676,0.704448,-0.350819,-0.882844,1.86331},
+{0.274213,1.26762,-1.38245,-0.199402,0.991432,0.00956448,0.865429,-0.678094},
+{0.626281,-0.19805,0.260867,-0.0897887,-0.426774,1.47313,-1.6055,1.00902},
+{-0.216025,0.0862033,0.445714,-0.0880767,0.301077,-1.3334,1.98526,-0.0555188},
+{-0.797843,0.586305,-0.154543,1.70117,1.03544,-0.0184295,-0.334302,-0.381217},
+{-1.42492,1.67326,0.405813,-0.506934,0.562486,0.469201,-0.147553,0.0748747},
+{0.913965,0.402575,0.682482,0.790534,0.391609,1.16972,0.299276,1.27145},
+{-0.640021,0.989951,1.17676,-1.66393,0.355064,0.121597,0.369959,0.403901},
+{1.23378,0.641514,-1.22876,0.234667,0.0827593,-0.880098,1.13685,0.527352},
+{0.356115,-0.509378,1.05565,-1.04099,0.371755,0.94073,-1.291,1.10064},
+{-0.943512,1.31169,-0.390361,-0.103097,1.11716,-1.12928,0.371843,0.818917},
+{-0.156317,-0.0418901,0.0723236,0.973233,0.730196,-0.966608,-0.947366,1.5693},
+{1.5829,1.33856,0.473229,0.0219714,-0.702468,-0.154917,-0.0369134,-0.470584},
+{-0.673854,0.699879,1.12444,-0.662892,-0.71571,1.18947,-0.640153,0.915725},
+{0.896011,0.787349,0.200906,-1.46967,0.347642,0.352741,-0.615997,1.25272},
+{1.09999,0.792396,-0.884367,-0.727592,0.784642,1.17963,-0.77986,-0.160579},
+{-1.05379,-0.0732156,1.59632,-0.132611,-0.169706,1.1097,0.543206,-0.45768},
+{0.707575,-0.166165,-0.10517,-0.384722,1.20009,0.203652,-1.55824,1.24602},
+{0.426702,-0.750799,-0.785802,0.106489,1.51227,0.957005,0.673555,-0.486873},
+{1.28994,-0.960517,0.545345,-0.159149,-0.32678,0.580855,-0.982405,1.49181},
+{0.741273,-0.0211484,-1.00192,1.6835,0.0392508,-1.07969,0.231873,0.672362},
+{-0.253722,1.1727,1.68946,0.493711,-0.0471442,-0.333803,-0.287764,-0.675685},
+{-1.32033,1.11807,0.0833384,0.562357,0.272908,-0.088752,1.31208,-0.778032},
+{-0.0803658,0.372868,0.449437,-1.40348,1.39748,0.966697,-0.814686,0.190767},
+{0.951774,0.427257,0.15036,-1.60358,1.14627,0.0810234,0.70735,-0.450667},
+{1.63808,0.109634,-0.99458,-0.434123,1.35836,-0.260683,-0.111738,0.185745},
+{-0.394671,-0.896337,0.646351,1.37455,0.625629,0.804453,0.458131,-0.811909},
+{0.0362565,-0.0235451,0.178868,-0.285337,0.0782079,-0.518704,0.189328,2.37162},
+{0.492691,1.13895,-0.86741,0.347883,-1.26497,0.380709,1.28738,-0.064377},
+{0.930297,1.28741,0.429463,0.245579,0.694034,-1.21605,-0.628591,0.0374087},
+{-0.199797,1.13671,-1.09067,1.37141,-0.517385,0.322349,0.764701,-0.852772},
+{-0.5007,0.303226,-0.0132675,-0.45596,-0.546562,0.277561,1.5487,1.46029},
+{1.65408,-0.842994,0.302966,-0.854034,0.662024,0.910017,-0.687823,0.250232},
+{1.12219,-0.5419,-0.336237,-0.655839,-0.373273,0.708425,1.64614,0.265602},
+{-0.743476,2.11592,-0.952805,0.264998,0.170145,-0.0560336,0.306247,-0.116348},
+{0.403037,-0.48668,0.817853,0.477643,-1.52252,0.964304,-0.546706,1.16473},
+{2.11011,-0.537778,-0.497273,0.602666,-0.48884,-0.125965,0.619928,-0.12306},
+{0.103031,1.79484,0.0818756,-1.13463,-0.13095,0.917941,0.259381,-0.552635},
+{0.428065,-0.557918,1.07281,-0.962703,1.37196,-0.963967,0.901819,-0.278916},
+{0.231896,0.041965,0.0632494,1.18255,-1.84059,1.07733,0.269347,-0.00577954},
+{0.557442,-1.02095,1.43921,-0.377425,-0.633907,1.32529,-0.709583,0.381231},
+{0.518884,1.09369,-1.13942,-0.105153,0.835027,-0.580586,-0.487998,1.39804},
+{-1.43902,-0.319956,-0.0826762,0.354559,1.1348,0.807323,0.546867,0.812576},
+{1.00645,-0.128206,0.28316,0.334308,-1.33777,-0.533485,1.17966,1.00905},
+{0.948813,0.119369,-1.01666,1.23683,0.105635,-0.459294,1.13103,-0.980494},
+{1.17283,-1.5799,1.33239,-0.485987,0.211327,0.169073,-0.387067,0.677013},
+{-0.247152,-0.0280727,-0.234614,1.39573,-0.963978,-0.0813067,-0.0728599,1.67411},
+{-0.449916,-0.274801,1.35576,0.451492,1.43631,0.141543,-0.896003,-0.0876196},
+{0.892366,-1.36578,0.444708,0.107565,1.44366,-0.755166,-0.0429619,0.585746},
+{0.939511,0.341971,-0.974305,0.928629,-1.00693,1.42408,-0.602308,0.126122},
+{-0.5307,-0.23615,1.20135,0.699046,-1.25741,-0.380481,1.25698,0.455196},
+{1.04482,1.14309,1.03158,0.939667,0.812349,0.425079,0.423823,0.0813321},
+{1.29549,-0.745042,-0.272242,1.15236,-0.838247,1.02629,0.227678,-0.774721},
+{0.981011,-1.45622,0.999967,0.725389,-1.11806,0.54881,0.176738,0.191717},
+{0.746684,-1.4211,1.37464,0.0883952,0.0254114,-0.573669,1.0495,-0.0720876},
+{0.565948,0.269033,-1.10345,1.01211,0.0768689,0.564008,-1.29685,1.19745},
+{1.84142,-1.60809,0.161708,0.38437,-0.0217134,0.210367,-0.0739498,0.363587},
+{-0.0523482,0.24593,-0.110338,0.493247,0.168289,-1.68577,0.925992,1.40436},
+{1.42867,-0.892126,0.262141,0.307225,-0.951306,1.38196,-0.728869,0.319043},
+{0.13951,-0.538299,-0.107962,0.370945,0.809012,1.83285,-0.951098,-0.0192296},
+{-0.24702,0.992114,-0.865963,0.681391,0.616911,-1.25823,1.37272,-0.405411},
+{1.55571,0.0192892,1.45179,0.186482,-0.152518,-0.257762,-0.833094,0.00577311},
+{-0.242198,-0.774192,-0.86156,0.991197,0.195455,0.670919,1.44314,0.515926},
+{0.405336,-0.228159,1.06259,-0.21443,-1.58614,1.13637,0.811685,-0.236429},
+{0.507745,0.074398,0.266039,-0.112387,0.977209,-0.600809,1.43474,-1.4099},
+{-0.0917663,0.669177,-0.911825,0.0500723,1.95743,0.0154906,-0.710767,0.243701},
+{0.481562,-0.951578,1.72838,-1.24032,0.629132,0.270267,0.185945,-0.0909246},
+{1.19697,-0.576168,-0.355474,1.184,1.18151,0.00954522,-0.758864,-0.38764},
+{1.36069,-0.965855,0.881144,-0.305908,-0.138624,0.95165,0.470982,-0.962228},
+{-0.412674,-0.162429,1.24246,0.215614,-0.190758,0.185485,-1.26035,1.59782},
+{1.7233,-1.02853,0.708902,-0.705601,0.736584,-0.463615,0.603755,-0.265125},
+{-0.171625,0.994245,-1.16615,1.47341,-0.906766,0.725075,-0.443446,0.507531},
+{-0.877189,1.47809,-0.597217,0.392568,-0.194374,0.270966,-0.589283,1.39253},
+{0.0658357,0.498163,-0.196594,0.147868,-0.348259,-0.196625,2.11986,-1.03849},
+{0.261188,0.170408,0.389773,0.034553,-0.891044,2.07769,-0.549077,-0.455646},
+{0.590399,-0.0467183,-1.27306,-0.617851,0.467039,0.87919,0.606851,1.28071},
+{-0.897853,0.713074,0.696729,-0.812095,1.4373,-0.592191,0.922986,-0.414167},
+{0.54709,0.646744,0.630487,1.50951,-0.345142,0.350881,-1.17514,-0.402886},
+{-0.0816486,0.289308,-0.293964,0.86241,-1.05741,1.40111,-1.11131,1.05698},
+{0.186736,0.0771509,1.41461,-1.00273,-0.153773,-0.114169,1.4834,-0.634813},
+{0.363376,0.423276,-1.35003,0.73783,1.35552,-1.15193,0.292795,0.411996},
+{0.731525,-1.33912,0.457722,1.0034,0.0192787,0.532992,-1.18752,0.913092},
+{-0.31047,1.2268,-1.553,1.20347,0.0226895,-0.455502,0.438372,0.527228},
+{-0.239933,1.39976,0.334577,1.10709,-0.871845,-1.04237,0.37649,0.427001},
+{0.971516,1.38103,-1.62783,0.60115,0.073291,0.180237,-0.252818,0.0398674},
+{1.10027,1.2861,-0.359542,-1.1075,-0.42857,-0.0905618,0.877396,0.683471},
+{-0.625662,-0.595133,1.40743,1.49617,-0.587654,-0.0180775,-0.155266,0.446349},
+{0.948704,0.636859,-0.179848,-0.685071,-1.20254,1.30743,0.10664,0.850157},
+{-0.097477,0.257188,0.40842,-1.28178,1.83085,-0.690013,-0.17072,0.73336},
+{1.88226,-0.462958,0.0975533,-0.398942,0.315353,-0.689253,0.0387385,1.21094},
+{0.139807,0.465299,0.548072,0.709881,1.07842,0.885513,1.30961,0.886652},
+{-0.294122,0.381301,-0.219781,-0.964707,0.404105,1.58573,1.13793,-0.482169},
+{0.377838,-0.0050249,0.535722,-1.15191,0.658768,-1.01305,1.19409,1.1331},
+{0.175,-0.0275022,-0.0336047,0.0388552,-0.180907,0.565689,-1.23001,2.13179},
+{0.931122,-0.787445,1.06286,-1.30927,1.16088,-0.357942,-0.230584,0.75641},
+{-0.451216,-0.159499,1.55692,-1.38334,0.764803,0.101408,-0.382677,0.980935}};
diff --git a/libspeex/testenc.c b/libspeex/testenc.c
index b7f0497..2175566 100644
--- a/libspeex/testenc.c
+++ b/libspeex/testenc.c
@@ -3,17 +3,19 @@
#include <stdlib.h>
#define FRAME_SIZE 160
-
+#include <math.h>
int main(int argc, char **argv)
{
char *inFile, *outFile;
FILE *fin, *fout;
short in[FRAME_SIZE];
- float input[FRAME_SIZE];
+ float input[FRAME_SIZE], bak[FRAME_SIZE], bak2[FRAME_SIZE];
int i;
EncState st;
FrameBits bits;
+ for (i=0;i<FRAME_SIZE;i++)
+ bak2[i]=0;
encoder_init(&st, &nb_mode);
if (argc != 3)
{
@@ -29,12 +31,24 @@ int main(int argc, char **argv)
{
fread(in, sizeof(short), FRAME_SIZE, fin);
for (i=0;i<FRAME_SIZE;i++)
- input[i]=in[i];
+ bak[i]=input[i]=in[i];
encode(&st, input, &bits);
+ {
+ float enoise=0, esig=0, snr;
+ for (i=0;i<FRAME_SIZE;i++)
+ {
+ enoise+=(bak2[i]-input[i])*(bak2[i]-input[i]);
+ esig += bak2[i]*bak2[i];
+ }
+ snr = 10*log10((esig+1)/(enoise+1));
+ printf ("real SNR = %f\n", snr);
+ }
/* Save the bits here */
frame_bits_reset(&bits);
for (i=0;i<FRAME_SIZE;i++)
in[i]=input[i];
+ for (i=0;i<FRAME_SIZE;i++)
+ bak2[i]=bak[i];
fwrite(in, sizeof(short), FRAME_SIZE, fout);
}