diff --git a/spa/plugins/audioconvert/fmt-ops.h b/spa/plugins/audioconvert/fmt-ops.h index 4d6d74e47..9d40c9d29 100644 --- a/spa/plugins/audioconvert/fmt-ops.h +++ b/spa/plugins/audioconvert/fmt-ops.h @@ -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) diff --git a/spa/plugins/audioconvert/test-fmt-ops.c b/spa/plugins/audioconvert/test-fmt-ops.c index da0a054b1..7236b994e 100644 --- a/spa/plugins/audioconvert/test-fmt-ops.c +++ b/spa/plugins/audioconvert/test-fmt-ops.c @@ -439,8 +439,8 @@ static void test_f32_u24_32(void) static void test_u24_32_f32(void) { - static const uint32_t in[] = { 0x800000, 0xffffff, 0x0, 0xc00000, 0x400000 }; - static const float out[] = { 0.0f, 0.999999880791f, -1.0f, 0.5f, -0.5f, }; + static const uint32_t in[] = { 0x800000, 0xffffff, 0x0, 0xc00000, 0x400000, 0x11000000 }; + static const float out[] = { 0.0f, 0.999999880791f, -1.0f, 0.5f, -0.5f, -1.0f }; run_test("test_u24_32_f32d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out), true, false, conv_u24_32_to_f32d_c); @@ -466,8 +466,8 @@ static void test_f32_s24_32(void) static void test_s24_32_f32(void) { - static const int32_t in[] = { 0, 0x7fffff, 0xff800000, 0x400000, 0xffc00000 }; - static const float out[] = { 0.0f, 0.999999880791f, -1.0f, 0.5f, -0.5f, }; + static const int32_t in[] = { 0, 0x7fffff, 0xff800000, 0x400000, 0xffc00000, 0x66800000 }; + static const float out[] = { 0.0f, 0.999999880791f, -1.0f, 0.5f, -0.5f, -1.0f }; run_test("test_s24_32_f32d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out), true, false, conv_s24_32_to_f32d_c);