From 5e0706c74f8315636203b8d8aba7bfc3115ad0b6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 24 Aug 2010 11:11:49 +0200 Subject: [PATCH] audioconvert: Use ORC for the float<->int32 conversion This should speed up standard Vorbis encoding and decoding pipelines a bit. Thanks to David Schleef for the assistance to get the ORC code right and explaining everything. --- gst/audioconvert/audioconvert.c | 33 ++++++++++++++--- gst/audioconvert/gstaudioconvertorc.orc | 63 +++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 4 deletions(-) diff --git a/gst/audioconvert/audioconvert.c b/gst/audioconvert/audioconvert.c index 8ac7d54..7924224 100644 --- a/gst/audioconvert/audioconvert.c +++ b/gst/audioconvert/audioconvert.c @@ -41,6 +41,8 @@ #define orc_audio_convert_unpack_u32_be orc_audio_convert_unpack_u32_swap #define orc_audio_convert_unpack_s32_le orc_audio_convert_unpack_s32 #define orc_audio_convert_unpack_s32_be orc_audio_convert_unpack_s32_swap +#define orc_audio_convert_unpack_float_le orc_audio_convert_unpack_float_s32 +#define orc_audio_convert_unpack_float_be orc_audio_convert_unpack_float_s32_swap #define orc_audio_convert_pack_u16_le orc_audio_convert_pack_u16 #define orc_audio_convert_pack_u16_be orc_audio_convert_pack_u16_swap #define orc_audio_convert_pack_s16_le orc_audio_convert_pack_s16 @@ -49,6 +51,8 @@ #define orc_audio_convert_pack_u32_be orc_audio_convert_pack_u32_swap #define orc_audio_convert_pack_s32_le orc_audio_convert_pack_s32 #define orc_audio_convert_pack_s32_be orc_audio_convert_pack_s32_swap +#define orc_audio_convert_pack_float_le orc_audio_convert_pack_s32_float +#define orc_audio_convert_pack_float_be orc_audio_convert_pack_s32_float_swap #else #define orc_audio_convert_unpack_u16_be orc_audio_convert_unpack_u16 #define orc_audio_convert_unpack_u16_le orc_audio_convert_unpack_u16_swap @@ -58,6 +62,8 @@ #define orc_audio_convert_unpack_u32_le orc_audio_convert_unpack_u32_swap #define orc_audio_convert_unpack_s32_be orc_audio_convert_unpack_s32 #define orc_audio_convert_unpack_s32_le orc_audio_convert_unpack_s32_swap +#define orc_audio_convert_unpack_float_be orc_audio_convert_unpack_float_s32 +#define orc_audio_convert_unpack_float_le orc_audio_convert_unpack_float_s32_swap #define orc_audio_convert_pack_u16_be orc_audio_convert_pack_u16 #define orc_audio_convert_pack_u16_le orc_audio_convert_pack_u16_swap #define orc_audio_convert_pack_s16_be orc_audio_convert_pack_s16 @@ -66,6 +72,8 @@ #define orc_audio_convert_pack_u32_le orc_audio_convert_pack_u32_swap #define orc_audio_convert_pack_s32_be orc_audio_convert_pack_s32 #define orc_audio_convert_pack_s32_le orc_audio_convert_pack_s32_swap +#define orc_audio_convert_pack_float_be orc_audio_convert_pack_s32_float +#define orc_audio_convert_pack_float_le orc_audio_convert_pack_s32_float_swap #endif /* sign bit in the intermediate format */ @@ -114,6 +122,14 @@ MAKE_UNPACK_FUNC_NAME (name) (type * src, gint32 * dst, gint s, gint count) \ } \ } +/* unpack from float to signed integer 32 with orc */ +#define MAKE_UNPACK_FUNC_ORC_FI(name, type, READ_FUNC) \ +static void \ +MAKE_UNPACK_FUNC_NAME (name) (type * src, gint32 * dst, gint s, gint count) \ +{ \ + MAKE_ORC_UNPACK_FUNC_NAME (name) ((guint32 *) dst, src, count); \ +} + /* unpack from float to float 64 (double) */ #define MAKE_UNPACK_FUNC_FF(name, type, FUNC) \ static void \ @@ -162,8 +178,8 @@ MAKE_UNPACK_FUNC_ORC_II (u32_le, 4, SIGNED, READ32_FROM_LE); MAKE_UNPACK_FUNC_ORC_II (s32_le, 4, 0, READ32_FROM_LE); MAKE_UNPACK_FUNC_ORC_II (u32_be, 4, SIGNED, READ32_FROM_BE); MAKE_UNPACK_FUNC_ORC_II (s32_be, 4, 0, READ32_FROM_BE); -MAKE_UNPACK_FUNC_FI (float_le, gfloat, GFLOAT_FROM_LE); -MAKE_UNPACK_FUNC_FI (float_be, gfloat, GFLOAT_FROM_BE); +MAKE_UNPACK_FUNC_ORC_FI (float_le, gfloat, GFLOAT_FROM_LE); +MAKE_UNPACK_FUNC_ORC_FI (float_be, gfloat, GFLOAT_FROM_BE); MAKE_UNPACK_FUNC_FI (double_le, gdouble, GDOUBLE_FROM_LE); MAKE_UNPACK_FUNC_FI (double_be, gdouble, GDOUBLE_FROM_BE); MAKE_UNPACK_FUNC_FF (float_hq_le, gfloat, GFLOAT_FROM_LE); @@ -231,6 +247,15 @@ MAKE_PACK_FUNC_NAME (name) (gint32 *src, guint8 * dst, \ } \ } +/* pack from signed integer 32 to float using orc */ +#define MAKE_PACK_FUNC_ORC_IF(name, type, FUNC) \ +static void \ +MAKE_PACK_FUNC_NAME (name) (gint32 * src, type * dst, gint scale, \ + gint count) \ +{ \ + MAKE_PACK_FUNC_NAME_ORC (name) (dst, src, count); \ +} + /* pack from signed integer 32 to float */ #define MAKE_PACK_FUNC_IF(name, type, FUNC) \ static void \ @@ -309,8 +334,8 @@ MAKE_PACK_FUNC_ORC_II (u32_le, 4, SIGNED, WRITE32_TO_LE); MAKE_PACK_FUNC_ORC_II (s32_le, 4, 0, WRITE32_TO_LE); MAKE_PACK_FUNC_ORC_II (u32_be, 4, SIGNED, WRITE32_TO_BE); MAKE_PACK_FUNC_ORC_II (s32_be, 4, 0, WRITE32_TO_BE); -MAKE_PACK_FUNC_IF (float_le, gfloat, GFLOAT_TO_LE); -MAKE_PACK_FUNC_IF (float_be, gfloat, GFLOAT_TO_BE); +MAKE_PACK_FUNC_ORC_IF (float_le, gfloat, GFLOAT_TO_LE); +MAKE_PACK_FUNC_ORC_IF (float_be, gfloat, GFLOAT_TO_BE); MAKE_PACK_FUNC_IF (double_le, gdouble, GDOUBLE_TO_LE); MAKE_PACK_FUNC_IF (double_be, gdouble, GDOUBLE_TO_BE); MAKE_PACK_FUNC_FF (float_hq_le, gfloat, GFLOAT_TO_LE); diff --git a/gst/audioconvert/gstaudioconvertorc.orc b/gst/audioconvert/gstaudioconvertorc.orc index 4f8b2ff..a78718e 100644 --- a/gst/audioconvert/gstaudioconvertorc.orc +++ b/gst/audioconvert/gstaudioconvertorc.orc @@ -113,7 +113,51 @@ xorl d1, t1, c1 swapl t1, s1 shll d1, t1, p1 +.function orc_audio_convert_unpack_float_s32 +.source 4 s1 gfloat +.dest 4 d1 guint32 +.temp 4 t1 +.temp 4 t2 +.temp 4 t3 +.temp 4 t4 + +loadl t1, s1 +# multiply with 2147483647.0 +mulf t1, t1, 0x4F000000 +# add 0.5 for rounding +addf t1, t1, 0x3F000000 +convfl t2, t1 +# if overflow, t3 = ~0 +cmpeql t3, t2, -2147483648 +# if negative, t4 = ~0 +shrsl t4, t1, 31 +# if overflow and !negative, t4 = ~0 +andnl t4, t4, t3 +# 0x80000000 + ~0 = 0x7fffffff +addl d1, t2, t4 + +.function orc_audio_convert_unpack_float_s32_swap +.source 4 s1 gfloat +.dest 4 d1 guint32 +.temp 4 t1 +.temp 4 t2 +.temp 4 t3 +.temp 4 t4 +swapl t1, s1 +# multiply with 2147483647.0 +mulf t1, t1, 0x4F000000 +# add 0.5 for rounding +addf t1, t1, 0x3F000000 +convfl t2, t1 +# if overflow, t3 = ~0 +cmpeql t3, t2, -2147483648 +# if negative, t4 = ~0 +shrsl t4, t1, 31 +# if overflow and !negative, t4 = ~0 +andnl t4, t4, t3 +# 0x80000000 + ~0 = 0x7fffffff +addl d1, t2, t4 .function orc_audio_convert_pack_u8 .dest 1 d1 guint8 @@ -231,4 +275,23 @@ swapl d1, t1 shrsl t1, s1, p1 swapl d1, t1 +.function orc_audio_convert_pack_s32_float +.dest 4 d1 gfloat +.source 4 s1 gint32 +.temp 4 t1 + +convlf t1, s1 +# divide by 2147483647.0 +divf t1, t1, 0x4F000000 +storel d1, t1 + +.function orc_audio_convert_pack_s32_float_swap +.dest 4 d1 gfloat +.source 4 s1 gint32 +.temp 4 t1 + +convlf t1, s1 +# divide by 2147483647.0 +divf t1, t1, 0x4F000000 +swapl d1, t1 -- 2.7.4