audioconvert: improve s24_32 and u24_32 conversion

We should ignore the upper 8 bits, so first shift them out and then
use the s32/u32 conversion functions.
Add a test for this.
This commit is contained in:
Wim Taymans 2022-07-09 18:07:49 +02:00
parent 20172bfbe6
commit 3ffb9f4b26
2 changed files with 8 additions and 8 deletions

View file

@ -90,7 +90,7 @@
#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) ((((uint32_t)(v)) * (1.0f / U24_SCALE)) - 1.0f)
#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 F32_TO_U24_32S(v) bswap_32(F32_TO_U24_32(v))
@ -101,11 +101,11 @@
#define U32_MAX 4294967295u
#define U32_SCALE 2147483648.f
#define U32_OFFS 2147483648.f
#define U32_TO_F32(v) U24_32_TO_F32((v) >> 8)
#define U32_TO_F32(v) (((((uint32_t)(v)) >> 8) * (1.0f / 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) (((int32_t)(v)) * (1.0f / S24_SCALE))
#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 F32_TO_S24_32S(v) bswap_32(F32_TO_S24_32(v))
@ -115,7 +115,7 @@
#define S32_MIN -2147483648
#define S32_MAX 2147483647
#define S32_SCALE 2147483648.f
#define S32_TO_F32(v) S24_32_TO_F32((v) >> 8)
#define S32_TO_F32(v) ((((int32_t)(v)) >> 8) * (1.0f / S24_SCALE))
#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)