History

avfilter/af_surround: split factors calculations

From multiplication with magnitude.

Paul B Mahol committed 3 years ago

Commit 3d330031 parent 08b4c3d1 file · +80 −53Browse files

Unified · Split

libavfilter/af_surround.c+80−53
@@ -96,9 +96,12 @@ typedef struct AudioSurroundContext { · 95 unmodified lines
96 int nb_in_channels;96 int nb_in_channels;
97 int nb_out_channels;97 int nb_out_channels;
98 98
99 AVFrame *factors;
99 AVFrame *input_in;100 AVFrame *input_in;
100 AVFrame *input;101 AVFrame *input;
101 AVFrame *output;102 AVFrame *output;
103 AVFrame *output_mag;
104 AVFrame *output_ph;
102 AVFrame *output_out;105 AVFrame *output_out;
103 AVFrame *overlap_buffer;106 AVFrame *overlap_buffer;
104 AVFrame *window;107 AVFrame *window;
@@ -293,10 +296,14 @@ static int config_output(AVFilterLink *outlink) · 188 unmodified lines
293 296
294 set_output_levels(ctx);297 set_output_levels(ctx);
295 298
299 s->factors = ff_get_audio_buffer(outlink, s->win_size + 2);
300 s->output_ph = ff_get_audio_buffer(outlink, s->win_size + 2);
301 s->output_mag = ff_get_audio_buffer(outlink, s->win_size + 2);
296 s->output_out = ff_get_audio_buffer(outlink, s->win_size + 2);302 s->output_out = ff_get_audio_buffer(outlink, s->win_size + 2);
297 s->output = ff_get_audio_buffer(outlink, s->win_size + 2);303 s->output = ff_get_audio_buffer(outlink, s->win_size + 2);
298 s->overlap_buffer = ff_get_audio_buffer(outlink, s->win_size * 2);304 s->overlap_buffer = ff_get_audio_buffer(outlink, s->win_size * 2);
299 if (!s->overlap_buffer || !s->output || !s->output_out)305 if (!s->overlap_buffer || !s->output || !s->output_out || !s->output_mag ||
306 !s->output_ph || !s->factors)
300 return AVERROR(ENOMEM);307 return AVERROR(ENOMEM);
301 308
302 s->rdft_size = s->win_size / 2 + 1;309 s->rdft_size = s->win_size / 2 + 1;
@@ -397,6 +404,9 @@ static int stereo_upmix(AVFilterContext *ctx, int ch) · 94 unmodified lines
397{404{
398 AudioSurroundContext *s = ctx->priv;405 AudioSurroundContext *s = ctx->priv;
399 float *dst = (float *)s->output->extended_data[ch];406 float *dst = (float *)s->output->extended_data[ch];
407 float *factor = (float *)s->factors->extended_data[ch];
408 float *omag = (float *)s->output_mag->extended_data[ch];
409 float *oph = (float *)s->output_ph->extended_data[ch];
400 const float *mag_total = s->mag_total;410 const float *mag_total = s->mag_total;
401 const int rdft_size = s->rdft_size;411 const int rdft_size = s->rdft_size;
402 const float *c_phase = s->c_phase;412 const float *c_phase = s->c_phase;
@@ -412,81 +422,95 @@ static int stereo_upmix(AVFilterContext *ctx, int ch) · 9 unmodified lines
412 422
413 switch (chan) {423 switch (chan) {
414 case AV_CHAN_FRONT_CENTER:424 case AV_CHAN_FRONT_CENTER:
415 for (int n = 0; n < rdft_size; n++) {425 for (int n = 0; n < rdft_size; n++)
416 float mag = powf(1.f - fabsf(x[n]), f_x) * powf((y[n] + 1.f) * .5f, f_y) * c_mag[n];426 factor[n] = powf(1.f - fabsf(x[n]), f_x) * powf((y[n] + 1.f) * .5f, f_y);
417 float ph = c_phase[n];
418
419 TRANSFORM
420 }
421 break;427 break;
422 case AV_CHAN_FRONT_LEFT:428 case AV_CHAN_FRONT_LEFT:
423 for (int n = 0; n < rdft_size; n++) {429 for (int n = 0; n < rdft_size; n++)
424 float mag = powf(.5f * ( x[n] + 1.f), f_x) * powf((y[n] + 1.f) * .5f, f_y) * mag_total[n];430 factor[n] = powf(.5f * ( x[n] + 1.f), f_x) * powf((y[n] + 1.f) * .5f, f_y);
425 float ph = l_phase[n];
426
427 TRANSFORM
428 }
429 break;431 break;
430 case AV_CHAN_FRONT_RIGHT:432 case AV_CHAN_FRONT_RIGHT:
431 for (int n = 0; n < rdft_size; n++) {433 for (int n = 0; n < rdft_size; n++)
432 float mag = powf(.5f * (-x[n] + 1.f), f_x) * powf((y[n] + 1.f) * .5f, f_y) * mag_total[n];434 factor[n] = powf(.5f * (-x[n] + 1.f), f_x) * powf((y[n] + 1.f) * .5f, f_y);
433 float ph = r_phase[n];
434
435 TRANSFORM
436 }
437 break;435 break;
438 case AV_CHAN_LOW_FREQUENCY:436 case AV_CHAN_LOW_FREQUENCY:
439 for (int n = 0; n < rdft_size; n++) {437 for (int n = 0; n < rdft_size; n++)
440 float mag = lfe_mag[n];438 factor[n] = lfe_mag[n];
441 float ph = c_phase[n];
442
443 TRANSFORM
444 }
445 break;439 break;
446 case AV_CHAN_BACK_CENTER:440 case AV_CHAN_BACK_CENTER:
447 for (int n = 0; n < rdft_size; n++) {441 for (int n = 0; n < rdft_size; n++)
448 float mag = powf(1.f - fabsf(x[n]), f_x) * powf((1.f - y[n]) * .5f, f_y) * mag_total[n];442 factor[n] = powf(1.f - fabsf(x[n]), f_x) * powf((1.f - y[n]) * .5f, f_y);
449 float ph = c_phase[n];
450
451 TRANSFORM
452 }
453 break;443 break;
454 case AV_CHAN_BACK_LEFT:444 case AV_CHAN_BACK_LEFT:
455 for (int n = 0; n < rdft_size; n++) {445 for (int n = 0; n < rdft_size; n++)
456 float mag = powf(.5f * ( x[n] + 1.f), f_x) * powf(1.f - ((y[n] + 1.f) * .5f), f_y) * mag_total[n];446 factor[n] = powf(.5f * ( x[n] + 1.f), f_x) * powf(1.f - ((y[n] + 1.f) * .5f), f_y);
457 float ph = l_phase[n];
458
459 TRANSFORM
460 }
461 break;447 break;
462 case AV_CHAN_BACK_RIGHT:448 case AV_CHAN_BACK_RIGHT:
463 for (int n = 0; n < rdft_size; n++) {449 for (int n = 0; n < rdft_size; n++)
464 float mag = powf(.5f * (-x[n] + 1.f), f_x) * powf(1.f - ((y[n] + 1.f) * .5f), f_y) * mag_total[n];450 factor[n] = powf(.5f * (-x[n] + 1.f), f_x) * powf(1.f - ((y[n] + 1.f) * .5f), f_y);
465 float ph = r_phase[n];
466
467 TRANSFORM
468 }
469 break;451 break;
470 case AV_CHAN_SIDE_LEFT:452 case AV_CHAN_SIDE_LEFT:
471 for (int n = 0; n < rdft_size; n++) {453 for (int n = 0; n < rdft_size; n++)
472 float mag = powf(.5f * ( x[n] + 1.f), f_x) * powf(1.f - fabsf(y[n]), f_y) * mag_total[n];454 factor[n] = powf(.5f * ( x[n] + 1.f), f_x) * powf(1.f - fabsf(y[n]), f_y);
473 float ph = l_phase[n];455 break;
456 case AV_CHAN_SIDE_RIGHT:
457 for (int n = 0; n < rdft_size; n++)
458 factor[n] = powf(.5f * (-x[n] + 1.f), f_x) * powf(1.f - fabsf(y[n]), f_y);
459 break;
460 default:
461 break;
462 }
474 463
475 TRANSFORM464 switch (chan) {
476 }465 case AV_CHAN_FRONT_CENTER:
466 memcpy(omag, c_mag, rdft_size * sizeof(*omag));
477 break;467 break;
468 case AV_CHAN_LOW_FREQUENCY:
469 memcpy(omag, lfe_mag, rdft_size * sizeof(*omag));
470 break;
471 case AV_CHAN_FRONT_LEFT:
472 case AV_CHAN_FRONT_RIGHT:
473 case AV_CHAN_BACK_CENTER:
474 case AV_CHAN_BACK_LEFT:
475 case AV_CHAN_BACK_RIGHT:
476 case AV_CHAN_SIDE_LEFT:
478 case AV_CHAN_SIDE_RIGHT:477 case AV_CHAN_SIDE_RIGHT:
479 for (int n = 0; n < rdft_size; n++) {478 memcpy(omag, mag_total, rdft_size * sizeof(*omag));
480 float mag = powf(.5f * (-x[n] + 1.f), f_x) * powf(1.f - fabsf(y[n]), f_y) * mag_total[n];479 break;
481 float ph = r_phase[n];480 default:
481 break;
482 }
482 483
483 TRANSFORM484 switch (chan) {
484 }485 case AV_CHAN_FRONT_CENTER:
486 case AV_CHAN_LOW_FREQUENCY:
487 case AV_CHAN_BACK_CENTER:
488 memcpy(oph, c_phase, rdft_size * sizeof(*oph));
489 break;
490 case AV_CHAN_FRONT_LEFT:
491 case AV_CHAN_BACK_LEFT:
492 case AV_CHAN_SIDE_LEFT:
493 memcpy(oph, l_phase, rdft_size * sizeof(*oph));
494 break;
495 case AV_CHAN_FRONT_RIGHT:
496 case AV_CHAN_BACK_RIGHT:
497 case AV_CHAN_SIDE_RIGHT:
498 memcpy(oph, r_phase, rdft_size * sizeof(*oph));
485 break;499 break;
486 default:500 default:
487 break;501 break;
488 }502 }
489 503
504 for (int n = 0; n < rdft_size; n++)
505 omag[n] *= factor[n];
506
507 for (int n = 0; n < rdft_size; n++) {
508 const float mag = omag[n];
509 const float ph = oph[n];
510
511 TRANSFORM
512 }
513
490 return 0;514 return 0;
491}515}
492 516
@@ -1329,10 +1353,13 @@ static av_cold void uninit(AVFilterContext *ctx) · 836 unmodified lines
1329{1353{
1330 AudioSurroundContext *s = ctx->priv;1354 AudioSurroundContext *s = ctx->priv;
1331 1355
1356 av_frame_free(&s->factors);
1332 av_frame_free(&s->window);1357 av_frame_free(&s->window);
1333 av_frame_free(&s->input_in);1358 av_frame_free(&s->input_in);
1334 av_frame_free(&s->input);1359 av_frame_free(&s->input);
1335 av_frame_free(&s->output);1360 av_frame_free(&s->output);
1361 av_frame_free(&s->output_ph);
1362 av_frame_free(&s->output_mag);
1336 av_frame_free(&s->output_out);1363 av_frame_free(&s->output_out);
1337 av_frame_free(&s->overlap_buffer);1364 av_frame_free(&s->overlap_buffer);
1338 1365

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t