aboutsummaryrefslogtreecommitdiffstats
path: root/test/ut.c
diff options
context:
space:
mode:
authorDaniil Cherednik <dan.cherednik@gmail.com>2021-10-22 19:24:28 +0300
committerDaniil Cherednik <dan.cherednik@gmail.com>2021-10-22 19:24:28 +0300
commit0168b9e49b69c90d9e2b5b8f4ab3e3f102d806a9 (patch)
treecb52a457d33e703f72fa99a7533e8274edba5b04 /test/ut.c
parent0c027d2ea17751f31c86a19583dfd72f86df75da (diff)
downloadlibpqf-0168b9e49b69c90d9e2b5b8f4ab3e3f102d806a9.tar.gz
Change implementation for a bit more clear
Diffstat (limited to 'test/ut.c')
-rw-r--r--test/ut.c154
1 files changed, 154 insertions, 0 deletions
diff --git a/test/ut.c b/test/ut.c
new file mode 100644
index 0000000..f099b70
--- /dev/null
+++ b/test/ut.c
@@ -0,0 +1,154 @@
+#include <3rd/fctx/fct.h>
+
+#include "ut_dca_pr.h"
+#include "ut_dca_pr_long.h"
+
+#include "libpqf.h"
+
+#include <stdio.h>
+#include <tgmath.h>
+
+////////////////////////////////////////////////////////////////////////////////
+
+static float* create_chirp(int sz)
+{
+ int i = 0;
+ float* buf = malloc(sizeof(float) * sz);
+ static int done = 0;
+ for(i = 0; i < sz; i++) {
+ float t = i;
+ buf[i] = sinf((t + t * t * 0.5 / 2.0) * 2.0 * M_PI/(float)sz);
+ }
+ return buf;
+}
+
+#define check_reconstruction(a, b, sz) \
+ do { \
+ uint16_t i = 0; \
+ int scale = 1 << 18; \
+ for (i = 0; i < sz; i ++) { \
+ fct_chk((abs((int)round((a)[i] * scale) - (int)round((b)[i] * scale))) < 2); \
+ } \
+ } while (0) \
+
+#define PQF_TEST_COVER(module) \
+ FCT_SUITE_BGN(module) \
+ { \
+ uint16_t sb_sz = module.get_subband_sz(); \
+ uint16_t sb_num = module.get_subbands_num(); \
+ uint16_t proto_sz = module.get_proto_sz(); \
+ const float* proto = module.get_proto(); \
+ const float* dummy = calloc(sb_sz * sb_num, sizeof(float)); \
+ FCT_TEST_BGN(module-IMP) \
+ { \
+ int k;\
+ pqf_a_ctx_t ctx; \
+ int status = pqf_create_a_ctx(sb_sz, sb_num, proto_sz, proto, &ctx); \
+ fct_chk_eq_int(status, PQF_SUCCESS); \
+ float* in_buf1 = calloc(sb_sz * sb_num, sizeof(float)); \
+ in_buf1[500] = 1.0; \
+ float* out_buf = malloc(sizeof(float) * sb_sz * sb_num); \
+ float* synth_buf = malloc(sizeof(float) * sb_sz * sb_num * 2); \
+ void* dec_ctx = module.create_ctx(); \
+ pqf_do_analyse(ctx, in_buf1, out_buf); \
+ module.synth_filter(out_buf, synth_buf, dec_ctx); \
+ pqf_do_analyse(ctx, dummy, out_buf); \
+ module.synth_filter(out_buf, synth_buf + sb_sz * sb_num, dec_ctx); \
+\
+ check_reconstruction(in_buf1, synth_buf + proto_sz, sb_sz * sb_num); \
+\
+ module.free_ctx(dec_ctx); \
+ free(synth_buf); \
+ free(out_buf); \
+ free(in_buf1); \
+ } \
+ FCT_TEST_END(); \
+ FCT_TEST_BGN(module-DC) \
+ { \
+ int k; \
+ pqf_a_ctx_t ctx; \
+ uint16_t i = 0; \
+ int status = pqf_create_a_ctx(sb_sz, sb_num, proto_sz, proto, &ctx); \
+ fct_chk_eq_int(status, PQF_SUCCESS); \
+ float* in_buf1 = calloc(sb_sz * sb_num, sizeof(float)); \
+ for (i = 0; i < sb_sz * sb_num; i++) \
+ in_buf1[i] = 1.0; \
+ float* out_buf = malloc(sizeof(float) * sb_sz * sb_num); \
+ float* synth_buf = malloc(sizeof(float) * sb_sz * sb_num * 2); \
+ void* dec_ctx = module.create_ctx(); \
+ pqf_do_analyse(ctx, in_buf1, out_buf); \
+ module.synth_filter(out_buf, synth_buf, dec_ctx); \
+ pqf_do_analyse(ctx, in_buf1, out_buf); \
+ module.synth_filter(out_buf, synth_buf + sb_sz * sb_num, dec_ctx); \
+\
+ check_reconstruction(in_buf1, synth_buf + proto_sz, sb_sz * sb_num); \
+\
+ module.free_ctx(dec_ctx); \
+ free(synth_buf); \
+ free(out_buf); \
+ free(in_buf1); \
+ } \
+ FCT_TEST_END(); \
+ FCT_TEST_BGN(module-CHIRP-SHORT) \
+ { \
+ pqf_a_ctx_t ctx; \
+ int status = pqf_create_a_ctx(sb_sz, sb_num, proto_sz, proto, &ctx); \
+ uint16_t i = 0; \
+ float* chirp = create_chirp(sb_sz * sb_num); \
+ float* out_buf = malloc(sizeof(float) * sb_sz * sb_num); \
+ float* synth_buf = malloc(sizeof(float) * sb_sz * sb_num * 2); \
+ fct_chk_eq_int(status, PQF_SUCCESS); \
+ void* dec_ctx = module.create_ctx(); \
+ pqf_do_analyse(ctx, chirp, out_buf); \
+ module.synth_filter(out_buf, synth_buf, dec_ctx); \
+ pqf_do_analyse(ctx, dummy, out_buf); \
+ module.synth_filter(out_buf, synth_buf + sb_sz * sb_num, dec_ctx); \
+\
+ check_reconstruction(chirp, synth_buf + proto_sz, sb_sz * sb_num); \
+\
+ module.free_ctx(dec_ctx); \
+ free(synth_buf); \
+ free(out_buf); \
+ free(chirp); \
+ } \
+ FCT_TEST_END(); \
+ FCT_TEST_BGN(module-CHIRP-LONG) \
+ { \
+ pqf_a_ctx_t ctx; \
+ int status = pqf_create_a_ctx(sb_sz, sb_num, proto_sz, proto, &ctx); \
+ uint16_t i = 0; \
+ float* chirp = create_chirp(16384); \
+ float* out_buf = malloc(sizeof(float) * sb_sz * sb_num); \
+ float* synth_buf = malloc(sizeof(float) * 16384 + sb_sz * sb_num); \
+ fct_chk_eq_int(status, PQF_SUCCESS); \
+ void* dec_ctx = module.create_ctx(); \
+ pqf_do_analyse(ctx, chirp, out_buf); \
+ module.synth_filter(out_buf, synth_buf, dec_ctx); \
+ for (i = sb_sz * sb_num; i < 16384; i += sb_sz * sb_num) { \
+ pqf_do_analyse(ctx, chirp + i, out_buf); \
+ module.synth_filter(out_buf, synth_buf + i, dec_ctx); \
+ } \
+ pqf_do_analyse(ctx, dummy, out_buf); \
+ module.synth_filter(out_buf, synth_buf + 16384, dec_ctx); \
+\
+ check_reconstruction(chirp, synth_buf + proto_sz, 16384); \
+\
+ module.free_ctx(dec_ctx); \
+ free(synth_buf); \
+ free(out_buf); \
+ free(chirp); \
+ } \
+ FCT_TEST_END(); \
+ free((void*)dummy); \
+ } \
+ FCT_SUITE_END(); \
+
+
+////////////////////////////////////////////////////////////////////////////////
+
+FCT_BGN()
+{
+ PQF_TEST_COVER(ut_dca_pr)
+ PQF_TEST_COVER(ut_dca_pr_long)
+}
+FCT_END();