0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 13:08:50 +02:00

libobs/media-io: Fix mono upmix

A mono source is currently upmixed by swresampler in the following way:
- for stereo output, FL=FR=input/sqrt(2)
- for other speaker layouts of the outputs, FC=input, other channels
are zeroed.

In the case of stereo output, this leads to a 3dB level decrease which
users have issue with [1].
The obvious fix of adding a 3dB gain is reported to be adding distortions
on some setups [2].
Note that the "Downmix to Mono" does not fix this upmix problem, since
it just makes all output channels identical by summing all input channels
and normalizing (by dividing by the number of output channels). This last
normalization step results in a level reduction for a mono input.

[1] This fixes https://obsproject.com/mantis/view.php?id=960.
[2] See also: https://obsproject.com/forum/threads/please-allow-for-mono-recording-of-microphones-ill-explain-why.84834
This commit is contained in:
pkv 2019-02-24 13:51:20 +01:00
parent ef270c8ba0
commit 918fc6d6c2

View File

@ -102,6 +102,21 @@ audio_resampler_t *audio_resampler_create(const struct resample_info *dst,
return NULL;
}
if (rs->input_layout == AV_CH_LAYOUT_MONO && rs->output_ch > 1) {
const double matrix[MAX_AUDIO_CHANNELS][MAX_AUDIO_CHANNELS] = {
{1},
{1, 1},
{1, 1, 0},
{1, 1, 1, 1},
{1, 1, 1, 0, 1},
{1, 1, 1, 1, 1, 1},
{1, 1, 1, 0, 1, 1, 1},
{1, 1, 1, 0, 1, 1, 1, 1},
};
if (swr_set_matrix(rs->context, matrix[rs->output_ch - 1], 1) < 0)
blog(LOG_DEBUG, "swr_set_matrix failed for mono upmix\n");
}
errcode = swr_init(rs->context);
if (errcode != 0) {
blog(LOG_ERROR, "avresample_open failed: error code %d",