| @@ -141,7 +141,8 @@ end: · 140 unmodified lines |
| 141 | } | 141 | } |
| 142 | | 142 | |
| 143 | static int fn(get_power)(AVFilterContext *ctx, AudioFIRContext *s, | 143 | static int fn(get_power)(AVFilterContext *ctx, AudioFIRContext *s, |
| 144 | int cur_nb_taps, int ch) | 144 | int cur_nb_taps, int ch, |
| | 145 | ftype *time) |
| 145 | { | 146 | { |
| 146 | ftype ch_gain = 1; | 147 | ftype ch_gain = 1; |
| 147 | | 148 | |
| @@ -151,7 +152,6 @@ static int fn(get_power)(AVFilterContext *ctx, AudioFIRContext *s, · 3 unmodified lines |
| 151 | break; | 152 | break; |
| 152 | case 0: | 153 | case 0: |
| 153 | { | 154 | { |
| 154 | ftype *time = (ftype *)s->norm_ir->extended_data[ch]; | | |
| 155 | ftype sum = 0; | 155 | ftype sum = 0; |
| 156 | | 156 | |
| 157 | for (int i = 0; i < cur_nb_taps; i++) | 157 | for (int i = 0; i < cur_nb_taps; i++) |
| @@ -161,7 +161,6 @@ static int fn(get_power)(AVFilterContext *ctx, AudioFIRContext *s, · 3 unmodified lines |
| 161 | break; | 161 | break; |
| 162 | case 1: | 162 | case 1: |
| 163 | { | 163 | { |
| 164 | ftype *time = (ftype *)s->norm_ir->extended_data[ch]; | | |
| 165 | ftype sum = 0; | 164 | ftype sum = 0; |
| 166 | | 165 | |
| 167 | for (int i = 0; i < cur_nb_taps; i++) | 166 | for (int i = 0; i < cur_nb_taps; i++) |
| @@ -171,7 +170,6 @@ static int fn(get_power)(AVFilterContext *ctx, AudioFIRContext *s, · 3 unmodified lines |
| 171 | break; | 170 | break; |
| 172 | case 2: | 171 | case 2: |
| 173 | { | 172 | { |
| 174 | ftype *time = (ftype *)s->norm_ir->extended_data[ch]; | | |
| 175 | ftype sum = 0; | 173 | ftype sum = 0; |
| 176 | | 174 | |
| 177 | for (int i = 0; i < cur_nb_taps; i++) | 175 | for (int i = 0; i < cur_nb_taps; i++) |
| @@ -182,7 +180,7 @@ static int fn(get_power)(AVFilterContext *ctx, AudioFIRContext *s, · 4 unmodified lines |
| 182 | case 3: | 180 | case 3: |
| 183 | case 4: | 181 | case 4: |
| 184 | { | 182 | { |
| 185 | ftype *inc, *outc, scale; | 183 | ftype *inc, *outc, scale, power; |
| 186 | AVTXContext *tx; | 184 | AVTXContext *tx; |
| 187 | av_tx_fn tx_fn; | 185 | av_tx_fn tx_fn; |
| 188 | int ret, size; | 186 | int ret, size; |
| @@ -205,7 +203,6 @@ static int fn(get_power)(AVFilterContext *ctx, AudioFIRContext *s, · 16 unmodified lines |
| 205 | } | 203 | } |
| 206 | | 204 | |
| 207 | { | 205 | { |
| 208 | ftype power, *time = (ftype *)s->norm_ir->extended_data[ch]; | | |
| 209 | memcpy(inc, time, cur_nb_taps * sizeof(SAMPLE_FORMAT)); | 206 | memcpy(inc, time, cur_nb_taps * sizeof(SAMPLE_FORMAT)); |
| 210 | tx_fn(tx, outc, inc, sizeof(SAMPLE_FORMAT)); | 207 | tx_fn(tx, outc, inc, sizeof(SAMPLE_FORMAT)); |
| 211 | | 208 | |
| @@ -233,7 +230,6 @@ static int fn(get_power)(AVFilterContext *ctx, AudioFIRContext *s, · 21 unmodified lines |
| 233 | } | 230 | } |
| 234 | | 231 | |
| 235 | if (ch_gain != 1. || s->ir_gain != 1.) { | 232 | if (ch_gain != 1. || s->ir_gain != 1.) { |
| 236 | ftype *time = (ftype *)s->norm_ir->extended_data[ch]; | | |
| 237 | ftype gain = ch_gain * s->ir_gain; | 233 | ftype gain = ch_gain * s->ir_gain; |
| 238 | | 234 | |
| 239 | av_log(ctx, AV_LOG_DEBUG, "ch%d gain %f\n", ch, gain); | 235 | av_log(ctx, AV_LOG_DEBUG, "ch%d gain %f\n", ch, gain); |
| @@ -248,45 +244,24 @@ static int fn(get_power)(AVFilterContext *ctx, AudioFIRContext *s, · 8 unmodified lines |
| 248 | } | 244 | } |
| 249 | | 245 | |
| 250 | static void fn(convert_channel)(AVFilterContext *ctx, AudioFIRContext *s, int ch, | 246 | static void fn(convert_channel)(AVFilterContext *ctx, AudioFIRContext *s, int ch, |
| 251 | AudioFIRSegment *seg) | 247 | AudioFIRSegment *seg, int coeff_partition, int selir) |
| 252 | { | 248 | { |
| 253 | const int coeff_partition = seg->loading[ch]; | | |
| 254 | const int coffset = coeff_partition * seg->coeff_size; | 249 | const int coffset = coeff_partition * seg->coeff_size; |
| 255 | const int selir = s->selir; | | |
| 256 | const int nb_taps = s->nb_taps[selir]; | 250 | const int nb_taps = s->nb_taps[selir]; |
| 257 | ftype *tsrc = (ftype *)s->ir[selir]->extended_data[!s->one2many * ch]; | 251 | ftype *time = (ftype *)s->norm_ir[selir]->extended_data[ch]; |
| 258 | ftype *time = (ftype *)s->norm_ir->extended_data[ch]; | | |
| 259 | ftype *tempin = (ftype *)seg->tempin->extended_data[ch]; | 252 | ftype *tempin = (ftype *)seg->tempin->extended_data[ch]; |
| 260 | ftype *tempout = (ftype *)seg->tempout->extended_data[ch]; | 253 | ftype *tempout = (ftype *)seg->tempout->extended_data[ch]; |
| 261 | ctype *coeff = (ctype *)seg->coeff->extended_data[ch]; | 254 | ctype *coeff = (ctype *)seg->coeff[selir]->extended_data[ch]; |
| 262 | int *loaded = (int *)seg->loaded->extended_data[ch]; | | |
| 263 | const int remaining = nb_taps - (seg->input_offset + coeff_partition * seg->part_size); | 255 | const int remaining = nb_taps - (seg->input_offset + coeff_partition * seg->part_size); |
| 264 | const int size = remaining >= seg->part_size ? seg->part_size : remaining; | 256 | const int size = remaining >= seg->part_size ? seg->part_size : remaining; |
| 265 | | 257 | |
| 266 | if (loaded[coeff_partition] == selir + 1) | | |
| 267 | return; | | |
| 268 | loaded[coeff_partition] = selir + 1; | | |
| 269 | | | |
| 270 | memcpy(time, tsrc, sizeof(*time) * nb_taps); | | |
| 271 | for (int i = FFMAX(1, s->length * nb_taps); i < nb_taps; i++) | | |
| 272 | time[i] = 0; | | |
| 273 | | | |
| 274 | #if DEPTH == 32 | | |
| 275 | get_power_float(ctx, s, nb_taps, ch); | | |
| 276 | #else | | |
| 277 | get_power_double(ctx, s, nb_taps, ch); | | |
| 278 | #endif | | |
| 279 | | | |
| 280 | av_log(ctx, AV_LOG_DEBUG, "channel: %d\n", ch); | | |
| 281 | | | |
| 282 | memset(tempin + size, 0, sizeof(*tempin) * (seg->block_size - size)); | 258 | memset(tempin + size, 0, sizeof(*tempin) * (seg->block_size - size)); |
| 283 | memcpy(tempin, time + seg->input_offset + coeff_partition * seg->part_size, | 259 | memcpy(tempin, time + seg->input_offset + coeff_partition * seg->part_size, |
| 284 | size * sizeof(*tempin)); | 260 | size * sizeof(*tempin)); |
| 285 | | | |
| 286 | seg->ctx_fn(seg->ctx[ch], tempout, tempin, sizeof(*tempin)); | 261 | seg->ctx_fn(seg->ctx[ch], tempout, tempin, sizeof(*tempin)); |
| 287 | | | |
| 288 | memcpy(coeff + coffset, tempout, seg->coeff_size * sizeof(*coeff)); | 262 | memcpy(coeff + coffset, tempout, seg->coeff_size * sizeof(*coeff)); |
| 289 | | 263 | |
| | 264 | av_log(ctx, AV_LOG_DEBUG, "channel: %d\n", ch); |
| 290 | av_log(ctx, AV_LOG_DEBUG, "nb_partitions: %d\n", seg->nb_partitions); | 265 | av_log(ctx, AV_LOG_DEBUG, "nb_partitions: %d\n", seg->nb_partitions); |
| 291 | av_log(ctx, AV_LOG_DEBUG, "partition size: %d\n", seg->part_size); | 266 | av_log(ctx, AV_LOG_DEBUG, "partition size: %d\n", seg->part_size); |
| 292 | av_log(ctx, AV_LOG_DEBUG, "block size: %d\n", seg->block_size); | 267 | av_log(ctx, AV_LOG_DEBUG, "block size: %d\n", seg->block_size); |
| @@ -314,11 +289,12 @@ static int fn(fir_quantum)(AVFilterContext *ctx, AVFrame *out, int ch, int offse · 21 unmodified lines |
| 314 | { | 289 | { |
| 315 | AudioFIRContext *s = ctx->priv; | 290 | AudioFIRContext *s = ctx->priv; |
| 316 | const ftype *in = (const ftype *)s->in->extended_data[ch] + offset; | 291 | const ftype *in = (const ftype *)s->in->extended_data[ch] + offset; |
| 317 | ftype *blockout, *buf, *ptr = (ftype *)out->extended_data[ch] + offset; | 292 | ftype *blockout, *ptr = (ftype *)out->extended_data[ch] + offset; |
| 318 | const int min_part_size = s->min_part_size; | 293 | const int min_part_size = s->min_part_size; |
| 319 | const int nb_samples = FFMIN(min_part_size, out->nb_samples - offset); | 294 | const int nb_samples = FFMIN(min_part_size, out->nb_samples - offset); |
| 320 | const int nb_segments = s->nb_segments; | 295 | const int nb_segments = s->nb_segments; |
| 321 | const float dry_gain = s->dry_gain; | 296 | const float dry_gain = s->dry_gain; |
| | 297 | const int selir = s->selir; |
| 322 | | 298 | |
| 323 | for (int segment = 0; segment < nb_segments; segment++) { | 299 | for (int segment = 0; segment < nb_segments; segment++) { |
| 324 | AudioFIRSegment *seg = &s->seg[segment]; | 300 | AudioFIRSegment *seg = &s->seg[segment]; |
| @@ -327,6 +303,7 @@ static int fn(fir_quantum)(AVFilterContext *ctx, AVFrame *out, int ch, int offse · 2 unmodified lines |
| 327 | ftype *sumin = (ftype *)seg->sumin->extended_data[ch]; | 303 | ftype *sumin = (ftype *)seg->sumin->extended_data[ch]; |
| 328 | ftype *sumout = (ftype *)seg->sumout->extended_data[ch]; | 304 | ftype *sumout = (ftype *)seg->sumout->extended_data[ch]; |
| 329 | ftype *tempin = (ftype *)seg->tempin->extended_data[ch]; | 305 | ftype *tempin = (ftype *)seg->tempin->extended_data[ch]; |
| | 306 | ftype *buf = (ftype *)seg->buffer->extended_data[ch]; |
| 330 | int *output_offset = &seg->output_offset[ch]; | 307 | int *output_offset = &seg->output_offset[ch]; |
| 331 | const int nb_partitions = seg->nb_partitions; | 308 | const int nb_partitions = seg->nb_partitions; |
| 332 | const int input_offset = seg->input_offset; | 309 | const int input_offset = seg->input_offset; |
| @@ -359,28 +336,71 @@ static int fn(fir_quantum)(AVFilterContext *ctx, AVFrame *out, int ch, int offse · 26 unmodified lines |
| 359 | } | 336 | } |
| 360 | | 337 | |
| 361 | memset(sumin, 0, sizeof(*sumin) * seg->fft_length); | 338 | memset(sumin, 0, sizeof(*sumin) * seg->fft_length); |
| | 339 | |
| | 340 | if (seg->loading[ch] < nb_partitions) { |
| | 341 | j = seg->part_index[ch] <= 0 ? nb_partitions - 1 : seg->part_index[ch] - 1; |
| | 342 | for (int i = 0; i < nb_partitions; i++) { |
| | 343 | const int input_partition = j; |
| | 344 | const int coeff_partition = i; |
| | 345 | const int coffset = coeff_partition * seg->coeff_size; |
| | 346 | const ftype *blockout = (const ftype *)seg->blockout->extended_data[ch] + input_partition * seg->block_size; |
| | 347 | const ctype *coeff = ((const ctype *)seg->coeff[selir]->extended_data[ch]) + coffset; |
| | 348 | |
| | 349 | if (j == 0) |
| | 350 | j = nb_partitions; |
| | 351 | j--; |
| | 352 | |
| | 353 | #if DEPTH == 32 |
| | 354 | s->afirdsp.fcmul_add(sumin, blockout, (const ftype *)coeff, part_size); |
| | 355 | #else |
| | 356 | s->afirdsp.dcmul_add(sumin, blockout, (const ftype *)coeff, part_size); |
| | 357 | #endif |
| | 358 | } |
| | 359 | |
| | 360 | seg->itx_fn(seg->itx[ch], sumout, sumin, sizeof(ctype)); |
| | 361 | memcpy(dst + part_size, sumout + part_size, part_size * sizeof(*buf)); |
| | 362 | memset(sumin, 0, sizeof(*sumin) * seg->fft_length); |
| | 363 | } |
| | 364 | |
| 362 | blockout = (ftype *)seg->blockout->extended_data[ch] + seg->part_index[ch] * seg->block_size; | 365 | blockout = (ftype *)seg->blockout->extended_data[ch] + seg->part_index[ch] * seg->block_size; |
| 363 | memset(tempin + part_size, 0, sizeof(*tempin) * (seg->block_size - part_size)); | 366 | memset(tempin + part_size, 0, sizeof(*tempin) * (seg->block_size - part_size)); |
| 364 | memcpy(tempin, src, sizeof(*src) * part_size); | 367 | memcpy(tempin, src, sizeof(*src) * part_size); |
| 365 | | | |
| 366 | seg->tx_fn(seg->tx[ch], blockout, tempin, sizeof(ftype)); | 368 | seg->tx_fn(seg->tx[ch], blockout, tempin, sizeof(ftype)); |
| 367 | | 369 | |
| 368 | j = seg->part_index[ch]; | | |
| 369 | if (seg->loading[ch] < nb_partitions) { | 370 | if (seg->loading[ch] < nb_partitions) { |
| | 371 | const int selir = s->prev_selir; |
| | 372 | |
| | 373 | j = seg->part_index[ch]; |
| | 374 | for (int i = 0; i < nb_partitions; i++) { |
| | 375 | const int input_partition = j; |
| | 376 | const int coeff_partition = i; |
| | 377 | const int coffset = coeff_partition * seg->coeff_size; |
| | 378 | const ftype *blockout = (const ftype *)seg->blockout->extended_data[ch] + input_partition * seg->block_size; |
| | 379 | const ctype *coeff = ((const ctype *)seg->coeff[selir]->extended_data[ch]) + coffset; |
| | 380 | |
| | 381 | if (j == 0) |
| | 382 | j = nb_partitions; |
| | 383 | j--; |
| | 384 | |
| 370 | #if DEPTH == 32 | 385 | #if DEPTH == 32 |
| 371 | convert_channel_float(ctx, s, ch, seg); | 386 | s->afirdsp.fcmul_add(sumin, blockout, (const ftype *)coeff, part_size); |
| 372 | #else | 387 | #else |
| 373 | convert_channel_double(ctx, s, ch, seg); | 388 | s->afirdsp.dcmul_add(sumin, blockout, (const ftype *)coeff, part_size); |
| 374 | #endif | 389 | #endif |
| 375 | seg->loading[ch]++; | 390 | } |
| | 391 | |
| | 392 | seg->itx_fn(seg->itx[ch], sumout, sumin, sizeof(ctype)); |
| | 393 | memcpy(dst + 2 * part_size, sumout, 2 * part_size * sizeof(*dst)); |
| | 394 | memset(sumin, 0, sizeof(*sumin) * seg->fft_length); |
| 376 | } | 395 | } |
| 377 | | 396 | |
| | 397 | j = seg->part_index[ch]; |
| 378 | for (int i = 0; i < nb_partitions; i++) { | 398 | for (int i = 0; i < nb_partitions; i++) { |
| 379 | const int input_partition = j; | 399 | const int input_partition = j; |
| 380 | const int coeff_partition = i; | 400 | const int coeff_partition = i; |
| 381 | const int coffset = coeff_partition * seg->coeff_size; | 401 | const int coffset = coeff_partition * seg->coeff_size; |
| 382 | const ftype *blockout = (const ftype *)seg->blockout->extended_data[ch] + input_partition * seg->block_size; | 402 | const ftype *blockout = (const ftype *)seg->blockout->extended_data[ch] + input_partition * seg->block_size; |
| 383 | const ctype *coeff = ((const ctype *)seg->coeff->extended_data[ch]) + coffset; | 403 | const ctype *coeff = ((const ctype *)seg->coeff[selir]->extended_data[ch]) + coffset; |
| 384 | | 404 | |
| 385 | if (j == 0) | 405 | if (j == 0) |
| 386 | j = nb_partitions; | 406 | j = nb_partitions; |
| @@ -395,18 +415,43 @@ static int fn(fir_quantum)(AVFilterContext *ctx, AVFrame *out, int ch, int offse · 8 unmodified lines |
| 395 | | 415 | |
| 396 | seg->itx_fn(seg->itx[ch], sumout, sumin, sizeof(ctype)); | 416 | seg->itx_fn(seg->itx[ch], sumout, sumin, sizeof(ctype)); |
| 397 | | 417 | |
| 398 | buf = (ftype *)seg->buffer->extended_data[ch]; | 418 | if (seg->loading[ch] < nb_partitions) { |
| 399 | fn(fir_fadd)(s, buf, sumout, part_size); | 419 | ftype *ptr1 = dst + part_size; |
| 400 | | 420 | ftype *ptr2 = dst + part_size * 2; |
| 401 | memcpy(dst, buf, part_size * sizeof(*dst)); | 421 | ftype *ptr3 = dst + part_size * 3; |
| 402 | memcpy(buf, sumout + part_size, part_size * sizeof(*buf)); | 422 | ftype *ptr4 = dst + part_size * 4; |
| | 423 | if (seg->loading[ch] == 0) |
| | 424 | memcpy(ptr4, buf, sizeof(*ptr4) * part_size); |
| | 425 | for (int n = 0; n < part_size; n++) |
| | 426 | ptr2[n] += ptr4[n]; |
| | 427 | |
| | 428 | if (seg->loading[ch] < nb_partitions - 1) |
| | 429 | memcpy(ptr4, ptr3, part_size * sizeof(*dst)); |
| | 430 | for (int n = 0; n < part_size; n++) |
| | 431 | ptr1[n] += sumout[n]; |
| | 432 | |
| | 433 | if (seg->loading[ch] == nb_partitions - 1) |
| | 434 | memcpy(buf, sumout + part_size, part_size * sizeof(*buf)); |
| | 435 | |
| | 436 | for (int i = 0; i < part_size; i++) { |
| | 437 | const ftype factor = (part_size * seg->loading[ch] + i) / (ftype)(part_size * nb_partitions); |
| | 438 | const ftype ifactor = 1 - factor; |
| | 439 | dst[i] = ptr1[i] * factor + ptr2[i] * ifactor; |
| | 440 | } |
| | 441 | } else { |
| | 442 | fn(fir_fadd)(s, buf, sumout, part_size); |
| | 443 | memcpy(dst, buf, part_size * sizeof(*dst)); |
| | 444 | memcpy(buf, sumout + part_size, part_size * sizeof(*buf)); |
| | 445 | } |
| 403 | | 446 | |
| 404 | seg->part_index[ch] = (seg->part_index[ch] + 1) % nb_partitions; | 447 | fn(fir_fadd)(s, ptr, dst, nb_samples); |
| 405 | | 448 | |
| 406 | if (part_size != min_part_size) | 449 | if (part_size != min_part_size) |
| 407 | memmove(src, src + min_part_size, (seg->input_size - min_part_size) * sizeof(*src)); | 450 | memmove(src, src + min_part_size, (seg->input_size - min_part_size) * sizeof(*src)); |
| 408 | | 451 | |
| 409 | fn(fir_fadd)(s, ptr, dst, nb_samples); | 452 | seg->part_index[ch] = (seg->part_index[ch] + 1) % nb_partitions; |
| | 453 | if (seg->loading[ch] < nb_partitions) |
| | 454 | seg->loading[ch]++; |
| 410 | } | 455 | } |
| 411 | | 456 | |
| 412 | if (s->wet_gain == 1.f) | 457 | if (s->wet_gain == 1.f) |