From f4387e0568b257ea0af1896a27803265dc44a548 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 27 Jan 2020 15:46:25 +0100 Subject: [PATCH] fmt-ops: add support for s24 with endian conversion --- spa/plugins/audioconvert/fmt-ops-c.c | 16 ++++++++++++++++ spa/plugins/audioconvert/fmt-ops.c | 2 ++ spa/plugins/audioconvert/fmt-ops.h | 25 +++++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/spa/plugins/audioconvert/fmt-ops-c.c b/spa/plugins/audioconvert/fmt-ops-c.c index 3dfe511d2..1b78ca103 100644 --- a/spa/plugins/audioconvert/fmt-ops-c.c +++ b/spa/plugins/audioconvert/fmt-ops-c.c @@ -316,6 +316,22 @@ conv_s24_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * } } +void +conv_s24s_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[], + uint32_t n_samples) +{ + const uint8_t *s = src[0]; + float **d = (float **) dst; + uint32_t i, j, n_channels = conv->n_channels; + + for (j = 0; j < n_samples; j++) { + for (i = 0; i < n_channels; i++) { + d[i][j] = S24_TO_F32(read_s24s(s)); + s += 3; + } + } +} + void conv_s24d_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[], uint32_t n_samples) diff --git a/spa/plugins/audioconvert/fmt-ops.c b/spa/plugins/audioconvert/fmt-ops.c index a18a25e72..6de6e0972 100644 --- a/spa/plugins/audioconvert/fmt-ops.c +++ b/spa/plugins/audioconvert/fmt-ops.c @@ -89,6 +89,8 @@ static struct conv_info conv_table[] = { SPA_AUDIO_FORMAT_S24, SPA_AUDIO_FORMAT_F32P, 0, 0, conv_s24_to_f32d_c }, { SPA_AUDIO_FORMAT_S24P, SPA_AUDIO_FORMAT_F32, 0, 0, conv_s24d_to_f32_c }, + { SPA_AUDIO_FORMAT_S24_OE, SPA_AUDIO_FORMAT_F32P, 0, 0, conv_s24s_to_f32d_c }, + { SPA_AUDIO_FORMAT_S24_32, SPA_AUDIO_FORMAT_F32, 0, 0, conv_s24_32_to_f32_c }, { SPA_AUDIO_FORMAT_S24_32P, SPA_AUDIO_FORMAT_F32P, 0, 0, conv_s24_32d_to_f32d_c }, { SPA_AUDIO_FORMAT_S24_32, SPA_AUDIO_FORMAT_F32P, 0, 0, conv_s24_32_to_f32d_c }, diff --git a/spa/plugins/audioconvert/fmt-ops.h b/spa/plugins/audioconvert/fmt-ops.h index c74ced540..9074c95db 100644 --- a/spa/plugins/audioconvert/fmt-ops.h +++ b/spa/plugins/audioconvert/fmt-ops.h @@ -63,6 +63,16 @@ static inline int32_t read_s24(const void *src) #endif } +static inline int32_t read_s24s(const void *src) +{ + const int8_t *s = src; +#if __BYTE_ORDER == __LITTLE_ENDIAN + return (((int32_t)s[0] << 16) | ((uint32_t)(uint8_t)s[1] << 8) | (uint32_t)(uint8_t)s[2]); +#else + return (((int32_t)s[2] << 16) | ((uint32_t)(uint8_t)s[1] << 8) | (uint32_t)(uint8_t)s[0]); +#endif +} + static inline void write_s24(void *dst, int32_t val) { uint8_t *d = dst; @@ -77,6 +87,20 @@ static inline void write_s24(void *dst, int32_t val) #endif } +static inline void write_s24s(void *dst, int32_t val) +{ + uint8_t *d = dst; +#if __BYTE_ORDER == __LITTLE_ENDIAN + d[0] = (uint8_t) (val >> 16); + d[1] = (uint8_t) (val >> 8); + d[2] = (uint8_t) (val); +#else + d[0] = (uint8_t) (val); + d[1] = (uint8_t) (val >> 8); + d[2] = (uint8_t) (val >> 16); +#endif +} + #define MAX_NS 64 struct convert { @@ -127,6 +151,7 @@ DEFINE_FUNCTION(s32d_to_f32, c); DEFINE_FUNCTION(s24d_to_f32d, c); DEFINE_FUNCTION(s24_to_f32, c); DEFINE_FUNCTION(s24_to_f32d, c); +DEFINE_FUNCTION(s24s_to_f32d, c); DEFINE_FUNCTION(s24d_to_f32, c); DEFINE_FUNCTION(s24_32d_to_f32d, c); DEFINE_FUNCTION(s24_32_to_f32, c);