From: "Volker Rümelin" <vr_qemu@t-online.de>
To: Gerd Hoffmann <kraxel@redhat.com>, Eric Blake <eblake@redhat.com>,
Markus Armbruster <armbru@redhat.com>
Cc: "John Arbuckle" <programmingkidx@gmail.com>,
"Howard Spoelstra" <hsp.cat7@gmail.com>,
"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
QEMU <qemu-devel@nongnu.org>,
"Zoltán Kővágó" <dirty.ice.hu@gmail.com>
Subject: [PATCH 4/5] audio: change mixing engine float range to [-1.f, 1.f]
Date: Mon, 2 Mar 2020 20:10:03 +0100 [thread overview]
Message-ID: <20200302191004.5991-4-vr_qemu@t-online.de> (raw)
In-Reply-To: <417bfe2f-e3c1-d83d-b437-47859daf524d@t-online.de>
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 <vr_qemu@t-online.de>
---
audio/mixeng.c | 4 ++--
audio/mixeng_template.h | 17 ++++++++---------
2 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/audio/mixeng.c b/audio/mixeng.c
index 725b529be7..739a500449 100644
--- a/audio/mixeng.c
+++ b/audio/mixeng.c
@@ -271,11 +271,11 @@ f_sample *mixeng_clip[2][2][2][3] = {
#define CONV_NATURAL_FLOAT(x) (x)
#define CLIP_NATURAL_FLOAT(x) (x)
#else
-static const float float_scale = UINT_MAX;
+static const float float_scale = UINT_MAX / 2.f;
#define CONV_NATURAL_FLOAT(x) ((x) * float_scale)
#ifdef RECIPROCAL
-static const float float_scale_reciprocal = 1.f / UINT_MAX;
+static const float float_scale_reciprocal = 2.f / UINT_MAX;
#define CLIP_NATURAL_FLOAT(x) ((x) * float_scale_reciprocal)
#else
#define CLIP_NATURAL_FLOAT(x) ((x) / float_scale)
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
}
--
2.16.4
next prev parent reply other threads:[~2020-03-02 19:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-02 19:08 [PATCH 0/5] mostly changes related to audio float samples Volker Rümelin
2020-03-02 19:10 ` [PATCH 1/5] qapi/audio: add documentation for AudioFormat Volker Rümelin
2020-03-03 5:47 ` Markus Armbruster
2020-03-02 19:10 ` [PATCH 2/5] audio: change naming scheme of FLOAT_CONV macros Volker Rümelin
2020-03-02 19:10 ` [PATCH 3/5] audio: consistency changes Volker Rümelin
2020-03-02 19:10 ` Volker Rümelin [this message]
2020-03-02 19:10 ` [PATCH 5/5] audio: fix saturation nonlinearity in clip_* functions Volker Rümelin
2020-03-02 23:30 ` [PATCH 0/5] mostly changes related to audio float samples Howard Spoelstra
2020-03-08 19:11 ` Volker Rümelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200302191004.5991-4-vr_qemu@t-online.de \
--to=vr_qemu@t-online.de \
--cc=armbru@redhat.com \
--cc=dirty.ice.hu@gmail.com \
--cc=eblake@redhat.com \
--cc=hsp.cat7@gmail.com \
--cc=kraxel@redhat.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=programmingkidx@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).