* [PATCH v2 0/6] mostly changes related to audio float samples
@ 2020-03-08 19:29 Volker Rümelin
2020-03-08 19:33 ` [PATCH v2 1/6] qapi/audio: add documentation for AudioFormat Volker Rümelin
` (6 more replies)
0 siblings, 7 replies; 9+ messages in thread
From: Volker Rümelin @ 2020-03-08 19:29 UTC (permalink / raw)
To: Gerd Hoffmann, Eric Blake, Markus Armbruster
Cc: John Arbuckle, Howard Spoelstra, Mark Cave-Ayland, QEMU,
Zoltán Kővágó
v2:
- "qapi/audio: add documentation for AudioFormat"
Markus suggested to correct a spelling mistake.
- "audio: add audiodev format=f32 option documentation"
New patch.
Volker Rümelin (6):
qapi/audio: add documentation for AudioFormat
audio: change naming scheme of FLOAT_CONV macros
audio: consistency changes
audio: change mixing engine float range to [-1.f, 1.f]
audio: fix saturation nonlinearity in clip_* functions
audio: add audiodev format=f32 option documentation
audio/mixeng.c | 26 +++++++++++++-------------
audio/mixeng_template.h | 22 ++++++++++------------
qapi/audio.json | 14 ++++++++++++++
qemu-options.hx | 4 ++--
4 files changed, 39 insertions(+), 27 deletions(-)
--
2.16.4
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 1/6] qapi/audio: add documentation for AudioFormat
2020-03-08 19:29 [PATCH v2 0/6] mostly changes related to audio float samples Volker Rümelin
@ 2020-03-08 19:33 ` Volker Rümelin
2020-03-09 14:57 ` G 3
2020-03-08 19:33 ` [PATCH v2 2/6] audio: change naming scheme of FLOAT_CONV macros Volker Rümelin
` (5 subsequent siblings)
6 siblings, 1 reply; 9+ messages in thread
From: Volker Rümelin @ 2020-03-08 19:33 UTC (permalink / raw)
To: Gerd Hoffmann, Eric Blake, Markus Armbruster
Cc: John Arbuckle, Howard Spoelstra, Mark Cave-Ayland, QEMU,
Zoltán Kővágó
The review for patch ed2a4a7941 "audio: proper support for
float samples in mixeng" suggested this would be a good idea.
Acked-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
---
qapi/audio.json | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/qapi/audio.json b/qapi/audio.json
index d8c507cced..c31251f45b 100644
--- a/qapi/audio.json
+++ b/qapi/audio.json
@@ -273,6 +273,20 @@
#
# An enumeration of possible audio formats.
#
+# @u8: unsigned 8 bit integer
+#
+# @s8: signed 8 bit integer
+#
+# @u16: unsigned 16 bit integer
+#
+# @s16: signed 16 bit integer
+#
+# @u32: unsigned 32 bit integer
+#
+# @s32: signed 32 bit integer
+#
+# @f32: single precision floating-point (since 5.0)
+#
# Since: 4.0
##
{ 'enum': 'AudioFormat',
--
2.16.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 2/6] audio: change naming scheme of FLOAT_CONV macros
2020-03-08 19:29 [PATCH v2 0/6] mostly changes related to audio float samples Volker Rümelin
2020-03-08 19:33 ` [PATCH v2 1/6] qapi/audio: add documentation for AudioFormat Volker Rümelin
@ 2020-03-08 19:33 ` Volker Rümelin
2020-03-08 19:33 ` [PATCH v2 3/6] audio: consistency changes Volker Rümelin
` (4 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Volker Rümelin @ 2020-03-08 19:33 UTC (permalink / raw)
To: Gerd Hoffmann, Eric Blake, Markus Armbruster
Cc: John Arbuckle, Howard Spoelstra, Mark Cave-Ayland, QEMU,
Zoltán Kővágó
This patch changes the naming scheme of the FLOAT_CONV_TO and
FLOAT_CONV_FROM macros to the scheme used in mixeng_template.h.
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
---
audio/mixeng.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/audio/mixeng.c b/audio/mixeng.c
index c14b0d874c..b57fad83bf 100644
--- a/audio/mixeng.c
+++ b/audio/mixeng.c
@@ -268,17 +268,17 @@ f_sample *mixeng_clip[2][2][2][3] = {
};
#ifdef FLOAT_MIXENG
-#define FLOAT_CONV_TO(x) (x)
-#define FLOAT_CONV_FROM(x) (x)
+#define CONV_NATURAL_FLOAT(x) (x)
+#define CLIP_NATURAL_FLOAT(x) (x)
#else
static const float float_scale = UINT_MAX;
-#define FLOAT_CONV_TO(x) ((x) * float_scale)
+#define CONV_NATURAL_FLOAT(x) ((x) * float_scale)
#ifdef RECIPROCAL
static const float float_scale_reciprocal = 1.f / UINT_MAX;
-#define FLOAT_CONV_FROM(x) ((x) * float_scale_reciprocal)
+#define CLIP_NATURAL_FLOAT(x) ((x) * float_scale_reciprocal)
#else
-#define FLOAT_CONV_FROM(x) ((x) / float_scale)
+#define CLIP_NATURAL_FLOAT(x) ((x) / float_scale)
#endif
#endif
@@ -288,7 +288,7 @@ static void conv_natural_float_to_mono(struct st_sample *dst, const void *src,
float *in = (float *)src;
while (samples--) {
- dst->r = dst->l = FLOAT_CONV_TO(*in++);
+ dst->r = dst->l = CONV_NATURAL_FLOAT(*in++);
dst++;
}
}
@@ -299,8 +299,8 @@ static void conv_natural_float_to_stereo(struct st_sample *dst, const void *src,
float *in = (float *)src;
while (samples--) {
- dst->l = FLOAT_CONV_TO(*in++);
- dst->r = FLOAT_CONV_TO(*in++);
+ dst->l = CONV_NATURAL_FLOAT(*in++);
+ dst->r = CONV_NATURAL_FLOAT(*in++);
dst++;
}
}
@@ -316,7 +316,7 @@ static void clip_natural_float_from_mono(void *dst, const struct st_sample *src,
float *out = (float *)dst;
while (samples--) {
- *out++ = FLOAT_CONV_FROM(src->l) + FLOAT_CONV_FROM(src->r);
+ *out++ = CLIP_NATURAL_FLOAT(src->l) + CLIP_NATURAL_FLOAT(src->r);
src++;
}
}
@@ -327,8 +327,8 @@ static void clip_natural_float_from_stereo(
float *out = (float *)dst;
while (samples--) {
- *out++ = FLOAT_CONV_FROM(src->l);
- *out++ = FLOAT_CONV_FROM(src->r);
+ *out++ = CLIP_NATURAL_FLOAT(src->l);
+ *out++ = CLIP_NATURAL_FLOAT(src->r);
src++;
}
}
--
2.16.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 3/6] audio: consistency changes
2020-03-08 19:29 [PATCH v2 0/6] mostly changes related to audio float samples Volker Rümelin
2020-03-08 19:33 ` [PATCH v2 1/6] qapi/audio: add documentation for AudioFormat Volker Rümelin
2020-03-08 19:33 ` [PATCH v2 2/6] audio: change naming scheme of FLOAT_CONV macros Volker Rümelin
@ 2020-03-08 19:33 ` Volker Rümelin
2020-03-08 19:33 ` [PATCH v2 4/6] audio: change mixing engine float range to [-1.f, 1.f] Volker Rümelin
` (3 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Volker Rümelin @ 2020-03-08 19:33 UTC (permalink / raw)
To: Gerd Hoffmann, Eric Blake, Markus Armbruster
Cc: John Arbuckle, Howard Spoelstra, Mark Cave-Ayland, QEMU,
Zoltán Kővágó
Change the clip_natural_float_from_mono() function in
audio/mixeng.c to be consistent with the clip_*_from_mono()
functions in audio/mixeng_template.h.
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
---
audio/mixeng.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/audio/mixeng.c b/audio/mixeng.c
index b57fad83bf..725b529be7 100644
--- a/audio/mixeng.c
+++ b/audio/mixeng.c
@@ -316,7 +316,7 @@ static void clip_natural_float_from_mono(void *dst, const struct st_sample *src,
float *out = (float *)dst;
while (samples--) {
- *out++ = CLIP_NATURAL_FLOAT(src->l) + CLIP_NATURAL_FLOAT(src->r);
+ *out++ = CLIP_NATURAL_FLOAT(src->l + src->r);
src++;
}
}
--
2.16.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 4/6] audio: change mixing engine float range to [-1.f, 1.f]
2020-03-08 19:29 [PATCH v2 0/6] mostly changes related to audio float samples Volker Rümelin
` (2 preceding siblings ...)
2020-03-08 19:33 ` [PATCH v2 3/6] audio: consistency changes Volker Rümelin
@ 2020-03-08 19:33 ` Volker Rümelin
2020-03-08 19:33 ` [PATCH v2 5/6] audio: fix saturation nonlinearity in clip_* functions Volker Rümelin
` (2 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Volker Rümelin @ 2020-03-08 19:33 UTC (permalink / raw)
To: Gerd Hoffmann, Eric Blake, Markus Armbruster
Cc: John Arbuckle, Howard Spoelstra, Mark Cave-Ayland, QEMU,
Zoltán Kővágó
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
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 5/6] audio: fix saturation nonlinearity in clip_* functions
2020-03-08 19:29 [PATCH v2 0/6] mostly changes related to audio float samples Volker Rümelin
` (3 preceding siblings ...)
2020-03-08 19:33 ` [PATCH v2 4/6] audio: change mixing engine float range to [-1.f, 1.f] Volker Rümelin
@ 2020-03-08 19:33 ` Volker Rümelin
2020-03-08 19:33 ` [PATCH v2 6/6] audio: add audiodev format=f32 option documentation Volker Rümelin
2020-03-16 11:32 ` [PATCH v2 0/6] mostly changes related to audio float samples Gerd Hoffmann
6 siblings, 0 replies; 9+ messages in thread
From: Volker Rümelin @ 2020-03-08 19:33 UTC (permalink / raw)
To: Gerd Hoffmann, Eric Blake, Markus Armbruster
Cc: John Arbuckle, Howard Spoelstra, Mark Cave-Ayland, QEMU,
Zoltán Kővágó
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 <vr_qemu@t-online.de>
---
audio/mixeng_template.h | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
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;
}
--
2.16.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 6/6] audio: add audiodev format=f32 option documentation
2020-03-08 19:29 [PATCH v2 0/6] mostly changes related to audio float samples Volker Rümelin
` (4 preceding siblings ...)
2020-03-08 19:33 ` [PATCH v2 5/6] audio: fix saturation nonlinearity in clip_* functions Volker Rümelin
@ 2020-03-08 19:33 ` Volker Rümelin
2020-03-16 11:32 ` [PATCH v2 0/6] mostly changes related to audio float samples Gerd Hoffmann
6 siblings, 0 replies; 9+ messages in thread
From: Volker Rümelin @ 2020-03-08 19:33 UTC (permalink / raw)
To: Gerd Hoffmann, Eric Blake, Markus Armbruster
Cc: John Arbuckle, Howard Spoelstra, Mark Cave-Ayland, QEMU,
Zoltán Kővágó
The documentaion for -audiodev format=f32 option was missing.
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
---
qemu-options.hx | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/qemu-options.hx b/qemu-options.hx
index f9fefd43be..2919eddf4d 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -551,7 +551,7 @@ DEF("audiodev", HAS_ARG, QEMU_OPTION_audiodev,
" in|out.frequency= frequency to use with fixed settings\n"
" in|out.channels= number of channels to use with fixed settings\n"
" in|out.format= sample format to use with fixed settings\n"
- " valid values: s8, s16, s32, u8, u16, u32\n"
+ " valid values: s8, s16, s32, u8, u16, u32, f32\n"
" in|out.voices= number of voices to use\n"
" in|out.buffer-length= length of buffer in microseconds\n"
"-audiodev none,id=id,[,prop[=value][,...]]\n"
@@ -647,7 +647,7 @@ SRST
``in|out.format=format``
Specify the sample format to use when using fixed-settings.
Valid values are: ``s8``, ``s16``, ``s32``, ``u8``, ``u16``,
- ``u32``. Default is ``s16``.
+ ``u32``, ``f32``. Default is ``s16``.
``in|out.voices=voices``
Specify the number of voices to use. Default is 1.
--
2.16.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/6] qapi/audio: add documentation for AudioFormat
2020-03-08 19:33 ` [PATCH v2 1/6] qapi/audio: add documentation for AudioFormat Volker Rümelin
@ 2020-03-09 14:57 ` G 3
0 siblings, 0 replies; 9+ messages in thread
From: G 3 @ 2020-03-09 14:57 UTC (permalink / raw)
To: Volker Rümelin
Cc: Zoltán Kővágó, Mark Cave-Ayland, QEMU,
Markus Armbruster, Gerd Hoffmann, Howard Spoelstra
[-- Attachment #1: Type: text/plain, Size: 583 bytes --]
On Sun, Mar 8, 2020 at 3:33 PM Volker Rümelin <vr_qemu@t-online.de> wrote:
> The review for patch ed2a4a7941 "audio: proper support for
> float samples in mixeng" suggested this would be a good idea.
>
> Acked-by: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
> ---
> <snip>
>
> Your patch applied cleanly to the latest commit I tried it out with. For
testing I used qemu-system-i386 with the AC97 sound card and a Windows 2000
guest. The audio played perfectly.
Tested-by: John Arbuckle <programmingkidx@gmail.com>
[-- Attachment #2: Type: text/html, Size: 1176 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 0/6] mostly changes related to audio float samples
2020-03-08 19:29 [PATCH v2 0/6] mostly changes related to audio float samples Volker Rümelin
` (5 preceding siblings ...)
2020-03-08 19:33 ` [PATCH v2 6/6] audio: add audiodev format=f32 option documentation Volker Rümelin
@ 2020-03-16 11:32 ` Gerd Hoffmann
6 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2020-03-16 11:32 UTC (permalink / raw)
To: Volker Rümelin
Cc: Zoltán Kővágó, Mark Cave-Ayland,
Markus Armbruster, QEMU, John Arbuckle, Howard Spoelstra
On Sun, Mar 08, 2020 at 08:29:05PM +0100, Volker Rümelin wrote:
> v2:
> - "qapi/audio: add documentation for AudioFormat"
> Markus suggested to correct a spelling mistake.
>
> - "audio: add audiodev format=f32 option documentation"
> New patch.
Pull request sent.
thanks,
Gerd
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2020-03-16 12:52 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-08 19:29 [PATCH v2 0/6] mostly changes related to audio float samples Volker Rümelin
2020-03-08 19:33 ` [PATCH v2 1/6] qapi/audio: add documentation for AudioFormat Volker Rümelin
2020-03-09 14:57 ` G 3
2020-03-08 19:33 ` [PATCH v2 2/6] audio: change naming scheme of FLOAT_CONV macros Volker Rümelin
2020-03-08 19:33 ` [PATCH v2 3/6] audio: consistency changes Volker Rümelin
2020-03-08 19:33 ` [PATCH v2 4/6] audio: change mixing engine float range to [-1.f, 1.f] Volker Rümelin
2020-03-08 19:33 ` [PATCH v2 5/6] audio: fix saturation nonlinearity in clip_* functions Volker Rümelin
2020-03-08 19:33 ` [PATCH v2 6/6] audio: add audiodev format=f32 option documentation Volker Rümelin
2020-03-16 11:32 ` [PATCH v2 0/6] mostly changes related to audio float samples Gerd Hoffmann
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).