Repository navigation
libobs/audio-monitoring: Fix PulseAudio monitoring volume for s32 format and u8 format - #5400
Conversation
8b011be to
583c496
Compare
| default: | ||
| // just ignore | ||
| break; |
There was a problem hiding this comment.
I'd like to note that process_volume will do nothing just in case if unknown format arrive rather than default to process as float.
There was a problem hiding this comment.
If the format is not known in pulseaudio_to_obs_audio_format the PA format is set as float anyway, so should probably never be hit anyway. Whether interpreting unknown formats as float is probably another discussion.
583c496 to
ebd3ff7
Compare
| default: | ||
| // just ignore | ||
| break; |
There was a problem hiding this comment.
If the format is not known in pulseaudio_to_obs_audio_format the PA format is set as float anyway, so should probably never be hit anyway. Whether interpreting unknown formats as float is probably another discussion.
|
Looks fine to me, Doesnt affect my system with float32 as the audio format. |
ebd3ff7 to
933c251
Compare
| for (; cur < end; cur++) | ||
| *cur = ((int)*cur - 128) * vol + 128; |
There was a problem hiding this comment.
I'm sorry to change the code after the review.
I realised unsigned 8-bit integer data was not correctly handled. it should consider the center level is 128 instead of 0.
I referred FFmpeg's volume filter is implemented as below.
static inline void scale_samples_u8(uint8_t *dst, const uint8_t *src,
int nb_samples, int volume)
{
int i;
for (i = 0; i < nb_samples; i++)
dst[i] = av_clip_uint8(((((int64_t)src[i] - 128) * volume + 128) >> 8) + 128);
}
There was a problem hiding this comment.
I guess id prefer if we just did everything in floating point then since our volume is a float unlike the ffmpeg impl. Considering we were char before and no one noticed it was incredibly incorrect I assume no one is actually using this format...
There was a problem hiding this comment.
The floating point data comes with const struct audio_data *audio_data so that it need to allocate a space to put the volume-processed floating point data.
Considering we were char before and no one noticed it was incredibly incorrect I assume no one is actually using this format...
I think so, too. 8-bit audio is too noisy.
Do you still want to multiply volume in floating point?
There was a problem hiding this comment.
I dont have a strong opinion. As is is fine.
RytoEX
left a comment
There was a problem hiding this comment.
As this PR does not actually touch the "linux-pulseaudio" plugin, the correct commit prefix is actually "libobs" or "libobs/audio-monitoring". It might be helpful to point out that this is specifically for "pulse" audio monitoring in the commit subject, if you can find space. If not, then at least it's mentioned int he commit message body.
When signed 32-bit audio arrived to pulseaudio-output and volume was lowered, audio data was broken. In the function `process_volume`, the type of the data is switched by `bytes_per_channel`. However the size of signed 32-bit integer and the size of float are same so that the signed 32-bit integer is processed as float. This commit changes these items. - Use `format` instead of `bytes_per_channel` so that all the sample types can be differentiated. - Change `short` to `int16_t` and renames existing function `process_short` to `process_s16` to clarify the function is processing signed 16-bit.
Change `char` to `uint8_t` in `process_byte` because the type is expected unsigned 8-bit.
933c251 to
4d0d1f1
Compare
Description
When pulseaudio-output chose signed 32-bit audio as the output format and volume was lowered, audio data was broken. In the function
process_volume, the type of the data is switched bybytes_per_channel. However the size of signed 32-bit integer and the size of float are same so that the signed 32-bit integer is processed as float.This commit changes these items.
formatinstead ofbytes_per_channelso that all the sample types can be differentiated.This fix the bug.
chartouint8_tinprocess_bytebecause the type is expected unsigned 8-bit.This also change behavior but I don't think there is a use case for unsigned 8-bit audio.
shorttoint16_tand renames existing functionprocess_shorttoprocess_s16to clarify the function is processing signed 16-bit.This is just a coding change. It should not affect anything.
Motivation and Context
The bug was reported on another PR and turned out it is an existing bug in master branch.
#4908 (comment)
#4908 (comment)
This bug was revealed when using PulseAudio with PipeWire.
How Has This Been Tested?
OS: Fedora 34
Tested with a
ffmpeg_sourcethat has a mp4 video, set the audio to monitor and output, and lower the volume.Types of changes
Checklist: