| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * various filters for ACELP-based codecs | ||
| 3 | * | ||
| 4 | * Copyright (c) 2008 Vladimir Voroshilov | ||
| 5 | * | ||
| 6 | * This file is part of FFmpeg. | ||
| 7 | * | ||
| 8 | * FFmpeg is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU Lesser General Public | ||
| 10 | * License as published by the Free Software Foundation; either | ||
| 11 | * version 2.1 of the License, or (at your option) any later version. | ||
| 12 | * | ||
| 13 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 16 | * Lesser General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU Lesser General Public | ||
| 19 | * License along with FFmpeg; if not, write to the Free Software | ||
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 21 | */ | ||
| 22 | |||
| 23 | #include <stdint.h> | ||
| 24 | #include <string.h> | ||
| 25 | |||
| 26 | #include "config.h" | ||
| 27 | #include "celp_filters.h" | ||
| 28 | #include "libavutil/attributes.h" | ||
| 29 | #include "libavutil/avassert.h" | ||
| 30 | #include "libavutil/common.h" | ||
| 31 | |||
| 32 | ✗ | void ff_celp_convolve_circ(int16_t* fc_out, const int16_t* fc_in, | |
| 33 | const int16_t* filter, int len) | ||
| 34 | { | ||
| 35 | int i, k; | ||
| 36 | |||
| 37 | ✗ | memset(fc_out, 0, len * sizeof(int16_t)); | |
| 38 | |||
| 39 | /* Since there are few pulses over an entire subframe (i.e. almost | ||
| 40 | all fc_in[i] are zero) it is faster to loop over fc_in first. */ | ||
| 41 | ✗ | for (i = 0; i < len; i++) { | |
| 42 | ✗ | if (fc_in[i]) { | |
| 43 | ✗ | for (k = 0; k < i; k++) | |
| 44 | ✗ | fc_out[k] += (fc_in[i] * filter[len + k - i]) >> 15; | |
| 45 | |||
| 46 | ✗ | for (k = i; k < len; k++) | |
| 47 | ✗ | fc_out[k] += (fc_in[i] * filter[ k - i]) >> 15; | |
| 48 | } | ||
| 49 | } | ||
| 50 | ✗ | } | |
| 51 | |||
| 52 | 35019 | void ff_celp_circ_addf(float *out, const float *in, | |
| 53 | const float *lagged, int lag, float fac, int n) | ||
| 54 | { | ||
| 55 | int k; | ||
| 56 |
2/2✓ Branch 0 taken 970459 times.
✓ Branch 1 taken 35019 times.
|
1005478 | for (k = 0; k < lag; k++) |
| 57 | 970459 | out[k] = in[k] + fac * lagged[n + k - lag]; | |
| 58 |
2/2✓ Branch 0 taken 945605 times.
✓ Branch 1 taken 35019 times.
|
980624 | for (; k < n; k++) |
| 59 | 945605 | out[k] = in[k] + fac * lagged[ k - lag]; | |
| 60 | 35019 | } | |
| 61 | |||
| 62 | 26908 | int ff_celp_lp_synthesis_filter(int16_t *out, const int16_t *filter_coeffs, | |
| 63 | const int16_t *in, int buffer_length, | ||
| 64 | int filter_length, int stop_on_overflow, | ||
| 65 | int shift, int rounder) | ||
| 66 | { | ||
| 67 | int i,n; | ||
| 68 | |||
| 69 |
2/2✓ Branch 0 taken 1126720 times.
✓ Branch 1 taken 26908 times.
|
1153628 | for (n = 0; n < buffer_length; n++) { |
| 70 | 1126720 | int sum = rounder, sum1; | |
| 71 |
2/2✓ Branch 0 taken 11267200 times.
✓ Branch 1 taken 1126720 times.
|
12393920 | for (i = 1; i <= filter_length; i++) |
| 72 | 11267200 | sum -= (unsigned)(filter_coeffs[i-1] * out[n-i]); | |
| 73 | |||
| 74 | 1126720 | sum1 = ((sum >> 12) + in[n]) >> shift; | |
| 75 | 1126720 | sum = av_clip_int16(sum1); | |
| 76 | |||
| 77 |
3/4✓ Branch 0 taken 975520 times.
✓ Branch 1 taken 151200 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 975520 times.
|
1126720 | if (stop_on_overflow && sum != sum1) |
| 78 | ✗ | return 1; | |
| 79 | |||
| 80 | 1126720 | out[n] = sum; | |
| 81 | } | ||
| 82 | |||
| 83 | 26908 | return 0; | |
| 84 | } | ||
| 85 | |||
| 86 | 701889 | void ff_celp_lp_synthesis_filterf(float *out, const float *filter_coeffs, | |
| 87 | const float* in, int buffer_length, | ||
| 88 | int filter_length) | ||
| 89 | { | ||
| 90 | int i,n; | ||
| 91 | |||
| 92 | #if 0 // Unoptimized code path for improved readability | ||
| 93 | for (n = 0; n < buffer_length; n++) { | ||
| 94 | out[n] = in[n]; | ||
| 95 | for (i = 1; i <= filter_length; i++) | ||
| 96 | out[n] -= filter_coeffs[i-1] * out[n-i]; | ||
| 97 | } | ||
| 98 | #else | ||
| 99 | float out0, out1, out2, out3; | ||
| 100 | float old_out0, old_out1, old_out2, old_out3; | ||
| 101 | float a,b,c; | ||
| 102 | |||
| 103 | 701889 | a = filter_coeffs[0]; | |
| 104 | 701889 | b = filter_coeffs[1]; | |
| 105 | 701889 | c = filter_coeffs[2]; | |
| 106 | 701889 | b -= filter_coeffs[0] * filter_coeffs[0]; | |
| 107 | 701889 | c -= filter_coeffs[1] * filter_coeffs[0]; | |
| 108 | 701889 | c -= filter_coeffs[0] * b; | |
| 109 | |||
| 110 | av_assert2((filter_length&1)==0 && filter_length>=4); | ||
| 111 | |||
| 112 | 701889 | old_out0 = out[-4]; | |
| 113 | 701889 | old_out1 = out[-3]; | |
| 114 | 701889 | old_out2 = out[-2]; | |
| 115 | 701889 | old_out3 = out[-1]; | |
| 116 |
2/2✓ Branch 0 taken 6953958 times.
✓ Branch 1 taken 701889 times.
|
7655847 | for (n = 0; n <= buffer_length - 4; n+=4) { |
| 117 | float tmp0,tmp1,tmp2; | ||
| 118 | float val; | ||
| 119 | |||
| 120 | 6953958 | out0 = in[0]; | |
| 121 | 6953958 | out1 = in[1]; | |
| 122 | 6953958 | out2 = in[2]; | |
| 123 | 6953958 | out3 = in[3]; | |
| 124 | |||
| 125 | 6953958 | out0 -= filter_coeffs[2] * old_out1; | |
| 126 | 6953958 | out1 -= filter_coeffs[2] * old_out2; | |
| 127 | 6953958 | out2 -= filter_coeffs[2] * old_out3; | |
| 128 | |||
| 129 | 6953958 | out0 -= filter_coeffs[1] * old_out2; | |
| 130 | 6953958 | out1 -= filter_coeffs[1] * old_out3; | |
| 131 | |||
| 132 | 6953958 | out0 -= filter_coeffs[0] * old_out3; | |
| 133 | |||
| 134 | 6953958 | val = filter_coeffs[3]; | |
| 135 | |||
| 136 | 6953958 | out0 -= val * old_out0; | |
| 137 | 6953958 | out1 -= val * old_out1; | |
| 138 | 6953958 | out2 -= val * old_out2; | |
| 139 | 6953958 | out3 -= val * old_out3; | |
| 140 | |||
| 141 |
2/2✓ Branch 0 taken 25948224 times.
✓ Branch 1 taken 6953958 times.
|
32902182 | for (i = 5; i < filter_length; i += 2) { |
| 142 | 25948224 | old_out3 = out[-i]; | |
| 143 | 25948224 | val = filter_coeffs[i-1]; | |
| 144 | |||
| 145 | 25948224 | out0 -= val * old_out3; | |
| 146 | 25948224 | out1 -= val * old_out0; | |
| 147 | 25948224 | out2 -= val * old_out1; | |
| 148 | 25948224 | out3 -= val * old_out2; | |
| 149 | |||
| 150 | 25948224 | old_out2 = out[-i-1]; | |
| 151 | |||
| 152 | 25948224 | val = filter_coeffs[i]; | |
| 153 | |||
| 154 | 25948224 | out0 -= val * old_out2; | |
| 155 | 25948224 | out1 -= val * old_out3; | |
| 156 | 25948224 | out2 -= val * old_out0; | |
| 157 | 25948224 | out3 -= val * old_out1; | |
| 158 | |||
| 159 | 25948224 | FFSWAP(float, old_out0, old_out2); | |
| 160 | 25948224 | old_out1 = old_out3; | |
| 161 | } | ||
| 162 | |||
| 163 | 6953958 | tmp0 = out0; | |
| 164 | 6953958 | tmp1 = out1; | |
| 165 | 6953958 | tmp2 = out2; | |
| 166 | |||
| 167 | 6953958 | out3 -= a * tmp2; | |
| 168 | 6953958 | out2 -= a * tmp1; | |
| 169 | 6953958 | out1 -= a * tmp0; | |
| 170 | |||
| 171 | 6953958 | out3 -= b * tmp1; | |
| 172 | 6953958 | out2 -= b * tmp0; | |
| 173 | |||
| 174 | 6953958 | out3 -= c * tmp0; | |
| 175 | |||
| 176 | |||
| 177 | 6953958 | out[0] = out0; | |
| 178 | 6953958 | out[1] = out1; | |
| 179 | 6953958 | out[2] = out2; | |
| 180 | 6953958 | out[3] = out3; | |
| 181 | |||
| 182 | 6953958 | old_out0 = out0; | |
| 183 | 6953958 | old_out1 = out1; | |
| 184 | 6953958 | old_out2 = out2; | |
| 185 | 6953958 | old_out3 = out3; | |
| 186 | |||
| 187 | 6953958 | out += 4; | |
| 188 | 6953958 | in += 4; | |
| 189 | } | ||
| 190 | |||
| 191 | 701889 | out -= n; | |
| 192 | 701889 | in -= n; | |
| 193 |
2/2✓ Branch 0 taken 118266 times.
✓ Branch 1 taken 701889 times.
|
820155 | for (; n < buffer_length; n++) { |
| 194 | 118266 | out[n] = in[n]; | |
| 195 |
2/2✓ Branch 0 taken 3421248 times.
✓ Branch 1 taken 118266 times.
|
3539514 | for (i = 1; i <= filter_length; i++) |
| 196 | 3421248 | out[n] -= filter_coeffs[i-1] * out[n-i]; | |
| 197 | } | ||
| 198 | #endif | ||
| 199 | 701889 | } | |
| 200 | |||
| 201 | 19615 | void ff_celp_lp_zero_synthesis_filterf(float *out, const float *filter_coeffs, | |
| 202 | const float *in, int buffer_length, | ||
| 203 | int filter_length) | ||
| 204 | { | ||
| 205 | int i,n; | ||
| 206 | |||
| 207 |
2/2✓ Branch 0 taken 1135680 times.
✓ Branch 1 taken 19615 times.
|
1155295 | for (n = 0; n < buffer_length; n++) { |
| 208 | 1135680 | out[n] = in[n]; | |
| 209 |
2/2✓ Branch 0 taken 12940800 times.
✓ Branch 1 taken 1135680 times.
|
14076480 | for (i = 1; i <= filter_length; i++) |
| 210 | 12940800 | out[n] += filter_coeffs[i-1] * in[n-i]; | |
| 211 | } | ||
| 212 | 19615 | } | |
| 213 | |||
| 214 | 42 | void av_cold ff_celp_filter_init(CELPFContext *c) | |
| 215 | { | ||
| 216 | 42 | c->celp_lp_synthesis_filterf = ff_celp_lp_synthesis_filterf; | |
| 217 | 42 | c->celp_lp_zero_synthesis_filterf = ff_celp_lp_zero_synthesis_filterf; | |
| 218 | |||
| 219 | #if HAVE_MIPSFPU | ||
| 220 | ff_celp_filter_init_mips(c); | ||
| 221 | #endif | ||
| 222 | 42 | } | |
| 223 |