Steve's patch to reduce memory use in the LPC arrays - thanks Steve
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 23 Jun 2014 20:52:07 +0000 (20:52 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 23 Jun 2014 20:52:07 +0000 (20:52 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1706 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/c2sim.c
codec2-dev/src/codec2.c
codec2-dev/src/defines.h
codec2-dev/src/fdmdv.c
codec2-dev/src/lpc.c
codec2-dev/src/lsp.c
codec2-dev/src/quantise.c
codec2-dev/src/quantise.h
codec2-dev/src/sine.c
codec2-dev/src/sine.h

index 9b3b8208f14e913b51f3b03189ed82f4661ce361..2099320431ad439635818484fa0e04f8d0afac56 100644 (file)
@@ -84,7 +84,7 @@ int main(int argc, char *argv[])
     char  phaseexp_arg[MAX_STR];
     float snr;
     float sum_snr;
-
+    int orderi;
     int lpc_model = 0, order = LPC_ORD;
     int lsp = 0, lspd = 0, lspvq = 0;
     int lspres = 0;
@@ -92,7 +92,7 @@ int main(int argc, char *argv[])
     int dt = 0, lspjvm = 0, lspanssi = 0, lspjnd = 0, lspmel = 0;
     int prede = 0;
     float pre_mem = 0.0, de_mem = 0.0;
-    float ak[LPC_MAX];
+    float ak[order];
     COMP  Sw_[FFT_ENC];
     COMP  Ew[FFT_ENC]; 
  
@@ -108,14 +108,14 @@ int main(int argc, char *argv[])
 
     MODEL prev_model, interp_model;
     int decimate = 0;
-    float lsps[LPC_MAX];
-    float prev_lsps[LPC_MAX], prev_lsps_[LPC_MAX];
-    float lsps__prev[LPC_MAX];
-    float lsps__prev2[LPC_MAX];
+    float lsps[order];
+    float prev_lsps[order], prev_lsps_[order];
+    float lsps__prev[order];
+    float lsps__prev2[order];
     float e, prev_e;
-    float ak_interp[LPC_MAX];
-    int   lsp_indexes[LPC_MAX];
-    float lsps_[LPC_MAX];
+    float ak_interp[order];
+    int   lsp_indexes[order];
+    float lsps_[order];
     float Woe_[2];
 
     void *nlp_states;
@@ -191,9 +191,9 @@ int main(int argc, char *argv[])
        //ex_phase[i] = (PI/3)*(float)rand()/RAND_MAX;
        ex_phase[i] = 0.0;
     }
-    for(i=0; i<LPC_ORD; i++) {
-       lsps_[i] = prev_lsps[i] = prev_lsps_[i] = i*PI/(LPC_ORD+1);
-       lsps__prev[i] = lsps__prev2[i] = i*PI/(LPC_ORD+1);
+    for(i=0; i<order; i++) {
+       lsps_[i] = prev_lsps[i] = prev_lsps_[i] = i*PI/(order+1);
+       lsps__prev[i] = lsps__prev2[i] = i*PI/(order+1);
     }
     e = prev_e = 1;
     hpf_states[0] = hpf_states[1] = 0.0;
@@ -219,11 +219,12 @@ int main(int argc, char *argv[])
         switch (opt) {
          case 0:
             if(strcmp(long_options[option_index].name, "lpc") == 0) {
-                order = atoi(optarg);
-                if((order < 4) || (order > 20)) {
-                    fprintf(stderr, "Error in LPC order: %s\n", optarg);
+                orderi = atoi(optarg);
+                if((orderi < 4) || (orderi > order)) {
+                    fprintf(stderr, "Error in LPC order (4 to %d): %s\n", order, optarg);
                     exit(1);
                 }
+                order = orderi;
             #ifdef DUMP
             } else if(strcmp(long_options[option_index].name, "dump") == 0) {
                 if (dump) 
@@ -264,7 +265,7 @@ int main(int argc, char *argv[])
                gain = atof(optarg);
            } else if(strcmp(long_options[option_index].name, "rate") == 0) {
                 if(strcmp(optarg,"3200") == 0) {
-                   lpc_model = 1; order = 10;
+                   lpc_model = 1;
                    scalar_quant_Wo_e = 1;
                    lspd = 1;
                    phase0 = 1;
@@ -272,7 +273,7 @@ int main(int argc, char *argv[])
                    decimate = 1;
                    lpcpf = 1;
                } else if(strcmp(optarg,"2400") == 0) {
-                   lpc_model = 1; order = 10;
+                   lpc_model = 1;
                    vector_quant_Wo_e = 1;
                    lsp = 1;
                    phase0 = 1;
@@ -280,7 +281,7 @@ int main(int argc, char *argv[])
                    decimate = 1;
                    lpcpf = 1;
                } else if(strcmp(optarg,"1400") == 0) {
-                   lpc_model = 1; order = 10;
+                   lpc_model = 1;
                    vector_quant_Wo_e = 1;
                    lsp = 1; lspdt = 1;
                    phase0 = 1;
@@ -289,7 +290,7 @@ int main(int argc, char *argv[])
                    dt = 1;
                    lpcpf = 1;
                 } else if(strcmp(optarg,"1200") == 0) {
-                   lpc_model = 1; order = 10;
+                   lpc_model = 1;
                    scalar_quant_Wo_e = 1;
                    lspjvm = 1; lspdt = 1;
                    phase0 = 1;
@@ -298,7 +299,7 @@ int main(int argc, char *argv[])
                    dt = 1;
                    lpcpf = 1;
                 } else {
-                    fprintf(stderr, "Error: invalid output rate %s\n", optarg);
+                    fprintf(stderr, "Error: invalid output rate (3200|2400|1400|1200) %s\n", optarg);
                     exit(1);
                 }
             }
@@ -425,7 +426,7 @@ int main(int argc, char *argv[])
 
        if (phase0) {
            float Wn[M];                        /* windowed speech samples */
-           float Rk[LPC_MAX+1];                /* autocorrelation coeffs  */
+           float Rk[order+1];                  /* autocorrelation coeffs  */
 
             #ifdef DUMP
            dump_phase(&model.phi[0], model.L);
@@ -447,7 +448,7 @@ int main(int argc, char *argv[])
 
            /* determine voicing */
 
-           snr = est_voicing_mbe(&model, Sw, W, Sw_, Ew, prev_uq_Wo);
+           snr = est_voicing_mbe(&model, Sw, W, Sw_, Ew);
 
            if (dump_pitch_e)
                fprintf(fjvm, "%f %f %d ", model.Wo, snr, model.voiced);
@@ -484,7 +485,7 @@ int main(int argc, char *argv[])
                e = speech_to_uq_lsps(lsps, ak, Sn, w, order);
 
             #ifdef DUMP
-           dump_ak(ak, LPC_ORD);
+           dump_ak(ak, order);
             #endif
        
            /* tracking down -ve energy values with BW expansion */
@@ -509,7 +510,7 @@ int main(int argc, char *argv[])
            /* dump order is different if we are decimating */
            if (!decimate)
                dump_lsp(lsps);
-           for(i=0; i<LPC_ORD; i++)
+           for(i=0; i<order; i++)
                prev_lsps[i] = lsps[i];
             #endif
 
@@ -711,7 +712,7 @@ int main(int argc, char *argv[])
            apply_lpc_correction(&model);
 
             #ifdef DUMP
-           dump_ak_(ak, LPC_ORD);
+           dump_ak_(ak, order);
             #endif
 
            /* note SNR on interpolated frames can't be measured properly
@@ -734,14 +735,14 @@ int main(int argc, char *argv[])
        \*------------------------------------------------------------*/
 
        if (decimate) {
-           float lsps_interp[LPC_ORD];
+           float lsps_interp[order];
 
            if (!phase0) {
                printf("needs --phase0 to resample phase for interpolated Wo\n");
                exit(0);
            }
            if (!lpc_model) {
-               printf("needs --lpc 10 to resample amplitudes\n");
+               printf("needs --lpc [order] to resample amplitudes\n");
                exit(0);
            }
 
@@ -772,19 +773,19 @@ int main(int argc, char *argv[])
                printf("  Wo: %1.5f  L: %d v1: %d prev_e: %f\n", 
                       interp_model.Wo, interp_model.L, interp_model.voiced, prev_e);
                printf("  lsps_interp: ");
-               for(i=0; i<LPC_ORD; i++)
+               for(i=0; i<order; i++)
                    printf("%5.3f  ", lsps_interp[i]);
                printf("\n  A..........: ");
-               for(i=0; i<10; i++)
+               for(i=0; i<order; i++)
                    printf("%5.3f  ",interp_model.A[i]);
 
                printf("\n  Wo: %1.5f  L: %d e: %3.2f v2: %d\n", 
                       model.Wo, model.L, e, model.voiced);
                printf("  lsps_......: ");
-               for(i=0; i<LPC_ORD; i++)
+               for(i=0; i<order; i++)
                    printf("%5.3f  ", lsps_[i]);
                printf("\n  A..........: ");
-               for(i=0; i<10; i++)
+               for(i=0; i<order; i++)
                    printf("%5.3f  ",model.A[i]);
                printf("\n");
                */
@@ -821,7 +822,7 @@ int main(int argc, char *argv[])
                /* update states for next time */
 
                prev_model = model;
-               for(i=0; i<LPC_ORD; i++)
+               for(i=0; i<order; i++)
                    prev_lsps_[i] = lsps_[i];
                prev_e = e;
            }
@@ -922,7 +923,7 @@ void print_help(const struct option* long_options, int num_opts, char* argv[])
                } else if (strcmp("dump_pitch_e", long_options[i].name) == 0) {
                        option_parameters = " <Dump File>";
                } else if (strcmp("rate", long_options[i].name) == 0) {
-                       option_parameters = " <4800|2400|1400|1200>";
+                       option_parameters = " <3200|2400|1400|1200>";
                } else if (strcmp("dump", long_options[i].name) == 0) {
                        option_parameters = " <DumpFilePrefix>";
                } else {
index f3cc4098d85f895b317dcafce73ab59cc97559aa..09dd757874b7eea94abe654aff010ad281414b6e 100644 (file)
@@ -1396,7 +1396,7 @@ void analyse_one_frame(struct CODEC2 *c2, MODEL *model, short speech[])
     TIMER_SAMPLE_AND_LOG(two_stage, model_start, "    two_stage"); 
     estimate_amplitudes(model, Sw, c2->W, 0);
     TIMER_SAMPLE_AND_LOG(estamps, two_stage, "    est_amps"); 
-    est_voicing_mbe(model, Sw, c2->W, Sw_, Ew, c2->prev_Wo_enc);
+    est_voicing_mbe(model, Sw, c2->W, Sw_, Ew);
     c2->prev_Wo_enc = model->Wo;
     TIMER_SAMPLE_AND_LOG2(estamps, "    est_voicing"); 
     #ifdef DUMP
index 4870770c9873e69fed4fe85a5fd8d48d90a13ac5..3c2b9cdbed3bdac33aed210816a658e2c0ed0839 100644 (file)
@@ -48,7 +48,6 @@
 #define FFT_DEC    512         /* size of FFT used in decoder          */
 #define TW         40          /* Trapezoidal synthesis window overlap */
 #define V_THRESH   6.0          /* voicing threshold in dB              */
-#define LPC_MAX    20          /* maximum LPC order                    */
 #define LPC_ORD    10          /* phase modelling LPC order            */
 
 /* Pitch estimation defines */
index 6c664f79e83c3d552704280c71aa60cd46aee7df..e58924da217f0fa6721940f379459d6c1a2195b3 100644 (file)
@@ -644,10 +644,10 @@ void lpf_peak_pick(float *foff, float *max, COMP pilot_baseband[],
 
     for(i=0; i<NPILOTLPF-nin; i++)
        pilot_lpf[i] = pilot_lpf[nin+i];
-    for(i=NPILOTLPF-nin, j=0; i<NPILOTLPF; i++,j++) {
+    for(i=NPILOTLPF-nin, j=NPILOTBASEBAND-nin; i<NPILOTLPF; i++,j++) {
        pilot_lpf[i].real = 0.0; pilot_lpf[i].imag = 0.0;
        for(k=0; k<NPILOTCOEFF; k++)
-           pilot_lpf[i] = cadd(pilot_lpf[i], fcmult(pilot_coeff[k], pilot_baseband[j+k]));
+           pilot_lpf[i] = cadd(pilot_lpf[i], fcmult(pilot_coeff[k], pilot_baseband[j-NPILOTCOEFF+1+k]));
     }
 
     /* decimate to improve DFT resolution, window and DFT */
index d03cb1782f9451b29539cc442c3a34425addf2da..66da9a9d8f77b2b17fcfebf9d1add881face3f38 100644 (file)
@@ -156,9 +156,9 @@ void levinson_durbin(
   int order            /* order of the LPC analysis */
 )
 {
-  float E[LPC_MAX+1];
-  float k[LPC_MAX+1];
-  float a[LPC_MAX+1][LPC_MAX+1];
+  float E[order+1];
+  float k[order+1];
+  float a[order+1][order+1];
   float sum;
   int i,j;                             /* loop variables */
 
@@ -269,10 +269,9 @@ void find_aks(
 )
 {
   float Wn[LPC_MAX_N]; /* windowed frame of Nsam speech samples */
-  float R[LPC_MAX+1];  /* order+1 autocorrelation values of Sn[] */
+  float R[order+1];    /* order+1 autocorrelation values of Sn[] */
   int i;
 
-  assert(order < LPC_MAX);
   assert(Nsam < LPC_MAX_N);
 
   hanning_window(Sn,Wn,Nsam);
index e708ec8c2b1172966266c94fa4594740e4d917c4..e47a5636ea90d8d0d827a7719ad0f68441d804a3 100644 (file)
@@ -34,8 +34,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#define LSP_MAX_ORDER  20
-
 /*---------------------------------------------------------------------------*\
 
   Introduction to Line Spectrum Pairs (LSPs)
 
 
 static float
-cheb_poly_eva(float *coef,float x,int m)
+cheb_poly_eva(float *coef,float x,int order)
 /*  float coef[]       coefficients of the polynomial to be evaluated  */
 /*  float x            the point where polynomial is to be evaluated   */
-/*  int m              order of the polynomial                         */
+/*  int order          order of the polynomial                         */
 {
     int i;
     float *t,*u,*v,sum;
-    float T[(LSP_MAX_ORDER / 2) + 1];
+    float T[(order / 2) + 1];
 
     /* Initialise pointers */
 
@@ -107,7 +105,7 @@ cheb_poly_eva(float *coef,float x,int m)
 
     /* Evaluate chebyshev series formulation using iterative approach  */
 
-    for(i=2;i<=m/2;i++)
+    for(i=2;i<=order/2;i++)
        *v++ = (2*x)*(*u++) - *t++;     /* T[i] = 2*x*T[i-1] - T[i-2]   */
 
     sum=0.0;                           /* initialise sum to zero       */
@@ -115,8 +113,8 @@ cheb_poly_eva(float *coef,float x,int m)
 
     /* Evaluate polynomial and return value also free memory space */
 
-    for(i=0;i<=m/2;i++)
-       sum+=coef[(m/2)-i]**t++;
+    for(i=0;i<=order/2;i++)
+       sum+=coef[(order/2)-i]**t++;
 
     return sum;
 }
@@ -132,9 +130,9 @@ cheb_poly_eva(float *coef,float x,int m)
 
 \*---------------------------------------------------------------------------*/
 
-int lpc_to_lsp (float *a, int lpcrdr, float *freq, int nb, float delta)
+int lpc_to_lsp (float *a, int order, float *freq, int nb, float delta)
 /*  float *a                   lpc coefficients                        */
-/*  int lpcrdr                 order of LPC coefficients (10)          */
+/*  int order                  order of LPC coefficients (10)          */
 /*  float *freq                LSP frequencies in radians              */
 /*  int nb                     number of sub-intervals (4)             */
 /*  float delta                        grid spacing interval (0.02)            */
@@ -149,11 +147,11 @@ int lpc_to_lsp (float *a, int lpcrdr, float *freq, int nb, float delta)
     float *pt;                 /* ptr used for cheb_poly_eval()
                                   whether P' or Q'                     */
     int roots=0;               /* number of roots found                */
-    float Q[LSP_MAX_ORDER + 1];
-    float P[LSP_MAX_ORDER + 1];
+    float Q[order + 1];
+    float P[order + 1];
 
     flag = 1;                  
-    m = lpcrdr/2;              /* order of P'(z) & Q'(z) polynimials   */
+    m = order/2;               /* order of P'(z) & Q'(z) polynimials   */
 
     /* Allocate memory space for polynomials */
 
@@ -167,8 +165,8 @@ int lpc_to_lsp (float *a, int lpcrdr, float *freq, int nb, float delta)
     *px++ = 1.0;
     *qx++ = 1.0;
     for(i=1;i<=m;i++){
-       *px++ = a[i]+a[lpcrdr+1-i]-*p++;
-       *qx++ = a[i]-a[lpcrdr+1-i]+*q++;
+       *px++ = a[i]+a[order+1-i]-*p++;
+       *qx++ = a[i]-a[order+1-i]+*q++;
     }
     px = P;
     qx = Q;
@@ -188,17 +186,17 @@ int lpc_to_lsp (float *a, int lpcrdr, float *freq, int nb, float delta)
     xl = 1.0;                  /* start at point xl = 1                */
 
 
-    for(j=0;j<lpcrdr;j++){
+    for(j=0;j<order;j++){
        if(j%2)                 /* determines whether P' or Q' is eval. */
            pt = qx;
        else
            pt = px;
 
-       psuml = cheb_poly_eva(pt,xl,lpcrdr);    /* evals poly. at xl    */
+       psuml = cheb_poly_eva(pt,xl,order);     /* evals poly. at xl    */
        flag = 1;
        while(flag && (xr >= -1.0)){
            xr = xl - delta ;                   /* interval spacing     */
-           psumr = cheb_poly_eva(pt,xr,lpcrdr);/* poly(xl-delta_x)     */
+           psumr = cheb_poly_eva(pt,xr,order);/* poly(xl-delta_x)      */
            temp_psumr = psumr;
            temp_xr = xr;
 
@@ -217,7 +215,7 @@ int lpc_to_lsp (float *a, int lpcrdr, float *freq, int nb, float delta)
                psumm=psuml;
                for(k=0;k<=nb;k++){
                    xm = (xl+xr)/2;             /* bisect the interval  */
-                   psumm=cheb_poly_eva(pt,xm,lpcrdr);
+                   psumm=cheb_poly_eva(pt,xm,order);
                    if(psumm*psuml>0.){
                        psuml=psumm;
                        xl=xm;
@@ -242,7 +240,7 @@ int lpc_to_lsp (float *a, int lpcrdr, float *freq, int nb, float delta)
 
     /* convert from x domain to radians */
 
-    for(i=0; i<lpcrdr; i++) {
+    for(i=0; i<order; i++) {
        freq[i] = acos(freq[i]);
     }
 
@@ -260,30 +258,29 @@ int lpc_to_lsp (float *a, int lpcrdr, float *freq, int nb, float delta)
 
 \*---------------------------------------------------------------------------*/
 
-void lsp_to_lpc(float *lsp, float *ak, int lpcrdr)
+void lsp_to_lpc(float *lsp, float *ak, int order)
 /*  float *freq         array of LSP frequencies in radians            */
 /*  float *ak          array of LPC coefficients                       */
-/*  int lpcrdr         order of LPC coefficients                       */
+/*  int order          order of LPC coefficients                       */
 
 
 {
     int i,j;
     float xout1,xout2,xin1,xin2;
     float *pw,*n1,*n2,*n3,*n4 = 0;
-    int m = lpcrdr/2;
-    float freq[LSP_MAX_ORDER];
-    float Wp[(LSP_MAX_ORDER * 4) + 2];
+    float freq[order];
+    float Wp[(order * 4) + 2];
     
     /* convert from radians to the x=cos(w) domain */
 
-    for(i=0; i<lpcrdr; i++)
+    for(i=0; i<order; i++)
        freq[i] = cos(lsp[i]);
 
     pw = Wp;
 
     /* initialise contents of array */
 
-    for(i=0;i<=4*m+1;i++){             /* set contents of buffer to 0 */
+    for(i=0;i<=4*(order/2)+1;i++){             /* set contents of buffer to 0 */
        *pw++ = 0.0;
     }
 
@@ -296,8 +293,8 @@ void lsp_to_lpc(float *lsp, float *ak, int lpcrdr)
     /* reconstruct P(z) and Q(z) by cascading second order polynomials
       in form 1 - 2xz(-1) +z(-2), where x is the LSP coefficient */
 
-    for(j=0;j<=lpcrdr;j++){
-       for(i=0;i<m;i++){
+    for(j=0;j<=order;j++){
+       for(i=0;i<(order/2);i++){
            n1 = pw+(i*4);
            n2 = n1 + 1;
            n3 = n2 + 1;
index a8bc71e4f7ef23a3951826da265d7b6688ccaa5e..b3431bd10e39f95b8d61091651ac867c121a53ce 100644 (file)
@@ -147,16 +147,14 @@ void encode_lspds_scalar(
 ) 
 {
     int   i,k,m;
-    float lsp_hz[LPC_MAX];
-    float lsp__hz[LPC_MAX];
-    float dlsp[LPC_MAX];
-    float dlsp_[LPC_MAX];
-    float wt[LPC_MAX];
+    float lsp_hz[order];
+    float lsp__hz[order];
+    float dlsp[order];
+    float dlsp_[order];
+    float wt[order];
     const float *cb;
     float se;
 
-    assert(order == LPC_ORD);
-
     for(i=0; i<order; i++) {
        wt[i] = 1.0;
     }
@@ -203,12 +201,10 @@ void decode_lspds_scalar(
 ) 
 {
     int   i,k;
-    float lsp__hz[LPC_MAX];
-    float dlsp_[LPC_MAX];
+    float lsp__hz[order];
+    float dlsp_[order];
     const float *cb;
 
-    assert(order == LPC_ORD);
-
      for(i=0; i<order; i++) {
 
        k = lsp_cbd[i].k;
@@ -243,12 +239,12 @@ void lspvq_quantise(
 ) 
 {
     int   i,k,m,ncb, nlsp;
-    float  wt[LPC_ORD], lsp_hz[LPC_ORD];
+    float  wt[order], lsp_hz[order];
     const float *cb;
     float se;
     int   index;
 
-    for(i=0; i<LPC_ORD; i++) {
+    for(i=0; i<order; i++) {
        wt[i] = 1.0;
        lsp_hz[i] = 4000.0*lsp[i]/PI;
     }
@@ -282,7 +278,7 @@ void lspvq_quantise(
     m = lsp_cbjnd[ncb].m;
     cb = lsp_cbjnd[ncb].cb;
     index = quantise(cb, &lsp_hz[nlsp], &wt[nlsp], k, m, &se);
-    for(i=4; i<LPC_ORD; i++) {
+    for(i=4; i<order; i++) {
        lsp_[i] = cb[index*k+i-4]*(PI/4000.0);
        //printf("%4.f (%4.f) ", lsp_hz[i], cb[index*k+i-4]);
     }
@@ -299,18 +295,18 @@ void lspvq_quantise(
 void lspjnd_quantise(float lsps[], float lsps_[], int order) 
 {
     int   i,k,m;
-    float  wt[LPC_ORD], lsps_hz[LPC_ORD];
+    float  wt[order], lsps_hz[order];
     const float *cb;
     float se = 0.0;
     int   index;
  
-    for(i=0; i<LPC_ORD; i++) {
+    for(i=0; i<order; i++) {
        wt[i] = 1.0;
     }
 
     /* convert to Hz */
 
-    for(i=0; i<LPC_ORD; i++) {
+    for(i=0; i<order; i++) {
        lsps_hz[i] = lsps[i]*(4000.0/PI);
        lsps_[i] = lsps[i];
     }
@@ -333,7 +329,7 @@ void lspjnd_quantise(float lsps[], float lsps_[], int order)
     index = quantise(cb, &lsps_hz[4], &wt[4], k, m, &se);
     //printf("k = %d m = %d c[0] %f cb[k] %f\n", k,m,cb[0],cb[k]);
     //printf("index = %4d: ", index);
-    for(i=4; i<LPC_ORD; i++) {
+    for(i=4; i<order; i++) {
        lsps_[i] = cb[index*k+i-4]*(PI/4000.0);
        //printf("%4.f (%4.f) ", lsps_hz[i], cb[index*k+i-4]);
     }
@@ -416,6 +412,7 @@ void compute_weights(const float *x, float *w, int ndim)
   //w[1]*=2;
 }
 
+#ifdef __EXPERIMENTAL__
 /* LSP weight calculation ported from m-file function kindly submitted
    by Anssi, OH3GDD */
 
@@ -448,6 +445,7 @@ void compute_weights_anssi_mode2(const float *x, float *w, int ndim)
         w[i]=pow(w[i]+0.3, 0.66);
   }
 }
+#endif
 
 int find_nearest(const float *codebook, int nb_entries, float *x, int ndim)
 {
@@ -489,43 +487,43 @@ int find_nearest_weighted(const float *codebook, int nb_entries, float *x, const
   return nearest;
 }
 
-void lspjvm_quantise(float *x, float *xq, int ndim)
+void lspjvm_quantise(float *x, float *xq, int order)
 {
   int i, n1, n2, n3;
-  float err[LPC_ORD], err2[LPC_ORD], err3[LPC_ORD];
-  float w[LPC_ORD], w2[LPC_ORD], w3[LPC_ORD];
+  float err[order], err2[order], err3[order];
+  float w[order], w2[order], w3[order];
   const float *codebook1 = lsp_cbjvm[0].cb;
   const float *codebook2 = lsp_cbjvm[1].cb;
   const float *codebook3 = lsp_cbjvm[2].cb;
 
   w[0] = MIN(x[0], x[1]-x[0]);
-  for (i=1;i<ndim-1;i++)
+  for (i=1;i<order-1;i++)
     w[i] = MIN(x[i]-x[i-1], x[i+1]-x[i]);
-  w[ndim-1] = MIN(x[ndim-1]-x[ndim-2], PI-x[ndim-1]);
+  w[order-1] = MIN(x[order-1]-x[order-2], PI-x[order-1]);
   
-  compute_weights(x, w, ndim);
+  compute_weights(x, w, order);
   
-  n1 = find_nearest(codebook1, lsp_cbjvm[0].m, x, ndim);
+  n1 = find_nearest(codebook1, lsp_cbjvm[0].m, x, order);
   
-  for (i=0;i<ndim;i++)
+  for (i=0;i<order;i++)
   {
-    xq[i] = codebook1[ndim*n1+i];
+    xq[i] = codebook1[order*n1+i];
     err[i] = x[i] - xq[i];
   }
-  for (i=0;i<ndim/2;i++)
+  for (i=0;i<order/2;i++)
   {
     err2[i] = err[2*i];  
     err3[i] = err[2*i+1];
     w2[i] = w[2*i];  
     w3[i] = w[2*i+1];
   }
-  n2 = find_nearest_weighted(codebook2, lsp_cbjvm[1].m, err2, w2, ndim/2);
-  n3 = find_nearest_weighted(codebook3, lsp_cbjvm[2].m, err3, w3, ndim/2);
+  n2 = find_nearest_weighted(codebook2, lsp_cbjvm[1].m, err2, w2, order/2);
+  n3 = find_nearest_weighted(codebook3, lsp_cbjvm[2].m, err3, w3, order/2);
   
-  for (i=0;i<ndim/2;i++)
+  for (i=0;i<order/2;i++)
   {
-    xq[2*i] += codebook2[ndim*n2/2+i];
-    xq[2*i+1] += codebook3[ndim*n3/2+i];
+    xq[2*i] += codebook2[order*n2/2+i];
+    xq[2*i+1] += codebook3[order*n3/2+i];
   }
 }
 
@@ -727,13 +725,13 @@ void lspanssi_quantise(float *x, float *xq, int ndim, int mbest_entries)
 }
 #endif
 
-int check_lsp_order(float lsp[], int lpc_order)
+int check_lsp_order(float lsp[], int order)
 {
     int   i;
     float tmp;
     int   swaps = 0;
 
-    for(i=1; i<lpc_order; i++)
+    for(i=1; i<order; i++)
        if (lsp[i] < lsp[i-1]) {
            //fprintf(stderr, "swap %d\n",i);
            swaps++;
@@ -746,11 +744,11 @@ int check_lsp_order(float lsp[], int lpc_order)
     return swaps;
 }
 
-void force_min_lsp_dist(float lsp[], int lpc_order)
+void force_min_lsp_dist(float lsp[], int order)
 {
     int   i;
 
-    for(i=1; i<lpc_order; i++)
+    for(i=1; i<order; i++)
        if ((lsp[i]-lsp[i-1]) < 0.01) {
            lsp[i] += 0.01;
        }
@@ -786,7 +784,7 @@ void force_min_lsp_dist(float lsp[], int lpc_order)
 
 \*---------------------------------------------------------------------------*/
 
-void lpc_post_filter(kiss_fft_cfg fft_fwd_cfg, MODEL *model, COMP Pw[], float ak[], 
+void lpc_post_filter(kiss_fft_cfg fft_fwd_cfg, COMP Pw[], float ak[], 
                      int order, int dump, float beta, float gamma, int bass_boost)
 {
     int   i;
@@ -969,7 +967,7 @@ void aks_to_M2(
   TIMER_SAMPLE_AND_LOG(tpw, tfft, "      Pw"); 
 
   if (pf)
-      lpc_post_filter(fft_fwd_cfg, model, Pw, ak, order, dump, beta, gamma, bass_boost);
+      lpc_post_filter(fft_fwd_cfg, Pw, ak, order, dump, beta, gamma, bass_boost);
 
   TIMER_SAMPLE_AND_LOG(tpf, tpw, "      LPC post filter"); 
 
@@ -1166,7 +1164,7 @@ float speech_to_uq_lsps(float lsp[],
 {
     int   i, roots;
     float Wn[M];
-    float R[LPC_MAX+1];
+    float R[order+1];
     float e, E;
 
     e = 0.0;
@@ -1223,7 +1221,7 @@ void encode_lsps_scalar(int indexes[], float lsp[], int order)
 {
     int    i,k,m;
     float  wt[1];
-    float  lsp_hz[LPC_MAX];
+    float  lsp_hz[order];
     const float * cb;
     float se;
 
@@ -1258,7 +1256,7 @@ void encode_lsps_scalar(int indexes[], float lsp[], int order)
 void decode_lsps_scalar(float lsp[], int indexes[], int order)
 {
     int    i,k;
-    float  lsp_hz[LPC_MAX];
+    float  lsp_hz[order];
     const float * cb;
 
     for(i=0; i<order; i++) {
@@ -1292,15 +1290,15 @@ void decode_lsps_scalar(float lsp[], int indexes[], int order)
 void encode_lsps_diff_freq_vq(int indexes[], float lsp[], int order)
 {
     int    i,k,m;
-    float  lsp_hz[LPC_MAX];
-    float lsp__hz[LPC_MAX];
-    float dlsp[LPC_MAX];
-    float dlsp_[LPC_MAX];
-    float wt[LPC_MAX];
+    float  lsp_hz[order];
+    float lsp__hz[order];
+    float dlsp[order];
+    float dlsp_[order];
+    float wt[order];
     const float * cb;
     float se;
 
-    for(i=0; i<LPC_ORD; i++) {
+    for(i=0; i<order; i++) {
        wt[i] = 1.0;
     }
 
@@ -1354,8 +1352,8 @@ void encode_lsps_diff_freq_vq(int indexes[], float lsp[], int order)
 void decode_lsps_diff_freq_vq(float lsp_[], int indexes[], int order)
 {
     int    i,k,m;
-    float  dlsp_[LPC_MAX];
-    float  lsp__hz[LPC_MAX];
+    float  dlsp_[order];
+    float  lsp__hz[order];
     const float * cb;
 
     /* scalar LSP differences */
@@ -1401,7 +1399,7 @@ void encode_lsps_diff_time(int indexes[],
                               int order)
 {
     int    i,k,m;
-    float  lsps_dt[LPC_ORD];
+    float  lsps_dt[order];
     float  wt[LPC_MAX];
     const  float * cb;
     float  se;
@@ -1409,7 +1407,7 @@ void encode_lsps_diff_time(int indexes[],
     /* Determine difference in time and convert from radians to Hz so
        we can use human readable frequencies */
 
-    for(i=0; i<LPC_ORD; i++) {
+    for(i=0; i<order; i++) {
        lsps_dt[i] = (4000/PI)*(lsps[i] - lsps__prev[i]);
     }
     
@@ -1468,40 +1466,38 @@ void decode_lsps_diff_time(
 
 \*---------------------------------------------------------------------------*/
 
-void encode_lsps_vq(int *indexes, float *x, float *xq, int ndim)
+void encode_lsps_vq(int *indexes, float *x, float *xq, int order)
 {
   int i, n1, n2, n3;
-  float err[LPC_ORD], err2[LPC_ORD], err3[LPC_ORD];
-  float w[LPC_ORD], w2[LPC_ORD], w3[LPC_ORD];
+  float err[order], err2[order], err3[order];
+  float w[order], w2[order], w3[order];
   const float *codebook1 = lsp_cbjvm[0].cb;
   const float *codebook2 = lsp_cbjvm[1].cb;
   const float *codebook3 = lsp_cbjvm[2].cb;
 
-  assert(ndim <= LPC_ORD);
-
   w[0] = MIN(x[0], x[1]-x[0]);
-  for (i=1;i<ndim-1;i++)
+  for (i=1;i<order-1;i++)
     w[i] = MIN(x[i]-x[i-1], x[i+1]-x[i]);
-  w[ndim-1] = MIN(x[ndim-1]-x[ndim-2], PI-x[ndim-1]);
+  w[order-1] = MIN(x[order-1]-x[order-2], PI-x[order-1]);
   
-  compute_weights(x, w, ndim);
+  compute_weights(x, w, order);
   
-  n1 = find_nearest(codebook1, lsp_cbjvm[0].m, x, ndim);
+  n1 = find_nearest(codebook1, lsp_cbjvm[0].m, x, order);
   
-  for (i=0;i<ndim;i++)
+  for (i=0;i<order;i++)
   {
-    xq[i]  = codebook1[ndim*n1+i];
+    xq[i]  = codebook1[order*n1+i];
     err[i] = x[i] - xq[i];
   }
-  for (i=0;i<ndim/2;i++)
+  for (i=0;i<order/2;i++)
   {
     err2[i] = err[2*i];  
     err3[i] = err[2*i+1];
     w2[i] = w[2*i];  
     w3[i] = w[2*i+1];
   }
-  n2 = find_nearest_weighted(codebook2, lsp_cbjvm[1].m, err2, w2, ndim/2);
-  n3 = find_nearest_weighted(codebook3, lsp_cbjvm[2].m, err3, w3, ndim/2);
+  n2 = find_nearest_weighted(codebook2, lsp_cbjvm[1].m, err2, w2, order/2);
+  n3 = find_nearest_weighted(codebook3, lsp_cbjvm[2].m, err3, w3, order/2);
   
   indexes[0] = n1;
   indexes[1] = n2;
@@ -1517,7 +1513,7 @@ void encode_lsps_vq(int *indexes, float *x, float *xq, int ndim)
 
 \*---------------------------------------------------------------------------*/
 
-void decode_lsps_vq(int *indexes, float *xq, int ndim)
+void decode_lsps_vq(int *indexes, float *xq, int order)
 {
   int i, n1, n2, n3;
   const float *codebook1 = lsp_cbjvm[0].cb;
@@ -1528,14 +1524,14 @@ void decode_lsps_vq(int *indexes, float *xq, int ndim)
   n2 = indexes[1];
   n3 = indexes[2];
 
-  for (i=0;i<ndim;i++)
+  for (i=0;i<order;i++)
   {
-    xq[i] = codebook1[ndim*n1+i];
+    xq[i] = codebook1[order*n1+i];
   }
-  for (i=0;i<ndim/2;i++)
+  for (i=0;i<order/2;i++)
   {
-    xq[2*i] += codebook2[ndim*n2/2+i];
-    xq[2*i+1] += codebook3[ndim*n3/2+i];
+    xq[2*i] += codebook2[order*n2/2+i];
+    xq[2*i+1] += codebook3[order*n3/2+i];
   }
 }
 
@@ -1775,7 +1771,7 @@ float decode_amplitudes(kiss_fft_cfg  fft_fwd_cfg,
 
 static float ge_coeff[2] = {0.8, 0.9};
 
-void compute_weights2(const float *x, const float *xp, float *w, int ndim)
+void compute_weights2(const float *x, const float *xp, float *w)
 {
   w[0] = 30;
   w[1] = 1;
@@ -1855,7 +1851,7 @@ void quantise_WoE(MODEL *model, float *e, float xq[])
   x[0] = log10f((model->Wo/PI)*4000.0/50.0)/log10f(2);
   x[1] = 10.0*log10f(1e-4 + *e);
 
-  compute_weights2(x, xq, w, ndim);
+  compute_weights2(x, xq, w);
   for (i=0;i<ndim;i++)
     err[i] = x[i]-ge_coeff[i]*xq[i];
   n1 = find_nearest_weighted(codebook1, nb_entries, err, w, ndim);
@@ -1913,7 +1909,7 @@ int encode_WoE(MODEL *model, float e, float xq[])
   x[0] = log10f((model->Wo/PI)*4000.0/50.0)/log10f(2);
   x[1] = 10.0*log10f(1e-4 + e);
 
-  compute_weights2(x, xq, w, ndim);
+  compute_weights2(x, xq, w);
   for (i=0;i<ndim;i++)
     err[i] = x[i]-ge_coeff[i]*xq[i];
   n1 = find_nearest_weighted(codebook1, nb_entries, err, w, ndim);
index 007d34d6f115b49e968b33e58afcc115ae1b8904..7e8b3836e22a5a2c2af37283830d1ca06985f37e 100644 (file)
@@ -78,8 +78,8 @@ void decode_lsps_diff_time(float lsp_[],
                           float lsp__prev[],
                           int order);
 
-void encode_lsps_vq(int *indexes, float *x, float *xq, int ndim);
-void decode_lsps_vq(int *indexes, float *xq, int ndim);
+void encode_lsps_vq(int *indexes, float *x, float *xq, int order);
+void decode_lsps_vq(int *indexes, float *xq, int order);
 
 long quantise(const float * cb, float vec[], float w[], int k, int m, float *se);
 void lspvq_quantise(float lsp[], float lsp_[], int order); 
index 254a61ec7fc8e7e4fb8a02b0e34b708491690bb3..44018ee680d062a4d823059deed047c1aa5382a5 100644 (file)
@@ -391,8 +391,7 @@ float est_voicing_mbe(
     COMP   W[],
     COMP   Sw_[],         /* DFT of all voiced synthesised signal  */
                           /* useful for debugging/dump file        */
-    COMP   Ew[],          /* DFT of error                          */
-    float prev_Wo)
+    COMP   Ew[])          /* DFT of error                          */
 {
     int   i,l,al,bl,m;    /* loop variables */
     COMP  Am;             /* amplitude sample for this band */
index da7dc28ed2b7361417b676b84f8ed4e380d4c85b..c7c52cc1b439081fa94c38e7a76c3dcf138d6991 100644 (file)
@@ -37,8 +37,7 @@ float hpf(float x, float states[]);
 void dft_speech(kiss_fft_cfg fft_fwd_cfg, COMP Sw[], float Sn[], float w[]);
 void two_stage_pitch_refinement(MODEL *model, COMP Sw[]);
 void estimate_amplitudes(MODEL *model, COMP Sw[], COMP W[], int est_phase);
-float est_voicing_mbe(MODEL *model, COMP Sw[], COMP W[], COMP Sw_[],COMP Ew[], 
-                     float prev_Wo);
+float est_voicing_mbe(MODEL *model, COMP Sw[], COMP W[], COMP Sw_[],COMP Ew[]);
 void make_synthesis_window(float Pn[]);
 void synthesise(kiss_fft_cfg fft_inv_cfg, float Sn_[], MODEL *model, float Pn[], int shift);