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