mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
audioconvert: tweak conversion constants
Tweak the conversion constants a bit so that they handle the extreme ranges a bit better. Align the C and vector instructions. Reactivate the unit test asserts when a conversion fails.
This commit is contained in:
parent
e3951cc1f1
commit
22317da685
4 changed files with 237 additions and 227 deletions
|
|
@ -50,11 +50,11 @@ static void compare_mem(int i, int j, const void *m1, const void *m2, size_t siz
|
|||
{
|
||||
int res = memcmp(m1, m2, size);
|
||||
if (res != 0) {
|
||||
fprintf(stderr, "%d %d:\n", i, j);
|
||||
fprintf(stderr, "%d %d %zd:\n", i, j, size);
|
||||
spa_debug_mem(0, m1, size);
|
||||
spa_debug_mem(0, m2, size);
|
||||
}
|
||||
// spa_assert_se(res == 0);
|
||||
spa_assert_se(res == 0);
|
||||
}
|
||||
|
||||
static void run_test(const char *name,
|
||||
|
|
@ -158,7 +158,7 @@ static void test_u8_f32(void)
|
|||
static void test_f32_u16(void)
|
||||
{
|
||||
static const float in[] = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
|
||||
static const uint16_t out[] = { 32767, 65535, 0, 49150, 16383, 65535, 0 };
|
||||
static const uint16_t out[] = { 32768, 65535, 0, 49151, 16384, 65535, 0 };
|
||||
|
||||
run_test("test_f32_u16", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, true, conv_f32_to_u16_c);
|
||||
|
|
@ -168,8 +168,8 @@ static void test_f32_u16(void)
|
|||
|
||||
static void test_u16_f32(void)
|
||||
{
|
||||
static const uint16_t in[] = { 32767, 65535, 0, 49150, 16383, };
|
||||
static const float out[] = { 0.0f, 1.0f, -1.0f, 0.4999847412f, -0.4999847412f };
|
||||
static const uint16_t in[] = { 32768, 65535, 0, 49152, 16384, };
|
||||
static const float out[] = { 0.0f, 0.999969482422f, -1.0f, 0.5f, -0.5f };
|
||||
|
||||
run_test("test_u16_f32d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, false, conv_u16_to_f32d_c);
|
||||
|
|
@ -180,7 +180,7 @@ static void test_u16_f32(void)
|
|||
static void test_f32_s16(void)
|
||||
{
|
||||
static const float in[] = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
|
||||
static const int16_t out[] = { 0, 32767, -32767, 16383, -16383, 32767, -32767 };
|
||||
static const int16_t out[] = { 0, 32767, -32768, 16384, -16384, 32767, -32768 };
|
||||
|
||||
run_test("test_f32_s16", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, true, conv_f32_to_s16_c);
|
||||
|
|
@ -192,16 +192,26 @@ static void test_f32_s16(void)
|
|||
false, false, conv_f32d_to_s16d_c);
|
||||
#if defined(HAVE_SSE2)
|
||||
if (cpu_flags & SPA_CPU_FLAG_SSE2) {
|
||||
run_test("test_f32_s16_sse2", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, true, conv_f32_to_s16_sse2);
|
||||
run_test("test_f32d_s16_sse2", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
false, true, conv_f32d_to_s16_sse2);
|
||||
run_test("test_f32d_s16d_sse2", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
false, false, conv_f32d_to_s16d_sse2);
|
||||
}
|
||||
#endif
|
||||
#if defined(HAVE_AVX2)
|
||||
if (cpu_flags & SPA_CPU_FLAG_AVX2) {
|
||||
run_test("test_f32d_s16_avx2", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
false, true, conv_f32d_to_s16_avx2);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void test_s16_f32(void)
|
||||
{
|
||||
static const int16_t in[] = { 0, 32767, -32767, 16383, -16383, };
|
||||
static const float out[] = { 0.0f, 1.0f, -1.0f, 0.4999847412f, -0.4999847412f };
|
||||
static const int16_t in[] = { 0, 32767, -32768, 16384, -16384, };
|
||||
static const float out[] = { 0.0f, 0.999969482422f, -1.0f, 0.5f, -0.5f };
|
||||
|
||||
run_test("test_s16_f32d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, false, conv_s16_to_f32d_c);
|
||||
|
|
@ -217,13 +227,19 @@ static void test_s16_f32(void)
|
|||
true, false, conv_s16_to_f32d_sse2);
|
||||
}
|
||||
#endif
|
||||
#if defined(HAVE_AVX2)
|
||||
if (cpu_flags & SPA_CPU_FLAG_AVX2) {
|
||||
run_test("test_s16_f32d_avx2", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, false, conv_s16_to_f32d_avx2);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void test_f32_u32(void)
|
||||
{
|
||||
static const float in[] = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
|
||||
static const uint32_t out[] = { 0, 0x7fffff00, 0x80000100, 0x3fffff00, 0xc0000100,
|
||||
0x7fffff00, 0x80000100 };
|
||||
static const uint32_t out[] = { 0x80000000, 0xffffffff, 0x0, 0xc0000000, 0x40000000,
|
||||
0xffffffff, 0x0 };
|
||||
|
||||
run_test("test_f32_u32", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, true, conv_f32_to_u32_c);
|
||||
|
|
@ -233,8 +249,8 @@ static void test_f32_u32(void)
|
|||
|
||||
static void test_u32_f32(void)
|
||||
{
|
||||
static const uint32_t in[] = { 0, 0x7fffff00, 0x80000100, 0x3fffff00, 0xc0000100 };
|
||||
static const float out[] = { 0.0f, 1.0f, -1.0f, 0.4999999404f, -0.4999999404f, };
|
||||
static const uint32_t in[] = { 0x80000000, 0xffffffff, 0x0, 0xc0000000, 0x40000000 };
|
||||
static const float out[] = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, };
|
||||
|
||||
run_test("test_u32_f32d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, false, conv_u32_to_f32d_c);
|
||||
|
|
@ -245,8 +261,8 @@ static void test_u32_f32(void)
|
|||
static void test_f32_s32(void)
|
||||
{
|
||||
static const float in[] = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
|
||||
static const int32_t out[] = { 0, 0x7fffff00, 0x80000100, 0x3fffff00, 0xc0000100,
|
||||
0x7fffff00, 0x80000100 };
|
||||
static const int32_t out[] = { 0, 0x7fffff80, 0x80000000, 0x40000000, 0xc0000000,
|
||||
0x7fffff80, 0x80000000 };
|
||||
|
||||
run_test("test_f32_s32", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, true, conv_f32_to_s32_c);
|
||||
|
|
@ -262,12 +278,18 @@ static void test_f32_s32(void)
|
|||
false, true, conv_f32d_to_s32_sse2);
|
||||
}
|
||||
#endif
|
||||
#if defined(HAVE_AVX2)
|
||||
if (cpu_flags & SPA_CPU_FLAG_AVX2) {
|
||||
run_test("test_f32d_s32_avx2", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
false, true, conv_f32d_to_s32_avx2);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void test_s32_f32(void)
|
||||
{
|
||||
static const int32_t in[] = { 0, 0x7fffff00, 0x80000100, 0x3fffff00, 0xc0000100 };
|
||||
static const float out[] = { 0.0f, 1.0f, -1.0f, 0.4999999404f, -0.4999999404f, };
|
||||
static const int32_t in[] = { 0, 0x7fffff80, 0x80000000, 0x40000000, 0xc0000000 };
|
||||
static const float out[] = { 0.0f, 0.999999940395f, -1.0f, 0.5, -0.5, };
|
||||
|
||||
run_test("test_s32_f32d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, false, conv_s32_to_f32d_c);
|
||||
|
|
@ -283,18 +305,20 @@ static void test_s32_f32(void)
|
|||
true, false, conv_s32_to_f32d_sse2);
|
||||
}
|
||||
#endif
|
||||
#if defined(HAVE_AVX2)
|
||||
if (cpu_flags & SPA_CPU_FLAG_AVX2) {
|
||||
run_test("test_s32_f32d_avx2", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, false, conv_s32_to_f32d_avx2);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void test_f32_u24(void)
|
||||
{
|
||||
static const float in[] = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
static const uint8_t out[] = { 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x01, 0x00, 0x80,
|
||||
0xff, 0xff, 0x3f, 0x01, 0x00, 0xc0, 0xff, 0xff, 0x7f, 0x01, 0x00, 0x80 };
|
||||
#else
|
||||
static const uint8_t out[] = { 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0x80, 0x00, 0x01,
|
||||
0x3f, 0xff, 0xff, 0xc0, 0x00, 0x01, 0x7f, 0xff, 0xff, 0x80, 0x00, 0x01 };
|
||||
#endif
|
||||
static const uint24_t out[] = { U32_TO_U24(0x00800000), U32_TO_U24(0xffffff),
|
||||
U32_TO_U24(0x000000), U32_TO_U24(0xc00000), U32_TO_U24(0x400000),
|
||||
U32_TO_U24(0xffffff), U32_TO_U24(0x000000) };
|
||||
|
||||
run_test("test_f32_u24", in, sizeof(in[0]), out, 3, SPA_N_ELEMENTS(in),
|
||||
true, true, conv_f32_to_u24_c);
|
||||
|
|
@ -304,14 +328,9 @@ static void test_f32_u24(void)
|
|||
|
||||
static void test_u24_f32(void)
|
||||
{
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
static const uint8_t in[] = { 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x01, 0x00, 0x80,
|
||||
0xff, 0xff, 0x3f, 0x01, 0x00, 0xc0, };
|
||||
#else
|
||||
static const uint8_t in[] = { 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0x80, 0x00, 0x01,
|
||||
0x3f, 0xff, 0xff, 0xc0, 0x00, 0x01, };
|
||||
#endif
|
||||
static const float out[] = { 0.0f, 1.0f, -1.0f, 0.4999999404f, -0.4999999404f, };
|
||||
static const uint24_t in[] = { U32_TO_U24(0x00800000), U32_TO_U24(0xffffff),
|
||||
U32_TO_U24(0x000000), U32_TO_U24(0xc00000), U32_TO_U24(0x400000) };
|
||||
static const float out[] = { 0.0f, 0.999999880791f, -1.0f, 0.5, -0.5, };
|
||||
|
||||
run_test("test_u24_f32d", in, 3, out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, false, conv_u24_to_f32d_c);
|
||||
|
|
@ -322,13 +341,9 @@ static void test_u24_f32(void)
|
|||
static void test_f32_s24(void)
|
||||
{
|
||||
static const float in[] = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
static const uint8_t out[] = { 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x01, 0x00, 0x80,
|
||||
0xff, 0xff, 0x3f, 0x01, 0x00, 0xc0, 0xff, 0xff, 0x7f, 0x01, 0x00, 0x80 };
|
||||
#else
|
||||
static const uint8_t out[] = { 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0x80, 0x00, 0x01,
|
||||
0x3f, 0xff, 0xff, 0xc0, 0x00, 0x01, 0x7f, 0xff, 0xff, 0x80, 0x00, 0x01 };
|
||||
#endif
|
||||
static const int24_t out[] = { S32_TO_S24(0), S32_TO_S24(0x7fffff),
|
||||
S32_TO_S24(0xff800000), S32_TO_S24(0x400000), S32_TO_S24(0xc00000),
|
||||
S32_TO_S24(0x7fffff), S32_TO_S24(0xff800000) };
|
||||
|
||||
run_test("test_f32_s24", in, sizeof(in[0]), out, 3, SPA_N_ELEMENTS(in),
|
||||
true, true, conv_f32_to_s24_c);
|
||||
|
|
@ -342,14 +357,9 @@ static void test_f32_s24(void)
|
|||
|
||||
static void test_s24_f32(void)
|
||||
{
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
static const uint8_t in[] = { 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x01, 0x00, 0x80,
|
||||
0xff, 0xff, 0x3f, 0x01, 0x00, 0xc0, };
|
||||
#else
|
||||
static const uint8_t in[] = { 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0x80, 0x00, 0x01,
|
||||
0x3f, 0xff, 0xff, 0xc0, 0x00, 0x01, };
|
||||
#endif
|
||||
static const float out[] = { 0.0f, 1.0f, -1.0f, 0.4999999404f, -0.4999999404f, };
|
||||
static const int24_t in[] = { S32_TO_S24(0), S32_TO_S24(0x7fffff),
|
||||
S32_TO_S24(0xff800000), S32_TO_S24(0x400000), S32_TO_S24(0xc00000) };
|
||||
static const float out[] = { 0.0f, 0.999999880791f, -1.0f, 0.5f, -0.5f, };
|
||||
|
||||
run_test("test_s24_f32d", in, 3, out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, false, conv_s24_to_f32d_c);
|
||||
|
|
@ -377,13 +387,19 @@ static void test_s24_f32(void)
|
|||
true, false, conv_s24_to_f32d_sse41);
|
||||
}
|
||||
#endif
|
||||
#if defined(HAVE_AVX2)
|
||||
if (cpu_flags & SPA_CPU_FLAG_AVX2) {
|
||||
run_test("test_s24_f32d_avx2", in, 3, out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, false, conv_s24_to_f32d_avx2);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void test_f32_u24_32(void)
|
||||
{
|
||||
static const float in[] = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
|
||||
static const uint32_t out[] = { 0, 0x7fffff, 0xff800001, 0x3fffff, 0xffc00001,
|
||||
0x7fffff, 0xff800001 };
|
||||
static const uint32_t out[] = { 0x800000, 0xffffff, 0x0, 0xc00000, 0x400000,
|
||||
0xffffff, 0x000000 };
|
||||
|
||||
run_test("test_f32_u24_32", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, true, conv_f32_to_u24_32_c);
|
||||
|
|
@ -393,8 +409,8 @@ static void test_f32_u24_32(void)
|
|||
|
||||
static void test_u24_32_f32(void)
|
||||
{
|
||||
static const uint32_t in[] = { 0, 0x7fffff, 0xff800001, 0x3fffff, 0xffc00001 };
|
||||
static const float out[] = { 0.0f, 1.0f, -1.0f, 0.4999999404f, -0.4999999404f, };
|
||||
static const uint32_t in[] = { 0x800000, 0xffffff, 0x0, 0xc00000, 0x400000 };
|
||||
static const float out[] = { 0.0f, 0.999999880791f, -1.0f, 0.5f, -0.5f, };
|
||||
|
||||
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);
|
||||
|
|
@ -405,8 +421,8 @@ static void test_u24_32_f32(void)
|
|||
static void test_f32_s24_32(void)
|
||||
{
|
||||
static const float in[] = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
|
||||
static const int32_t out[] = { 0, 0x7fffff, 0xff800001, 0x3fffff, 0xffc00001,
|
||||
0x7fffff, 0xff800001 };
|
||||
static const int32_t out[] = { 0, 0x7fffff, 0xff800000, 0x400000, 0xffc00000,
|
||||
0x7fffff, 0xff800000 };
|
||||
|
||||
run_test("test_f32_s24_32", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, true, conv_f32_to_s24_32_c);
|
||||
|
|
@ -420,8 +436,8 @@ static void test_f32_s24_32(void)
|
|||
|
||||
static void test_s24_32_f32(void)
|
||||
{
|
||||
static const int32_t in[] = { 0, 0x7fffff, 0xff800001, 0x3fffff, 0xffc00001 };
|
||||
static const float out[] = { 0.0f, 1.0f, -1.0f, 0.4999999404f, -0.4999999404f, };
|
||||
static const int32_t in[] = { 0, 0x7fffff, 0xff800000, 0x400000, 0xffc00000 };
|
||||
static const float out[] = { 0.0f, 0.999999880791f, -1.0f, 0.5f, -0.5f, };
|
||||
|
||||
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);
|
||||
|
|
@ -435,8 +451,8 @@ static void test_s24_32_f32(void)
|
|||
|
||||
static void test_f64_f32(void)
|
||||
{
|
||||
static const double in[] = { 0.0, 1.0, -1.0, 0.4999999404, -0.4999999404, };
|
||||
static const float out[] = { 0.0f, 1.0f, -1.0f, 0.4999999404f, -0.4999999404f, };
|
||||
static const double in[] = { 0.0, 1.0, -1.0, 0.5, -0.5, };
|
||||
static const float out[] = { 0.0, 1.0, -1.0, 0.5, -0.5, };
|
||||
|
||||
run_test("test_f64_f32d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, false, conv_f64_to_f32d_c);
|
||||
|
|
@ -451,7 +467,7 @@ static void test_f64_f32(void)
|
|||
static void test_f32_f64(void)
|
||||
{
|
||||
static const float in[] = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
|
||||
static const double out[] = { 0.0, 1.0, -1.0, 0.5, -0.5, 1.1, -1.1 };
|
||||
static const double out[] = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
|
||||
|
||||
run_test("test_f32_f64", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, true, conv_f32_to_f64_c);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue