Comment typo
[libav.git] / libavcodec / qcelpdec.c
CommitLineData
cb377ec5
KG
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
2ae1a9b2
KG
41static void weighted_vector_sumf(float *out,
42 const float *in_a,
43 const float *in_b,
44 float weight_coeff_a,
45 float weight_coeff_b,
46 int length) {
47 int i;
48
49 for (i = 0; i < length; i++)
50 out[i] = weight_coeff_a * in_a[i]
51 + weight_coeff_b * in_b[i];
52}
53
cb377ec5
KG
54/**
55 * Apply filter in pitch-subframe steps.
56 *
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
67 *
68 * @return filter output vector
69 */
70static const float *do_pitchfilter(float memory[303],
71 const float v_in[160],
72 const float gain[4],
73 const uint8_t *lag,
74 const uint8_t pfrac[4]) {
75 int i, j;
76 float *v_lag, *v_out;
77 const float *v_len;
78
79 v_out = memory + 143; // Output vector starts at memory[143].
80
81 for (i = 0; i < 4; i++)
82 if (gain[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]);
88 } else
89 *v_out = *v_lag;
90
91 *v_out = *v_in + gain[i] * *v_out;
92
93 v_lag++;
94 v_out++;
95 }
96 } else {
97 memcpy(v_out, v_in, 40 * sizeof(float));
98 v_in += 40;
99 v_out += 40;
100 }
101
102 memmove(memory, memory + 160, 143 * sizeof(float));
103 return memory + 143;
104}
105
2ae1a9b2
KG
106static int buf_size2framerate(const int buf_size) {
107 switch (buf_size) {
108 case 35:
109 return RATE_FULL;
110 case 17:
111 return RATE_HALF;
112 case 8:
113 return RATE_QUARTER;
114 case 4:
115 return RATE_OCTAVE;
116 case 1:
117 return SILENCE;
118 }
119 return -1;
120}
121
cb377ec5
KG
122static 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);
125}