History

avfilter/af_headphone: Fix channel assignment

The documentation of the map argument of the headphone filter states: "Set mapping of input streams for convolution. The argument is a ’|’-separated list of channel names in order as they are given as additional stream inputs for filter." Yet this has not been honoured at all. Instead for the kth given HRIR channel pair it was checked whether there was a kth mapping and if the channel position so given was present in the channel layout of the main input; if so, then the given HRIR channel pair was matched to the kth channel of the main input. It should actually have been matched to the channel given by the kth mapping. A consequence of the current algorithm is that if N additional HRIR channel pairs are given, a permutation of the first N entries of the mapping does not affect the output at all. The old code might even set arrays belonging to streams that don't exist (i.e. whose index is >= the number of channels of the main input stream); these parts were not read lateron at all. The new code doesn't do this any longer and therefore the number of elements of some of the allocated arrays has been reduced (in case the number of mappings was bigger than the number of channels of the first input stream).

Andreas Rheinhardt committed 6 years ago

Commit 0952f8f1 parent d883bca1 file · +11 −10Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/af_headphone.c+11−10
@@ -117,8 +117,6 @@ static void parse_map(AVFilterContext *ctx) · 116 unmodified lines
117117 continue;
118118 }
119119 used_channels |= out_channel;
120− if (out_channel == AV_CH_LOW_FREQUENCY)
121− s->lfe_channel = s->nb_irs;
122120 s->mapping[s->nb_irs] = out_channel;
123121 s->nb_irs++;
124122 }
@@ -368,7 +366,6 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) · 243 unmodified lines
368366 {
369367 struct HeadphoneContext *s = ctx->priv;
370368 const int ir_len = s->ir_len;
371− int nb_irs = s->nb_irs;
372369 int nb_input_channels = ctx->inputs[0]->channels;
373370 float gain_lin = expf((s->gain - 3 * nb_input_channels) / 20 * M_LN10);
374371 FFTComplex *fft_in_l = NULL;
@@ -430,15 +427,15 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) · 55 unmodified lines
430427 s->temp_src[0] = av_calloc(s->air_len, sizeof(float));
431428 s->temp_src[1] = av_calloc(s->air_len, sizeof(float));
432429
433− s->data_ir[0] = av_calloc(nb_irs * s->air_len, sizeof(*s->data_ir[0]));
434− s->data_ir[1] = av_calloc(nb_irs * s->air_len, sizeof(*s->data_ir[1]));
430+ s->data_ir[0] = av_calloc(nb_input_channels * s->air_len, sizeof(*s->data_ir[0]));
431+ s->data_ir[1] = av_calloc(nb_input_channels * s->air_len, sizeof(*s->data_ir[1]));
435432 if (!s->data_ir[0] || !s->data_ir[1] || !s->temp_src[0] || !s->temp_src[1]) {
436433 ret = AVERROR(ENOMEM);
437434 goto fail;
438435 }
439436 } else {
440− s->data_hrtf[0] = av_calloc(n_fft, sizeof(*s->data_hrtf[0]) * nb_irs);
441− s->data_hrtf[1] = av_calloc(n_fft, sizeof(*s->data_hrtf[1]) * nb_irs);
437+ s->data_hrtf[0] = av_calloc(n_fft, sizeof(*s->data_hrtf[0]) * nb_input_channels);
438+ s->data_hrtf[1] = av_calloc(n_fft, sizeof(*s->data_hrtf[1]) * nb_input_channels);
442439 if (!s->data_hrtf[0] || !s->data_hrtf[1]) {
443440 ret = AVERROR(ENOMEM);
444441 goto fail;
@@ -459,7 +456,9 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) · 14 unmodified lines
459456
460457 for (j = 0; j < inlink->channels; j++) {
461458 if ((av_channel_layout_extract_channel(inlink->channel_layout, j)) == s->mapping[i]) {
462− idx = i;
459+ idx = j;
460+ if (s->mapping[i] == AV_CH_LOW_FREQUENCY)
461+ s->lfe_channel = j;
463462 break;
464463 }
465464 }
@@ -499,14 +498,16 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) · 33 unmodified lines
499498
500499 for (j = 0; j < inlink->channels; j++) {
501500 if ((av_channel_layout_extract_channel(inlink->channel_layout, j)) == s->mapping[k]) {
502− idx = k;
501+ idx = j;
502+ if (s->mapping[k] == AV_CH_LOW_FREQUENCY)
503+ s->lfe_channel = j;
503504 break;
504505 }
505506 }
506507 if (idx == -1)
507508 continue;
508509
509− I = idx * 2;
510+ I = k * 2;
510511 if (s->type == TIME_DOMAIN) {
511512 float *data_ir_l = s->data_ir[0] + idx * s->air_len;
512513 float *data_ir_r = s->data_ir[1] + idx * s->air_len;

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