From a2664186d385dcb503eef47e9742119157fac142 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Mon, 23 Jun 2014 20:52:07 +0000 Subject: [PATCH] Steve's patch to reduce memory use in the LPC arrays - thanks Steve git-svn-id: https://svn.code.sf.net/p/freetel/code@1706 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/src/c2sim.c | 67 ++++++++--------- codec2-dev/src/codec2.c | 2 +- codec2-dev/src/defines.h | 1 - codec2-dev/src/fdmdv.c | 4 +- codec2-dev/src/lpc.c | 9 ++- codec2-dev/src/lsp.c | 55 +++++++------- codec2-dev/src/quantise.c | 146 ++++++++++++++++++-------------------- codec2-dev/src/quantise.h | 4 +- codec2-dev/src/sine.c | 3 +- codec2-dev/src/sine.h | 3 +- 10 files changed, 142 insertions(+), 152 deletions(-) diff --git a/codec2-dev/src/c2sim.c b/codec2-dev/src/c2sim.c index 9b3b8208..20993204 100644 --- a/codec2-dev/src/c2sim.c +++ b/codec2-dev/src/c2sim.c @@ -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 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; iW, 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 diff --git a/codec2-dev/src/defines.h b/codec2-dev/src/defines.h index 4870770c..3c2b9cdb 100644 --- a/codec2-dev/src/defines.h +++ b/codec2-dev/src/defines.h @@ -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 */ diff --git a/codec2-dev/src/fdmdv.c b/codec2-dev/src/fdmdv.c index 6c664f79..e58924da 100644 --- a/codec2-dev/src/fdmdv.c +++ b/codec2-dev/src/fdmdv.c @@ -644,10 +644,10 @@ void lpf_peak_pick(float *foff, float *max, COMP pilot_baseband[], for(i=0; i #include -#define LSP_MAX_ORDER 20 - /*---------------------------------------------------------------------------*\ Introduction to Line Spectrum Pairs (LSPs) @@ -88,14 +86,14 @@ 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= -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; iWo/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;iWo/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