Chris@69: /* Copyright (c) 2009-2010 Xiph.Org Foundation Chris@69: Written by Jean-Marc Valin */ Chris@69: /* Chris@69: Redistribution and use in source and binary forms, with or without Chris@69: modification, are permitted provided that the following conditions Chris@69: are met: Chris@69: Chris@69: - Redistributions of source code must retain the above copyright Chris@69: notice, this list of conditions and the following disclaimer. Chris@69: Chris@69: - Redistributions in binary form must reproduce the above copyright Chris@69: notice, this list of conditions and the following disclaimer in the Chris@69: documentation and/or other materials provided with the distribution. Chris@69: Chris@69: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS Chris@69: ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT Chris@69: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR Chris@69: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER Chris@69: OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, Chris@69: EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, Chris@69: PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR Chris@69: PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF Chris@69: LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING Chris@69: NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS Chris@69: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Chris@69: */ Chris@69: Chris@69: #ifdef HAVE_CONFIG_H Chris@69: #include "config.h" Chris@69: #endif Chris@69: Chris@69: #include "celt_lpc.h" Chris@69: #include "stack_alloc.h" Chris@69: #include "mathops.h" Chris@69: #include "pitch.h" Chris@69: Chris@69: void _celt_lpc( Chris@69: opus_val16 *_lpc, /* out: [0...p-1] LPC coefficients */ Chris@69: const opus_val32 *ac, /* in: [0...p] autocorrelation values */ Chris@69: int p Chris@69: ) Chris@69: { Chris@69: int i, j; Chris@69: opus_val32 r; Chris@69: opus_val32 error = ac[0]; Chris@69: #ifdef FIXED_POINT Chris@69: opus_val32 lpc[LPC_ORDER]; Chris@69: #else Chris@69: float *lpc = _lpc; Chris@69: #endif Chris@69: Chris@69: OPUS_CLEAR(lpc, p); Chris@69: if (ac[0] != 0) Chris@69: { Chris@69: for (i = 0; i < p; i++) { Chris@69: /* Sum up this iteration's reflection coefficient */ Chris@69: opus_val32 rr = 0; Chris@69: for (j = 0; j < i; j++) Chris@69: rr += MULT32_32_Q31(lpc[j],ac[i - j]); Chris@69: rr += SHR32(ac[i + 1],3); Chris@69: r = -frac_div32(SHL32(rr,3), error); Chris@69: /* Update LPC coefficients and total error */ Chris@69: lpc[i] = SHR32(r,3); Chris@69: for (j = 0; j < (i+1)>>1; j++) Chris@69: { Chris@69: opus_val32 tmp1, tmp2; Chris@69: tmp1 = lpc[j]; Chris@69: tmp2 = lpc[i-1-j]; Chris@69: lpc[j] = tmp1 + MULT32_32_Q31(r,tmp2); Chris@69: lpc[i-1-j] = tmp2 + MULT32_32_Q31(r,tmp1); Chris@69: } Chris@69: Chris@69: error = error - MULT32_32_Q31(MULT32_32_Q31(r,r),error); Chris@69: /* Bail out once we get 30 dB gain */ Chris@69: #ifdef FIXED_POINT Chris@69: if (error=1;j--) Chris@69: { Chris@69: mem[j]=mem[j-1]; Chris@69: } Chris@69: mem[0] = SROUND16(sum, SIG_SHIFT); Chris@69: _y[i] = sum; Chris@69: } Chris@69: #else Chris@69: int i,j; Chris@69: VARDECL(opus_val16, rden); Chris@69: VARDECL(opus_val16, y); Chris@69: SAVE_STACK; Chris@69: Chris@69: celt_assert((ord&3)==0); Chris@69: ALLOC(rden, ord, opus_val16); Chris@69: ALLOC(y, N+ord, opus_val16); Chris@69: for(i=0;i0); Chris@69: celt_assert(overlap>=0); Chris@69: if (overlap == 0) Chris@69: { Chris@69: xptr = x; Chris@69: } else { Chris@69: for (i=0;i0) Chris@69: { Chris@69: for(i=0;i= 536870912) Chris@69: { Chris@69: int shift2=1; Chris@69: if (ac[0] >= 1073741824) Chris@69: shift2++; Chris@69: for (i=0;i<=lag;i++) Chris@69: ac[i] = SHR32(ac[i], shift2); Chris@69: shift += shift2; Chris@69: } Chris@69: #endif Chris@69: Chris@69: RESTORE_STACK; Chris@69: return shift; Chris@69: }