3 * Copyright (c) 2007 Reynaldo H. Verdejo Pinochet
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 * @author Reynaldo H. Verdejo Pinochet
30 #include "bitstream.h"
33 #include "qcelpdata.h"
35 #include "celp_math.h"
36 #include "celp_filters.h"
41 static void weighted_vector_sumf(float *out,
49 for (i = 0; i < length; i++)
50 out[i] = weight_coeff_a * in_a[i]
51 + weight_coeff_b * in_b[i];
55 * Apply filter in pitch-subframe steps.
57 * @param memory buffer for the previous state of the filter
58 * - must be able to contain 303 elements
59 * - the 143 first elements are from the previous state
60 * - the next 160 are for output
61 * @param v_in input filter vector
62 * @param gain per-subframe gain array, each element is between 0.0 and 2.0
63 * @param lag per-subframe lag array, each element is
64 * - between 16 and 143 if its corresponding pfrac is 0,
65 * - between 16 and 139 otherwise
66 * @param pfrac per-subframe boolean array, 1 if the lag is fractional, 0 otherwise
68 * @return filter output vector
70 static const float *do_pitchfilter(float memory[303],
71 const float v_in[160],
74 const uint8_t pfrac[4]) {
79 v_out = memory + 143; // Output vector starts at memory[143].
81 for (i = 0; i < 4; i++)
83 v_lag = memory + 143 + 40 * i - lag[i];
84 for (v_len = v_in + 40; v_in < v_len; v_in++) {
85 if (pfrac[i]) { // If it is a fractional lag...
86 for (j = 0, *v_out = 0.; j < 4; j++)
87 *v_out += qcelp_hammsinc_table[j] * (v_lag[j-4] + v_lag[3-j]);
91 *v_out = *v_in + gain[i] * *v_out;
97 memcpy(v_out, v_in, 40 * sizeof(float));
102 memmove(memory, memory + 160, 143 * sizeof(float));
106 static int buf_size2framerate(const int buf_size) {
122 static void warn_insufficient_frame_quality(AVCodecContext *avctx,
123 const char *message) {
124 av_log(avctx, AV_LOG_WARNING, "Frame #%d, IFQ: %s\n", avctx->frame_number, message);