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
117 continue;117 continue;
118 }118 }
119 used_channels |= out_channel;119 used_channels |= out_channel;
120 if (out_channel == AV_CH_LOW_FREQUENCY)
121 s->lfe_channel = s->nb_irs;
122 s->mapping[s->nb_irs] = out_channel;120 s->mapping[s->nb_irs] = out_channel;
123 s->nb_irs++;121 s->nb_irs++;
124 }122 }
@@ -368,7 +366,6 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) · 243 unmodified lines
368{366{
369 struct HeadphoneContext *s = ctx->priv;367 struct HeadphoneContext *s = ctx->priv;
370 const int ir_len = s->ir_len;368 const int ir_len = s->ir_len;
371 int nb_irs = s->nb_irs;
372 int nb_input_channels = ctx->inputs[0]->channels;369 int nb_input_channels = ctx->inputs[0]->channels;
373 float gain_lin = expf((s->gain - 3 * nb_input_channels) / 20 * M_LN10);370 float gain_lin = expf((s->gain - 3 * nb_input_channels) / 20 * M_LN10);
374 FFTComplex *fft_in_l = NULL;371 FFTComplex *fft_in_l = NULL;
@@ -430,15 +427,15 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) · 55 unmodified lines
430 s->temp_src[0] = av_calloc(s->air_len, sizeof(float));427 s->temp_src[0] = av_calloc(s->air_len, sizeof(float));
431 s->temp_src[1] = av_calloc(s->air_len, sizeof(float));428 s->temp_src[1] = av_calloc(s->air_len, sizeof(float));
432 429
433 s->data_ir[0] = av_calloc(nb_irs * s->air_len, sizeof(*s->data_ir[0]));430 s->data_ir[0] = av_calloc(nb_input_channels * 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]));431 s->data_ir[1] = av_calloc(nb_input_channels * s->air_len, sizeof(*s->data_ir[1]));
435 if (!s->data_ir[0] || !s->data_ir[1] || !s->temp_src[0] || !s->temp_src[1]) {432 if (!s->data_ir[0] || !s->data_ir[1] || !s->temp_src[0] || !s->temp_src[1]) {
436 ret = AVERROR(ENOMEM);433 ret = AVERROR(ENOMEM);
437 goto fail;434 goto fail;
438 }435 }
439 } else {436 } else {
440 s->data_hrtf[0] = av_calloc(n_fft, sizeof(*s->data_hrtf[0]) * nb_irs);437 s->data_hrtf[0] = av_calloc(n_fft, sizeof(*s->data_hrtf[0]) * nb_input_channels);
441 s->data_hrtf[1] = av_calloc(n_fft, sizeof(*s->data_hrtf[1]) * nb_irs);438 s->data_hrtf[1] = av_calloc(n_fft, sizeof(*s->data_hrtf[1]) * nb_input_channels);
442 if (!s->data_hrtf[0] || !s->data_hrtf[1]) {439 if (!s->data_hrtf[0] || !s->data_hrtf[1]) {
443 ret = AVERROR(ENOMEM);440 ret = AVERROR(ENOMEM);
444 goto fail;441 goto fail;
@@ -459,7 +456,9 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) · 14 unmodified lines
459 456
460 for (j = 0; j < inlink->channels; j++) {457 for (j = 0; j < inlink->channels; j++) {
461 if ((av_channel_layout_extract_channel(inlink->channel_layout, j)) == s->mapping[i]) {458 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;
463 break;462 break;
464 }463 }
465 }464 }
@@ -499,14 +498,16 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink) · 33 unmodified lines
499 498
500 for (j = 0; j < inlink->channels; j++) {499 for (j = 0; j < inlink->channels; j++) {
501 if ((av_channel_layout_extract_channel(inlink->channel_layout, j)) == s->mapping[k]) {500 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;
503 break;504 break;
504 }505 }
505 }506 }
506 if (idx == -1)507 if (idx == -1)
507 continue;508 continue;
508 509
509 I = idx * 2;510 I = k * 2;
510 if (s->type == TIME_DOMAIN) {511 if (s->type == TIME_DOMAIN) {
511 float *data_ir_l = s->data_ir[0] + idx * s->air_len;512 float *data_ir_l = s->data_ir[0] + idx * s->air_len;
512 float *data_ir_r = s->data_ir[1] + idx * s->air_len;513 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