1 // SPDX-License-Identifier: BSD-3-Clause 2 // 3 // Copyright(c) 2018 Intel Corporation. All rights reserved. 4 // 5 // Author: Shriram Shastry <malladi.sastry@linux.intel.com> 6 7 #include <stdio.h> 8 #include <stdint.h> 9 #include <stdarg.h> 10 #include <stddef.h> 11 #include <setjmp.h> 12 #include <math.h> 13 #include <cmocka.h> 14 15 #include <sof/audio/format.h> 16 #include <sof/math/trig.h> 17 #include <sof/common.h> 18 #include "trig_tables.h" 19 /* 'Error (max = 0.000059799232976), THD+N = -89.824298401466635 (dBc) */ 20 #define CMP_TOLERANCE 0.0001152158 21 #define _M_PI 3.14159265358979323846 /* pi */ 22 test_math_trig_asin_16b_fixed(void ** state)23static void test_math_trig_asin_16b_fixed(void **state) 24 { 25 (void)state; 26 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(asin_fixed_16b(b_i), 13); 42 float diff = fabsf(asin_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_asin_16b_fixed) 57 }; 58 59 cmocka_set_message_output(CM_OUTPUT_TAP); 60 61 return cmocka_run_group_tests(tests, NULL, NULL); 62 } 63