Browse Source

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.
jp9000 11 years ago
parent
commit
caa6251054
1 changed files with 8 additions and 8 deletions
  1. 8 8
      libobs/obs-source.c

+ 8 - 8
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];
 	}
 }