diff options
| author | Stefan Hajnoczi <stefanha@redhat.com> | 2025-05-25 09:51:07 -0400 |
|---|---|---|
| committer | Stefan Hajnoczi <stefanha@redhat.com> | 2025-05-25 09:51:07 -0400 |
| commit | 3c5a5e213e5f08fbfe70728237f7799ac70f5b99 (patch) | |
| tree | 2e52f3386c8d2494b9fce222c446c559472a6e50 /audio/mixeng.c | |
| parent | 6f388a37e6dc2df4457692afe6adb5448b7db31d (diff) | |
| parent | 2bccabe6df5e91145c1313bb79b98200aa13b5ff (diff) | |
| download | focaccia-qemu-3c5a5e213e5f08fbfe70728237f7799ac70f5b99.tar.gz focaccia-qemu-3c5a5e213e5f08fbfe70728237f7799ac70f5b99.zip | |
Merge tag 'audio-pull-request' of https://gitlab.com/marcandre.lureau/qemu into staging
Audio patches - add float sample endianness converters - various fixes # -----BEGIN PGP SIGNATURE----- # # iQJQBAABCgA6FiEEh6m9kz+HxgbSdvYt2ujhCXWWnOUFAmgzGnEcHG1hcmNhbmRy # ZS5sdXJlYXVAcmVkaGF0LmNvbQAKCRDa6OEJdZac5YkCEACA7BmZRorXwWuozmOK # /I6ar0j6VjpKOzFQFo2Sy4vfLOb2rl5Q3Fb02Dk3nR9f3FpYmoIKF9sbBUdL095v # Nhj8wNyCiM/QTFFPXNKa92ubovCyC25pyVLogXmMaa5YhhZpF4wcx/ermhbyhhmL # GTmqfbnN8ki6jQ22ftKGBbcvny4xakKaLJdQtk/joSk0PF67FKZrenjVkcNThFwY # kHyyBCdm2G8VVVyxfHk+/S22+eMkeTZfJgMo2WfYpWWqLTTkrASJNjf8oG+bfzAa # +iMyUzEHDK+rOatcb5SbZltfEljdBh+2LaPEziEZWGfbwKA1/QHztBn3Rs6CwVdS # AU2F9gWhL1GOBIaop1I3EvJ1eGQZCZex08gV7jgdLdBh0x6NLKahqHU9CMHsY07a # zhp4FsFPs4G9cmmbw064qPAdI11hhLiqckaI91gYVIJQXOf92hGcyP5M03qXbPDL # D3WXjnBdVXhaB0Ih41TqYbkTwTMxGGC13lB10UsnNO03yzrIkGOMywJJ564dtpHX # TzchYDLO9Vg/p6Y9fW95jC+AbCZasStzmkOwxWiIK5hBhxoV2iAdiLsTtSMNO1P7 # eyMUE9P+LaPgTz57cXQ+QpD3126T/QKmAzfgPXu7AHDCmaz4/boc0sOQLa5UVRNN # KH506pqjeOLRaAcTdEubTDiriw== # =UYr7 # -----END PGP SIGNATURE----- # gpg: Signature made Sun 25 May 2025 09:26:09 EDT # gpg: using RSA key 87A9BD933F87C606D276F62DDAE8E10975969CE5 # gpg: issuer "marcandre.lureau@redhat.com" # gpg: Good signature from "Marc-André Lureau <marcandre.lureau@redhat.com>" [full] # gpg: aka "Marc-André Lureau <marcandre.lureau@gmail.com>" [full] # Primary key fingerprint: 87A9 BD93 3F87 C606 D276 F62D DAE8 E109 7596 9CE5 * tag 'audio-pull-request' of https://gitlab.com/marcandre.lureau/qemu: audio: Reset rate control when adding bytes alsaaudio: Set try-poll to false by default audio: add float sample endianness converters audio/mixeng: remove unnecessary pointer type casts hw/audio/asc: replace g_malloc0() with g_malloc() hw/audio/asc: fix SIGSEGV in asc_realize() audio: fix size calculation in AUD_get_buffer_size_out() audio: fix SIGSEGV in AUD_get_buffer_size_out() tests/functional: use 'none' audio driver for q800 tests Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'audio/mixeng.c')
| -rw-r--r-- | audio/mixeng.c | 83 |
1 files changed, 73 insertions, 10 deletions
diff --git a/audio/mixeng.c b/audio/mixeng.c index 69f6549224..703ee5448f 100644 --- a/audio/mixeng.c +++ b/audio/mixeng.c @@ -283,10 +283,15 @@ static const float float_scale_reciprocal = 1.f / ((int64_t)INT32_MAX + 1); #endif #endif +#define F32_TO_F32S(v) \ + bswap32((union { uint32_t i; float f; }){ .f = (v) }.i) +#define F32S_TO_F32(v) \ + ((union { uint32_t i; float f; }){ .i = bswap32(v) }.f) + static void conv_natural_float_to_mono(struct st_sample *dst, const void *src, int samples) { - float *in = (float *)src; + const float *in = src; while (samples--) { dst->r = dst->l = CONV_NATURAL_FLOAT(*in++); @@ -294,10 +299,21 @@ static void conv_natural_float_to_mono(struct st_sample *dst, const void *src, } } +static void conv_swap_float_to_mono(struct st_sample *dst, const void *src, + int samples) +{ + const uint32_t *in_f32s = src; + + while (samples--) { + dst->r = dst->l = CONV_NATURAL_FLOAT(F32S_TO_F32(*in_f32s++)); + dst++; + } +} + static void conv_natural_float_to_stereo(struct st_sample *dst, const void *src, int samples) { - float *in = (float *)src; + const float *in = src; while (samples--) { dst->l = CONV_NATURAL_FLOAT(*in++); @@ -306,15 +322,33 @@ static void conv_natural_float_to_stereo(struct st_sample *dst, const void *src, } } -t_sample *mixeng_conv_float[2] = { - conv_natural_float_to_mono, - conv_natural_float_to_stereo, +static void conv_swap_float_to_stereo(struct st_sample *dst, const void *src, + int samples) +{ + const uint32_t *in_f32s = src; + + while (samples--) { + dst->l = CONV_NATURAL_FLOAT(F32S_TO_F32(*in_f32s++)); + dst->r = CONV_NATURAL_FLOAT(F32S_TO_F32(*in_f32s++)); + dst++; + } +} + +t_sample *mixeng_conv_float[2][2] = { + { + conv_natural_float_to_mono, + conv_swap_float_to_mono, + }, + { + conv_natural_float_to_stereo, + conv_swap_float_to_stereo, + } }; static void clip_natural_float_from_mono(void *dst, const struct st_sample *src, int samples) { - float *out = (float *)dst; + float *out = dst; while (samples--) { *out++ = CLIP_NATURAL_FLOAT(src->l + src->r); @@ -322,10 +356,21 @@ static void clip_natural_float_from_mono(void *dst, const struct st_sample *src, } } +static void clip_swap_float_from_mono(void *dst, const struct st_sample *src, + int samples) +{ + uint32_t *out_f32s = dst; + + while (samples--) { + *out_f32s++ = F32_TO_F32S(CLIP_NATURAL_FLOAT(src->l + src->r)); + src++; + } +} + static void clip_natural_float_from_stereo( void *dst, const struct st_sample *src, int samples) { - float *out = (float *)dst; + float *out = dst; while (samples--) { *out++ = CLIP_NATURAL_FLOAT(src->l); @@ -334,9 +379,27 @@ static void clip_natural_float_from_stereo( } } -f_sample *mixeng_clip_float[2] = { - clip_natural_float_from_mono, - clip_natural_float_from_stereo, +static void clip_swap_float_from_stereo( + void *dst, const struct st_sample *src, int samples) +{ + uint32_t *out_f32s = dst; + + while (samples--) { + *out_f32s++ = F32_TO_F32S(CLIP_NATURAL_FLOAT(src->l)); + *out_f32s++ = F32_TO_F32S(CLIP_NATURAL_FLOAT(src->r)); + src++; + } +} + +f_sample *mixeng_clip_float[2][2] = { + { + clip_natural_float_from_mono, + clip_swap_float_from_mono, + }, + { + clip_natural_float_from_stereo, + clip_swap_float_from_stereo, + } }; void audio_sample_to_uint64(const void *samples, int pos, |