From 3a879e8b1a1639d6d61ef30964d62b497400ce04 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 6 Jul 2021 12:42:39 +0200 Subject: [PATCH] audioconvert: fix s24_32 to float s24_32 needs to be sign extended before converting to float because the upper bits are undefined and might be anything. Fixes #1393 --- spa/plugins/audioconvert/fmt-ops-c.c | 19 ++++++++++--------- spa/plugins/audioconvert/fmt-ops.h | 3 +++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/spa/plugins/audioconvert/fmt-ops-c.c b/spa/plugins/audioconvert/fmt-ops-c.c index d134a8481..0fb591a43 100644 --- a/spa/plugins/audioconvert/fmt-ops-c.c +++ b/spa/plugins/audioconvert/fmt-ops-c.c @@ -414,7 +414,7 @@ conv_s24_32d_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const vo float *d = dst[i]; for (j = 0; j < n_samples; j++) - d[j] = S24_TO_F32(s[j]); + d[j] = S24_32_TO_F32(s[j]); } } @@ -428,8 +428,9 @@ conv_s24_32_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void n_samples *= n_channels; - for (i = 0; i < n_samples; i++) - d[i] = S24_TO_F32(s[i]); + for (i = 0; i < n_samples; i++) { + d[i] = S24_32_TO_F32(s[i]); + } } void @@ -442,7 +443,7 @@ conv_s24_32_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const voi for (j = 0; j < n_samples; j++) { for (i = 0; i < n_channels; i++) - d[i][j] = S24_TO_F32(*s++); + d[i][j] = S24_32_TO_F32(*s++); } } @@ -456,7 +457,7 @@ conv_s24_32d_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst[], const voi for (j = 0; j < n_samples; j++) { for (i = 0; i < n_channels; i++) - *d++ = S24_TO_F32(s[i][j]); + *d++ = S24_32_TO_F32(s[i][j]); } } @@ -782,7 +783,7 @@ conv_f32d_to_s24_32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const vo int32_t *d = dst[i]; for (j = 0; j < n_samples; j++) - d[j] = F32_TO_S24(s[j]); + d[j] = F32_TO_S24_32(s[j]); } } @@ -797,7 +798,7 @@ conv_f32_to_s24_32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void n_samples *= n_channels; for (i = 0; i < n_samples; i++) - d[i] = F32_TO_S24(s[i]); + d[i] = F32_TO_S24_32(s[i]); } void @@ -810,7 +811,7 @@ conv_f32_to_s24_32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const voi for (j = 0; j < n_samples; j++) { for (i = 0; i < n_channels; i++) - d[i][j] = F32_TO_S24(*s++); + d[i][j] = F32_TO_S24_32(*s++); } } @@ -824,7 +825,7 @@ conv_f32d_to_s24_32_c(struct convert *conv, void * SPA_RESTRICT dst[], const voi for (j = 0; j < n_samples; j++) { for (i = 0; i < n_channels; i++) - *d++ = F32_TO_S24(s[i][j]); + *d++ = F32_TO_S24_32(s[i][j]); } } diff --git a/spa/plugins/audioconvert/fmt-ops.h b/spa/plugins/audioconvert/fmt-ops.h index 2dc4809d2..893c5a94a 100644 --- a/spa/plugins/audioconvert/fmt-ops.h +++ b/spa/plugins/audioconvert/fmt-ops.h @@ -60,6 +60,9 @@ #define S32_TO_F32(v) S24_TO_F32((v) >> 8) #define F32_TO_S32(v) (F32_TO_S24(v) << 8) +#define S24_32_TO_F32(v) S32_TO_F32((v)<<8) +#define F32_TO_S24_32(v) F32_TO_S24(v) + static inline int32_t read_s24(const void *src) { const int8_t *s = src;