mirror of
https://gitlab.freedesktop.org/pipewire/pipewire
synced 2024-11-05 16:26:16 +00:00
audiconvert: make macros for conversions
Make a common macro for float to int and int to float so that we can change the algorithms easily.
This commit is contained in:
parent
117fb6d697
commit
d18428f8bb
1 changed files with 38 additions and 31 deletions
|
@ -35,87 +35,94 @@
|
|||
#include <spa/utils/defs.h>
|
||||
#include <spa/utils/string.h>
|
||||
|
||||
#define ROUND(v) (v)
|
||||
|
||||
#define ITOF(type,v,scale,offs) \
|
||||
(((type)(v)) * (1.0f / (scale)) - (offs))
|
||||
#define FTOI(type,v,scale,offs,dither,min,max) \
|
||||
(type)ROUND(SPA_CLAMP((v) * (scale) + (offs) + (dither), min, max))
|
||||
|
||||
#define FMT_OPS_MAX_ALIGN 32
|
||||
|
||||
#define U8_MIN 0u
|
||||
#define U8_MAX 255u
|
||||
#define U8_SCALE 128.f
|
||||
#define U8_OFFS 128.f
|
||||
#define U8_TO_F32(v) ((((uint8_t)(v)) * (1.0f / U8_SCALE)) - 1.0f)
|
||||
#define F32_TO_U8(v) (uint8_t)SPA_CLAMP((v) * U8_SCALE + U8_OFFS, U8_MIN, U8_MAX)
|
||||
#define F32_TO_U8_D(v,d) (uint8_t)SPA_CLAMP((v) * U8_SCALE + U8_OFFS + (d), U8_MIN, U8_MAX)
|
||||
#define U8_TO_F32(v) ITOF(uint8_t, v, U8_SCALE, 1.0f)
|
||||
#define F32_TO_U8_D(v,d) FTOI(uint8_t, v, U8_SCALE, U8_OFFS, d, U8_MIN, U8_MAX)
|
||||
#define F32_TO_U8(v) F32_TO_U8_D(v, 0.0f)
|
||||
|
||||
#define S8_MIN -128
|
||||
#define S8_MAX 127
|
||||
#define S8_SCALE 128.0f
|
||||
#define S8_TO_F32(v) (((int8_t)(v)) * (1.0f / S8_SCALE))
|
||||
#define F32_TO_S8(v) (int8_t)SPA_CLAMP((v) * S8_SCALE, S8_MIN, S8_MAX)
|
||||
#define F32_TO_S8_D(v,d) (int8_t)SPA_CLAMP((v) * S8_SCALE + (d), S8_MIN, S8_MAX)
|
||||
#define S8_TO_F32(v) ITOF(int8_t, v, S8_SCALE, 0.0f)
|
||||
#define F32_TO_S8_D(v,d) FTOI(int8_t, v, S8_SCALE, 0.0f, d, S8_MIN, S8_MAX)
|
||||
#define F32_TO_S8(v) F32_TO_S8_D(v, 0.0f);
|
||||
|
||||
#define U16_MIN 0u
|
||||
#define U16_MAX 65535u
|
||||
#define U16_SCALE 32768.f
|
||||
#define U16_OFFS 32768.f
|
||||
#define U16_TO_F32(v) ((((uint16_t)(v)) * (1.0f / U16_SCALE)) - 1.0f)
|
||||
#define U16S_TO_F32(v) (((uint16_t)bswap_16((uint16_t)(v)) * (1.0f / U16_OFFS)) - 1.0f)
|
||||
#define F32_TO_U16(v) (uint16_t)SPA_CLAMP((v) * U16_SCALE + U16_OFFS, U16_MIN, U16_MAX)
|
||||
#define F32_TO_U16_D(v,d) (uint16_t)SPA_CLAMP((v) * U16_SCALE + U16_OFFS + (d), U16_MIN, U16_MAX)
|
||||
#define F32_TO_U16S(v) bswap_16(F32_TO_U16(v))
|
||||
#define U16_TO_F32(v) ITOF(uint16_t, v, U16_SCALE, 1.0f)
|
||||
#define U16S_TO_F32(v) U16_TO_F32(bswap_16(v))
|
||||
#define F32_TO_U16_D(v,d) FTOI(uint16_t, v, U16_SCALE, U16_OFFS, d, U16_MIN, U16_MAX)
|
||||
#define F32_TO_U16(v) F32_TO_U16_D(v, 0.0f);
|
||||
#define F32_TO_U16S_D(v,d) bswap_16(F32_TO_U16_D(v,d))
|
||||
#define F32_TO_U16S(v) bswap_16(F32_TO_U16(v))
|
||||
|
||||
#define S16_MIN -32768
|
||||
#define S16_MAX 32767
|
||||
#define S16_SCALE 32768.0f
|
||||
#define S16_TO_F32(v) (((int16_t)(v)) * (1.0f / S16_SCALE))
|
||||
#define S16S_TO_F32(v) (((int16_t)bswap_16(v)) * (1.0f / S16_SCALE))
|
||||
#define F32_TO_S16(v) (int16_t)SPA_CLAMP((v) * S16_SCALE, S16_MIN, S16_MAX)
|
||||
#define F32_TO_S16_D(v,d) (int16_t)SPA_CLAMP((v) * S16_SCALE + (d), S16_MIN, S16_MAX)
|
||||
#define F32_TO_S16S(v) bswap_16(F32_TO_S16(v))
|
||||
#define S16_TO_F32(v) ITOF(int16_t, v, S16_SCALE, 0.0f)
|
||||
#define S16S_TO_F32(v) S16_TO_F32(bswap_16(v))
|
||||
#define F32_TO_S16_D(v,d) FTOI(int16_t, v, S16_SCALE, 0.0f, d, S16_MIN, S16_MAX)
|
||||
#define F32_TO_S16(v) F32_TO_S16_D(v, 0.0f)
|
||||
#define F32_TO_S16S_D(v,d) bswap_16(F32_TO_S16_D(v,d))
|
||||
#define F32_TO_S16S(v) bswap_16(F32_TO_S16(v))
|
||||
|
||||
#define U24_MIN 0u
|
||||
#define U24_MAX 16777215u
|
||||
#define U24_SCALE 8388608.f
|
||||
#define U24_OFFS 8388608.f
|
||||
#define U24_TO_F32(v) ((u24_to_u32(v) * (1.0f / U24_SCALE)) - 1.0f)
|
||||
#define F32_TO_U24(v) u32_to_u24(SPA_CLAMP((v) * U24_SCALE + U24_OFFS, U24_MIN, U24_MAX))
|
||||
#define F32_TO_U24_D(v,d) u32_to_u24(SPA_CLAMP((v) * U24_SCALE + U24_OFFS + (d), U24_MIN, U24_MAX))
|
||||
#define U24_TO_F32(v) ITOF(uint32_t, u24_to_u32(v), U24_SCALE, 1.0f)
|
||||
#define F32_TO_U24_D(v,d) u32_to_u24(FTOI(uint32_t, v, U24_SCALE, U24_OFFS, d, U24_MIN, U24_MAX))
|
||||
#define F32_TO_U24(v) F32_TO_U24_D(v, 0.0f)
|
||||
|
||||
#define S24_MIN -8388608
|
||||
#define S24_MAX 8388607
|
||||
#define S24_SCALE 8388608.0f
|
||||
#define S24_TO_F32(v) (s24_to_s32(v) * (1.0f / S24_SCALE))
|
||||
#define S24S_TO_F32(v) (s24_to_s32(bswap_s24(v)) * (1.0f / S24_SCALE))
|
||||
#define F32_TO_S24(v) s32_to_s24(SPA_CLAMP((v) * S24_SCALE, S24_MIN, S24_MAX))
|
||||
#define S24_TO_F32(v) ITOF(int32_t, s24_to_s32(v), S24_SCALE, 0.0f)
|
||||
#define S24S_TO_F32(v) S24_TO_F32(bswap_s24(v))
|
||||
#define F32_TO_S24_D(v,d) s32_to_s24(FTOI(int32_t, v, S24_SCALE, 0.0f, d, S24_MIN, S24_MAX))
|
||||
#define F32_TO_S24(v) F32_TO_S24_D(v, 0.0f)
|
||||
#define F32_TO_S24S(v) bswap_s24(F32_TO_S24(v))
|
||||
#define F32_TO_S24_D(v,d) s32_to_s24(SPA_CLAMP((v) * S24_SCALE + (d), S24_MIN, S24_MAX))
|
||||
|
||||
#define U24_32_TO_F32(v) U32_TO_F32((v)<<8)
|
||||
#define U24_32S_TO_F32(v) U24_32_TO_F32(((uint32_t)bswap_32(v)))
|
||||
#define F32_TO_U24_32(v) (uint32_t)SPA_CLAMP((v) * U24_SCALE + U24_OFFS, U24_MIN, U24_MAX)
|
||||
#define U24_32S_TO_F32(v) U24_32_TO_F32(bswap_32(v))
|
||||
#define F32_TO_U24_32_D(v,d) FTOI(uint32_t, v, U24_SCALE, U24_OFFS, d, U24_MIN, U24_MAX)
|
||||
#define F32_TO_U24_32(v) F32_TO_U24_32_D(v, 0.0f)
|
||||
#define F32_TO_U24_32S(v) bswap_32(F32_TO_U24_32(v))
|
||||
#define F32_TO_U24_32_D(v,d) (uint32_t)SPA_CLAMP((v) * U24_SCALE + U24_OFFS + (d), U24_MIN, U24_MAX)
|
||||
#define F32_TO_U24_32S_D(v,d) bswap_32(F32_TO_U24_32_D(v,d))
|
||||
|
||||
#define U32_MIN 0u
|
||||
#define U32_MAX 4294967295u
|
||||
#define U32_SCALE 2147483648.f
|
||||
#define U32_OFFS 2147483648.f
|
||||
#define U32_TO_F32(v) (((((uint32_t)(v)) >> 8) * (1.0f / U24_SCALE)) - 1.0f)
|
||||
#define U32_TO_F32(v) ITOF(uint32_t, (v) >> 8, U24_SCALE, 1.0f)
|
||||
#define F32_TO_U32(v) (F32_TO_U24_32(v) << 8)
|
||||
#define F32_TO_U32_D(v,d) (F32_TO_U24_32_D(v,d) << 8)
|
||||
|
||||
#define S24_32_TO_F32(v) S32_TO_F32((v)<<8)
|
||||
#define S24_32S_TO_F32(v) S24_32_TO_F32(((int32_t)bswap_32(v)))
|
||||
#define F32_TO_S24_32(v) (int32_t)SPA_CLAMP((v) * S24_SCALE, S24_MIN, S24_MAX)
|
||||
#define S24_32S_TO_F32(v) S24_32_TO_F32(bswap_32(v))
|
||||
#define F32_TO_S24_32_D(v,d) FTOI(int32_t, v, S24_SCALE, 0.0f, d, S24_MIN, S24_MAX)
|
||||
#define F32_TO_S24_32(v) F32_TO_S24_32_D(v, 0.0f)
|
||||
#define F32_TO_S24_32S(v) bswap_32(F32_TO_S24_32(v))
|
||||
#define F32_TO_S24_32_D(v,d) (int32_t)SPA_CLAMP((v) * S24_SCALE + (d), S24_MIN, S24_MAX)
|
||||
#define F32_TO_S24_32S_D(v,d) bswap_32(F32_TO_S24_32_D(v,d))
|
||||
|
||||
#define S32_MIN -2147483648
|
||||
#define S32_MAX 2147483647
|
||||
#define S32_SCALE 2147483648.f
|
||||
#define S32_TO_F32(v) ((((int32_t)(v)) >> 8) * (1.0f / S24_SCALE))
|
||||
#define S32_TO_F32(v) ITOF(int32_t, (v) >> 8, S24_SCALE, 0.0f)
|
||||
#define S32S_TO_F32(v) S32_TO_F32(bswap_32(v))
|
||||
#define F32_TO_S32(v) (F32_TO_S24_32(v) << 8)
|
||||
#define F32_TO_S32_D(v,d) (F32_TO_S24_32_D(v,d) << 8)
|
||||
|
|
Loading…
Reference in a new issue