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 "trig_tables.h" 18 /* 'Error (max = 0.000061), THD+N = -91.502670' */ 19 #define CMP_TOLERANCE 0.000065 20 #define _M_PI 3.14159265358979323846 /* pi */ 21 test_math_trig_sin_fixed(void ** state)22static void test_math_trig_sin_fixed(void **state) 23 { 24 (void)state; 25 26 int theta; 27 28 for (theta = 0; theta < 360; ++theta) { 29 double rad = _M_PI * (theta / 180.0); 30 int32_t rad_q28 = Q_CONVERT_FLOAT(rad, 28); 31 32 float r = Q_CONVERT_QTOF(sin_fixed_16b(rad_q28), 15); 33 float diff = fabsf(sin_ref_table[theta] - r); 34 35 if (diff > CMP_TOLERANCE) { 36 printf("%s: diff for %d deg = %.10f\n", __func__, 37 theta, diff); 38 } 39 40 assert_true(diff <= CMP_TOLERANCE); 41 } 42 } 43 main(void)44int main(void) 45 { 46 const struct CMUnitTest tests[] = { 47 cmocka_unit_test(test_math_trig_sin_fixed) 48 }; 49 50 cmocka_set_message_output(CM_OUTPUT_TAP); 51 52 return cmocka_run_group_tests(tests, NULL, NULL); 53 } 54