From 4218fdd77f1c8ab4dab5ced30c3a0db946a6f04c Mon Sep 17 00:00:00 2001 From: Volker Rümelin Date: Sun, 8 Mar 2020 20:33:19 +0100 Subject: audio: change mixing engine float range to [-1.f, 1.f] Currently the internal float range of the mixing engine is [-.5f, .5f]. PulseAudio, SDL2 and libasound use a [-1.f, 1.f] range. This means with float samples the audio playback volume is 6dB too low and audio recording signals will be clipped in most cases. To avoid another scaling factor in the conv_natural_float_* and clip_natural_float_* functions with FLOAT_MIXENG defined this patch changes the mixing engine float range to [-1.f, 1.f]. Signed-off-by: Volker Rümelin Message-id: 20200308193321.20668-4-vr_qemu@t-online.de Signed-off-by: Gerd Hoffmann --- audio/mixeng_template.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'audio/mixeng_template.h') diff --git a/audio/mixeng_template.h b/audio/mixeng_template.h index 77cc89b9e8..fc8e1d4d9e 100644 --- a/audio/mixeng_template.h +++ b/audio/mixeng_template.h @@ -41,32 +41,31 @@ static inline mixeng_real glue (conv_, ET) (IN_T v) #ifdef RECIPROCAL #ifdef SIGNED - return nv * (1.f / (mixeng_real) (IN_MAX - IN_MIN)); + return nv * (2.f / ((mixeng_real)IN_MAX - IN_MIN)); #else - return (nv - HALF) * (1.f / (mixeng_real) IN_MAX); + return (nv - HALF) * (2.f / (mixeng_real)IN_MAX); #endif #else /* !RECIPROCAL */ #ifdef SIGNED - return nv / (mixeng_real) ((mixeng_real) IN_MAX - IN_MIN); + return nv / (((mixeng_real)IN_MAX - IN_MIN) / 2.f); #else - return (nv - HALF) / (mixeng_real) IN_MAX; + return (nv - HALF) / ((mixeng_real)IN_MAX / 2.f); #endif #endif } static inline IN_T glue (clip_, ET) (mixeng_real v) { - if (v >= 0.5) { + if (v >= 1.f) { return IN_MAX; - } - else if (v < -0.5) { + } else if (v < -1.f) { return IN_MIN; } #ifdef SIGNED - return ENDIAN_CONVERT ((IN_T) (v * ((mixeng_real) IN_MAX - IN_MIN))); + return ENDIAN_CONVERT((IN_T)(v * (((mixeng_real)IN_MAX - IN_MIN) / 2.f))); #else - return ENDIAN_CONVERT ((IN_T) ((v * IN_MAX) + HALF)); + return ENDIAN_CONVERT((IN_T)((v * ((mixeng_real)IN_MAX / 2.f)) + HALF)); #endif } -- cgit v1.2.3-55-g7522 From 194bdf50697689768335096b6c01c5b010f023ca Mon Sep 17 00:00:00 2001 From: Volker Rümelin Date: Sun, 8 Mar 2020 20:33:20 +0100 Subject: audio: fix saturation nonlinearity in clip_* functions The current positive limit for the saturation nonlinearity is only correct if the type of the result has 8 bits or less. Signed-off-by: Volker Rümelin Message-id: 20200308193321.20668-5-vr_qemu@t-online.de Signed-off-by: Gerd Hoffmann --- audio/mixeng_template.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'audio/mixeng_template.h') diff --git a/audio/mixeng_template.h b/audio/mixeng_template.h index fc8e1d4d9e..bc8509e423 100644 --- a/audio/mixeng_template.h +++ b/audio/mixeng_template.h @@ -83,10 +83,9 @@ static inline int64_t glue (conv_, ET) (IN_T v) static inline IN_T glue (clip_, ET) (int64_t v) { - if (v >= 0x7f000000) { + if (v >= 0x7fffffffLL) { return IN_MAX; - } - else if (v < -2147483648LL) { + } else if (v < -2147483648LL) { return IN_MIN; } -- cgit v1.2.3-55-g7522