]> git.sesse.net Git - ffmpeg/blob - libavcodec/qcelpdec.c
Add missing #include "libavutil/avstring.h", fixes
[ffmpeg] / libavcodec / qcelpdec.c
1 /*
2  * QCELP decoder
3  * Copyright (c) 2007 Reynaldo H. Verdejo Pinochet
4  *
5  * This file is part of FFmpeg.
6  *
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.
11  *
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.
16  *
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
20  */
21 /**
22  * @file qcelpdec.c
23  * QCELP decoder
24  * @author Reynaldo H. Verdejo Pinochet
25  */
26
27 #include <stddef.h>
28
29 #include "avcodec.h"
30 #include "bitstream.h"
31
32 #include "qcelp.h"
33 #include "qcelpdata.h"
34
35 #include "celp_math.h"
36 #include "celp_filters.h"
37
38 #undef NDEBUG
39 #include <assert.h>
40
41 /**
42  * Apply filter in pitch-subframe steps.
43  *
44  * @param memory buffer for the previous state of the filter
45  *        - must be able to contain 303 elements
46  *        - the 143 first elements are from the previous state
47  *        - the next 160 are for output
48  * @param v_in input filter vector
49  * @param gain per-subframe gain array, each element is between 0.0 and 2.0
50  * @param lag per-subframe lag array, each element is
51  *        - between 16 and 143 if its corresponding pfrac is 0,
52  *        - between 16 and 139 otherwise
53  * @param pfrac per-subframe boolean array, 1 if the lag is fractional, 0 otherwise
54  *
55  * @return filter output vector
56  */
57 static const float *do_pitchfilter(float memory[303],
58                                    const float v_in[160],
59                                    const float gain[4],
60                                    const uint8_t *lag,
61                                    const uint8_t pfrac[4]) {
62     int         i, j;
63     float       *v_lag, *v_out;
64     const float *v_len;
65
66     v_out = memory + 143; // Output vector starts at memory[143].
67
68     for (i = 0; i < 4; i++)
69         if (gain[i]) {
70             v_lag = memory + 143 + 40 * i - lag[i];
71             for (v_len = v_in + 40; v_in < v_len; v_in++) {
72                 if (pfrac[i]) { // If it is a fractional lag...
73                     for (j = 0, *v_out = 0.; j < 4; j++)
74                         *v_out += qcelp_hammsinc_table[j] * (v_lag[j-4] + v_lag[3-j]);
75                 } else
76                     *v_out = *v_lag;
77
78                 *v_out = *v_in + gain[i] * *v_out;
79
80                 v_lag++;
81                 v_out++;
82             }
83         } else {
84             memcpy(v_out, v_in, 40 * sizeof(float));
85             v_in  += 40;
86             v_out += 40;
87         }
88
89     memmove(memory, memory + 160, 143 * sizeof(float));
90     return memory + 143;
91 }
92
93 static void warn_insufficient_frame_quality(AVCodecContext *avctx,
94                                             const char *message) {
95     av_log(avctx, AV_LOG_WARNING, "Frame #%d, IFQ: %s\n", avctx->frame_number, message);
96 }