| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * AC-3 encoder float/fixed template | ||
| 3 | * Copyright (c) 2000 Fabrice Bellard | ||
| 4 | * Copyright (c) 2006-2011 Justin Ruggles <justin.ruggles@gmail.com> | ||
| 5 | * Copyright (c) 2006-2010 Prakash Punnoor <prakash@punnoor.de> | ||
| 6 | * | ||
| 7 | * This file is part of FFmpeg. | ||
| 8 | * | ||
| 9 | * FFmpeg is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU Lesser General Public | ||
| 11 | * License as published by the Free Software Foundation; either | ||
| 12 | * version 2.1 of the License, or (at your option) any later version. | ||
| 13 | * | ||
| 14 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 17 | * Lesser General Public License for more details. | ||
| 18 | * | ||
| 19 | * You should have received a copy of the GNU Lesser General Public | ||
| 20 | * License along with FFmpeg; if not, write to the Free Software | ||
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 22 | */ | ||
| 23 | |||
| 24 | /** | ||
| 25 | * @file | ||
| 26 | * AC-3 encoder float/fixed template | ||
| 27 | */ | ||
| 28 | |||
| 29 | #include "config_components.h" | ||
| 30 | |||
| 31 | #include <stdint.h> | ||
| 32 | |||
| 33 | #include "libavutil/attributes.h" | ||
| 34 | #include "libavutil/avassert.h" | ||
| 35 | #include "libavutil/mem_internal.h" | ||
| 36 | |||
| 37 | #include "audiodsp.h" | ||
| 38 | #include "ac3enc.h" | ||
| 39 | #include "eac3enc.h" | ||
| 40 | |||
| 41 | #if AC3ENC_FLOAT | ||
| 42 | #define RENAME(element) element ## _float | ||
| 43 | #else | ||
| 44 | #define RENAME(element) element ## _fixed | ||
| 45 | #endif | ||
| 46 | |||
| 47 | /* | ||
| 48 | * Apply the MDCT to input samples to generate frequency coefficients. | ||
| 49 | * This applies the KBD window and normalizes the input to reduce precision | ||
| 50 | * loss due to fixed-point calculations. | ||
| 51 | */ | ||
| 52 | 1231 | static void apply_mdct(AC3EncodeContext *s, uint8_t * const *samples) | |
| 53 | { | ||
| 54 | av_assert1(s->num_blocks > 0); | ||
| 55 | |||
| 56 |
2/2✓ Branch 0 taken 1990 times.
✓ Branch 1 taken 1231 times.
|
3221 | for (int ch = 0; ch < s->channels; ch++) { |
| 57 | 1990 | const SampleType *input_samples0 = (const SampleType*)s->planar_samples[ch]; | |
| 58 | /* Reorder channels from native order to AC-3 order. */ | ||
| 59 | 1990 | const SampleType *input_samples1 = (const SampleType*)samples[s->channel_map[ch]]; | |
| 60 | 1990 | int blk = 0; | |
| 61 | |||
| 62 | do { | ||
| 63 | 11940 | AC3Block *block = &s->blocks[blk]; | |
| 64 | 11940 | SampleType *windowed_samples = s->RENAME(windowed_samples); | |
| 65 | |||
| 66 | 11940 | s->fdsp->vector_fmul(windowed_samples, input_samples0, | |
| 67 | 11940 | s->RENAME(mdct_window), AC3_BLOCK_SIZE); | |
| 68 | 11940 | s->fdsp->vector_fmul_reverse(windowed_samples + AC3_BLOCK_SIZE, | |
| 69 | input_samples1, | ||
| 70 | 11940 | s->RENAME(mdct_window), AC3_BLOCK_SIZE); | |
| 71 | |||
| 72 | 11940 | s->tx_fn(s->tx, block->mdct_coef[ch+1], | |
| 73 | windowed_samples, sizeof(*windowed_samples)); | ||
| 74 | 11940 | input_samples0 = input_samples1; | |
| 75 | 11940 | input_samples1 += AC3_BLOCK_SIZE; | |
| 76 |
2/2✓ Branch 0 taken 9950 times.
✓ Branch 1 taken 1990 times.
|
11940 | } while (++blk < s->num_blocks); |
| 77 | |||
| 78 | /* Store last 256 samples of current frame */ | ||
| 79 | 1990 | memcpy(s->planar_samples[ch], input_samples0, | |
| 80 | AC3_BLOCK_SIZE * sizeof(*input_samples0)); | ||
| 81 | } | ||
| 82 | 1231 | } | |
| 83 | |||
| 84 | |||
| 85 | /* | ||
| 86 | * Calculate coupling channel and coupling coordinates. | ||
| 87 | */ | ||
| 88 | 727 | static void apply_channel_coupling(AC3EncodeContext *s) | |
| 89 | { | ||
| 90 | 727 | LOCAL_ALIGNED_32(CoefType, cpl_coords, [AC3_MAX_BLOCKS], [AC3_MAX_CHANNELS][16]); | |
| 91 | #if AC3ENC_FLOAT | ||
| 92 | 546 | LOCAL_ALIGNED_32(int32_t, fixed_cpl_coords, [AC3_MAX_BLOCKS], [AC3_MAX_CHANNELS][16]); | |
| 93 | #else | ||
| 94 | 181 | int32_t (*fixed_cpl_coords)[AC3_MAX_CHANNELS][16] = cpl_coords; | |
| 95 | #endif | ||
| 96 | 727 | int av_uninit(blk), ch, bnd, i, j; | |
| 97 | 727 | CoefSumType energy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][16] = {{{0}}}; | |
| 98 | int cpl_start, num_cpl_coefs; | ||
| 99 | |||
| 100 | 727 | memset(cpl_coords, 0, AC3_MAX_BLOCKS * sizeof(*cpl_coords)); | |
| 101 | #if AC3ENC_FLOAT | ||
| 102 | 546 | memset(fixed_cpl_coords, 0, AC3_MAX_BLOCKS * sizeof(*cpl_coords)); | |
| 103 | #endif | ||
| 104 | |||
| 105 | /* align start to 16-byte boundary. align length to multiple of 32. | ||
| 106 | note: coupling start bin % 4 will always be 1 */ | ||
| 107 | 727 | cpl_start = s->start_freq[CPL_CH] - 1; | |
| 108 | 727 | num_cpl_coefs = FFALIGN(s->num_cpl_subbands * 12 + 1, 32); | |
| 109 | 727 | cpl_start = FFMIN(256, cpl_start + num_cpl_coefs) - num_cpl_coefs; | |
| 110 | |||
| 111 | /* calculate coupling channel from fbw channels */ | ||
| 112 |
2/2✓ Branch 0 taken 4362 times.
✓ Branch 1 taken 727 times.
|
5089 | for (blk = 0; blk < s->num_blocks; blk++) { |
| 113 | 4362 | AC3Block *block = &s->blocks[blk]; | |
| 114 | 4362 | CoefType *cpl_coef = &block->mdct_coef[CPL_CH][cpl_start]; | |
| 115 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4362 times.
|
4362 | if (!block->cpl_in_use) |
| 116 | ✗ | continue; | |
| 117 | 4362 | memset(cpl_coef, 0, num_cpl_coefs * sizeof(*cpl_coef)); | |
| 118 |
2/2✓ Branch 0 taken 8868 times.
✓ Branch 1 taken 4362 times.
|
13230 | for (ch = 1; ch <= s->fbw_channels; ch++) { |
| 119 | 8868 | CoefType *ch_coef = &block->mdct_coef[ch][cpl_start]; | |
| 120 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8868 times.
|
8868 | if (!block->channel_in_cpl[ch]) |
| 121 | ✗ | continue; | |
| 122 |
2/2✓ Branch 0 taken 567552 times.
✓ Branch 1 taken 8868 times.
|
576420 | for (i = 0; i < num_cpl_coefs; i++) |
| 123 | 567552 | cpl_coef[i] += ch_coef[i]; | |
| 124 | } | ||
| 125 | |||
| 126 | /* coefficients must be clipped in order to be encoded */ | ||
| 127 | 4362 | clip_coefficients(&s->adsp, cpl_coef, num_cpl_coefs); | |
| 128 | } | ||
| 129 | |||
| 130 | /* calculate energy in each band in coupling channel and each fbw channel */ | ||
| 131 | /* TODO: possibly use SIMD to speed up energy calculation */ | ||
| 132 | 727 | bnd = 0; | |
| 133 | 727 | i = s->start_freq[CPL_CH]; | |
| 134 |
2/2✓ Branch 0 taken 2892 times.
✓ Branch 1 taken 727 times.
|
3619 | while (i < s->cpl_end_freq) { |
| 135 | 2892 | int band_size = s->cpl_band_sizes[bnd]; | |
| 136 |
2/2✓ Branch 0 taken 8724 times.
✓ Branch 1 taken 2892 times.
|
11616 | for (ch = CPL_CH; ch <= s->fbw_channels; ch++) { |
| 137 |
2/2✓ Branch 0 taken 52344 times.
✓ Branch 1 taken 8724 times.
|
61068 | for (blk = 0; blk < s->num_blocks; blk++) { |
| 138 | 52344 | AC3Block *block = &s->blocks[blk]; | |
| 139 |
4/6✓ Branch 0 taken 52344 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34992 times.
✓ Branch 3 taken 17352 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 34992 times.
|
52344 | if (!block->cpl_in_use || (ch > CPL_CH && !block->channel_in_cpl[ch])) |
| 140 | ✗ | continue; | |
| 141 |
2/2✓ Branch 0 taken 786888 times.
✓ Branch 1 taken 52344 times.
|
839232 | for (j = 0; j < band_size; j++) { |
| 142 | 786888 | CoefType v = block->mdct_coef[ch][i+j]; | |
| 143 | 786888 | MAC_COEF(energy[blk][ch][bnd], v, v); | |
| 144 | } | ||
| 145 | } | ||
| 146 | } | ||
| 147 | 2892 | i += band_size; | |
| 148 | 2892 | bnd++; | |
| 149 | } | ||
| 150 | |||
| 151 | /* calculate coupling coordinates for all blocks for all channels */ | ||
| 152 |
2/2✓ Branch 0 taken 4362 times.
✓ Branch 1 taken 727 times.
|
5089 | for (blk = 0; blk < s->num_blocks; blk++) { |
| 153 | 4362 | AC3Block *block = &s->blocks[blk]; | |
| 154 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4362 times.
|
4362 | if (!block->cpl_in_use) |
| 155 | ✗ | continue; | |
| 156 |
2/2✓ Branch 0 taken 8868 times.
✓ Branch 1 taken 4362 times.
|
13230 | for (ch = 1; ch <= s->fbw_channels; ch++) { |
| 157 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8868 times.
|
8868 | if (!block->channel_in_cpl[ch]) |
| 158 | ✗ | continue; | |
| 159 |
2/2✓ Branch 0 taken 34992 times.
✓ Branch 1 taken 8868 times.
|
43860 | for (bnd = 0; bnd < s->num_cpl_bands; bnd++) { |
| 160 | 34992 | cpl_coords[blk][ch][bnd] = calc_cpl_coord(energy[blk][ch][bnd], | |
| 161 | energy[blk][CPL_CH][bnd]); | ||
| 162 | } | ||
| 163 | } | ||
| 164 | } | ||
| 165 | |||
| 166 | /* determine which blocks to send new coupling coordinates for */ | ||
| 167 |
2/2✓ Branch 0 taken 4362 times.
✓ Branch 1 taken 727 times.
|
5089 | for (blk = 0; blk < s->num_blocks; blk++) { |
| 168 | 4362 | AC3Block *block = &s->blocks[blk]; | |
| 169 |
2/2✓ Branch 0 taken 3635 times.
✓ Branch 1 taken 727 times.
|
4362 | AC3Block *block0 = blk ? &s->blocks[blk-1] : NULL; |
| 170 | |||
| 171 | 4362 | memset(block->new_cpl_coords, 0, sizeof(block->new_cpl_coords)); | |
| 172 | |||
| 173 |
1/2✓ Branch 0 taken 4362 times.
✗ Branch 1 not taken.
|
4362 | if (block->cpl_in_use) { |
| 174 | /* send new coordinates if this is the first block, if previous | ||
| 175 | * block did not use coupling but this block does, the channels | ||
| 176 | * using coupling has changed from the previous block, or the | ||
| 177 | * coordinate difference from the last block for any channel is | ||
| 178 | * greater than a threshold value. */ | ||
| 179 |
3/4✓ Branch 0 taken 3635 times.
✓ Branch 1 taken 727 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3635 times.
|
4362 | if (blk == 0 || !block0->cpl_in_use) { |
| 180 |
2/2✓ Branch 0 taken 1478 times.
✓ Branch 1 taken 727 times.
|
2205 | for (ch = 1; ch <= s->fbw_channels; ch++) |
| 181 | 1478 | block->new_cpl_coords[ch] = 1; | |
| 182 | } else { | ||
| 183 |
2/2✓ Branch 0 taken 7390 times.
✓ Branch 1 taken 3635 times.
|
11025 | for (ch = 1; ch <= s->fbw_channels; ch++) { |
| 184 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7390 times.
|
7390 | if (!block->channel_in_cpl[ch]) |
| 185 | ✗ | continue; | |
| 186 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7390 times.
|
7390 | if (!block0->channel_in_cpl[ch]) { |
| 187 | ✗ | block->new_cpl_coords[ch] = 1; | |
| 188 | } else { | ||
| 189 | 7390 | CoefSumType coord_diff = 0; | |
| 190 |
2/2✓ Branch 0 taken 29160 times.
✓ Branch 1 taken 7390 times.
|
36550 | for (bnd = 0; bnd < s->num_cpl_bands; bnd++) { |
| 191 |
2/2✓ Branch 0 taken 7273 times.
✓ Branch 1 taken 47 times.
|
29160 | coord_diff += FFABS(cpl_coords[blk-1][ch][bnd] - |
| 192 | cpl_coords[blk ][ch][bnd]); | ||
| 193 | } | ||
| 194 | 7390 | coord_diff /= s->num_cpl_bands; | |
| 195 |
2/2✓ Branch 0 taken 35 times.
✓ Branch 1 taken 7355 times.
|
7390 | if (coord_diff > NEW_CPL_COORD_THRESHOLD) |
| 196 | 35 | block->new_cpl_coords[ch] = 1; | |
| 197 | } | ||
| 198 | } | ||
| 199 | } | ||
| 200 | } | ||
| 201 | } | ||
| 202 | |||
| 203 | av_assert1(s->fbw_channels > 0); | ||
| 204 | |||
| 205 | /* calculate final coupling coordinates, taking into account reusing of | ||
| 206 | coordinates in successive blocks */ | ||
| 207 |
2/2✓ Branch 0 taken 2892 times.
✓ Branch 1 taken 727 times.
|
3619 | for (bnd = 0; bnd < s->num_cpl_bands; bnd++) { |
| 208 | 2892 | blk = 0; | |
| 209 |
2/2✓ Branch 0 taken 2980 times.
✓ Branch 1 taken 2892 times.
|
5872 | while (blk < s->num_blocks) { |
| 210 | 2980 | int av_uninit(blk1); | |
| 211 | 2980 | AC3Block *block = &s->blocks[blk]; | |
| 212 | |||
| 213 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2980 times.
|
2980 | if (!block->cpl_in_use) { |
| 214 | ✗ | blk++; | |
| 215 | ✗ | continue; | |
| 216 | } | ||
| 217 | |||
| 218 |
2/2✓ Branch 0 taken 6008 times.
✓ Branch 1 taken 2980 times.
|
8988 | for (ch = 1; ch <= s->fbw_channels; ch++) { |
| 219 | CoefSumType energy_ch, energy_cpl; | ||
| 220 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6008 times.
|
6008 | if (!block->channel_in_cpl[ch]) |
| 221 | ✗ | continue; | |
| 222 | 6008 | energy_cpl = energy[blk][CPL_CH][bnd]; | |
| 223 | 6008 | energy_ch = energy[blk][ch][bnd]; | |
| 224 | 6008 | blk1 = blk+1; | |
| 225 |
4/4✓ Branch 0 taken 29264 times.
✓ Branch 1 taken 5882 times.
✓ Branch 2 taken 29138 times.
✓ Branch 3 taken 126 times.
|
35146 | while (blk1 < s->num_blocks && !s->blocks[blk1].new_cpl_coords[ch]) { |
| 226 |
1/2✓ Branch 0 taken 29138 times.
✗ Branch 1 not taken.
|
29138 | if (s->blocks[blk1].cpl_in_use) { |
| 227 | 29138 | energy_cpl += energy[blk1][CPL_CH][bnd]; | |
| 228 | 29138 | energy_ch += energy[blk1][ch][bnd]; | |
| 229 | } | ||
| 230 | 29138 | blk1++; | |
| 231 | } | ||
| 232 | 6008 | cpl_coords[blk][ch][bnd] = calc_cpl_coord(energy_ch, energy_cpl); | |
| 233 | } | ||
| 234 | 2980 | blk = blk1; | |
| 235 | } | ||
| 236 | } | ||
| 237 | |||
| 238 | /* calculate exponents/mantissas for coupling coordinates */ | ||
| 239 |
2/2✓ Branch 0 taken 4362 times.
✓ Branch 1 taken 727 times.
|
5089 | for (blk = 0; blk < s->num_blocks; blk++) { |
| 240 | 4362 | AC3Block *block = &s->blocks[blk]; | |
| 241 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4362 times.
|
4362 | if (!block->cpl_in_use) |
| 242 | ✗ | continue; | |
| 243 | |||
| 244 | #if AC3ENC_FLOAT | ||
| 245 | 3276 | s->ac3dsp.float_to_fixed24(fixed_cpl_coords[blk][1], | |
| 246 | 3276 | cpl_coords[blk][1], | |
| 247 | 3276 | s->fbw_channels * 16); | |
| 248 | #endif | ||
| 249 | 4362 | s->ac3dsp.extract_exponents(block->cpl_coord_exp[1], | |
| 250 | 4362 | fixed_cpl_coords[blk][1], | |
| 251 | 4362 | s->fbw_channels * 16); | |
| 252 | |||
| 253 |
2/2✓ Branch 0 taken 8868 times.
✓ Branch 1 taken 4362 times.
|
13230 | for (ch = 1; ch <= s->fbw_channels; ch++) { |
| 254 | int bnd, min_exp, max_exp, master_exp; | ||
| 255 | |||
| 256 |
2/2✓ Branch 0 taken 7355 times.
✓ Branch 1 taken 1513 times.
|
8868 | if (!block->new_cpl_coords[ch]) |
| 257 | 7355 | continue; | |
| 258 | |||
| 259 | /* determine master exponent */ | ||
| 260 | 1513 | min_exp = max_exp = block->cpl_coord_exp[ch][0]; | |
| 261 |
2/2✓ Branch 0 taken 4453 times.
✓ Branch 1 taken 1513 times.
|
5966 | for (bnd = 1; bnd < s->num_cpl_bands; bnd++) { |
| 262 | 4453 | int exp = block->cpl_coord_exp[ch][bnd]; | |
| 263 | 4453 | min_exp = FFMIN(exp, min_exp); | |
| 264 | 4453 | max_exp = FFMAX(exp, max_exp); | |
| 265 | } | ||
| 266 | 1513 | master_exp = ((max_exp - 15) + 2) / 3; | |
| 267 | 1513 | master_exp = FFMAX(master_exp, 0); | |
| 268 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1513 times.
|
1513 | while (min_exp < master_exp * 3) |
| 269 | ✗ | master_exp--; | |
| 270 |
2/2✓ Branch 0 taken 5966 times.
✓ Branch 1 taken 1513 times.
|
7479 | for (bnd = 0; bnd < s->num_cpl_bands; bnd++) { |
| 271 | 5966 | block->cpl_coord_exp[ch][bnd] = av_clip(block->cpl_coord_exp[ch][bnd] - | |
| 272 | 5966 | master_exp * 3, 0, 15); | |
| 273 | } | ||
| 274 | 1513 | block->cpl_master_exp[ch] = master_exp; | |
| 275 | |||
| 276 | /* quantize mantissas */ | ||
| 277 |
2/2✓ Branch 0 taken 5966 times.
✓ Branch 1 taken 1513 times.
|
7479 | for (bnd = 0; bnd < s->num_cpl_bands; bnd++) { |
| 278 | 5966 | int cpl_exp = block->cpl_coord_exp[ch][bnd]; | |
| 279 | 5966 | int cpl_mant = (fixed_cpl_coords[blk][ch][bnd] << (5 + cpl_exp + master_exp * 3)) >> 24; | |
| 280 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5966 times.
|
5966 | if (cpl_exp == 15) |
| 281 | ✗ | cpl_mant >>= 1; | |
| 282 | else | ||
| 283 | 5966 | cpl_mant -= 16; | |
| 284 | |||
| 285 | 5966 | block->cpl_coord_mant[ch][bnd] = cpl_mant; | |
| 286 | } | ||
| 287 | } | ||
| 288 | } | ||
| 289 | |||
| 290 |
2/2✓ Branch 0 taken 273 times.
✓ Branch 1 taken 273 times.
|
546 | if (AC3ENC_FLOAT && CONFIG_EAC3_ENCODER && s->eac3) |
| 291 | 273 | ff_eac3_set_cpl_states(s); | |
| 292 | 727 | } | |
| 293 | |||
| 294 | |||
| 295 | /* | ||
| 296 | * Determine rematrixing flags for each block and band. | ||
| 297 | */ | ||
| 298 | 1231 | static void compute_rematrixing_strategy(AC3EncodeContext *s) | |
| 299 | { | ||
| 300 | int nb_coefs; | ||
| 301 | int blk, bnd; | ||
| 302 | 1231 | AC3Block *block, *block0 = NULL; | |
| 303 | |||
| 304 |
2/2✓ Branch 0 taken 512 times.
✓ Branch 1 taken 719 times.
|
1231 | if (s->channel_mode != AC3_CHMODE_STEREO) |
| 305 | 512 | return; | |
| 306 | |||
| 307 |
2/2✓ Branch 0 taken 4314 times.
✓ Branch 1 taken 719 times.
|
5033 | for (blk = 0; blk < s->num_blocks; blk++) { |
| 308 | 4314 | block = &s->blocks[blk]; | |
| 309 | 4314 | block->new_rematrixing_strategy = !blk; | |
| 310 | |||
| 311 | 4314 | block->num_rematrixing_bands = 4; | |
| 312 |
1/2✓ Branch 0 taken 4314 times.
✗ Branch 1 not taken.
|
4314 | if (block->cpl_in_use) { |
| 313 | 4314 | block->num_rematrixing_bands -= (s->start_freq[CPL_CH] <= 61); | |
| 314 | 4314 | block->num_rematrixing_bands -= (s->start_freq[CPL_CH] == 37); | |
| 315 |
3/4✓ Branch 0 taken 3595 times.
✓ Branch 1 taken 719 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3595 times.
|
4314 | if (blk && block->num_rematrixing_bands != block0->num_rematrixing_bands) |
| 316 | ✗ | block->new_rematrixing_strategy = 1; | |
| 317 | } | ||
| 318 | 4314 | nb_coefs = FFMIN(block->end_freq[1], block->end_freq[2]); | |
| 319 | |||
| 320 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4314 times.
|
4314 | if (!s->rematrixing_enabled) { |
| 321 | ✗ | block0 = block; | |
| 322 | ✗ | continue; | |
| 323 | } | ||
| 324 | |||
| 325 |
2/2✓ Branch 0 taken 17256 times.
✓ Branch 1 taken 4314 times.
|
21570 | for (bnd = 0; bnd < block->num_rematrixing_bands; bnd++) { |
| 326 | /* calculate sum of squared coeffs for one band in one block */ | ||
| 327 | 17256 | int start = ff_ac3_rematrix_band_tab[bnd]; | |
| 328 | 17256 | int end = FFMIN(nb_coefs, ff_ac3_rematrix_band_tab[bnd+1]); | |
| 329 | CoefSumType sum[4]; | ||
| 330 | 17256 | sum_square_butterfly(s, sum, block->mdct_coef[1] + start, | |
| 331 | 17256 | block->mdct_coef[2] + start, end - start); | |
| 332 | |||
| 333 | /* compare sums to determine if rematrixing will be used for this band */ | ||
| 334 |
6/6✓ Branch 0 taken 14315 times.
✓ Branch 1 taken 2941 times.
✓ Branch 2 taken 5234 times.
✓ Branch 3 taken 7870 times.
✓ Branch 4 taken 7354 times.
✓ Branch 5 taken 5750 times.
|
17256 | if (FFMIN(sum[2], sum[3]) < FFMIN(sum[0], sum[1])) |
| 335 | 9547 | block->rematrixing_flags[bnd] = 1; | |
| 336 | else | ||
| 337 | 7709 | block->rematrixing_flags[bnd] = 0; | |
| 338 | |||
| 339 | /* determine if new rematrixing flags will be sent */ | ||
| 340 |
2/2✓ Branch 0 taken 14380 times.
✓ Branch 1 taken 2876 times.
|
17256 | if (blk && |
| 341 |
2/2✓ Branch 0 taken 1886 times.
✓ Branch 1 taken 12494 times.
|
14380 | block->rematrixing_flags[bnd] != block0->rematrixing_flags[bnd]) { |
| 342 | 1886 | block->new_rematrixing_strategy = 1; | |
| 343 | } | ||
| 344 | } | ||
| 345 | 4314 | block0 = block; | |
| 346 | } | ||
| 347 | } | ||
| 348 | |||
| 349 | |||
| 350 | 1231 | static void encode_frame(AC3EncodeContext *s, uint8_t * const *samples) | |
| 351 | { | ||
| 352 | 1231 | apply_mdct(s, samples); | |
| 353 | |||
| 354 | 1231 | s->cpl_on = s->cpl_enabled; | |
| 355 | 1231 | ff_ac3_compute_coupling_strategy(s); | |
| 356 | |||
| 357 |
2/2✓ Branch 0 taken 727 times.
✓ Branch 1 taken 504 times.
|
1231 | if (s->cpl_on) |
| 358 | 727 | apply_channel_coupling(s); | |
| 359 | |||
| 360 | 1231 | compute_rematrixing_strategy(s); | |
| 361 | |||
| 362 | #if AC3ENC_FLOAT | ||
| 363 | 546 | scale_coefficients(s); | |
| 364 | #endif | ||
| 365 | 1231 | } | |
| 366 |