mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
audioconvert: add unit test for format conversion
Add unit test for fmt conversion and fix some bugs Add empty fmt-ops benchmark
This commit is contained in:
parent
a1d45d2b25
commit
6f586602af
6 changed files with 362 additions and 47 deletions
37
spa/plugins/audioconvert/benchmark-fmt-ops.c
Normal file
37
spa/plugins/audioconvert/benchmark-fmt-ops.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* Spa
|
||||
*
|
||||
* Copyright © 2019 Wim Taymans
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "fmt-ops.c"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -147,7 +147,7 @@ conv_s24_to_f32d_1_sse2(void *data, int n_dst, void *dst[n_dst], const void *src
|
|||
s += 12 * n_dst;
|
||||
}
|
||||
for(; n_samples--; n++) {
|
||||
out = _mm_cvtsi32_ss(out, READ24(s));
|
||||
out = _mm_cvtsi32_ss(out, read_s24(s));
|
||||
out = _mm_mul_ss(out, factor);
|
||||
_mm_store_ss(&d0[n], out);
|
||||
s += 3 * n_dst;
|
||||
|
|
|
|||
|
|
@ -24,28 +24,36 @@
|
|||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <spa/support/cpu.h>
|
||||
#include <spa/utils/defs.h>
|
||||
#include <spa/param/audio/format-utils.h>
|
||||
|
||||
#define U8_MIN 0
|
||||
#define U8_MAX 255
|
||||
#define U8_SCALE 127
|
||||
#define U8_SCALE 127.5f
|
||||
#define U8_OFFS 128
|
||||
#define U8_TO_F32(v) ((((uint8_t)(v)) * (1.0f / U8_OFFS)) - 1.0)
|
||||
#define F32_TO_U8(v) (uint8_t)((SPA_CLAMP(v, -1.0f, 1.0f) * U8_SCALE) + U8_OFFS)
|
||||
|
||||
#define S16_MIN -32767
|
||||
#define S16_MAX 32767
|
||||
#define S16_MAX_F 32767.0f
|
||||
#define S16_SCALE 32767
|
||||
#define S16_SCALE 32767.0f
|
||||
#define S16_TO_F32(v) (((int16_t)(v)) * (1.0f / S16_SCALE))
|
||||
#define F32_TO_S16(v) (int16_t)(SPA_CLAMP(v, -1.0f, 1.0f) * S16_SCALE)
|
||||
|
||||
#define S24_MIN -8388607
|
||||
#define S24_MAX 8388607
|
||||
#define S24_MAX_F 8388607.0f
|
||||
#define S24_SCALE 8388607
|
||||
#define S24_SCALE 8388607.0f
|
||||
#define S24_TO_F32(v) (((int32_t)(v)) * (1.0f / S24_SCALE))
|
||||
#define F32_TO_S24(v) (int32_t)(SPA_CLAMP(v, -1.0f, 1.0f) * S24_SCALE)
|
||||
|
||||
#define S32_MIN -2147483647
|
||||
#define S32_MAX 2147483647
|
||||
#define S32_SCALE 2147483647
|
||||
|
||||
#define S32_TO_F32(v) S24_TO_F32((v) >> 8)
|
||||
#define F32_TO_S32(v) (F32_TO_S24(v) << 8)
|
||||
|
||||
|
||||
static inline int32_t read_s24(const void *src)
|
||||
|
|
@ -58,7 +66,19 @@ static inline int32_t read_s24(const void *src)
|
|||
#endif
|
||||
}
|
||||
|
||||
#define READ24(s) read_s24(s)
|
||||
static inline void write_s24(void *dst, int32_t val)
|
||||
{
|
||||
uint8_t *d = dst;
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
d[0] = (uint8_t) (val);
|
||||
d[1] = (uint8_t) (val >> 8);
|
||||
d[2] = (uint8_t) (val >> 16);
|
||||
#else
|
||||
d[0] = (uint8_t) (val >> 16);
|
||||
d[1] = (uint8_t) (val >> 8);
|
||||
d[2] = (uint8_t) (val);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined (__SSE2__)
|
||||
#include "fmt-ops-sse2.c"
|
||||
|
|
@ -96,8 +116,6 @@ conv_copy32(void *data, int n_dst, void *dst[n_dst], int n_src, const void *src[
|
|||
memcpy(dst[i], src[i], n_samples * sizeof(int32_t));
|
||||
}
|
||||
|
||||
#define U8_TO_F32(v) (((v) * (1.0f / U8_OFFS)) - 1.0)
|
||||
|
||||
static void
|
||||
conv_u8_to_f32(void *data, int n_dst, void *dst[n_dst], int n_src, const void *src[n_src], int n_samples)
|
||||
{
|
||||
|
|
@ -138,8 +156,6 @@ conv_u8d_to_f32(void *data, int n_dst, void *dst[n_dst], int n_src, const void *
|
|||
}
|
||||
}
|
||||
|
||||
#define S16_TO_F32(v) ((v) * (1.0f / S16_SCALE))
|
||||
|
||||
static void
|
||||
conv_s16_to_f32(void *data, int n_dst, void *dst[n_dst], int n_src, const void *src[n_src], int n_samples)
|
||||
{
|
||||
|
|
@ -179,8 +195,6 @@ conv_s16d_to_f32(void *data, int n_dst, void *dst[n_dst], int n_src, const void
|
|||
}
|
||||
}
|
||||
|
||||
#define S32_TO_F32(v) ((v) * (1.0f / S32_SCALE))
|
||||
|
||||
static void
|
||||
conv_s32_to_f32(void *data, int n_dst, void *dst[n_dst], int n_src, const void *src[n_src], int n_samples)
|
||||
{
|
||||
|
|
@ -222,8 +236,6 @@ conv_s32d_to_f32(void *data, int n_dst, void *dst[n_dst], int n_src, const void
|
|||
}
|
||||
|
||||
|
||||
#define S24_TO_F32(v) (((int32_t)(v)) * (1.0f / S24_SCALE))
|
||||
|
||||
static void
|
||||
conv_s24_to_f32(void *data, int n_dst, void *dst[n_dst], int n_src, const void *src[n_src], int n_samples)
|
||||
{
|
||||
|
|
@ -234,7 +246,7 @@ conv_s24_to_f32(void *data, int n_dst, void *dst[n_dst], int n_src, const void *
|
|||
float *d = dst[i];
|
||||
|
||||
for (j = 0; j < n_samples; j++) {
|
||||
d[j] = S24_TO_F32(READ24(s));
|
||||
d[j] = S24_TO_F32(read_s24(s));
|
||||
s += 3;
|
||||
}
|
||||
}
|
||||
|
|
@ -249,7 +261,7 @@ conv_s24_to_f32d(void *data, int n_dst, void *dst[n_dst], int n_src, const void
|
|||
|
||||
for (j = 0; j < n_samples; j++) {
|
||||
for (i = 0; i < n_dst; i++) {
|
||||
d[i][j] = S24_TO_F32(READ24(s));
|
||||
d[i][j] = S24_TO_F32(read_s24(s));
|
||||
s += 3;
|
||||
}
|
||||
}
|
||||
|
|
@ -264,8 +276,7 @@ conv_s24d_to_f32(void *data, int n_dst, void *dst[n_dst], int n_src, const void
|
|||
|
||||
for (j = 0; j < n_samples; j++) {
|
||||
for (i = 0; i < n_src; i++) {
|
||||
*d++ = S24_TO_F32(READ24(s[i]));
|
||||
s += 3;
|
||||
*d++ = S24_TO_F32(read_s24(&s[i][j*3]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -310,8 +321,6 @@ conv_s24_32d_to_f32(void *data, int n_dst, void *dst[n_dst], int n_src, const vo
|
|||
}
|
||||
}
|
||||
|
||||
#define F32_TO_U8(v) ((SPA_CLAMP(v, -1.0f, 1.0f) * U8_SCALE) + U8_OFFS)
|
||||
|
||||
static void
|
||||
conv_f32_to_u8(void *data, int n_dst, void *dst[n_dst], int n_src, const void *src[n_src], int n_samples)
|
||||
{
|
||||
|
|
@ -352,8 +361,6 @@ conv_f32d_to_u8(void *data, int n_dst, void *dst[n_dst], int n_src, const void *
|
|||
}
|
||||
}
|
||||
|
||||
#define F32_TO_S16(v) (SPA_CLAMP(v, -1.0f, 1.0f) * S16_SCALE)
|
||||
|
||||
static void
|
||||
conv_f32_to_s16(void *data, int n_dst, void *dst[n_dst], int n_src, const void *src[n_src], int n_samples)
|
||||
{
|
||||
|
|
@ -394,8 +401,6 @@ conv_f32d_to_s16(void *data, int n_dst, void *dst[n_dst], int n_src, const void
|
|||
}
|
||||
}
|
||||
|
||||
#define F32_TO_S32(v) (SPA_CLAMP(v, -1.0f, 1.0f) * S32_SCALE)
|
||||
|
||||
static void
|
||||
conv_f32_to_s32(void *data, int n_dst, void *dst[n_dst], int n_src, const void *src[n_src], int n_samples)
|
||||
{
|
||||
|
|
@ -437,15 +442,6 @@ conv_f32d_to_s32(void *data, int n_dst, void *dst[n_dst], int n_src, const void
|
|||
}
|
||||
|
||||
|
||||
#define F32_TO_S24(v) (SPA_CLAMP(v, -1.0f, 1.0f) * S24_SCALE)
|
||||
|
||||
#define WRITE24(d,v) \
|
||||
({ \
|
||||
int32_t _v = (v); \
|
||||
d[0] = (uint8_t) (_v >> 16); \
|
||||
d[1] = (uint8_t) (_v >> 8); \
|
||||
d[2] = (uint8_t) _v; \
|
||||
})
|
||||
|
||||
static void
|
||||
conv_f32_to_s24(void *data, int n_dst, void *dst[n_dst], int n_src, const void *src[n_src], int n_samples)
|
||||
|
|
@ -456,9 +452,10 @@ conv_f32_to_s24(void *data, int n_dst, void *dst[n_dst], int n_src, const void *
|
|||
const float *s = src[i];
|
||||
uint8_t *d = dst[i];
|
||||
|
||||
for (j = 0; j < n_samples; j++)
|
||||
WRITE24(d, F32_TO_S24(s[j]));
|
||||
for (j = 0; j < n_samples; j++) {
|
||||
write_s24(d, F32_TO_S24(s[j]));
|
||||
d += 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -471,8 +468,7 @@ conv_f32_to_s24d(void *data, int n_dst, void *dst[n_dst], int n_src, const void
|
|||
|
||||
for (j = 0; j < n_samples; j++) {
|
||||
for (i = 0; i < n_dst; i++) {
|
||||
WRITE24(d[i], F32_TO_S24(*s++));
|
||||
d[i] += 3;
|
||||
write_s24(&d[i][j*3], F32_TO_S24(*s++));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -486,7 +482,7 @@ conv_f32d_to_s24(void *data, int n_dst, void *dst[n_dst], int n_src, const void
|
|||
|
||||
for (j = 0; j < n_samples; j++) {
|
||||
for (i = 0; i < n_src; i++) {
|
||||
WRITE24(d, F32_TO_S24(s[i][j]));
|
||||
write_s24(d, F32_TO_S24(s[i][j]));
|
||||
d += 3;
|
||||
}
|
||||
}
|
||||
|
|
@ -568,8 +564,7 @@ deinterleave_24(void *data, int n_dst, void *dst[n_dst], int n_src, const void *
|
|||
|
||||
for (j = 0; j < n_samples; j++) {
|
||||
for (i = 0; i < n_dst; i++) {
|
||||
WRITE24(d[i], READ24(s));
|
||||
d += 3;
|
||||
write_s24(&d[i][j*3], read_s24(s));
|
||||
s += 3;
|
||||
}
|
||||
}
|
||||
|
|
@ -623,9 +618,8 @@ interleave_24(void *data, int n_dst, void *dst[n_dst], int n_src, const void *sr
|
|||
|
||||
for (j = 0; j < n_samples; j++) {
|
||||
for (i = 0; i < n_src; i++) {
|
||||
WRITE24(d, READ24(s[i]));
|
||||
write_s24(d, read_s24(&s[i][j*3]));
|
||||
d += 3;
|
||||
s += 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,38 @@ audioconvert_sources = ['fmtconvert.c',
|
|||
audioconvertlib = shared_library('spa-audioconvert',
|
||||
audioconvert_sources,
|
||||
include_directories : [spa_inc],
|
||||
dependencies : speexdsp_dep,
|
||||
dependencies : [ speexdsp_dep, mathlib ],
|
||||
install : true,
|
||||
install_dir : '@0@/spa/audioconvert/'.format(get_option('libdir')))
|
||||
|
||||
test_apps = [
|
||||
'test-fmt-ops',
|
||||
]
|
||||
|
||||
foreach a : test_apps
|
||||
test(a,
|
||||
executable(a, a + '.c',
|
||||
dependencies : [dl_lib, pthread_lib, mathlib ],
|
||||
include_directories : [spa_inc ],
|
||||
c_args : [ '-D_GNU_SOURCE' ],
|
||||
install : false),
|
||||
env : [
|
||||
'SPA_PLUGIN_DIR=@0@/spa/plugins/'.format(meson.build_root()),
|
||||
])
|
||||
endforeach
|
||||
|
||||
benchmark_apps = [
|
||||
'benchmark-fmt-ops',
|
||||
]
|
||||
|
||||
foreach a : benchmark_apps
|
||||
benchmark(a,
|
||||
executable(a, a + '.c',
|
||||
dependencies : [dl_lib, pthread_lib, mathlib ],
|
||||
include_directories : [spa_inc ],
|
||||
c_args : [ '-D_GNU_SOURCE' ],
|
||||
install : false),
|
||||
env : [
|
||||
'SPA_PLUGIN_DIR=@0@/spa/plugins/'.format(meson.build_root()),
|
||||
])
|
||||
endforeach
|
||||
|
|
|
|||
252
spa/plugins/audioconvert/test-fmt-ops.c
Normal file
252
spa/plugins/audioconvert/test-fmt-ops.c
Normal file
|
|
@ -0,0 +1,252 @@
|
|||
/* Spa
|
||||
*
|
||||
* Copyright © 2019 Wim Taymans
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <spa/debug/mem.h>
|
||||
|
||||
#include "fmt-ops.c"
|
||||
|
||||
#define N_SAMPLES 29
|
||||
#define N_CHANNELS 11
|
||||
|
||||
static uint8_t samp_in[N_SAMPLES * 4];
|
||||
static uint8_t samp_out[N_SAMPLES * 4];
|
||||
static uint8_t temp_in[N_SAMPLES * N_CHANNELS * 4];
|
||||
static uint8_t temp_out[N_SAMPLES * N_CHANNELS * 4];
|
||||
|
||||
static void run_test(const char *name,
|
||||
const void *in, size_t in_size, const void *out, size_t out_size, size_t n_samples,
|
||||
bool in_packed, bool out_packed, convert_func_t func)
|
||||
{
|
||||
const void *ip[N_CHANNELS];
|
||||
void *tp[N_CHANNELS];
|
||||
int i, j, ic, oc, ns;
|
||||
const uint8_t *in8 = in, *out8 = out;
|
||||
|
||||
for (j = 0; j < N_SAMPLES; j++) {
|
||||
memcpy(&samp_in[j * in_size], &in8[(j % n_samples) * in_size], in_size);
|
||||
memcpy(&samp_out[j * out_size], &out8[(j % n_samples) * out_size], out_size);
|
||||
}
|
||||
|
||||
for (j = 0; j < N_CHANNELS; j++)
|
||||
ip[j] = samp_in;
|
||||
|
||||
if (in_packed) {
|
||||
tp[0] = temp_in;
|
||||
switch(in_size) {
|
||||
case 1:
|
||||
interleave_8(NULL, 1, tp, N_CHANNELS, ip, N_SAMPLES);
|
||||
break;
|
||||
case 2:
|
||||
interleave_16(NULL, 1, tp, N_CHANNELS, ip, N_SAMPLES);
|
||||
break;
|
||||
case 3:
|
||||
interleave_24(NULL, 1, tp, N_CHANNELS, ip, N_SAMPLES);
|
||||
break;
|
||||
case 4:
|
||||
interleave_32(NULL, 1, tp, N_CHANNELS, ip, N_SAMPLES);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "unknown size %zd\n", in_size);
|
||||
return;
|
||||
}
|
||||
ip[0] = temp_in;
|
||||
}
|
||||
|
||||
spa_zero(temp_out);
|
||||
for (j = 0; j < N_CHANNELS; j++)
|
||||
tp[j] = &temp_out[j * N_SAMPLES * out_size];
|
||||
|
||||
ic = in_packed ? 1 : N_CHANNELS;
|
||||
oc = out_packed ? 1 : N_CHANNELS;
|
||||
ns = (in_packed && out_packed) ? N_SAMPLES * N_CHANNELS : N_SAMPLES;
|
||||
|
||||
func(NULL, oc, tp, ic, ip, ns);
|
||||
|
||||
fprintf(stderr, "test %s:\n", name);
|
||||
if (out_packed) {
|
||||
const uint8_t *d = tp[0], *s = samp_out;
|
||||
spa_debug_mem(0, d, N_SAMPLES * N_CHANNELS * out_size);
|
||||
for (i = 0; i < N_SAMPLES; i++) {
|
||||
for (j = 0; j < N_CHANNELS; j++) {
|
||||
spa_assert(memcmp(d, s, out_size) == 0);
|
||||
d += out_size;
|
||||
}
|
||||
s += out_size;
|
||||
}
|
||||
} else {
|
||||
for (j = 0; j < N_CHANNELS; j++) {
|
||||
spa_assert(memcmp(tp[j], samp_out, N_SAMPLES * out_size) == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void test_f32_u8(void)
|
||||
{
|
||||
const float in[] = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
|
||||
uint8_t out[] = { 128, 255, 0, 191, 64, 255, 0, };
|
||||
|
||||
run_test("test_f32_u8", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, true, conv_f32_to_u8);
|
||||
run_test("test_f32d_u8", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
false, true, conv_f32d_to_u8);
|
||||
run_test("test_f32_u8d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, false, conv_f32_to_u8d);
|
||||
}
|
||||
|
||||
static void test_u8_f32(void)
|
||||
{
|
||||
uint8_t in[] = { 128, 255, 0, 192, 64, };
|
||||
const float out[] = { 0.0f, 0.9921875f, -1.0f, 0.5f, -0.5f, };
|
||||
|
||||
run_test("test_u8_f32", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, true, conv_u8_to_f32);
|
||||
run_test("test_u8d_f32", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
false, true, conv_u8d_to_f32);
|
||||
run_test("test_u8_f32d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, false, conv_u8_to_f32d);
|
||||
}
|
||||
|
||||
static void test_f32_s16(void)
|
||||
{
|
||||
const float in[] = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
|
||||
const int16_t out[] = { 0, 32767, -32767, 16383, -16383, 32767, -32767 };
|
||||
|
||||
run_test("test_f32_s16", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, true, conv_f32_to_s16);
|
||||
run_test("test_f32d_s16", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
false, true, conv_f32d_to_s16);
|
||||
run_test("test_f32_s16d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, false, conv_f32_to_s16d);
|
||||
}
|
||||
|
||||
static void test_s16_f32(void)
|
||||
{
|
||||
const int16_t in[] = { 0, 32767, -32767, 16383, -16383, };
|
||||
const float out[] = { 0.0f, 1.0f, -1.0f, 0.4999847412f, -0.4999847412f };
|
||||
|
||||
run_test("test_s16_f32d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, false, conv_s16_to_f32d);
|
||||
run_test("test_s16d_f32", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
false, true, conv_s16d_to_f32);
|
||||
run_test("test_s16_f32", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, true, conv_s16_to_f32);
|
||||
}
|
||||
|
||||
static void test_f32_s32(void)
|
||||
{
|
||||
const float in[] = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
|
||||
const int32_t out[] = { 0, 0x7fffff00, 0x80000100, 0x3fffff00, 0xc0000100,
|
||||
0x7fffff00, 0x80000100 };
|
||||
|
||||
run_test("test_f32_s32", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, true, conv_f32_to_s32);
|
||||
run_test("test_f32d_s32", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
false, true, conv_f32d_to_s32);
|
||||
run_test("test_f32_s32d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, false, conv_f32_to_s32d);
|
||||
}
|
||||
|
||||
static void test_s32_f32(void)
|
||||
{
|
||||
const int32_t in[] = { 0, 0x7fffff00, 0x80000100, 0x3fffff00, 0xc0000100 };
|
||||
const float out[] = { 0.0f, 1.0f, -1.0f, 0.4999999404f, -0.4999999404f, };
|
||||
|
||||
run_test("test_s32_f32d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, false, conv_s32_to_f32d);
|
||||
run_test("test_s32d_f32", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
false, true, conv_s32d_to_f32);
|
||||
run_test("test_s32_f32", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, true, conv_s32_to_f32);
|
||||
}
|
||||
|
||||
static void test_f32_s24(void)
|
||||
{
|
||||
const float in[] = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
|
||||
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 };
|
||||
|
||||
run_test("test_f32_s24", in, sizeof(in[0]), out, 3, SPA_N_ELEMENTS(in), true, true, conv_f32_to_s24);
|
||||
run_test("test_f32d_s24", in, sizeof(in[0]), out, 3, SPA_N_ELEMENTS(in), false, true, conv_f32d_to_s24);
|
||||
run_test("test_f32_s24d", in, sizeof(in[0]), out, 3, SPA_N_ELEMENTS(in), true, false, conv_f32_to_s24d);
|
||||
}
|
||||
|
||||
static void test_s24_f32(void)
|
||||
{
|
||||
const uint8_t in[] = { 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x01, 0x00, 0x80,
|
||||
0xff, 0xff, 0x3f, 0x01, 0x00, 0xc0, };
|
||||
const float out[] = { 0.0f, 1.0f, -1.0f, 0.4999999404f, -0.4999999404f, };
|
||||
|
||||
run_test("test_s24_f32d", in, 3, out, sizeof(out[0]), SPA_N_ELEMENTS(out), true, false, conv_s24_to_f32d);
|
||||
run_test("test_s24d_f32", in, 3, out, sizeof(out[0]), SPA_N_ELEMENTS(out), false, true, conv_s24d_to_f32);
|
||||
run_test("test_s24_f32", in, 3, out, sizeof(out[0]), SPA_N_ELEMENTS(out), true, true, conv_s24_to_f32);
|
||||
}
|
||||
|
||||
static void test_f32_s24_32(void)
|
||||
{
|
||||
const float in[] = { 0.0f, 1.0f, -1.0f, 0.5f, -0.5f, 1.1f, -1.1f };
|
||||
const int32_t out[] = { 0, 0x7fffff, 0xff800001, 0x3fffff, 0xffc00001,
|
||||
0x7fffff, 0xff800001 };
|
||||
|
||||
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);
|
||||
run_test("test_f32d_s24_32", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
false, true, conv_f32d_to_s24_32);
|
||||
run_test("test_f32_s24_32d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, false, conv_f32_to_s24_32d);
|
||||
}
|
||||
|
||||
static void test_s24_32_f32(void)
|
||||
{
|
||||
const int32_t in[] = { 0, 0x7fffff, 0xff800001, 0x3fffff, 0xffc00001 };
|
||||
const float out[] = { 0.0f, 1.0f, -1.0f, 0.4999999404f, -0.4999999404f, };
|
||||
|
||||
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);
|
||||
run_test("test_s24_32d_f32", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
false, true, conv_s24_32d_to_f32);
|
||||
run_test("test_s24_32_f32", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, true, conv_s24_32_to_f32);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
test_f32_u8();
|
||||
test_u8_f32();
|
||||
test_f32_s16();
|
||||
test_s16_f32();
|
||||
test_f32_s32();
|
||||
test_s32_f32();
|
||||
test_f32_s24();
|
||||
test_s24_f32();
|
||||
test_f32_s24_32();
|
||||
test_s24_32_f32();
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@ test_apps = [
|
|||
foreach a : test_apps
|
||||
test(a,
|
||||
executable(a, a + '.c',
|
||||
dependencies : [dl_lib, pthread_lib],
|
||||
dependencies : [dl_lib, pthread_lib, mathlib ],
|
||||
include_directories : [spa_inc ],
|
||||
c_args : [ '-D_GNU_SOURCE' ],
|
||||
install : false),
|
||||
|
|
@ -32,7 +32,7 @@ benchmark_apps = [
|
|||
foreach a : benchmark_apps
|
||||
benchmark(a,
|
||||
executable(a, a + '.c',
|
||||
dependencies : [dl_lib, pthread_lib],
|
||||
dependencies : [dl_lib, pthread_lib, mathlib ],
|
||||
include_directories : [spa_inc ],
|
||||
c_args : [ '-D_GNU_SOURCE' ],
|
||||
install : false),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue