X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Flpc.c;h=0d6910fd2d974d017182135fc86aede1dcf8ae1b;hb=34ca5ae51d7d411a5a891521a79c1284e046bf2f;hp=dd145ca8756a0e07987f54be4f5d85afe4217be3;hpb=1be0fc2909fbcefd800d20cfff1420234fd0715b;p=ffmpeg diff --git a/libavcodec/lpc.c b/libavcodec/lpc.c index dd145ca8756..0d6910fd2d9 100644 --- a/libavcodec/lpc.c +++ b/libavcodec/lpc.c @@ -1,31 +1,86 @@ -/** +/* * LPC utility code * Copyright (c) 2006 Justin Ruggles * - * This file is part of FFmpeg. + * This file is part of Libav. * - * FFmpeg is free software; you can redistribute it and/or + * Libav is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * FFmpeg is distributed in the hope that it will be useful, + * Libav is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software + * License along with Libav; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "libavutil/lls.h" -#include "dsputil.h" #define LPC_USE_DOUBLE #include "lpc.h" +/** + * Apply Welch window function to audio block + */ +static void lpc_apply_welch_window_c(const int32_t *data, int len, + double *w_data) +{ + int i, n2; + double w; + double c; + + /* The optimization in commit fa4ed8c does not support odd len. + * If someone wants odd len extend that change. */ + assert(!(len & 1)); + + n2 = (len >> 1); + c = 2.0 / (len - 1.0); + + w_data+=n2; + data+=n2; + for(i=0; i= MIN_LPC_ORDER && max_order <= MAX_LPC_ORDER); + assert(max_order >= MIN_LPC_ORDER && max_order <= MAX_LPC_ORDER && + lpc_type > FF_LPC_TYPE_FIXED); + + /* reinit LPC context if parameters have changed */ + if (blocksize != s->blocksize || max_order != s->max_order || + lpc_type != s->lpc_type) { + ff_lpc_end(s); + ff_lpc_init(s, blocksize, max_order, lpc_type); + } + + if (lpc_type == FF_LPC_TYPE_LEVINSON) { + double *windowed_samples = s->windowed_samples + max_order; + + s->lpc_apply_welch_window(samples, blocksize, windowed_samples); - if(use_lpc == 1){ - s->flac_compute_autocorr(samples, blocksize, max_order, autoc); + s->lpc_compute_autocorr(windowed_samples, blocksize, max_order, autoc); compute_lpc_coefs(autoc, max_order, &lpc[0][0], MAX_LPC_ORDER, 0, 1); for(i=0; iblocksize = blocksize; + s->max_order = max_order; + s->lpc_type = lpc_type; + + if (lpc_type == FF_LPC_TYPE_LEVINSON) { + s->windowed_samples = av_mallocz((blocksize + max_order + 2) * + sizeof(*s->windowed_samples)); + if (!s->windowed_samples) + return AVERROR(ENOMEM); + } else { + s->windowed_samples = NULL; + } + + s->lpc_apply_welch_window = lpc_apply_welch_window_c; + s->lpc_compute_autocorr = lpc_compute_autocorr_c; + + if (HAVE_MMX) + ff_lpc_init_x86(s); + + return 0; +} + +av_cold void ff_lpc_end(LPCContext *s) +{ + av_freep(&s->windowed_samples); +}