void levinson_durbin( scalar R[], /* order+1 autocorrelation coeff */ scalar lpcs[], /* order+1 LPC's */ int order /* order of the LPC analysis */ ) { scalar a[order+1][order+1]; scalar sum, e, k; int i,j; /* loop variables */ scalar ZERO = fl_to_numb(0.0); e = R[0]; /* Equation 38a, Makhoul */ for(i=1; i<=order; i++) { sum = ZERO; for(j=1; j<=i-1; j++) sum = s_add(sum, s_mul(a[i-1][j],R[i-j])); k = s_mul(-1.0, s_div(s_add(R[i], sum),e)); /* Equation 38b, Makhoul */ if (s_abs(k) > fl_to_numb(1.0)) k = ZERO; a[i][i] = k; for(j=1; j<=i-1; j++) a[i][j] = s_add(a[i-1][j] , s_mul(k,a[i-1][i-j])); /* Equation 38c, Makhoul */ e = s_mul(e, s_sub(fl_to_numb(1.0),s_mul(k,k))); /* Equation 38d, Makhoul */ } for(i=1; i<=order; i++) lpcs[i] = a[order][i]; lpcs[0] = fl_to_numb(1.0); }
void hanning_window( scalar Sn[], /* input frame of speech samples */ scalar Wn[], /* output frame of windowed samples */ int Nsam /* number of samples */ ) { int i; /* loop variable */ scalar HALF = fl_to_numb(0.5); scalar PI2_ = fl_to_numb(2*PI); scalar Nsam_ = int_to_numb(Nsam-1); for(i=0; i<Nsam; i++){ scalar sc_cos = s_mul(HALF,s_cos(s_mul( PI2_, s_div(fl_to_numb((float)i),Nsam_)))); scalar sc_a = s_sub(HALF, sc_cos); Wn[i] = s_mul(Sn[i], sc_a); } }
void *nlp_create( int m /* analysis window size */ ) { NLP *nlp; int i; assert(m <= PMAX_M); nlp = (NLP*)malloc(sizeof(NLP)); if (nlp == NULL) return NULL; nlp->m = m; scalar PI2_ = fl_to_numb(2*PI); scalar DEC_ = int_to_numb(m/DEC - 1); scalar HALF = fl_to_numb(.5); scalar ZERO = fl_to_numb(0.0); scalar a, b, c; for(i=0; i<m/DEC; i++) { a = s_div(s_mul(PI2_, int_to_numb(i) ) , DEC_); b = s_mul(HALF,s_cos(a)); nlp->w[i] = s_sub(HALF, b); //nlp->w[i] = 0.5 - 0.5*cosf(2*PI*i/(m/DEC-1)); } for(i=0; i<PMAX_M; i++) nlp->sq[i] = ZERO; nlp->mem_x = ZERO; nlp->mem_y = ZERO; for(i=0; i<NLP_NTAP; i++) nlp->mem_fir[i] = ZERO; nlp->fft_cfg = kiss_fft_alloc (PE_FFT_SIZE, 0, NULL, NULL); assert(nlp->fft_cfg != NULL); return (void*)nlp; }
void mp_sdiv(MINT *a, short n, MINT *q, short *r) { MINT x, y; short sign; sign = 1; x.len = a->len; x.val = a->val; if (n < 0) { sign = -sign; n = -n; } if (x.len < 0) { sign = -sign; x.len = -x.len; } s_div(&x, n, &y, r); _mp_xfree(q); q->val = y.val; q->len = sign * y.len; *r = *r * sign; }