forked from thesofproject/sof
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasin_16b_fixed.c
More file actions
62 lines (51 loc) · 1.54 KB
/
Copy pathasin_16b_fixed.c
File metadata and controls
62 lines (51 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2018 Intel Corporation. All rights reserved.
//
// Author: Shriram Shastry <malladi.sastry@linux.intel.com>
#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <math.h>
#include <cmocka.h>
#include <sof/audio/format.h>
#include <sof/math/trig.h>
#include <sof/common.h>
#include "trig_tables.h"
/* 'Error (max = 0.000059799232976), THD+N = -89.824298401466635 (dBc) */
#define CMP_TOLERANCE 0.0001152158
#define _M_PI 3.14159265358979323846 /* pi */
static void test_math_trig_asin_16b_fixed(void **state)
{
(void)state;
double u;
double v;
int indx;
int b_i;
for (indx = 0; indx < ARRAY_SIZE(degree_table); ++indx) {
/* convert angle unit degrees to radians */
/* angleInRadians = pi/180 * angleInDegrees & const Q2.30 format */
u = (0.017453292519943295 * (double)degree_table[indx] * 0x40000000);
v = fabs(u);
/* GitHub macro Q_CONVERT_FLOAT is inaccurate, so replaced with below */
u = (v >= 0.5) ? floor(u + 0.5) : 0.0;
b_i = (int)u;
float r = Q_CONVERT_QTOF(asin_fixed_16b(b_i), 13);
float diff = fabsf(asin_ref_table[indx] - r);
if (diff > CMP_TOLERANCE) {
printf("%s: diff for %.16f deg = %.10f\n", __func__,
((180 / _M_PI) * b_i) / (1 << 30), diff);
}
assert_true(diff <= CMP_TOLERANCE);
}
}
int main(void)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_math_trig_asin_16b_fixed)
};
cmocka_set_message_output(CM_OUTPUT_TAP);
return cmocka_run_group_tests(tests, NULL, NULL);
}