pictor: Correctly check frame dimensions
[ffmpeg.git] / libavcodec / sipr16k.c
index f195597..6a0ef8d 100644 (file)
@@ -4,29 +4,32 @@
  * Copyright (c) 2008 Vladimir Voroshilov
  * Copyright (c) 2009 Vitor Sessak
  *
  * Copyright (c) 2008 Vladimir Voroshilov
  * Copyright (c) 2009 Vitor Sessak
  *
- * 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.
  *
  * 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
  * 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 <math.h>
 
 #include "sipr.h"
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <math.h>
 
 #include "sipr.h"
+#include "libavutil/attributes.h"
+#include "libavutil/common.h"
+#include "libavutil/float_dsp.h"
 #include "libavutil/mathematics.h"
 #include "lsp.h"
 #include "libavutil/mathematics.h"
 #include "lsp.h"
-#include "celp_math.h"
+#include "celp_filters.h"
 #include "acelp_vectors.h"
 #include "acelp_pitch_delay.h"
 #include "acelp_filters.h"
 #include "acelp_vectors.h"
 #include "acelp_pitch_delay.h"
 #include "acelp_filters.h"
@@ -48,7 +51,7 @@ static void lsf2lsp(const float *lsf, double *lsp)
         lsp[i] = cosf(lsf[i]);
 }
 
         lsp[i] = cosf(lsf[i]);
 }
 
-static void dequant(float *out, const int *idx, const float *cbs[])
+static void dequant(float *out, const int *idx, const float * const cbs[])
 {
     int i;
 
 {
     int i;
 
@@ -94,8 +97,8 @@ static int dec_delay3_2nd(int index, int pit_min, int pit_max,
         return 3 * pitch_lag_prev;
 }
 
         return 3 * pitch_lag_prev;
 }
 
-static void postfilter(float* synth, float* iir_mem, float* filt_mem[2],
-                       float* mem_preemph)
+static void postfilter(float *out_data, float* synth, float* iir_mem,
+                       float* filt_mem[2], float* mem_preemph)
 {
     float buf[30 + LP_FILTER_ORDER_16k];
     float *tmpbuf = buf + LP_FILTER_ORDER_16k;
 {
     float buf[30 + LP_FILTER_ORDER_16k];
     float *tmpbuf = buf + LP_FILTER_ORDER_16k;
@@ -114,15 +117,24 @@ static void postfilter(float* synth, float* iir_mem, float* filt_mem[2],
     memcpy(synth - LP_FILTER_ORDER_16k, mem_preemph,
            LP_FILTER_ORDER_16k * sizeof(*synth));
 
     memcpy(synth - LP_FILTER_ORDER_16k, mem_preemph,
            LP_FILTER_ORDER_16k * sizeof(*synth));
 
-    ff_celp_lp_synthesis_filterf(synth, filt_mem[0], synth, 2*L_SUBFR_16k,
+    ff_celp_lp_synthesis_filterf(synth, filt_mem[0], synth, 30,
+                                 LP_FILTER_ORDER_16k);
+
+    memcpy(out_data + 30 - LP_FILTER_ORDER_16k,
+           synth    + 30 - LP_FILTER_ORDER_16k,
+           LP_FILTER_ORDER_16k * sizeof(*synth));
+
+    ff_celp_lp_synthesis_filterf(out_data + 30, filt_mem[0],
+                                 synth + 30, 2 * L_SUBFR_16k - 30,
                                  LP_FILTER_ORDER_16k);
 
                                  LP_FILTER_ORDER_16k);
 
-    memcpy(mem_preemph, synth + 2*L_SUBFR_16k - LP_FILTER_ORDER_16k,
+
+    memcpy(mem_preemph, out_data + 2*L_SUBFR_16k - LP_FILTER_ORDER_16k,
            LP_FILTER_ORDER_16k * sizeof(*synth));
 
     FFSWAP(float *, filt_mem[0], filt_mem[1]);
     for (i = 0, s = 0; i < 30; i++, s += 1.0/30)
            LP_FILTER_ORDER_16k * sizeof(*synth));
 
     FFSWAP(float *, filt_mem[0], filt_mem[1]);
     for (i = 0, s = 0; i < 30; i++, s += 1.0/30)
-        synth[i] = tmpbuf[i] + s * (synth[i] - tmpbuf[i]);
+        out_data[i] = tmpbuf[i] + s * (synth[i] - tmpbuf[i]);
 }
 
 /**
 }
 
 /**
@@ -152,11 +164,11 @@ static float acelp_decode_gain_codef(float gain_corr_factor, const float *fc_v,
                                      const float *ma_prediction_coeff,
                                      int subframe_size, int ma_pred_order)
 {
                                      const float *ma_prediction_coeff,
                                      int subframe_size, int ma_pred_order)
 {
-    mr_energy +=
-        ff_dot_productf(quant_energy, ma_prediction_coeff, ma_pred_order);
+    mr_energy += avpriv_scalarproduct_float_c(quant_energy, ma_prediction_coeff,
+                                              ma_pred_order);
 
     mr_energy = gain_corr_factor * exp(M_LN10 / 20. * mr_energy) /
 
     mr_energy = gain_corr_factor * exp(M_LN10 / 20. * mr_energy) /
-        sqrt((0.01 + ff_dot_productf(fc_v, fc_v, subframe_size)));
+        sqrt((0.01 + avpriv_scalarproduct_float_c(fc_v, fc_v, subframe_size)));
     return mr_energy;
 }
 
     return mr_energy;
 }
 
@@ -252,15 +264,12 @@ void ff_sipr_decode_frame_16k(SiprContext *ctx, SiprParameters *params,
     memmove(ctx->excitation, ctx->excitation + 2 * L_SUBFR_16k,
             (L_INTERPOL+PITCH_MAX) * sizeof(float));
 
     memmove(ctx->excitation, ctx->excitation + 2 * L_SUBFR_16k,
             (L_INTERPOL+PITCH_MAX) * sizeof(float));
 
-    postfilter(synth, ctx->iir_mem, ctx->filt_mem, ctx->mem_preemph);
+    postfilter(out_data, synth, ctx->iir_mem, ctx->filt_mem, ctx->mem_preemph);
 
     memcpy(ctx->iir_mem, Az[1], LP_FILTER_ORDER_16k * sizeof(float));
 
     memcpy(ctx->iir_mem, Az[1], LP_FILTER_ORDER_16k * sizeof(float));
-
-    ctx->dsp.vector_clipf(out_data, synth, -1, 32767./(1<<15), frame_size);
-
 }
 
 }
 
-void ff_sipr_init_16k(SiprContext *ctx)
+av_cold void ff_sipr_init_16k(SiprContext *ctx)
 {
     int i;
 
 {
     int i;