diff --git a/spa/plugins/audioconvert/fmt-ops-c.c b/spa/plugins/audioconvert/fmt-ops-c.c index 0fb591a43..2d99c6117 100644 --- a/spa/plugins/audioconvert/fmt-ops-c.c +++ b/spa/plugins/audioconvert/fmt-ops-c.c @@ -252,6 +252,20 @@ conv_s16_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * } } +void +conv_s16s_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[], + uint32_t n_samples) +{ + const int16_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] = S16S_TO_F32(*s++); + } +} + void conv_s16d_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[], uint32_t n_samples) @@ -309,6 +323,20 @@ conv_s32_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * } } +void +conv_s32s_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[], + uint32_t n_samples) +{ + const int32_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] = S32S_TO_F32(*s++); + } +} + void conv_s32d_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[], uint32_t n_samples) @@ -447,6 +475,20 @@ conv_s24_32_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const voi } } +void +conv_s24_32s_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[], + uint32_t n_samples) +{ + const int32_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_32S_TO_F32(*s++); + } +} + void conv_s24_32d_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[], uint32_t n_samples) @@ -632,6 +674,20 @@ conv_f32d_to_s16_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * } } +void +conv_f32d_to_s16s_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[], + uint32_t n_samples) +{ + const float **s = (const float **) src; + int16_t *d = dst[0]; + uint32_t i, j, n_channels = conv->n_channels; + + for (j = 0; j < n_samples; j++) { + for (i = 0; i < n_channels; i++) + *d++ = F32_TO_S16S(s[i][j]); + } +} + void conv_f32d_to_s32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[], uint32_t n_samples) @@ -689,7 +745,19 @@ conv_f32d_to_s32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * } } +void +conv_f32d_to_s32s_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[], + uint32_t n_samples) +{ + const float **s = (const float **) src; + int32_t *d = dst[0]; + uint32_t i, j, n_channels = conv->n_channels; + for (j = 0; j < n_samples; j++) { + for (i = 0; i < n_channels; i++) + *d++ = F32_TO_S32S(s[i][j]); + } +} void conv_f32d_to_s24d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[], @@ -829,6 +897,20 @@ conv_f32d_to_s24_32_c(struct convert *conv, void * SPA_RESTRICT dst[], const voi } } +void +conv_f32d_to_s24_32s_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[], + uint32_t n_samples) +{ + const float **s = (const float **) src; + int32_t *d = dst[0]; + uint32_t i, j, n_channels = conv->n_channels; + + for (j = 0; j < n_samples; j++) { + for (i = 0; i < n_channels; i++) + *d++ = F32_TO_S24_32S(s[i][j]); + } +} + void conv_deinterleave_8_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[], uint32_t n_samples) @@ -887,6 +969,20 @@ conv_deinterleave_32_c(struct convert *conv, void * SPA_RESTRICT dst[], const vo } } +void +conv_deinterleave_32s_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[], + uint32_t n_samples) +{ + const uint32_t *s = src[0]; + uint32_t **d = (uint32_t **) 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] = bswap_32(*s++); + } +} + void conv_interleave_8_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[], uint32_t n_samples) @@ -944,3 +1040,17 @@ conv_interleave_32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void *d++ = s[i][j]; } } + +void +conv_interleave_32s_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[], + uint32_t n_samples) +{ + const int32_t **s = (const int32_t **) src; + uint32_t *d = dst[0]; + uint32_t i, j, n_channels = conv->n_channels; + + for (j = 0; j < n_samples; j++) { + for (i = 0; i < n_channels; i++) + *d++ = bswap_32(s[i][j]); + } +} diff --git a/spa/plugins/audioconvert/fmt-ops.c b/spa/plugins/audioconvert/fmt-ops.c index ea6ffe662..ff30905d1 100644 --- a/spa/plugins/audioconvert/fmt-ops.c +++ b/spa/plugins/audioconvert/fmt-ops.c @@ -73,11 +73,16 @@ static struct conv_info conv_table[] = { SPA_AUDIO_FORMAT_S16, SPA_AUDIO_FORMAT_F32P, 0, 0, conv_s16_to_f32d_c }, { SPA_AUDIO_FORMAT_S16P, SPA_AUDIO_FORMAT_F32, 0, 0, conv_s16d_to_f32_c }, + { SPA_AUDIO_FORMAT_S16_OE, SPA_AUDIO_FORMAT_F32P, 0, 0, conv_s16s_to_f32d_c }, + { SPA_AUDIO_FORMAT_F32, SPA_AUDIO_FORMAT_F32, 0, 0, conv_copy32_c }, { SPA_AUDIO_FORMAT_F32P, SPA_AUDIO_FORMAT_F32P, 0, 0, conv_copy32d_c }, { SPA_AUDIO_FORMAT_F32, SPA_AUDIO_FORMAT_F32P, 0, 0, conv_deinterleave_32_c }, { SPA_AUDIO_FORMAT_F32P, SPA_AUDIO_FORMAT_F32, 0, 0, conv_interleave_32_c }, + { SPA_AUDIO_FORMAT_F32_OE, SPA_AUDIO_FORMAT_F32P, 0, 0, conv_deinterleave_32s_c }, + { SPA_AUDIO_FORMAT_F32P, SPA_AUDIO_FORMAT_F32_OE, 0, 0, conv_interleave_32s_c }, + #if defined (HAVE_AVX2) { SPA_AUDIO_FORMAT_S32, SPA_AUDIO_FORMAT_F32P, 0, SPA_CPU_FLAG_AVX2, conv_s32_to_f32d_avx2 }, #endif @@ -89,6 +94,8 @@ static struct conv_info conv_table[] = { SPA_AUDIO_FORMAT_S32, SPA_AUDIO_FORMAT_F32P, 0, 0, conv_s32_to_f32d_c }, { SPA_AUDIO_FORMAT_S32P, SPA_AUDIO_FORMAT_F32, 0, 0, conv_s32d_to_f32_c }, + { SPA_AUDIO_FORMAT_S32_OE, SPA_AUDIO_FORMAT_F32P, 0, 0, conv_s32s_to_f32d_c }, + { SPA_AUDIO_FORMAT_S24, SPA_AUDIO_FORMAT_F32, 0, 0, conv_s24_to_f32_c }, { SPA_AUDIO_FORMAT_S24P, SPA_AUDIO_FORMAT_F32P, 0, 0, conv_s24d_to_f32d_c }, #if defined (HAVE_AVX2) @@ -113,6 +120,8 @@ static struct conv_info conv_table[] = { SPA_AUDIO_FORMAT_S24_32, SPA_AUDIO_FORMAT_F32P, 0, 0, conv_s24_32_to_f32d_c }, { SPA_AUDIO_FORMAT_S24_32P, SPA_AUDIO_FORMAT_F32, 0, 0, conv_s24_32d_to_f32_c }, + { SPA_AUDIO_FORMAT_S24_32_OE, SPA_AUDIO_FORMAT_F32P, 0, 0, conv_s24_32s_to_f32d_c }, + /* from f32 */ { SPA_AUDIO_FORMAT_F32, SPA_AUDIO_FORMAT_U8, 0, 0, conv_f32_to_u8_c }, { SPA_AUDIO_FORMAT_F32P, SPA_AUDIO_FORMAT_U8P, 0, 0, conv_f32d_to_u8d_c }, @@ -150,6 +159,8 @@ static struct conv_info conv_table[] = #endif { SPA_AUDIO_FORMAT_F32P, SPA_AUDIO_FORMAT_S16, 0, 0, conv_f32d_to_s16_c }, + { SPA_AUDIO_FORMAT_F32P, SPA_AUDIO_FORMAT_S16_OE, 0, 0, conv_f32d_to_s16s_c }, + { SPA_AUDIO_FORMAT_F32, SPA_AUDIO_FORMAT_S32, 0, 0, conv_f32_to_s32_c }, { SPA_AUDIO_FORMAT_F32P, SPA_AUDIO_FORMAT_S32P, 0, 0, conv_f32d_to_s32d_c }, { SPA_AUDIO_FORMAT_F32, SPA_AUDIO_FORMAT_S32P, 0, 0, conv_f32_to_s32d_c }, @@ -161,6 +172,8 @@ static struct conv_info conv_table[] = #endif { SPA_AUDIO_FORMAT_F32P, SPA_AUDIO_FORMAT_S32, 0, 0, conv_f32d_to_s32_c }, + { SPA_AUDIO_FORMAT_F32P, SPA_AUDIO_FORMAT_S32_OE, 0, 0, conv_f32d_to_s32s_c }, + { SPA_AUDIO_FORMAT_F32, SPA_AUDIO_FORMAT_S24, 0, 0, conv_f32_to_s24_c }, { SPA_AUDIO_FORMAT_F32P, SPA_AUDIO_FORMAT_S24P, 0, 0, conv_f32d_to_s24d_c }, { SPA_AUDIO_FORMAT_F32, SPA_AUDIO_FORMAT_S24P, 0, 0, conv_f32_to_s24d_c }, @@ -173,6 +186,8 @@ static struct conv_info conv_table[] = { SPA_AUDIO_FORMAT_F32, SPA_AUDIO_FORMAT_S24_32P, 0, 0, conv_f32_to_s24_32d_c }, { SPA_AUDIO_FORMAT_F32P, SPA_AUDIO_FORMAT_S24_32, 0, 0, conv_f32d_to_s24_32_c }, + { SPA_AUDIO_FORMAT_F32P, SPA_AUDIO_FORMAT_S24_32_OE, 0, 0, conv_f32d_to_s24_32s_c }, + /* u8 */ { SPA_AUDIO_FORMAT_U8, SPA_AUDIO_FORMAT_U8, 0, 0, conv_copy8_c }, { SPA_AUDIO_FORMAT_U8P, SPA_AUDIO_FORMAT_U8P, 0, 0, conv_copy8d_c }, diff --git a/spa/plugins/audioconvert/fmt-ops.h b/spa/plugins/audioconvert/fmt-ops.h index 893c5a94a..5ef0544fe 100644 --- a/spa/plugins/audioconvert/fmt-ops.h +++ b/spa/plugins/audioconvert/fmt-ops.h @@ -23,6 +23,7 @@ */ #include +#include #include @@ -45,7 +46,9 @@ #define S16_MAX_F 32767.0f #define S16_SCALE 32767.0f #define S16_TO_F32(v) (((int16_t)(v)) * (1.0f / S16_SCALE)) +#define S16S_TO_F32(v) (((int16_t)bswap_16((uint16_t)v)) * (1.0f / S16_SCALE)) #define F32_TO_S16(v) (int16_t)(SPA_CLAMP(v, -1.0f, 1.0f) * S16_SCALE) +#define F32_TO_S16S(v) ((int16_t)bswap_16((uint16_t)(SPA_CLAMP(v, -1.0f, 1.0f) * S16_SCALE))) #define S24_MIN -8388607 #define S24_MAX 8388607 @@ -58,10 +61,14 @@ #define S32_MIN 2147483520.0f #define S32_TO_F32(v) S24_TO_F32((v) >> 8) +#define S32S_TO_F32(v) bswap_32(S24_TO_F32((v) >> 8)) #define F32_TO_S32(v) (F32_TO_S24(v) << 8) +#define F32_TO_S32S(v) bswap_32((F32_TO_S24(v) << 8)) #define S24_32_TO_F32(v) S32_TO_F32((v)<<8) +#define S24_32S_TO_F32(v) bswap_32(S32_TO_F32((v)<<8)) #define F32_TO_S24_32(v) F32_TO_S24(v) +#define F32_TO_S24_32S(v) bswap_32(F32_TO_S24(v)) static inline int32_t read_s24(const void *src) { @@ -157,10 +164,12 @@ DEFINE_FUNCTION(s8d_to_f32, c); DEFINE_FUNCTION(s16d_to_f32d, c); DEFINE_FUNCTION(s16_to_f32, c); DEFINE_FUNCTION(s16_to_f32d, c); +DEFINE_FUNCTION(s16s_to_f32d, c); DEFINE_FUNCTION(s16d_to_f32, c); DEFINE_FUNCTION(s32d_to_f32d, c); DEFINE_FUNCTION(s32_to_f32, c); DEFINE_FUNCTION(s32_to_f32d, c); +DEFINE_FUNCTION(s32s_to_f32d, c); DEFINE_FUNCTION(s32d_to_f32, c); DEFINE_FUNCTION(s24d_to_f32d, c); DEFINE_FUNCTION(s24_to_f32, c); @@ -170,6 +179,7 @@ DEFINE_FUNCTION(s24d_to_f32, c); DEFINE_FUNCTION(s24_32d_to_f32d, c); DEFINE_FUNCTION(s24_32_to_f32, c); DEFINE_FUNCTION(s24_32_to_f32d, c); +DEFINE_FUNCTION(s24_32s_to_f32d, c); DEFINE_FUNCTION(s24_32d_to_f32, c); DEFINE_FUNCTION(f32d_to_u8d, c); DEFINE_FUNCTION(f32_to_u8, c); @@ -183,10 +193,12 @@ DEFINE_FUNCTION(f32d_to_s16d, c); DEFINE_FUNCTION(f32_to_s16, c); DEFINE_FUNCTION(f32_to_s16d, c); DEFINE_FUNCTION(f32d_to_s16, c); +DEFINE_FUNCTION(f32d_to_s16s, c); DEFINE_FUNCTION(f32d_to_s32d, c); DEFINE_FUNCTION(f32_to_s32, c); DEFINE_FUNCTION(f32_to_s32d, c); DEFINE_FUNCTION(f32d_to_s32, c); +DEFINE_FUNCTION(f32d_to_s32s, c); DEFINE_FUNCTION(f32d_to_s24d, c); DEFINE_FUNCTION(f32_to_s24, c); DEFINE_FUNCTION(f32_to_s24d, c); @@ -196,14 +208,17 @@ DEFINE_FUNCTION(f32d_to_s24_32d, c); DEFINE_FUNCTION(f32_to_s24_32, c); DEFINE_FUNCTION(f32_to_s24_32d, c); DEFINE_FUNCTION(f32d_to_s24_32, c); +DEFINE_FUNCTION(f32d_to_s24_32s, c); DEFINE_FUNCTION(deinterleave_8, c); DEFINE_FUNCTION(deinterleave_16, c); DEFINE_FUNCTION(deinterleave_24, c); DEFINE_FUNCTION(deinterleave_32, c); +DEFINE_FUNCTION(deinterleave_32s, c); DEFINE_FUNCTION(interleave_8, c); DEFINE_FUNCTION(interleave_16, c); DEFINE_FUNCTION(interleave_24, c); DEFINE_FUNCTION(interleave_32, c); +DEFINE_FUNCTION(interleave_32s, c); #if defined(HAVE_NEON) DEFINE_FUNCTION(s16_to_f32d, neon);