/* Copyright (C) 2002-2006 Jean-Marc Valin File: filters.c Various analysis/synthesis filters Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Xiph.org Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "filters.h" #include "stack_alloc.h" #include "misc.h" #include "math_approx.h" #include "ltp.h" #include #ifdef _USE_SSE #include "filters_sse.h" #elif defined (ARM4_ASM) || defined(ARM5E_ASM) #include "filters_arm4.h" #elif defined (BFIN_ASM) #include "filters_bfin.h" #endif void bw_lpc(spx_word16_t gamma, const spx_coef_t *lpc_in, spx_coef_t *lpc_out, int order) { int i; spx_word16_t tmp=gamma; for (i=0;i4) filtID=4; den = Pcoef[filtID]; num = Zcoef[filtID]; /*return;*/ for (i=0;i SHL32(EXTEND32(SIG_SCALING), 8)) { spx_word16_t scale_1; scale = PSHR32(scale, SIG_SHIFT); scale_1 = EXTRACT16(PDIV32_16(SHL32(EXTEND32(SIG_SCALING),7),scale)); for (i=0;i SHR32(EXTEND32(SIG_SCALING), 2)) { spx_word16_t scale_1; scale = PSHR32(scale, SIG_SHIFT-5); scale_1 = DIV32_16(SHL32(EXTEND32(SIG_SCALING),3),scale); for (i=0;i max_val) max_val = tmp; } sig_shift=0; while (max_val>16383) { sig_shift++; max_val >>= 1; } for (i=0;i max_val) max_val = tmp; } if (max_val>16383) { spx_word32_t sum=0; for (i=0;i= max_val) max_val = tmp; } sig_shift=0; while (max_val>max_scale) { sig_shift++; max_val >>= 1; } for (i=0;i>1; for (i=0;i7) i2 = 7; for (k=i1;k maxcorr) { maxcorr = corr[i][j]; maxi=i; maxj=j; } } } for (i=0;i0) { for (k=0;k<7;k++) { tmp += MULT16_16(exc[i-(pitch-maxj+3)+k-3],shift_filt[maxi-1][k]); } } else { tmp = SHL32(exc[i-(pitch-maxj+3)],15); } interp[i] = PSHR32(tmp,15); } return pitch-maxj+3; } void multicomb( spx_word16_t *exc, /*decoded excitation*/ spx_word16_t *new_exc, /*enhanced excitation*/ spx_coef_t *ak, /*LPC filter coefs*/ int p, /*LPC order*/ int nsf, /*sub-frame size*/ int pitch, /*pitch period*/ int max_pitch, spx_word16_t comb_gain, /*gain of comb filter*/ char *stack ) { int i; VARDECL(spx_word16_t *iexc); spx_word16_t old_ener, new_ener; int corr_pitch; spx_word16_t iexc0_mag, iexc1_mag, exc_mag; spx_word32_t corr0, corr1; spx_word16_t gain0, gain1; spx_word16_t pgain1, pgain2; spx_word16_t c1, c2; spx_word16_t g1, g2; spx_word16_t ngain; spx_word16_t gg1, gg2; #ifdef FIXED_POINT int scaledown=0; #endif #if 0 /* Set to 1 to enable full pitch search */ int nol_pitch[6]; spx_word16_t nol_pitch_coef[6]; spx_word16_t ol_pitch_coef; open_loop_nbest_pitch(exc, 20, 120, nsf, nol_pitch, nol_pitch_coef, 6, stack); corr_pitch=nol_pitch[0]; ol_pitch_coef = nol_pitch_coef[0]; /*Try to remove pitch multiples*/ for (i=1;i<6;i++) { #ifdef FIXED_POINT if ((nol_pitch_coef[i]>MULT16_16_Q15(nol_pitch_coef[0],19661)) && #else if ((nol_pitch_coef[i]>.6*nol_pitch_coef[0]) && #endif (ABS(2*nol_pitch[i]-corr_pitch)<=2 || ABS(3*nol_pitch[i]-corr_pitch)<=3 || ABS(4*nol_pitch[i]-corr_pitch)<=4 || ABS(5*nol_pitch[i]-corr_pitch)<=5)) { corr_pitch = nol_pitch[i]; } } #else corr_pitch = pitch; #endif ALLOC(iexc, 2*nsf, spx_word16_t); interp_pitch(exc, iexc, corr_pitch, 80); if (corr_pitch>max_pitch) interp_pitch(exc, iexc+nsf, 2*corr_pitch, 80); else interp_pitch(exc, iexc+nsf, -corr_pitch, 80); #ifdef FIXED_POINT for (i=0;i16383) { scaledown = 1; break; } } if (scaledown) { for (i=0;i MULT16_16(iexc0_mag,exc_mag)) pgain1 = QCONST16(1., 14); else pgain1 = PDIV32_16(SHL32(PDIV32(corr0, exc_mag),14),iexc0_mag); if (corr1 > MULT16_16(iexc1_mag,exc_mag)) pgain2 = QCONST16(1., 14); else pgain2 = PDIV32_16(SHL32(PDIV32(corr1, exc_mag),14),iexc1_mag); gg1 = PDIV32_16(SHL32(EXTEND32(exc_mag),8), iexc0_mag); gg2 = PDIV32_16(SHL32(EXTEND32(exc_mag),8), iexc1_mag); if (comb_gain>0) { #ifdef FIXED_POINT c1 = (MULT16_16_Q15(QCONST16(.4,15),comb_gain)+QCONST16(.07,15)); c2 = QCONST16(.5,15)+MULT16_16_Q14(QCONST16(1.72,14),(c1-QCONST16(.07,15))); #else c1 = .4*comb_gain+.07; c2 = .5+1.72*(c1-.07); #endif } else { c1=c2=0; } #ifdef FIXED_POINT g1 = 32767 - MULT16_16_Q13(MULT16_16_Q15(c2, pgain1),pgain1); g2 = 32767 - MULT16_16_Q13(MULT16_16_Q15(c2, pgain2),pgain2); #else g1 = 1-c2*pgain1*pgain1; g2 = 1-c2*pgain2*pgain2; #endif if (g1max_pitch) { gain0 = MULT16_16_Q15(QCONST16(.7,15),MULT16_16_Q14(g1,gg1)); gain1 = MULT16_16_Q15(QCONST16(.3,15),MULT16_16_Q14(g2,gg2)); } else { gain0 = MULT16_16_Q15(QCONST16(.6,15),MULT16_16_Q14(g1,gg1)); gain1 = MULT16_16_Q15(QCONST16(.6,15),MULT16_16_Q14(g2,gg2)); } for (i=0;i new_ener) old_ener = new_ener; ngain = PDIV32_16(SHL32(EXTEND32(old_ener),14),new_ener); for (i=0;i