/* Copyright (c) 2009-2010 Xiph.Org Foundation Written by Jean-Marc Valin */ /* 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. 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 COPYRIGHT OWNER 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 "celt_lpc.h" #include "stack_alloc.h" #include "mathops.h" #include "pitch.h" void _celt_lpc( opus_val16 *_lpc, /* out: [0...p-1] LPC coefficients */ const opus_val32 *ac, /* in: [0...p] autocorrelation values */ int p ) { int i, j; opus_val32 r; opus_val32 error = ac[0]; #ifdef FIXED_POINT opus_val32 lpc[LPC_ORDER]; #else float *lpc = _lpc; #endif OPUS_CLEAR(lpc, p); if (ac[0] != 0) { for (i = 0; i < p; i++) { /* Sum up this iteration's reflection coefficient */ opus_val32 rr = 0; for (j = 0; j < i; j++) rr += MULT32_32_Q31(lpc[j],ac[i - j]); rr += SHR32(ac[i + 1],6); r = -frac_div32(SHL32(rr,6), error); /* Update LPC coefficients and total error */ lpc[i] = SHR32(r,6); for (j = 0; j < (i+1)>>1; j++) { opus_val32 tmp1, tmp2; tmp1 = lpc[j]; tmp2 = lpc[i-1-j]; lpc[j] = tmp1 + MULT32_32_Q31(r,tmp2); lpc[i-1-j] = tmp2 + MULT32_32_Q31(r,tmp1); } error = error - MULT32_32_Q31(MULT32_32_Q31(r,r),error); /* Bail out once we get 30 dB gain */ #ifdef FIXED_POINT if (error maxabs) { maxabs = absval; idx = i; } } maxabs = PSHR32(maxabs, 13); /* Q25->Q12 */ if (maxabs > 32767) { maxabs = MIN32(maxabs, 163838); chirp_Q16 = QCONST32(0.999, 16) - DIV32(SHL32(maxabs - 32767, 14), SHR32(MULT32_32_32(maxabs, idx + 1), 2)); chirp_minus_one_Q16 = chirp_Q16 - 65536; /* Apply bandwidth expansion. */ for (i = 0; i < p - 1; i++) { lpc[i] = MULT32_32_Q16(chirp_Q16, lpc[i]); chirp_Q16 += PSHR32(MULT32_32_32(chirp_Q16, chirp_minus_one_Q16), 16); } lpc[p - 1] = MULT32_32_Q16(chirp_Q16, lpc[p - 1]); } else { break; } } if (iter == 10) { /* If the coeffs still do not fit into the 16 bit range after 10 iterations, fall back to the A(z)=1 filter. */ OPUS_CLEAR(lpc, p); _lpc[0] = 4096; /* Q12 */ } else { for (i = 0; i < p; i++) { _lpc[i] = EXTRACT16(PSHR32(lpc[i], 13)); /* Q25->Q12 */ } } } #endif } void celt_fir_c( const opus_val16 *x, const opus_val16 *num, opus_val16 *y, int N, int ord, int arch) { int i,j; VARDECL(opus_val16, rnum); SAVE_STACK; celt_assert(x != y); ALLOC(rnum, ord, opus_val16); for(i=0;i=1;j--) { mem[j]=mem[j-1]; } mem[0] = SROUND16(sum, SIG_SHIFT); _y[i] = sum; } #else int i,j; VARDECL(opus_val16, rden); VARDECL(opus_val16, y); SAVE_STACK; celt_assert((ord&3)==0); ALLOC(rden, ord, opus_val16); ALLOC(y, N+ord, opus_val16); for(i=0;i0); celt_assert(overlap>=0); if (overlap == 0) { xptr = x; } else { for (i=0;i0) { for(i=0;i= 536870912) { int shift2=1; if (ac[0] >= 1073741824) shift2++; for (i=0;i<=lag;i++) ac[i] = SHR32(ac[i], shift2); shift += shift2; } #endif RESTORE_STACK; return shift; }