| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (C) 2011-2012 Michael Niedermayer (michaelni@gmx.at) | ||
| 3 | * | ||
| 4 | * This file is part of libswresample | ||
| 5 | * | ||
| 6 | * libswresample is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU Lesser General Public | ||
| 8 | * License as published by the Free Software Foundation; either | ||
| 9 | * version 2.1 of the License, or (at your option) any later version. | ||
| 10 | * | ||
| 11 | * libswresample is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | * Lesser General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU Lesser General Public | ||
| 17 | * License along with libswresample; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include "swresample_internal.h" | ||
| 22 | #include "libavutil/avassert.h" | ||
| 23 | #include "libavutil/channel_layout.h" | ||
| 24 | #include "libavutil/mem.h" | ||
| 25 | |||
| 26 | #define TEMPLATE_REMATRIX_FLT | ||
| 27 | #include "rematrix_template.c" | ||
| 28 | #undef TEMPLATE_REMATRIX_FLT | ||
| 29 | |||
| 30 | #define TEMPLATE_REMATRIX_DBL | ||
| 31 | #include "rematrix_template.c" | ||
| 32 | #undef TEMPLATE_REMATRIX_DBL | ||
| 33 | |||
| 34 | #define TEMPLATE_REMATRIX_S16 | ||
| 35 | #include "rematrix_template.c" | ||
| 36 | #define TEMPLATE_CLIP | ||
| 37 | #include "rematrix_template.c" | ||
| 38 | #undef TEMPLATE_CLIP | ||
| 39 | #undef TEMPLATE_REMATRIX_S16 | ||
| 40 | |||
| 41 | #define TEMPLATE_REMATRIX_S32 | ||
| 42 | #include "rematrix_template.c" | ||
| 43 | #undef TEMPLATE_REMATRIX_S32 | ||
| 44 | |||
| 45 | #define FRONT_LEFT 0 | ||
| 46 | #define FRONT_RIGHT 1 | ||
| 47 | #define FRONT_CENTER 2 | ||
| 48 | #define LOW_FREQUENCY 3 | ||
| 49 | #define BACK_LEFT 4 | ||
| 50 | #define BACK_RIGHT 5 | ||
| 51 | #define FRONT_LEFT_OF_CENTER 6 | ||
| 52 | #define FRONT_RIGHT_OF_CENTER 7 | ||
| 53 | #define BACK_CENTER 8 | ||
| 54 | #define SIDE_LEFT 9 | ||
| 55 | #define SIDE_RIGHT 10 | ||
| 56 | #define TOP_CENTER 11 | ||
| 57 | #define TOP_FRONT_LEFT 12 | ||
| 58 | #define TOP_FRONT_CENTER 13 | ||
| 59 | #define TOP_FRONT_RIGHT 14 | ||
| 60 | #define TOP_BACK_LEFT 15 | ||
| 61 | #define TOP_BACK_CENTER 16 | ||
| 62 | #define TOP_BACK_RIGHT 17 | ||
| 63 | #define LOW_FREQUENCY_2 35 | ||
| 64 | #define TOP_SIDE_LEFT 36 | ||
| 65 | #define TOP_SIDE_RIGHT 37 | ||
| 66 | #define BOTTOM_FRONT_CENTER 38 | ||
| 67 | #define BOTTOM_FRONT_LEFT 39 | ||
| 68 | #define BOTTOM_FRONT_RIGHT 40 | ||
| 69 | #define NUM_NAMED_CHANNELS 41 | ||
| 70 | |||
| 71 | 10 | int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride) | |
| 72 | { | ||
| 73 | int nb_in, nb_out, in, out; | ||
| 74 | |||
| 75 |
3/6✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
20 | if (!s || s->in_convert || // s needs to be allocated but not initialized |
| 76 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
20 | swri_check_chlayout(s, &s->user_in_chlayout , "input") || |
| 77 | 10 | swri_check_chlayout(s, &s->user_out_chlayout, "output") | |
| 78 | ) | ||
| 79 | ✗ | return AVERROR(EINVAL); | |
| 80 | 10 | memset(s->matrix, 0, sizeof(s->matrix)); | |
| 81 | |||
| 82 | 10 | nb_in = s->user_in_chlayout.nb_channels; | |
| 83 | 10 | nb_out = s->user_out_chlayout.nb_channels; | |
| 84 |
2/2✓ Branch 0 taken 31 times.
✓ Branch 1 taken 10 times.
|
41 | for (out = 0; out < nb_out; out++) { |
| 85 |
2/2✓ Branch 0 taken 147 times.
✓ Branch 1 taken 31 times.
|
178 | for (in = 0; in < nb_in; in++) |
| 86 | 147 | s->matrix[out][in] = matrix[in]; | |
| 87 | 31 | matrix += stride; | |
| 88 | } | ||
| 89 | 10 | s->rematrix_custom = 1; | |
| 90 | 10 | return 0; | |
| 91 | } | ||
| 92 | |||
| 93 | 31392 | static int even(int64_t layout){ | |
| 94 |
2/2✓ Branch 0 taken 24086 times.
✓ Branch 1 taken 7306 times.
|
31392 | if(!layout) return 1; |
| 95 |
1/2✓ Branch 0 taken 7306 times.
✗ Branch 1 not taken.
|
7306 | if(layout&(layout-1)) return 1; |
| 96 | ✗ | return 0; | |
| 97 | } | ||
| 98 | |||
| 99 | 3946 | static int clean_layout(AVChannelLayout *out, const AVChannelLayout *in, void *s) | |
| 100 | { | ||
| 101 | 3946 | int used = in->nb_channels, idx = 0; | |
| 102 | |||
| 103 |
3/4✓ Branch 0 taken 12 times.
✓ Branch 1 taken 3934 times.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
|
3946 | if (in->order == AV_CHANNEL_ORDER_CUSTOM && in->nb_channels > 1) { |
| 104 | 12 | used = 0; | |
| 105 |
2/2✓ Branch 0 taken 106 times.
✓ Branch 1 taken 12 times.
|
118 | for (int i = 0; i < in->nb_channels; i++) { |
| 106 |
2/2✓ Branch 0 taken 34 times.
✓ Branch 1 taken 72 times.
|
106 | if (in->u.map[i].id != AV_CHAN_UNUSED) { |
| 107 | 34 | idx = i; | |
| 108 | 34 | used++; | |
| 109 | } | ||
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 |
4/4✓ Branch 0 taken 287 times.
✓ Branch 1 taken 3659 times.
✓ Branch 2 taken 278 times.
✓ Branch 3 taken 9 times.
|
4233 | if (used != 1 || |
| 114 | 287 | av_channel_layout_channel_from_index(in, idx) == AV_CHAN_FRONT_CENTER) | |
| 115 | 3937 | return av_channel_layout_copy(out, in); | |
| 116 | |||
| 117 | char buf[128]; | ||
| 118 | 9 | av_channel_layout_describe(in, buf, sizeof(buf)); | |
| 119 | 9 | av_log(s, AV_LOG_VERBOSE, "Treating %s as mono\n", buf); | |
| 120 | |||
| 121 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2 times.
|
9 | if (in->nb_channels == 1) { |
| 122 | 7 | *out = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO; | |
| 123 | 7 | return 0; | |
| 124 | } | ||
| 125 | |||
| 126 | /* the channel keeps its place among the unused ones */ | ||
| 127 | 2 | int ret = av_channel_layout_copy(out, in); | |
| 128 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (ret < 0) |
| 129 | ✗ | return ret; | |
| 130 | 2 | out->u.map[idx].id = AV_CHAN_FRONT_CENTER; | |
| 131 | |||
| 132 | 2 | return 0; | |
| 133 | } | ||
| 134 | |||
| 135 | /** | ||
| 136 | * Stereo downmix channels are mixed like stereo, unless the other layout has | ||
| 137 | * such channels as well. The channels keep their places. | ||
| 138 | */ | ||
| 139 | 3946 | static void clean_downmix(AVChannelLayout *ch_layout, const AVChannelLayout *other) | |
| 140 | { | ||
| 141 |
3/4✓ Branch 1 taken 2 times.
✓ Branch 2 taken 3944 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
|
3948 | if (av_channel_layout_subset(ch_layout, ~(uint64_t)0) != AV_CH_LAYOUT_STEREO_DOWNMIX || |
| 142 | 2 | av_channel_layout_subset(other, AV_CH_LAYOUT_STEREO_DOWNMIX)) | |
| 143 | 3944 | return; | |
| 144 | |||
| 145 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (ch_layout->order == AV_CHANNEL_ORDER_NATIVE) { |
| 146 | ✗ | ch_layout->u.mask = AV_CH_LAYOUT_STEREO; | |
| 147 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | } else if (ch_layout->order == AV_CHANNEL_ORDER_CUSTOM) { |
| 148 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
|
7 | for (int i = 0; i < ch_layout->nb_channels; i++) { |
| 149 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
|
5 | if (ch_layout->u.map[i].id == AV_CHAN_STEREO_LEFT) |
| 150 | 2 | ch_layout->u.map[i].id = AV_CHAN_FRONT_LEFT; | |
| 151 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | else if (ch_layout->u.map[i].id == AV_CHAN_STEREO_RIGHT) |
| 152 | 2 | ch_layout->u.map[i].id = AV_CHAN_FRONT_RIGHT; | |
| 153 | } | ||
| 154 | } | ||
| 155 | } | ||
| 156 | |||
| 157 | 3946 | static int sane_layout(const AVChannelLayout *ch_layout, int mixed) { | |
| 158 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3946 times.
|
3946 | if(ch_layout->nb_channels > SWR_CH_MAX) |
| 159 | ✗ | return 0; | |
| 160 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 3934 times.
|
3946 | if(ch_layout->order == AV_CHANNEL_ORDER_CUSTOM) |
| 161 |
2/2✓ Branch 0 taken 106 times.
✓ Branch 1 taken 12 times.
|
118 | for (int i = 0; i < ch_layout->nb_channels; i++) { |
| 162 | 106 | enum AVChannel id = ch_layout->u.map[i].id; | |
| 163 | |||
| 164 |
2/2✓ Branch 0 taken 72 times.
✓ Branch 1 taken 34 times.
|
106 | if (id == AV_CHAN_UNUSED) |
| 165 | 72 | continue; | |
| 166 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 34 times.
|
34 | if (id >= 64) |
| 167 | ✗ | return 0; | |
| 168 | } | ||
| 169 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3934 times.
|
3934 | else if (ch_layout->order != AV_CHANNEL_ORDER_NATIVE) |
| 170 | ✗ | return 0; | |
| 171 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 3924 times.
|
3946 | if (!mixed) |
| 172 | 22 | return 1; | |
| 173 | 3924 | uint64_t mask = av_channel_layout_subset(ch_layout, ~(uint64_t)0); | |
| 174 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3924 times.
|
3924 | if(!(mask & AV_CH_LAYOUT_SURROUND)) // at least 1 front speaker |
| 175 | ✗ | return 0; | |
| 176 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3924 times.
|
3924 | if (!even(mask & (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT))) // no asymmetric front |
| 177 | ✗ | return 0; | |
| 178 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3924 times.
|
3924 | if (!even(mask & (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT))) // no asymmetric side |
| 179 | ✗ | return 0; | |
| 180 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3924 times.
|
3924 | if (!even(mask & (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT))) |
| 181 | ✗ | return 0; | |
| 182 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3924 times.
|
3924 | if (!even(mask & (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER))) |
| 183 | ✗ | return 0; | |
| 184 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3924 times.
|
3924 | if (!even(mask & (AV_CH_TOP_FRONT_LEFT | AV_CH_TOP_FRONT_RIGHT))) |
| 185 | ✗ | return 0; | |
| 186 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3924 times.
|
3924 | if (!even(mask & (AV_CH_TOP_BACK_LEFT | AV_CH_TOP_BACK_RIGHT))) |
| 187 | ✗ | return 0; | |
| 188 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3924 times.
|
3924 | if (!even(mask & (AV_CH_TOP_SIDE_LEFT | AV_CH_TOP_SIDE_RIGHT))) |
| 189 | ✗ | return 0; | |
| 190 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3924 times.
|
3924 | if (!even(mask & (AV_CH_BOTTOM_FRONT_LEFT | AV_CH_BOTTOM_FRONT_RIGHT))) |
| 191 | ✗ | return 0; | |
| 192 | |||
| 193 | 3924 | return 1; | |
| 194 | } | ||
| 195 | |||
| 196 | 1973 | static void build_matrix(const AVChannelLayout *in_ch_layout, const AVChannelLayout *out_ch_layout, | |
| 197 | double center_mix_level, double surround_mix_level, | ||
| 198 | double lfe_mix_level, double maxval, double rematrix_volume, double *matrix_param, | ||
| 199 | ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding) | ||
| 200 | { | ||
| 201 | 1973 | double matrix[NUM_NAMED_CHANNELS][NUM_NAMED_CHANNELS]={{0}}; | |
| 202 | 1973 | uint64_t in_mask = av_channel_layout_subset(in_ch_layout, ~(uint64_t)0); | |
| 203 | 1973 | uint64_t out_mask = av_channel_layout_subset(out_ch_layout, ~(uint64_t)0); | |
| 204 | 1973 | uint64_t unaccounted = in_mask & ~out_mask; | |
| 205 | 1973 | double maxcoef=0; | |
| 206 | int i, j; | ||
| 207 | |||
| 208 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1968 times.
|
1973 | if (in_ch_layout->order == AV_CHANNEL_ORDER_CUSTOM) { |
| 209 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 5 times.
|
25 | for (j = 0; j < in_ch_layout->nb_channels; j++) { |
| 210 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 15 times.
|
20 | if (in_ch_layout->u.map[j].id == AV_CHAN_UNUSED) { |
| 211 | /* the named-channel loop below cannot visit AV_CHAN_UNUSED. | ||
| 212 | * explicitly clear its column so callers may reuse a matrix. */ | ||
| 213 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 5 times.
|
24 | for (i = 0; i < out_ch_layout->nb_channels; i++) |
| 214 | 19 | matrix_param[stride * i + j] = 0.0; | |
| 215 | } | ||
| 216 | } | ||
| 217 | } | ||
| 218 | |||
| 219 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1966 times.
|
1973 | if (out_ch_layout->order == AV_CHANNEL_ORDER_CUSTOM) { |
| 220 |
2/2✓ Branch 0 taken 86 times.
✓ Branch 1 taken 7 times.
|
93 | for (i = 0; i < out_ch_layout->nb_channels; i++) { |
| 221 |
2/2✓ Branch 0 taken 67 times.
✓ Branch 1 taken 19 times.
|
86 | if (out_ch_layout->u.map[i].id == AV_CHAN_UNUSED) { |
| 222 | /* the named-channel loop below cannot visit AV_CHAN_UNUSED. | ||
| 223 | * explicitly clear its row so callers may reuse a matrix. */ | ||
| 224 |
2/2✓ Branch 0 taken 395 times.
✓ Branch 1 taken 67 times.
|
462 | for (j = 0; j < in_ch_layout->nb_channels; j++) |
| 225 | 395 | matrix_param[stride * i + j] = 0.0; | |
| 226 | } | ||
| 227 | } | ||
| 228 | } | ||
| 229 | |||
| 230 |
2/2✓ Branch 0 taken 80893 times.
✓ Branch 1 taken 1973 times.
|
82866 | for(i=0; i<FF_ARRAY_ELEMS(matrix); i++){ |
| 231 |
2/2✓ Branch 0 taken 5758 times.
✓ Branch 1 taken 75135 times.
|
80893 | if (in_mask & out_mask & (1ULL << i)) |
| 232 | 5758 | matrix[i][i]= 1.0; | |
| 233 | } | ||
| 234 | |||
| 235 | //FIXME implement dolby surround | ||
| 236 | //FIXME implement full ac3 | ||
| 237 | |||
| 238 |
2/2✓ Branch 0 taken 444 times.
✓ Branch 1 taken 1529 times.
|
1973 | if(unaccounted & AV_CH_FRONT_CENTER){ |
| 239 |
1/2✓ Branch 0 taken 444 times.
✗ Branch 1 not taken.
|
444 | if ((out_mask & AV_CH_LAYOUT_STEREO) == AV_CH_LAYOUT_STEREO) { |
| 240 |
2/2✓ Branch 0 taken 405 times.
✓ Branch 1 taken 39 times.
|
444 | if (in_mask & AV_CH_LAYOUT_STEREO) { |
| 241 | 405 | matrix[ FRONT_LEFT][FRONT_CENTER]+= center_mix_level; | |
| 242 | 405 | matrix[FRONT_RIGHT][FRONT_CENTER]+= center_mix_level; | |
| 243 | } else { | ||
| 244 | 39 | matrix[ FRONT_LEFT][FRONT_CENTER]+= M_SQRT1_2; | |
| 245 | 39 | matrix[FRONT_RIGHT][FRONT_CENTER]+= M_SQRT1_2; | |
| 246 | } | ||
| 247 | }else | ||
| 248 | ✗ | av_assert0(0); | |
| 249 | } | ||
| 250 |
2/2✓ Branch 0 taken 144 times.
✓ Branch 1 taken 1829 times.
|
1973 | if(unaccounted & AV_CH_LAYOUT_STEREO){ |
| 251 |
1/2✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
|
144 | if (out_mask & AV_CH_FRONT_CENTER) { |
| 252 | 144 | matrix[FRONT_CENTER][ FRONT_LEFT]+= M_SQRT1_2; | |
| 253 | 144 | matrix[FRONT_CENTER][FRONT_RIGHT]+= M_SQRT1_2; | |
| 254 |
2/2✓ Branch 0 taken 101 times.
✓ Branch 1 taken 43 times.
|
144 | if (in_mask & AV_CH_FRONT_CENTER) |
| 255 | 101 | matrix[FRONT_CENTER][ FRONT_CENTER] = center_mix_level*sqrt(2); | |
| 256 | }else | ||
| 257 | ✗ | av_assert0(0); | |
| 258 | } | ||
| 259 | |||
| 260 |
2/2✓ Branch 0 taken 269 times.
✓ Branch 1 taken 1704 times.
|
1973 | if(unaccounted & AV_CH_BACK_CENTER){ |
| 261 |
2/2✓ Branch 0 taken 113 times.
✓ Branch 1 taken 156 times.
|
269 | if (out_mask & AV_CH_BACK_LEFT) { |
| 262 | 113 | matrix[ BACK_LEFT][BACK_CENTER]+= M_SQRT1_2; | |
| 263 | 113 | matrix[BACK_RIGHT][BACK_CENTER]+= M_SQRT1_2; | |
| 264 |
2/2✓ Branch 0 taken 90 times.
✓ Branch 1 taken 66 times.
|
156 | } else if (out_mask & AV_CH_SIDE_LEFT) { |
| 265 | 90 | matrix[ SIDE_LEFT][BACK_CENTER]+= M_SQRT1_2; | |
| 266 | 90 | matrix[SIDE_RIGHT][BACK_CENTER]+= M_SQRT1_2; | |
| 267 |
2/2✓ Branch 0 taken 39 times.
✓ Branch 1 taken 27 times.
|
66 | } else if (out_mask & AV_CH_FRONT_LEFT) { |
| 268 |
2/4✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 39 times.
|
39 | if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY || |
| 269 | matrix_encoding == AV_MATRIX_ENCODING_DPLII) { | ||
| 270 | ✗ | if (unaccounted & (AV_CH_BACK_LEFT | AV_CH_SIDE_LEFT)) { | |
| 271 | ✗ | matrix[FRONT_LEFT ][BACK_CENTER] -= surround_mix_level * M_SQRT1_2; | |
| 272 | ✗ | matrix[FRONT_RIGHT][BACK_CENTER] += surround_mix_level * M_SQRT1_2; | |
| 273 | } else { | ||
| 274 | ✗ | matrix[FRONT_LEFT ][BACK_CENTER] -= surround_mix_level; | |
| 275 | ✗ | matrix[FRONT_RIGHT][BACK_CENTER] += surround_mix_level; | |
| 276 | } | ||
| 277 | } else { | ||
| 278 | 39 | matrix[ FRONT_LEFT][BACK_CENTER]+= surround_mix_level * M_SQRT1_2; | |
| 279 | 39 | matrix[FRONT_RIGHT][BACK_CENTER]+= surround_mix_level * M_SQRT1_2; | |
| 280 | } | ||
| 281 |
1/2✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
|
27 | } else if (out_mask & AV_CH_FRONT_CENTER) { |
| 282 | 27 | matrix[ FRONT_CENTER][BACK_CENTER]+= surround_mix_level * M_SQRT1_2; | |
| 283 | }else | ||
| 284 | ✗ | av_assert0(0); | |
| 285 | } | ||
| 286 |
2/2✓ Branch 0 taken 521 times.
✓ Branch 1 taken 1452 times.
|
1973 | if(unaccounted & AV_CH_BACK_LEFT){ |
| 287 |
2/2✓ Branch 0 taken 105 times.
✓ Branch 1 taken 416 times.
|
521 | if (out_mask & AV_CH_BACK_CENTER) { |
| 288 | 105 | matrix[BACK_CENTER][ BACK_LEFT]+= M_SQRT1_2; | |
| 289 | 105 | matrix[BACK_CENTER][BACK_RIGHT]+= M_SQRT1_2; | |
| 290 |
2/2✓ Branch 0 taken 220 times.
✓ Branch 1 taken 196 times.
|
416 | } else if (out_mask & AV_CH_SIDE_LEFT) { |
| 291 |
2/2✓ Branch 0 taken 88 times.
✓ Branch 1 taken 132 times.
|
220 | if (in_mask & AV_CH_SIDE_LEFT) { |
| 292 | 88 | matrix[ SIDE_LEFT][ BACK_LEFT]+= M_SQRT1_2; | |
| 293 | 88 | matrix[SIDE_RIGHT][BACK_RIGHT]+= M_SQRT1_2; | |
| 294 | }else{ | ||
| 295 | 132 | matrix[ SIDE_LEFT][ BACK_LEFT]+= 1.0; | |
| 296 | 132 | matrix[SIDE_RIGHT][BACK_RIGHT]+= 1.0; | |
| 297 | } | ||
| 298 |
2/2✓ Branch 0 taken 137 times.
✓ Branch 1 taken 59 times.
|
196 | } else if (out_mask & AV_CH_FRONT_LEFT) { |
| 299 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 137 times.
|
137 | if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) { |
| 300 | ✗ | matrix[FRONT_LEFT ][BACK_LEFT ] -= surround_mix_level * M_SQRT1_2; | |
| 301 | ✗ | matrix[FRONT_LEFT ][BACK_RIGHT] -= surround_mix_level * M_SQRT1_2; | |
| 302 | ✗ | matrix[FRONT_RIGHT][BACK_LEFT ] += surround_mix_level * M_SQRT1_2; | |
| 303 | ✗ | matrix[FRONT_RIGHT][BACK_RIGHT] += surround_mix_level * M_SQRT1_2; | |
| 304 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 137 times.
|
137 | } else if (matrix_encoding == AV_MATRIX_ENCODING_DPLII) { |
| 305 | ✗ | matrix[FRONT_LEFT ][BACK_LEFT ] -= surround_mix_level * SQRT3_2; | |
| 306 | ✗ | matrix[FRONT_LEFT ][BACK_RIGHT] -= surround_mix_level * M_SQRT1_2; | |
| 307 | ✗ | matrix[FRONT_RIGHT][BACK_LEFT ] += surround_mix_level * M_SQRT1_2; | |
| 308 | ✗ | matrix[FRONT_RIGHT][BACK_RIGHT] += surround_mix_level * SQRT3_2; | |
| 309 | } else { | ||
| 310 | 137 | matrix[ FRONT_LEFT][ BACK_LEFT] += surround_mix_level; | |
| 311 | 137 | matrix[FRONT_RIGHT][BACK_RIGHT] += surround_mix_level; | |
| 312 | } | ||
| 313 |
1/2✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
|
59 | } else if (out_mask & AV_CH_FRONT_CENTER) { |
| 314 | 59 | matrix[ FRONT_CENTER][BACK_LEFT ]+= surround_mix_level*M_SQRT1_2; | |
| 315 | 59 | matrix[ FRONT_CENTER][BACK_RIGHT]+= surround_mix_level*M_SQRT1_2; | |
| 316 | }else | ||
| 317 | ✗ | av_assert0(0); | |
| 318 | } | ||
| 319 | |||
| 320 |
2/2✓ Branch 0 taken 537 times.
✓ Branch 1 taken 1436 times.
|
1973 | if(unaccounted & AV_CH_SIDE_LEFT){ |
| 321 |
2/2✓ Branch 0 taken 196 times.
✓ Branch 1 taken 341 times.
|
537 | if (out_mask & AV_CH_BACK_LEFT) { |
| 322 | /* if back channels do not exist in the input, just copy side | ||
| 323 | channels to back channels, otherwise mix side into back */ | ||
| 324 |
2/2✓ Branch 0 taken 62 times.
✓ Branch 1 taken 134 times.
|
196 | if (in_mask & AV_CH_BACK_LEFT) { |
| 325 | 62 | matrix[BACK_LEFT ][SIDE_LEFT ] += M_SQRT1_2; | |
| 326 | 62 | matrix[BACK_RIGHT][SIDE_RIGHT] += M_SQRT1_2; | |
| 327 | } else { | ||
| 328 | 134 | matrix[BACK_LEFT ][SIDE_LEFT ] += 1.0; | |
| 329 | 134 | matrix[BACK_RIGHT][SIDE_RIGHT] += 1.0; | |
| 330 | } | ||
| 331 |
2/2✓ Branch 0 taken 136 times.
✓ Branch 1 taken 205 times.
|
341 | } else if (out_mask & AV_CH_BACK_CENTER) { |
| 332 | 136 | matrix[BACK_CENTER][ SIDE_LEFT]+= M_SQRT1_2; | |
| 333 | 136 | matrix[BACK_CENTER][SIDE_RIGHT]+= M_SQRT1_2; | |
| 334 |
2/2✓ Branch 0 taken 145 times.
✓ Branch 1 taken 60 times.
|
205 | } else if (out_mask & AV_CH_FRONT_LEFT) { |
| 335 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 145 times.
|
145 | if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) { |
| 336 | ✗ | matrix[FRONT_LEFT ][SIDE_LEFT ] -= surround_mix_level * M_SQRT1_2; | |
| 337 | ✗ | matrix[FRONT_LEFT ][SIDE_RIGHT] -= surround_mix_level * M_SQRT1_2; | |
| 338 | ✗ | matrix[FRONT_RIGHT][SIDE_LEFT ] += surround_mix_level * M_SQRT1_2; | |
| 339 | ✗ | matrix[FRONT_RIGHT][SIDE_RIGHT] += surround_mix_level * M_SQRT1_2; | |
| 340 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 145 times.
|
145 | } else if (matrix_encoding == AV_MATRIX_ENCODING_DPLII) { |
| 341 | ✗ | matrix[FRONT_LEFT ][SIDE_LEFT ] -= surround_mix_level * SQRT3_2; | |
| 342 | ✗ | matrix[FRONT_LEFT ][SIDE_RIGHT] -= surround_mix_level * M_SQRT1_2; | |
| 343 | ✗ | matrix[FRONT_RIGHT][SIDE_LEFT ] += surround_mix_level * M_SQRT1_2; | |
| 344 | ✗ | matrix[FRONT_RIGHT][SIDE_RIGHT] += surround_mix_level * SQRT3_2; | |
| 345 | } else { | ||
| 346 | 145 | matrix[ FRONT_LEFT][ SIDE_LEFT] += surround_mix_level; | |
| 347 | 145 | matrix[FRONT_RIGHT][SIDE_RIGHT] += surround_mix_level; | |
| 348 | } | ||
| 349 |
1/2✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
|
60 | } else if (out_mask & AV_CH_FRONT_CENTER) { |
| 350 | 60 | matrix[ FRONT_CENTER][SIDE_LEFT ]+= surround_mix_level * M_SQRT1_2; | |
| 351 | 60 | matrix[ FRONT_CENTER][SIDE_RIGHT]+= surround_mix_level * M_SQRT1_2; | |
| 352 | }else | ||
| 353 | ✗ | av_assert0(0); | |
| 354 | } | ||
| 355 | |||
| 356 |
2/2✓ Branch 0 taken 160 times.
✓ Branch 1 taken 1813 times.
|
1973 | if(unaccounted & AV_CH_FRONT_LEFT_OF_CENTER){ |
| 357 |
2/2✓ Branch 0 taken 149 times.
✓ Branch 1 taken 11 times.
|
160 | if (out_mask & AV_CH_FRONT_LEFT) { |
| 358 | 149 | matrix[ FRONT_LEFT][ FRONT_LEFT_OF_CENTER]+= 1.0; | |
| 359 | 149 | matrix[FRONT_RIGHT][FRONT_RIGHT_OF_CENTER]+= 1.0; | |
| 360 |
1/2✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
|
11 | } else if (out_mask & AV_CH_FRONT_CENTER) { |
| 361 | 11 | matrix[ FRONT_CENTER][ FRONT_LEFT_OF_CENTER]+= M_SQRT1_2; | |
| 362 | 11 | matrix[ FRONT_CENTER][FRONT_RIGHT_OF_CENTER]+= M_SQRT1_2; | |
| 363 | }else | ||
| 364 | ✗ | av_assert0(0); | |
| 365 | } | ||
| 366 | |||
| 367 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 1933 times.
|
1973 | if (unaccounted & AV_CH_TOP_FRONT_LEFT) { |
| 368 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
|
40 | if (out_mask & AV_CH_TOP_FRONT_CENTER) { |
| 369 | ✗ | matrix[TOP_FRONT_CENTER][TOP_FRONT_LEFT ] += M_SQRT1_2; | |
| 370 | ✗ | matrix[TOP_FRONT_CENTER][TOP_FRONT_RIGHT] += M_SQRT1_2; | |
| 371 | ✗ | if (in_mask & AV_CH_TOP_FRONT_CENTER) | |
| 372 | ✗ | matrix[TOP_FRONT_CENTER][TOP_FRONT_CENTER] = center_mix_level * sqrt(2); | |
| 373 |
2/2✓ Branch 0 taken 30 times.
✓ Branch 1 taken 10 times.
|
40 | } else if (out_mask & AV_CH_FRONT_LEFT) { |
| 374 | /* U+030 -> M+030 in ITU-R BS.2127-1, Table 16. */ | ||
| 375 | 30 | matrix[FRONT_LEFT ][TOP_FRONT_LEFT ] += 1.0; | |
| 376 | 30 | matrix[FRONT_RIGHT][TOP_FRONT_RIGHT] += 1.0; | |
| 377 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | } else if (out_mask & AV_CH_FRONT_CENTER) { |
| 378 | 10 | matrix[FRONT_CENTER][TOP_FRONT_LEFT ] += M_SQRT1_2; | |
| 379 | 10 | matrix[FRONT_CENTER][TOP_FRONT_RIGHT] += M_SQRT1_2; | |
| 380 | } else | ||
| 381 | ✗ | av_assert0(0); | |
| 382 | } | ||
| 383 | |||
| 384 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 1948 times.
|
1973 | if (unaccounted & AV_CH_TOP_FRONT_CENTER) { |
| 385 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 12 times.
|
25 | if (out_mask & AV_CH_TOP_FRONT_LEFT) { |
| 386 | /* U+030 = U-030 = sqrt(1/2) */ | ||
| 387 | 13 | matrix[TOP_FRONT_LEFT ][TOP_FRONT_CENTER]+= M_SQRT1_2; | |
| 388 | 13 | matrix[TOP_FRONT_RIGHT][TOP_FRONT_CENTER]+= M_SQRT1_2; | |
| 389 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
|
12 | } else if (out_mask & AV_CH_FRONT_CENTER) { |
| 390 | /* M+000 = 1 */ | ||
| 391 | 9 | matrix[FRONT_CENTER][TOP_FRONT_CENTER] += 1.0; | |
| 392 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | } else if (out_mask & AV_CH_FRONT_LEFT) { |
| 393 | /* M+030 = M-030 = sqrt(1/2) */ | ||
| 394 | 3 | matrix[FRONT_LEFT ][TOP_FRONT_CENTER] += center_mix_level; | |
| 395 | 3 | matrix[FRONT_RIGHT][TOP_FRONT_CENTER] += center_mix_level; | |
| 396 | } else | ||
| 397 | ✗ | av_assert0(0); | |
| 398 | } | ||
| 399 | |||
| 400 |
2/2✓ Branch 0 taken 43 times.
✓ Branch 1 taken 1930 times.
|
1973 | if (unaccounted & AV_CH_TOP_BACK_LEFT) { |
| 401 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 40 times.
|
43 | if (out_mask & AV_CH_TOP_BACK_CENTER) { |
| 402 | 3 | matrix[TOP_BACK_CENTER][TOP_BACK_LEFT ] += M_SQRT1_2; | |
| 403 | 3 | matrix[TOP_BACK_CENTER][TOP_BACK_RIGHT] += M_SQRT1_2; | |
| 404 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 28 times.
|
40 | } else if (out_mask & AV_CH_TOP_FRONT_LEFT) { |
| 405 | /* IAMF v1.1.0, Section 7.3.2.1.1. */ | ||
| 406 | 12 | matrix[TOP_FRONT_LEFT ][TOP_BACK_LEFT ] += M_SQRT1_2; | |
| 407 | 12 | matrix[TOP_FRONT_RIGHT][TOP_BACK_RIGHT] += M_SQRT1_2; | |
| 408 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 14 times.
|
28 | } else if (out_mask & AV_CH_BACK_LEFT) { |
| 409 | 14 | matrix[BACK_LEFT ][TOP_BACK_LEFT ] += 1.0; | |
| 410 | 14 | matrix[BACK_RIGHT][TOP_BACK_RIGHT] += 1.0; | |
| 411 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
|
14 | } else if (out_mask & AV_CH_SIDE_LEFT) { |
| 412 | ✗ | matrix[SIDE_LEFT ][TOP_BACK_LEFT ] += 1.0; | |
| 413 | ✗ | matrix[SIDE_RIGHT][TOP_BACK_RIGHT] += 1.0; | |
| 414 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 7 times.
|
14 | } else if (out_mask & AV_CH_FRONT_LEFT) { |
| 415 | 7 | matrix[FRONT_LEFT ][TOP_BACK_LEFT ] += surround_mix_level; | |
| 416 | 7 | matrix[FRONT_RIGHT][TOP_BACK_RIGHT] += surround_mix_level; | |
| 417 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | } else if (out_mask & AV_CH_FRONT_CENTER) { |
| 418 | 7 | matrix[FRONT_CENTER][TOP_BACK_LEFT ] += surround_mix_level*M_SQRT1_2; | |
| 419 | 7 | matrix[FRONT_CENTER][TOP_BACK_RIGHT] += surround_mix_level*M_SQRT1_2; | |
| 420 | } else | ||
| 421 | ✗ | av_assert0(0); | |
| 422 | } | ||
| 423 | |||
| 424 | /* BS.2127-1 maps U+180 to rear outputs before front outputs. */ | ||
| 425 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 1953 times.
|
1973 | if (unaccounted & AV_CH_TOP_BACK_CENTER) { |
| 426 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 12 times.
|
20 | if (out_mask & AV_CH_TOP_BACK_LEFT) { |
| 427 | 8 | matrix[TOP_BACK_LEFT ][TOP_BACK_CENTER] += M_SQRT1_2; | |
| 428 | 8 | matrix[TOP_BACK_RIGHT][TOP_BACK_CENTER] += M_SQRT1_2; | |
| 429 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | } else if (out_mask & AV_CH_BACK_LEFT) { |
| 430 | 6 | matrix[BACK_LEFT ][TOP_BACK_CENTER] += M_SQRT1_2; | |
| 431 | 6 | matrix[BACK_RIGHT][TOP_BACK_CENTER] += M_SQRT1_2; | |
| 432 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
|
6 | } else if (out_mask & AV_CH_SIDE_LEFT) { |
| 433 | 2 | matrix[SIDE_LEFT ][TOP_BACK_CENTER] += M_SQRT1_2; | |
| 434 | 2 | matrix[SIDE_RIGHT][TOP_BACK_CENTER] += M_SQRT1_2; | |
| 435 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | } else if (out_mask & AV_CH_FRONT_LEFT) { |
| 436 | 2 | matrix[FRONT_LEFT ][TOP_BACK_CENTER] += 0.5; | |
| 437 | 2 | matrix[FRONT_RIGHT][TOP_BACK_CENTER] += 0.5; | |
| 438 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | } else if (out_mask & AV_CH_FRONT_CENTER) |
| 439 | 2 | matrix[FRONT_CENTER][TOP_BACK_CENTER] += 0.5; | |
| 440 | else | ||
| 441 | ✗ | av_assert0(0); | |
| 442 | } | ||
| 443 | |||
| 444 | |||
| 445 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1949 times.
|
1973 | if (unaccounted & AV_CH_TOP_SIDE_LEFT) { |
| 446 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 22 times.
|
24 | if ((out_mask & (AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_BACK_CENTER)) == |
| 447 | (AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_BACK_CENTER)) { | ||
| 448 | /* UH+180 = sqrt(1/3); U±045 = sqrt(2/3)*/ | ||
| 449 | 2 | matrix[TOP_FRONT_LEFT ][TOP_SIDE_LEFT ] += SQRT2_3; | |
| 450 | 2 | matrix[TOP_FRONT_RIGHT][TOP_SIDE_RIGHT] += SQRT2_3; | |
| 451 | 2 | matrix[TOP_BACK_CENTER][TOP_SIDE_LEFT ] += SQRT1_3; | |
| 452 | 2 | matrix[TOP_BACK_CENTER][TOP_SIDE_RIGHT] += SQRT1_3; | |
| 453 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 12 times.
|
22 | } else if ((out_mask & (AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_BACK_LEFT)) == |
| 454 | (AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_BACK_LEFT)) { | ||
| 455 | /* U±030 = U±110 = sqrt(1/2) */ | ||
| 456 | 10 | matrix[TOP_FRONT_LEFT ][TOP_SIDE_LEFT ] += M_SQRT1_2; | |
| 457 | 10 | matrix[TOP_FRONT_RIGHT][TOP_SIDE_RIGHT] += M_SQRT1_2; | |
| 458 | 10 | matrix[TOP_BACK_LEFT ][TOP_SIDE_LEFT ] += M_SQRT1_2; | |
| 459 | 10 | matrix[TOP_BACK_RIGHT][TOP_SIDE_RIGHT] += M_SQRT1_2; | |
| 460 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8 times.
|
12 | } else if (out_mask & AV_CH_TOP_FRONT_LEFT && |
| 461 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | (out_mask & (AV_CH_BACK_LEFT|AV_CH_SIDE_LEFT))) { |
| 462 | /* U±030 = M±110 = sqrt(1/2) */ | ||
| 463 | 4 | matrix[TOP_FRONT_LEFT ][TOP_SIDE_LEFT] += M_SQRT1_2; | |
| 464 | 4 | matrix[TOP_FRONT_RIGHT][TOP_SIDE_RIGHT] += M_SQRT1_2; | |
| 465 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | if (out_mask & AV_CH_BACK_LEFT) { |
| 466 | 2 | matrix[BACK_LEFT ][TOP_SIDE_LEFT] += M_SQRT1_2; | |
| 467 | 2 | matrix[BACK_RIGHT][TOP_SIDE_RIGHT] += M_SQRT1_2; | |
| 468 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | } else if (out_mask & AV_CH_SIDE_LEFT) { |
| 469 | 2 | matrix[SIDE_LEFT ][TOP_SIDE_LEFT] += M_SQRT1_2; | |
| 470 | 2 | matrix[SIDE_RIGHT][TOP_SIDE_RIGHT] += M_SQRT1_2; | |
| 471 | } | ||
| 472 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
|
8 | } else if (out_mask & AV_CH_SIDE_LEFT) { |
| 473 | /* M±090 = 1 */ | ||
| 474 | 2 | matrix[SIDE_LEFT ][TOP_SIDE_LEFT ] += 1.0; | |
| 475 | 2 | matrix[SIDE_RIGHT][TOP_SIDE_RIGHT] += 1.0; | |
| 476 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
|
6 | } else if (out_mask & AV_CH_FRONT_LEFT) { |
| 477 | /* M±030 = M±110 = sqrt(1/2) */ | ||
| 478 | 4 | matrix[FRONT_LEFT ][TOP_SIDE_LEFT ] += surround_mix_level; | |
| 479 | 4 | matrix[FRONT_RIGHT][TOP_SIDE_RIGHT] += surround_mix_level; | |
| 480 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | if (out_mask & AV_CH_BACK_LEFT) { |
| 481 | 2 | matrix[BACK_LEFT ][TOP_SIDE_LEFT ] += M_SQRT1_2; | |
| 482 | 2 | matrix[BACK_RIGHT][TOP_SIDE_RIGHT] += M_SQRT1_2; | |
| 483 | } | ||
| 484 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | } else if (out_mask & AV_CH_FRONT_CENTER) { |
| 485 | 2 | matrix[FRONT_CENTER][TOP_SIDE_LEFT ] += surround_mix_level*M_SQRT1_2; | |
| 486 | 2 | matrix[FRONT_CENTER][TOP_SIDE_RIGHT] += surround_mix_level*M_SQRT1_2; | |
| 487 | } else | ||
| 488 | ✗ | av_assert0(0); | |
| 489 | } | ||
| 490 | |||
| 491 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 1948 times.
|
1973 | if (unaccounted & AV_CH_TOP_CENTER) { |
| 492 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 18 times.
|
25 | if ((out_mask & (AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_BACK_LEFT)) == |
| 493 | (AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_BACK_LEFT)) { | ||
| 494 | /* U+045 = U-045 = U+135 = U-135 = sqrt(1/4) */ | ||
| 495 | 7 | matrix[TOP_FRONT_LEFT ][TOP_CENTER] += 0.5; | |
| 496 | 7 | matrix[TOP_FRONT_RIGHT][TOP_CENTER] += 0.5; | |
| 497 | 7 | matrix[TOP_BACK_LEFT ][TOP_CENTER] += 0.5; | |
| 498 | 7 | matrix[TOP_BACK_RIGHT][TOP_CENTER] += 0.5; | |
| 499 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 17 times.
|
18 | } else if ((out_mask & (AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_BACK_CENTER)) == |
| 500 | (AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_BACK_CENTER)) { | ||
| 501 | /* U+045 = U-045 = UH+180 = sqrt(1/3) */ | ||
| 502 | 1 | matrix[TOP_FRONT_LEFT ][TOP_CENTER] += SQRT1_3; | |
| 503 | 1 | matrix[TOP_FRONT_RIGHT][TOP_CENTER] += SQRT1_3; | |
| 504 | 1 | matrix[TOP_BACK_CENTER][TOP_CENTER] += SQRT1_3; | |
| 505 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 12 times.
|
17 | } else if (out_mask & AV_CH_TOP_FRONT_LEFT && |
| 506 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | out_mask & (AV_CH_BACK_LEFT|AV_CH_SIDE_LEFT)) { |
| 507 | /* U+045 = U-045 = M+135 = M-135 = sqrt(1/4) * | ||
| 508 | * U+030 = U-030 = M+110 = M-110 = sqrt(1/4) */ | ||
| 509 | 5 | matrix[TOP_FRONT_LEFT ][TOP_CENTER] += 0.5; | |
| 510 | 5 | matrix[TOP_FRONT_RIGHT][TOP_CENTER] += 0.5; | |
| 511 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
|
5 | if (out_mask & AV_CH_BACK_LEFT) { |
| 512 | 2 | matrix[BACK_LEFT ][TOP_CENTER] += 0.5; | |
| 513 | 2 | matrix[BACK_RIGHT][TOP_CENTER] += 0.5; | |
| 514 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | } else if (out_mask & AV_CH_SIDE_LEFT) { |
| 515 | 3 | matrix[SIDE_LEFT ][TOP_CENTER] += 0.5; | |
| 516 | 3 | matrix[SIDE_RIGHT][TOP_CENTER] += 0.5; | |
| 517 | } | ||
| 518 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
|
12 | } else if (out_mask & AV_CH_FRONT_LEFT) { |
| 519 | /* M+030 = M-030 = M+135 = M-135 = sqrt(1/4) */ | ||
| 520 | /* M+030 = M-030 = sqrt(1/4) */ | ||
| 521 | 9 | matrix[FRONT_LEFT ][TOP_CENTER] += 0.5; | |
| 522 | 9 | matrix[FRONT_RIGHT][TOP_CENTER] += 0.5; | |
| 523 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
|
9 | if (out_mask & AV_CH_BACK_LEFT) { |
| 524 | 6 | matrix[BACK_LEFT ][TOP_CENTER] += 0.5; | |
| 525 | 6 | matrix[BACK_RIGHT][TOP_CENTER] += 0.5; | |
| 526 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | } else if (out_mask & AV_CH_SIDE_LEFT) { |
| 527 | ✗ | matrix[SIDE_LEFT ][TOP_CENTER] += 0.5; | |
| 528 | ✗ | matrix[SIDE_RIGHT][TOP_CENTER] += 0.5; | |
| 529 | } | ||
| 530 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | } else if (out_mask & AV_CH_FRONT_CENTER) { |
| 531 | 3 | matrix[FRONT_CENTER][TOP_CENTER] += 0.5; | |
| 532 | } else | ||
| 533 | ✗ | av_assert0(0); | |
| 534 | } | ||
| 535 | |||
| 536 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 1960 times.
|
1973 | if (unaccounted & AV_CH_BOTTOM_FRONT_CENTER) { |
| 537 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 1 times.
|
13 | if (out_mask & AV_CH_FRONT_CENTER) { |
| 538 | 12 | matrix[FRONT_CENTER][BOTTOM_FRONT_CENTER] += 1.0; | |
| 539 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | } else if (out_mask & AV_CH_FRONT_LEFT) { |
| 540 | 1 | matrix[FRONT_LEFT ][BOTTOM_FRONT_CENTER] += center_mix_level; | |
| 541 | 1 | matrix[FRONT_RIGHT][BOTTOM_FRONT_CENTER] += center_mix_level; | |
| 542 | } else | ||
| 543 | ✗ | av_assert0(0); | |
| 544 | } | ||
| 545 | |||
| 546 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 1960 times.
|
1973 | if (unaccounted & AV_CH_BOTTOM_FRONT_LEFT) { |
| 547 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | if (out_mask & AV_CH_BOTTOM_FRONT_CENTER) { |
| 548 | ✗ | matrix[BOTTOM_FRONT_CENTER][BOTTOM_FRONT_LEFT ] += M_SQRT1_2; | |
| 549 | ✗ | matrix[BOTTOM_FRONT_CENTER][BOTTOM_FRONT_RIGHT] += M_SQRT1_2; | |
| 550 | ✗ | if (in_mask & AV_CH_BOTTOM_FRONT_CENTER) | |
| 551 | ✗ | matrix[BOTTOM_FRONT_CENTER][BOTTOM_FRONT_CENTER] = center_mix_level * sqrt(2); | |
| 552 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 1 times.
|
13 | } else if (out_mask & AV_CH_FRONT_LEFT) { |
| 553 | /* M±030 = 1 */ | ||
| 554 | 12 | matrix[FRONT_LEFT ][BOTTOM_FRONT_LEFT ] += 1.0; | |
| 555 | 12 | matrix[FRONT_RIGHT][BOTTOM_FRONT_RIGHT] += 1.0; | |
| 556 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | } else if (out_mask & AV_CH_FRONT_CENTER) { |
| 557 | 1 | matrix[FRONT_CENTER][BOTTOM_FRONT_LEFT ] += M_SQRT1_2; | |
| 558 | 1 | matrix[FRONT_CENTER][BOTTOM_FRONT_RIGHT] += M_SQRT1_2; | |
| 559 | } else | ||
| 560 | ✗ | av_assert0(0); | |
| 561 | } | ||
| 562 | |||
| 563 | /* mix LFE into front left/right or center */ | ||
| 564 |
2/2✓ Branch 0 taken 455 times.
✓ Branch 1 taken 1518 times.
|
1973 | if (unaccounted & AV_CH_LOW_FREQUENCY) { |
| 565 |
2/2✓ Branch 0 taken 263 times.
✓ Branch 1 taken 192 times.
|
455 | if (out_mask & AV_CH_FRONT_CENTER) { |
| 566 | 263 | matrix[FRONT_CENTER][LOW_FREQUENCY] += lfe_mix_level; | |
| 567 |
1/2✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
|
192 | } else if (out_mask & AV_CH_FRONT_LEFT) { |
| 568 | 192 | matrix[FRONT_LEFT ][LOW_FREQUENCY] += lfe_mix_level * M_SQRT1_2; | |
| 569 | 192 | matrix[FRONT_RIGHT][LOW_FREQUENCY] += lfe_mix_level * M_SQRT1_2; | |
| 570 | } else | ||
| 571 | ✗ | av_assert0(0); | |
| 572 | } | ||
| 573 | |||
| 574 | /* mix LFE2 into LFE, front left/right or center */ | ||
| 575 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 1953 times.
|
1973 | if (unaccounted & AV_CH_LOW_FREQUENCY_2) { |
| 576 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
|
20 | if (out_mask & AV_CH_LOW_FREQUENCY) { |
| 577 | 16 | matrix[LOW_FREQUENCY][LOW_FREQUENCY_2] += M_SQRT1_2; | |
| 578 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | } else if (out_mask & AV_CH_FRONT_CENTER) { |
| 579 | 2 | matrix[FRONT_CENTER][LOW_FREQUENCY_2] += lfe_mix_level; | |
| 580 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | } else if (out_mask & AV_CH_FRONT_LEFT) { |
| 581 | 2 | matrix[FRONT_LEFT ][LOW_FREQUENCY_2] += lfe_mix_level * M_SQRT1_2; | |
| 582 | 2 | matrix[FRONT_RIGHT][LOW_FREQUENCY_2] += lfe_mix_level * M_SQRT1_2; | |
| 583 | } else | ||
| 584 | ✗ | av_assert0(0); | |
| 585 | } | ||
| 586 | |||
| 587 | |||
| 588 |
2/2✓ Branch 0 taken 126272 times.
✓ Branch 1 taken 1973 times.
|
128245 | for (i = 0; i < 64; i++) { |
| 589 | 126272 | double sum=0; | |
| 590 | 126272 | int out_i = av_channel_layout_index_from_channel(out_ch_layout, i); | |
| 591 |
2/2✓ Branch 0 taken 116884 times.
✓ Branch 1 taken 9388 times.
|
126272 | if (out_i < 0) |
| 592 | 116884 | continue; | |
| 593 |
2/2✓ Branch 0 taken 600832 times.
✓ Branch 1 taken 9388 times.
|
610220 | for(j=0; j<64; j++){ |
| 594 | 600832 | int in_i = av_channel_layout_index_from_channel(in_ch_layout, j); | |
| 595 |
2/2✓ Branch 0 taken 551465 times.
✓ Branch 1 taken 49367 times.
|
600832 | if (in_i < 0) |
| 596 | 551465 | continue; | |
| 597 |
2/4✓ Branch 0 taken 49367 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 49367 times.
✗ Branch 3 not taken.
|
49367 | if (i < FF_ARRAY_ELEMS(matrix) && j < FF_ARRAY_ELEMS(matrix[0])) |
| 598 | 49367 | matrix_param[stride*out_i + in_i] = matrix[i][j]; | |
| 599 | else | ||
| 600 | ✗ | matrix_param[stride*out_i + in_i] = i == j && (in_mask & out_mask & (1ULL << i)); | |
| 601 | 49367 | sum += fabs(matrix_param[stride*out_i + in_i]); | |
| 602 | } | ||
| 603 |
2/2✓ Branch 0 taken 3488 times.
✓ Branch 1 taken 5900 times.
|
9388 | maxcoef= FFMAX(maxcoef, sum); |
| 604 | } | ||
| 605 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1973 times.
|
1973 | if(rematrix_volume < 0) |
| 606 | ✗ | maxcoef = -rematrix_volume; | |
| 607 | |||
| 608 |
3/4✓ Branch 0 taken 1390 times.
✓ Branch 1 taken 583 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1390 times.
|
1973 | if(maxcoef > maxval || rematrix_volume < 0){ |
| 609 | 583 | maxcoef /= maxval; | |
| 610 |
2/2✓ Branch 0 taken 37312 times.
✓ Branch 1 taken 583 times.
|
37895 | for(i=0; i<SWR_CH_MAX; i++) |
| 611 |
2/2✓ Branch 0 taken 2387968 times.
✓ Branch 1 taken 37312 times.
|
2425280 | for(j=0; j<SWR_CH_MAX; j++){ |
| 612 | 2387968 | matrix_param[stride*i + j] /= maxcoef; | |
| 613 | } | ||
| 614 | } | ||
| 615 | 1973 | } | |
| 616 | |||
| 617 | 1973 | av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelLayout *out_layout, | |
| 618 | double center_mix_level, double surround_mix_level, | ||
| 619 | double lfe_mix_level, double maxval, | ||
| 620 | double rematrix_volume, double *matrix_param, | ||
| 621 | ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding, void *log_context) | ||
| 622 | { | ||
| 623 | int i, j, ret, mixed; | ||
| 624 | 1973 | AVChannelLayout in_ch_layout = { 0 }, out_ch_layout = { 0 }; | |
| 625 | char buf[128]; | ||
| 626 | |||
| 627 | 1973 | ret = clean_layout(&in_ch_layout, in_layout, log_context); | |
| 628 | 1973 | ret |= clean_layout(&out_ch_layout, out_layout, log_context); | |
| 629 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1973 times.
|
1973 | if (ret < 0) |
| 630 | ✗ | goto fail; | |
| 631 | |||
| 632 | 1973 | clean_downmix(&out_ch_layout, &in_ch_layout); | |
| 633 | 1973 | clean_downmix(&in_ch_layout, &out_ch_layout); | |
| 634 | |||
| 635 | /* the same channels on both sides change their places at most */ | ||
| 636 | 1973 | mixed = av_channel_layout_subset(&in_ch_layout, ~(uint64_t)0) != | |
| 637 | 1973 | av_channel_layout_subset(&out_ch_layout, ~(uint64_t)0); | |
| 638 | |||
| 639 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1973 times.
|
1973 | if(!av_channel_layout_check(&in_ch_layout)) { |
| 640 | ✗ | av_log(log_context, AV_LOG_ERROR, "Input channel layout is invalid\n"); | |
| 641 | ✗ | ret = AVERROR(EINVAL); | |
| 642 | ✗ | goto fail; | |
| 643 | } | ||
| 644 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1973 times.
|
1973 | if(!sane_layout(&in_ch_layout, mixed)) { |
| 645 | ✗ | av_channel_layout_describe(&in_ch_layout, buf, sizeof(buf)); | |
| 646 | ✗ | av_log(log_context, AV_LOG_ERROR, "Input channel layout '%s' is not supported\n", buf); | |
| 647 | ✗ | ret = AVERROR(EINVAL); | |
| 648 | ✗ | goto fail; | |
| 649 | } | ||
| 650 | |||
| 651 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1973 times.
|
1973 | if(!av_channel_layout_check(&out_ch_layout)) { |
| 652 | ✗ | av_log(log_context, AV_LOG_ERROR, "Output channel layout is invalid\n"); | |
| 653 | ✗ | ret = AVERROR(EINVAL); | |
| 654 | ✗ | goto fail; | |
| 655 | } | ||
| 656 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1973 times.
|
1973 | if(!sane_layout(&out_ch_layout, mixed)) { |
| 657 | ✗ | av_channel_layout_describe(&out_ch_layout, buf, sizeof(buf)); | |
| 658 | ✗ | av_log(log_context, AV_LOG_ERROR, "Output channel layout '%s' is not supported\n", buf); | |
| 659 | ✗ | ret = AVERROR(EINVAL); | |
| 660 | ✗ | goto fail; | |
| 661 | } | ||
| 662 | |||
| 663 | 1973 | build_matrix(&in_ch_layout, &out_ch_layout, center_mix_level, | |
| 664 | surround_mix_level, lfe_mix_level, maxval, rematrix_volume, | ||
| 665 | matrix_param, stride, matrix_encoding); | ||
| 666 | |||
| 667 |
1/2✓ Branch 0 taken 1973 times.
✗ Branch 1 not taken.
|
1973 | if(rematrix_volume > 0){ |
| 668 |
2/2✓ Branch 0 taken 126272 times.
✓ Branch 1 taken 1973 times.
|
128245 | for(i=0; i<SWR_CH_MAX; i++) |
| 669 |
2/2✓ Branch 0 taken 8081408 times.
✓ Branch 1 taken 126272 times.
|
8207680 | for(j=0; j<SWR_CH_MAX; j++){ |
| 670 | 8081408 | matrix_param[stride*i + j] *= rematrix_volume; | |
| 671 | } | ||
| 672 | } | ||
| 673 | |||
| 674 | 1973 | av_log(log_context, AV_LOG_DEBUG, "Matrix coefficients:\n"); | |
| 675 |
2/2✓ Branch 0 taken 9455 times.
✓ Branch 1 taken 1973 times.
|
11428 | for (i = 0; i < out_ch_layout.nb_channels; i++){ |
| 676 | 9455 | av_channel_name(buf, sizeof(buf), av_channel_layout_channel_from_index(&out_ch_layout, i)); | |
| 677 | 9455 | av_log(log_context, AV_LOG_DEBUG, "%s: ", buf); | |
| 678 |
2/2✓ Branch 0 taken 49780 times.
✓ Branch 1 taken 9455 times.
|
59235 | for (j = 0; j < in_ch_layout.nb_channels; j++){ |
| 679 | 49780 | av_channel_name(buf, sizeof(buf), av_channel_layout_channel_from_index(&in_ch_layout, j)); | |
| 680 | 49780 | av_log(log_context, AV_LOG_DEBUG, "%s:%f ", buf, matrix_param[stride*i + j]); | |
| 681 | } | ||
| 682 | 9455 | av_log(log_context, AV_LOG_DEBUG, "\n"); | |
| 683 | } | ||
| 684 | |||
| 685 | 1973 | ret = 0; | |
| 686 | 1973 | fail: | |
| 687 | 1973 | av_channel_layout_uninit(&in_ch_layout); | |
| 688 | 1973 | av_channel_layout_uninit(&out_ch_layout); | |
| 689 | |||
| 690 | 1973 | return ret; | |
| 691 | } | ||
| 692 | |||
| 693 | 1879 | av_cold static int auto_matrix(SwrContext *s) | |
| 694 | { | ||
| 695 | double maxval; | ||
| 696 | |||
| 697 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1879 times.
|
1879 | if (s->rematrix_maxval > 0) { |
| 698 | ✗ | maxval = s->rematrix_maxval; | |
| 699 |
2/2✓ Branch 1 taken 740 times.
✓ Branch 2 taken 1139 times.
|
1879 | } else if ( av_get_packed_sample_fmt(s->out_sample_fmt) < AV_SAMPLE_FMT_FLT |
| 700 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 740 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
740 | || (s->user_int_sample_fmt != AV_SAMPLE_FMT_NONE && |
| 701 | ✗ | av_get_packed_sample_fmt(s->user_int_sample_fmt) < AV_SAMPLE_FMT_FLT)) { | |
| 702 | 1139 | maxval = 1.0; | |
| 703 | } else | ||
| 704 | 740 | maxval = INT_MAX; | |
| 705 | |||
| 706 | 1879 | memset(s->matrix, 0, sizeof(s->matrix)); | |
| 707 | 3758 | return swr_build_matrix2(&s->in_ch_layout, &s->out_ch_layout, | |
| 708 | 1879 | s->clev, s->slev, s->lfe_mix_level, | |
| 709 | 1879 | maxval, s->rematrix_volume, (double*)s->matrix, | |
| 710 | 1879 | s->matrix[1] - s->matrix[0], s->matrix_encoding, s); | |
| 711 | } | ||
| 712 | |||
| 713 | 1889 | av_cold int swri_rematrix_build(SwrContext *s) | |
| 714 | { | ||
| 715 | int i, j; | ||
| 716 | 1889 | int nb_in = s->used_ch_layout.nb_channels; | |
| 717 | 1889 | int nb_out = s->out.ch_count; | |
| 718 | |||
| 719 |
2/2✓ Branch 0 taken 1879 times.
✓ Branch 1 taken 10 times.
|
1889 | if (!s->rematrix_custom) { |
| 720 | 1879 | int r = auto_matrix(s); | |
| 721 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1879 times.
|
1879 | if (r) |
| 722 | ✗ | return r; | |
| 723 | } else { | ||
| 724 | char buf[128]; | ||
| 725 | 10 | av_log(s, AV_LOG_DEBUG, "Custom matrix coefficients:\n"); | |
| 726 | 10 | double *matrix_param = (double*)s->matrix; | |
| 727 | 10 | ptrdiff_t stride = s->matrix[1] - s->matrix[0]; | |
| 728 |
2/2✓ Branch 0 taken 31 times.
✓ Branch 1 taken 10 times.
|
41 | for (i = 0; i < s->out_ch_layout.nb_channels; i++) { |
| 729 | 31 | av_channel_name(buf, sizeof(buf), av_channel_layout_channel_from_index(&s->out_ch_layout, i)); | |
| 730 | 31 | av_log(s, AV_LOG_DEBUG, "%s: ", buf); | |
| 731 |
2/2✓ Branch 0 taken 147 times.
✓ Branch 1 taken 31 times.
|
178 | for (j = 0; j < s->in_ch_layout.nb_channels; j++){ |
| 732 | 147 | av_channel_name(buf, sizeof(buf), av_channel_layout_channel_from_index(&s->in_ch_layout, j)); | |
| 733 | 147 | av_log(s, AV_LOG_DEBUG, "%s:%f ", buf, matrix_param[stride*i + j]); | |
| 734 | } | ||
| 735 | 31 | av_log(s, AV_LOG_DEBUG, "\n"); | |
| 736 | } | ||
| 737 | } | ||
| 738 | |||
| 739 | /* a channel that is one channel of the input, or silent, is not mixed */ | ||
| 740 |
2/2✓ Branch 0 taken 6451 times.
✓ Branch 1 taken 730 times.
|
7181 | for (i = 0; i < nb_out; i++) { |
| 741 | 6451 | int sources = 0; | |
| 742 |
2/2✓ Branch 0 taken 22991 times.
✓ Branch 1 taken 5292 times.
|
28283 | for (j = 0; j < nb_in; j++) { |
| 743 |
2/2✓ Branch 0 taken 18330 times.
✓ Branch 1 taken 4661 times.
|
22991 | if (s->matrix[i][j] == 0.0) |
| 744 | 18330 | continue; | |
| 745 |
4/4✓ Branch 0 taken 3535 times.
✓ Branch 1 taken 1126 times.
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 3502 times.
|
4661 | if (s->matrix[i][j] != 1.0 || sources++) |
| 746 | 1159 | return 1; | |
| 747 | } | ||
| 748 | } | ||
| 749 | |||
| 750 | 730 | return 0; | |
| 751 | } | ||
| 752 | |||
| 753 | 1889 | av_cold int swri_rematrix_init(SwrContext *s){ | |
| 754 | int i, j; | ||
| 755 | 1889 | int nb_in = s->used_ch_layout.nb_channels; | |
| 756 | 1889 | int nb_out = s->out.ch_count; | |
| 757 | |||
| 758 | 1889 | s->mix_any_f = NULL; | |
| 759 | |||
| 760 | /* a matrix that is applied was built by swri_rematrix_build() */ | ||
| 761 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1889 times.
|
1889 | if (!s->rematrix) { |
| 762 | ✗ | int r = auto_matrix(s); | |
| 763 | ✗ | if (r) | |
| 764 | ✗ | return r; | |
| 765 | } | ||
| 766 |
2/2✓ Branch 0 taken 280 times.
✓ Branch 1 taken 1609 times.
|
1889 | if (s->midbuf.fmt == AV_SAMPLE_FMT_S16P){ |
| 767 | 280 | int maxsum = 0; | |
| 768 | 280 | s->native_matrix = av_calloc(nb_in * nb_out, sizeof(int)); | |
| 769 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 280 times.
|
280 | if (!s->native_matrix) |
| 770 | ✗ | return AVERROR(ENOMEM); | |
| 771 |
2/2✓ Branch 0 taken 1271 times.
✓ Branch 1 taken 280 times.
|
1551 | for (i = 0; i < nb_out; i++) { |
| 772 | 1271 | double rem = 0; | |
| 773 | 1271 | int sum = 0; | |
| 774 | |||
| 775 |
2/2✓ Branch 0 taken 5704 times.
✓ Branch 1 taken 1271 times.
|
6975 | for (j = 0; j < nb_in; j++) { |
| 776 | 5704 | double target = s->matrix[i][j] * 32768 + rem; | |
| 777 | 5704 | ((int*)s->native_matrix)[i * nb_in + j] = lrintf(target); | |
| 778 | 5704 | rem += target - ((int*)s->native_matrix)[i * nb_in + j]; | |
| 779 | 5704 | sum += FFABS(((int*)s->native_matrix)[i * nb_in + j]); | |
| 780 | } | ||
| 781 | 1271 | maxsum = FFMAX(maxsum, sum); | |
| 782 | } | ||
| 783 | 280 | s->native_one.i = 32768; | |
| 784 |
2/2✓ Branch 0 taken 237 times.
✓ Branch 1 taken 43 times.
|
280 | if (maxsum <= 32768) { |
| 785 | 237 | s->mix_1_1_f = copy_s16; | |
| 786 | 237 | s->mix_2_1_f = sum2_s16; | |
| 787 | 237 | s->mix_any_f = get_mix_any_func_s16(s); | |
| 788 | } else { | ||
| 789 | 43 | s->mix_1_1_f = copy_clip_s16; | |
| 790 | 43 | s->mix_2_1_f = sum2_clip_s16; | |
| 791 | 43 | s->mix_any_f = get_mix_any_func_clip_s16(s); | |
| 792 | } | ||
| 793 |
2/2✓ Branch 0 taken 1250 times.
✓ Branch 1 taken 359 times.
|
1609 | }else if(s->midbuf.fmt == AV_SAMPLE_FMT_FLTP){ |
| 794 | 1250 | s->native_matrix = av_calloc(nb_in * nb_out, sizeof(float)); | |
| 795 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1250 times.
|
1250 | if (!s->native_matrix) |
| 796 | ✗ | return AVERROR(ENOMEM); | |
| 797 |
2/2✓ Branch 0 taken 5852 times.
✓ Branch 1 taken 1250 times.
|
7102 | for (i = 0; i < nb_out; i++) |
| 798 |
2/2✓ Branch 0 taken 26742 times.
✓ Branch 1 taken 5852 times.
|
32594 | for (j = 0; j < nb_in; j++) |
| 799 | 26742 | ((float*)s->native_matrix)[i * nb_in + j] = s->matrix[i][j]; | |
| 800 | 1250 | s->native_one.f = 1.0; | |
| 801 | 1250 | s->mix_1_1_f = copy_float; | |
| 802 | 1250 | s->mix_2_1_f = sum2_float; | |
| 803 | 1250 | s->mix_any_f = get_mix_any_func_float(s); | |
| 804 |
2/2✓ Branch 0 taken 354 times.
✓ Branch 1 taken 5 times.
|
359 | }else if(s->midbuf.fmt == AV_SAMPLE_FMT_DBLP){ |
| 805 | 354 | s->native_matrix = av_calloc(nb_in * nb_out, sizeof(double)); | |
| 806 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 354 times.
|
354 | if (!s->native_matrix) |
| 807 | ✗ | return AVERROR(ENOMEM); | |
| 808 |
2/2✓ Branch 0 taken 1645 times.
✓ Branch 1 taken 354 times.
|
1999 | for (i = 0; i < nb_out; i++) |
| 809 |
2/2✓ Branch 0 taken 7731 times.
✓ Branch 1 taken 1645 times.
|
9376 | for (j = 0; j < nb_in; j++) |
| 810 | 7731 | ((double*)s->native_matrix)[i * nb_in + j] = s->matrix[i][j]; | |
| 811 | 354 | s->native_one.d = 1.0; | |
| 812 | 354 | s->mix_1_1_f = copy_double; | |
| 813 | 354 | s->mix_2_1_f = sum2_double; | |
| 814 | 354 | s->mix_any_f = get_mix_any_func_double(s); | |
| 815 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | }else if(s->midbuf.fmt == AV_SAMPLE_FMT_S32P){ |
| 816 | 5 | s->native_matrix = av_calloc(nb_in * nb_out, sizeof(int)); | |
| 817 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (!s->native_matrix) |
| 818 | ✗ | return AVERROR(ENOMEM); | |
| 819 |
2/2✓ Branch 0 taken 27 times.
✓ Branch 1 taken 5 times.
|
32 | for (i = 0; i < nb_out; i++) { |
| 820 | 27 | double rem = 0; | |
| 821 | |||
| 822 |
2/2✓ Branch 0 taken 121 times.
✓ Branch 1 taken 27 times.
|
148 | for (j = 0; j < nb_in; j++) { |
| 823 | 121 | double target = s->matrix[i][j] * 32768 + rem; | |
| 824 | 121 | ((int*)s->native_matrix)[i * nb_in + j] = lrintf(target); | |
| 825 | 121 | rem += target - ((int*)s->native_matrix)[i * nb_in + j]; | |
| 826 | } | ||
| 827 | } | ||
| 828 | 5 | s->native_one.i = 32768; | |
| 829 | 5 | s->mix_1_1_f = copy_s32; | |
| 830 | 5 | s->mix_2_1_f = sum2_s32; | |
| 831 | 5 | s->mix_any_f = get_mix_any_func_s32(s); | |
| 832 | }else | ||
| 833 | ✗ | av_assert0(0); | |
| 834 | //FIXME quantize for integeres | ||
| 835 |
2/2✓ Branch 0 taken 120896 times.
✓ Branch 1 taken 1889 times.
|
122785 | for (i = 0; i < SWR_CH_MAX; i++) { |
| 836 | 120896 | int ch_in=0; | |
| 837 |
2/2✓ Branch 0 taken 7737344 times.
✓ Branch 1 taken 120896 times.
|
7858240 | for (j = 0; j < SWR_CH_MAX; j++) { |
| 838 | 7737344 | const double coeff = s->matrix[i][j]; | |
| 839 |
2/2✓ Branch 0 taken 9061 times.
✓ Branch 1 taken 7728283 times.
|
7737344 | if (coeff) |
| 840 | 9061 | s->matrix_ch[i][++ch_in]= j; | |
| 841 |
3/3✓ Branch 0 taken 5120000 times.
✓ Branch 1 taken 1449984 times.
✓ Branch 2 taken 1167360 times.
|
7737344 | switch (s->int_sample_fmt) { |
| 842 | 5120000 | case AV_SAMPLE_FMT_FLTP: | |
| 843 | 5120000 | s->matrix_flt[i][j] = coeff; | |
| 844 | 5120000 | break; | |
| 845 | 1449984 | case AV_SAMPLE_FMT_DBLP: | |
| 846 | 1449984 | break; | |
| 847 | 1167360 | default: | |
| 848 | 1167360 | s->matrix32[i][j] = lrintf(coeff * 32768); | |
| 849 | 1167360 | break; | |
| 850 | } | ||
| 851 | } | ||
| 852 | 120896 | s->matrix_ch[i][0]= ch_in; | |
| 853 | } | ||
| 854 | |||
| 855 | #if ARCH_X86 && HAVE_X86ASM | ||
| 856 | 1889 | return swri_rematrix_init_x86(s); | |
| 857 | #endif | ||
| 858 | |||
| 859 | return 0; | ||
| 860 | } | ||
| 861 | |||
| 862 | 6484 | av_cold void swri_rematrix_free(SwrContext *s){ | |
| 863 | 6484 | av_freep(&s->native_matrix); | |
| 864 | 6484 | av_freep(&s->native_simd_matrix); | |
| 865 | 6484 | } | |
| 866 | |||
| 867 | 4300 | int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mustcopy){ | |
| 868 | int out_i, in_i, i, j; | ||
| 869 | 4300 | int len1 = 0; | |
| 870 | 4300 | int off = 0; | |
| 871 | |||
| 872 |
2/2✓ Branch 0 taken 72 times.
✓ Branch 1 taken 4228 times.
|
4300 | if(s->mix_any_f) { |
| 873 | 72 | s->mix_any_f(out->ch, (const uint8_t *const *)in->ch, s->native_matrix, len); | |
| 874 | 72 | return 0; | |
| 875 | } | ||
| 876 | |||
| 877 |
3/4✓ Branch 0 taken 1678 times.
✓ Branch 1 taken 2550 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1678 times.
|
4228 | if(s->mix_2_1_simd || s->mix_1_1_simd){ |
| 878 | 2550 | len1= len&~15; | |
| 879 | 2550 | off = len1 * out->bps; | |
| 880 | } | ||
| 881 | |||
| 882 |
3/4✓ Branch 0 taken 4207 times.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4207 times.
|
4228 | av_assert0(s->out_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC || out->ch_count == s->out_ch_layout.nb_channels); |
| 883 |
3/4✓ Branch 0 taken 4207 times.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4207 times.
|
4228 | av_assert0(s-> in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC || in ->ch_count == s->in_ch_layout.nb_channels); |
| 884 | |||
| 885 |
2/2✓ Branch 0 taken 16638 times.
✓ Branch 1 taken 4228 times.
|
20866 | for(out_i=0; out_i<out->ch_count; out_i++){ |
| 886 |
4/4✓ Branch 0 taken 3930 times.
✓ Branch 1 taken 8618 times.
✓ Branch 2 taken 3160 times.
✓ Branch 3 taken 930 times.
|
16638 | switch(s->matrix_ch[out_i][0]){ |
| 887 | 3930 | case 0: | |
| 888 |
2/2✓ Branch 0 taken 235 times.
✓ Branch 1 taken 3695 times.
|
3930 | if(mustcopy) |
| 889 | 235 | memset(out->ch[out_i], 0, len * av_get_bytes_per_sample(s->int_sample_fmt)); | |
| 890 | 3930 | break; | |
| 891 | 8618 | case 1: | |
| 892 | 8618 | in_i= s->matrix_ch[out_i][1]; | |
| 893 |
2/2✓ Branch 0 taken 2154 times.
✓ Branch 1 taken 6464 times.
|
8618 | if(s->matrix[out_i][in_i]!=1.0){ |
| 894 |
4/4✓ Branch 0 taken 1657 times.
✓ Branch 1 taken 497 times.
✓ Branch 2 taken 1117 times.
✓ Branch 3 taken 540 times.
|
2154 | if(s->mix_1_1_simd && len1) |
| 895 | 1117 | s->mix_1_1_simd(out->ch[out_i] , in->ch[in_i] , s->native_simd_matrix, in->ch_count*out_i + in_i, len1); | |
| 896 |
2/2✓ Branch 0 taken 1952 times.
✓ Branch 1 taken 202 times.
|
2154 | if(len != len1) |
| 897 | 1952 | s->mix_1_1_f (out->ch[out_i]+off, in->ch[in_i]+off, s->native_matrix, in->ch_count*out_i + in_i, len-len1); | |
| 898 |
2/2✓ Branch 0 taken 724 times.
✓ Branch 1 taken 5740 times.
|
6464 | }else if(mustcopy){ |
| 899 | 724 | memcpy(out->ch[out_i], in->ch[in_i], len*out->bps); | |
| 900 | }else{ | ||
| 901 | 5740 | out->ch[out_i]= in->ch[in_i]; | |
| 902 | } | ||
| 903 | 8618 | break; | |
| 904 | 3160 | case 2: { | |
| 905 | 3160 | int in_i1 = s->matrix_ch[out_i][1]; | |
| 906 | 3160 | int in_i2 = s->matrix_ch[out_i][2]; | |
| 907 |
4/4✓ Branch 0 taken 2030 times.
✓ Branch 1 taken 1130 times.
✓ Branch 2 taken 1242 times.
✓ Branch 3 taken 788 times.
|
3160 | if(s->mix_2_1_simd && len1) |
| 908 | 1242 | s->mix_2_1_simd(out->ch[out_i] , in->ch[in_i1] , in->ch[in_i2] , s->native_simd_matrix, in->ch_count*out_i + in_i1, in->ch_count*out_i + in_i2, len1); | |
| 909 | else | ||
| 910 | 1918 | s->mix_2_1_f (out->ch[out_i] , in->ch[in_i1] , in->ch[in_i2] , s->native_matrix, in->ch_count*out_i + in_i1, in->ch_count*out_i + in_i2, len1); | |
| 911 |
2/2✓ Branch 0 taken 3019 times.
✓ Branch 1 taken 141 times.
|
3160 | if(len != len1) |
| 912 | 3019 | s->mix_2_1_f (out->ch[out_i]+off, in->ch[in_i1]+off, in->ch[in_i2]+off, s->native_matrix, in->ch_count*out_i + in_i1, in->ch_count*out_i + in_i2, len-len1); | |
| 913 | 3160 | break;} | |
| 914 | 930 | default: | |
| 915 |
2/2✓ Branch 0 taken 547 times.
✓ Branch 1 taken 383 times.
|
930 | if(s->int_sample_fmt == AV_SAMPLE_FMT_FLTP){ |
| 916 |
2/2✓ Branch 0 taken 332590 times.
✓ Branch 1 taken 547 times.
|
333137 | for(i=0; i<len; i++){ |
| 917 | 332590 | float v=0; | |
| 918 |
2/2✓ Branch 0 taken 1247646 times.
✓ Branch 1 taken 332590 times.
|
1580236 | for(j=0; j<s->matrix_ch[out_i][0]; j++){ |
| 919 | 1247646 | in_i= s->matrix_ch[out_i][1+j]; | |
| 920 | 1247646 | v+= ((float*)in->ch[in_i])[i] * s->matrix_flt[out_i][in_i]; | |
| 921 | } | ||
| 922 | 332590 | ((float*)out->ch[out_i])[i]= v; | |
| 923 | } | ||
| 924 |
2/2✓ Branch 0 taken 166 times.
✓ Branch 1 taken 217 times.
|
383 | }else if(s->int_sample_fmt == AV_SAMPLE_FMT_DBLP){ |
| 925 |
2/2✓ Branch 0 taken 93815 times.
✓ Branch 1 taken 166 times.
|
93981 | for(i=0; i<len; i++){ |
| 926 | 93815 | double v=0; | |
| 927 |
2/2✓ Branch 0 taken 357920 times.
✓ Branch 1 taken 93815 times.
|
451735 | for(j=0; j<s->matrix_ch[out_i][0]; j++){ |
| 928 | 357920 | in_i= s->matrix_ch[out_i][1+j]; | |
| 929 | 357920 | v+= ((double*)in->ch[in_i])[i] * s->matrix[out_i][in_i]; | |
| 930 | } | ||
| 931 | 93815 | ((double*)out->ch[out_i])[i]= v; | |
| 932 | } | ||
| 933 | }else{ | ||
| 934 |
2/2✓ Branch 0 taken 591483 times.
✓ Branch 1 taken 217 times.
|
591700 | for(i=0; i<len; i++){ |
| 935 | 591483 | int v=0; | |
| 936 |
2/2✓ Branch 0 taken 2342426 times.
✓ Branch 1 taken 591483 times.
|
2933909 | for(j=0; j<s->matrix_ch[out_i][0]; j++){ |
| 937 | 2342426 | in_i= s->matrix_ch[out_i][1+j]; | |
| 938 | 2342426 | v+= ((int16_t*)in->ch[in_i])[i] * s->matrix32[out_i][in_i]; | |
| 939 | } | ||
| 940 | 591483 | ((int16_t*)out->ch[out_i])[i]= (v + 16384)>>15; | |
| 941 | } | ||
| 942 | } | ||
| 943 | } | ||
| 944 | } | ||
| 945 | 4228 | return 0; | |
| 946 | } | ||
| 947 |