aboutsummaryrefslogtreecommitdiff
path: root/audio/mixeng.c
diff options
context:
space:
mode:
authorKővágó, Zoltán <dirty.ice.hu@gmail.com>2020-02-02 20:38:07 +0100
committerGerd Hoffmann <kraxel@redhat.com>2020-02-06 14:35:57 +0100
commited2a4a794184df3dbd5ee4cc06e86fe220663faf (patch)
treeed340e8120188691fd89b764ef45ad509005c9a6 /audio/mixeng.c
parent180b044ffde2cdd4a7209c727b5a8ce93d36741f (diff)
downloadqemu-ed2a4a794184df3dbd5ee4cc06e86fe220663faf.zip
qemu-ed2a4a794184df3dbd5ee4cc06e86fe220663faf.tar.gz
qemu-ed2a4a794184df3dbd5ee4cc06e86fe220663faf.tar.bz2
audio: proper support for float samples in mixeng
This adds proper support for float samples in mixeng by adding a new audio format for it. Limitations: only native endianness is supported. None of the virtual sound cards support float samples (it looks like most of them only support 8 and 16 bit, only hda supports 32 bit), it is only used for the audio backends (i.e. host side). Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com> Acked-by: Markus Armbruster <armbru@redhat.com> Message-id: 8a8b0b5698401b78d3c4c8ec90aef83b95babb06.1580672076.git.DirtY.iCE.hu@gmail.com Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'audio/mixeng.c')
-rw-r--r--audio/mixeng.c88
1 files changed, 55 insertions, 33 deletions
diff --git a/audio/mixeng.c b/audio/mixeng.c
index 16b646d..c14b0d8 100644
--- a/audio/mixeng.c
+++ b/audio/mixeng.c
@@ -267,55 +267,77 @@ f_sample *mixeng_clip[2][2][2][3] = {
}
};
-void conv_natural_float_to_stereo(struct st_sample *dst, const void *src,
- int samples)
+#ifdef FLOAT_MIXENG
+#define FLOAT_CONV_TO(x) (x)
+#define FLOAT_CONV_FROM(x) (x)
+#else
+static const float float_scale = UINT_MAX;
+#define FLOAT_CONV_TO(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)
+#else
+#define FLOAT_CONV_FROM(x) ((x) / float_scale)
+#endif
+#endif
+
+static void conv_natural_float_to_mono(struct st_sample *dst, const void *src,
+ int samples)
{
float *in = (float *)src;
-#ifndef FLOAT_MIXENG
- const float scale = UINT_MAX;
-#endif
while (samples--) {
-#ifdef FLOAT_MIXENG
- dst->l = *in++;
- dst->r = *in++;
-#else
- dst->l = *in++ * scale;
- dst->r = *in++ * scale;
-#endif
+ dst->r = dst->l = FLOAT_CONV_TO(*in++);
+ dst++;
+ }
+}
+
+static void conv_natural_float_to_stereo(struct st_sample *dst, const void *src,
+ int samples)
+{
+ float *in = (float *)src;
+
+ while (samples--) {
+ dst->l = FLOAT_CONV_TO(*in++);
+ dst->r = FLOAT_CONV_TO(*in++);
dst++;
}
}
-void clip_natural_float_from_stereo(void *dst, const struct st_sample *src,
- int samples)
+t_sample *mixeng_conv_float[2] = {
+ conv_natural_float_to_mono,
+ conv_natural_float_to_stereo,
+};
+
+static void clip_natural_float_from_mono(void *dst, const struct st_sample *src,
+ int samples)
+{
+ float *out = (float *)dst;
+
+ while (samples--) {
+ *out++ = FLOAT_CONV_FROM(src->l) + FLOAT_CONV_FROM(src->r);
+ src++;
+ }
+}
+
+static void clip_natural_float_from_stereo(
+ void *dst, const struct st_sample *src, int samples)
{
float *out = (float *)dst;
-#ifndef FLOAT_MIXENG
-#ifdef RECIPROCAL
- const float scale = 1.f / UINT_MAX;
-#else
- const float scale = UINT_MAX;
-#endif
-#endif
while (samples--) {
-#ifdef FLOAT_MIXENG
- *out++ = src->l;
- *out++ = src->r;
-#else
-#ifdef RECIPROCAL
- *out++ = src->l * scale;
- *out++ = src->r * scale;
-#else
- *out++ = src->l / scale;
- *out++ = src->r / scale;
-#endif
-#endif
+ *out++ = FLOAT_CONV_FROM(src->l);
+ *out++ = FLOAT_CONV_FROM(src->r);
src++;
}
}
+f_sample *mixeng_clip_float[2] = {
+ clip_natural_float_from_mono,
+ clip_natural_float_from_stereo,
+};
+
void audio_sample_to_uint64(void *samples, int pos,
uint64_t *left, uint64_t *right)
{