From caa6251054ef71222ef9cb6a9e63f61e72122a69 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Sun, 28 Dec 2014 03:51:06 -0800 Subject: [PATCH] libobs: Fix force mono channel count I unintentionally made it use obs_source::sample_info instead of using the actual target channel count, which is designated by the OBS output sampler info. obs_source::sample_info is actually used to indicate the currently set sampler information for incoming samples. So if a source is outputting 5.1 channel 48khz audio, and OBS is running at stereo 44.1khz, then the obs_source::sample_info value would be set to 5.1/48khz, not the other way around. It indicates what the source itself is running at, not what OBS is running at. I suppose the variable needs a better name because even I used it incorrectly despite actually having been the one who wrote it. --- libobs/obs-source.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libobs/obs-source.c b/libobs/obs-source.c index 38b97fd6b..0cd298b11 100644 --- a/libobs/obs-source.c +++ b/libobs/obs-source.c @@ -1474,11 +1474,11 @@ static void copy_audio_data(obs_source_t *source, /* TODO: SSE optimization */ static void downmix_to_mono_planar(struct obs_source *source, uint32_t frames) { - uint32_t channels = get_audio_channels(source->sample_info.speakers); + size_t channels = audio_output_get_channels(obs->audio.audio); const float channels_i = 1.0f / (float)channels; float **data = (float**)source->audio_data.data; - for (uint32_t channel = 1; channel < channels; channel++) { + for (size_t channel = 1; channel < channels; channel++) { for (uint32_t frame = 0; frame < frames; frame++) data[0][frame] += data[channel][frame]; } @@ -1486,7 +1486,7 @@ static void downmix_to_mono_planar(struct obs_source *source, uint32_t frames) for (uint32_t frame = 0; frame < frames; frame++) data[0][frame] *= channels_i; - for (uint32_t channel = 1; channel < channels; channel++) { + for (size_t channel = 1; channel < channels; channel++) { for (uint32_t frame = 0; frame < frames; frame++) data[channel][frame] = data[0][frame]; } @@ -1495,14 +1495,14 @@ static void downmix_to_mono_planar(struct obs_source *source, uint32_t frames) static void downmix_to_mono_interleaved(struct obs_source *source, uint32_t frames) { - uint32_t channels = get_audio_channels(source->sample_info.speakers); + size_t channels = audio_output_get_channels(obs->audio.audio); const float channels_i = 1.0f / (float)channels; float *data = (float*)source->audio_data.data[0]; for (uint32_t frame = 0; frame < frames; frame++) { - uint32_t pos = frame * channels; + size_t pos = frame * channels; - for (uint32_t channel = 1; channel < channels; channel++) + for (size_t channel = 1; channel < channels; channel++) data[pos] += data[pos + channel]; } @@ -1510,9 +1510,9 @@ static void downmix_to_mono_interleaved(struct obs_source *source, data[frame * channels] *= channels_i; for (uint32_t frame = 0; frame < frames; frame++) { - uint32_t pos = frame * channels; + size_t pos = frame * channels; - for (uint32_t channel = 1; channel < channels; channel++) + for (size_t channel = 1; channel < channels; channel++) data[pos + channel] = data[pos]; } }