Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2 | mjames | 1 | #include "jtest.h" |
| 2 | #include "ref.h" |
||
| 3 | #include "arm_math.h" |
||
| 4 | #include "arr_desc.h" |
||
| 5 | #include "transform_templates.h" |
||
| 6 | #include "transform_test_data.h" |
||
| 7 | #include "type_abbrev.h" |
||
| 8 | #include <math.h> /* sqrtf() */ |
||
| 9 | |||
| 10 | /*--------------------------------------------------------------------------------*/ |
||
| 11 | /* Aliases to aid macro expansion */ |
||
| 12 | /*--------------------------------------------------------------------------------*/ |
||
| 13 | #define ref_sqrt_f32(x) sqrtf(x) |
||
| 14 | |||
| 15 | /*--------------------------------------------------------------------------------*/ |
||
| 16 | /* Test Definitions */ |
||
| 17 | /*--------------------------------------------------------------------------------*/ |
||
| 18 | |||
| 19 | /* |
||
| 20 | DCT function test template. Arguments are: function configuration suffix |
||
| 21 | (q7/q15/q31/f32) and input type (q7_t/q15_t/q31_t/float32_t) |
||
| 22 | */ |
||
| 23 | #define DCT4_DEFINE_TEST(suffix, input_type) \ |
||
| 24 | JTEST_DEFINE_TEST(arm_dct4_##suffix##_test, arm_dct4_##suffix) \ |
||
| 25 | { \ |
||
| 26 | CONCAT(arm_dct4_instance_,suffix) dct4_inst_fut = {0}; \ |
||
| 27 | CONCAT(arm_rfft_instance_,suffix) rfft_inst_fut = {0}; \ |
||
| 28 | CONCAT(arm_cfft_radix4_instance_,suffix) cfft_inst_fut = {0}; \ |
||
| 29 | \ |
||
| 30 | CONCAT(arm_dct4_instance_,suffix) dct4_inst_ref = {0}; \ |
||
| 31 | CONCAT(arm_rfft_instance_,suffix) rfft_inst_ref = {0}; \ |
||
| 32 | CONCAT(arm_cfft_radix4_instance_,suffix) cfft_inst_ref = {0}; \ |
||
| 33 | \ |
||
| 34 | /* Go through all dct lengths */ \ |
||
| 35 | TEMPLATE_DO_ARR_DESC( \ |
||
| 36 | fftlen_idx, uint16_t, fftlen, transform_dct_fftlens \ |
||
| 37 | , \ |
||
| 38 | \ |
||
| 39 | float32_t normalize_f32 = \ |
||
| 40 | ref_sqrt_f32((2.0f/(float32_t)fftlen)); \ |
||
| 41 | input_type normalize; \ |
||
| 42 | \ |
||
| 43 | /* Calculate normalized DCT4 value for input_type. */ \ |
||
| 44 | TEST_CONVERT_FLOAT_TO(&normalize_f32, &normalize, \ |
||
| 45 | 1, input_type); \ |
||
| 46 | \ |
||
| 47 | /* Initialize the DCT4, RFFT, and CFFT instances */ \ |
||
| 48 | arm_dct4_init_##suffix( \ |
||
| 49 | &dct4_inst_fut, &rfft_inst_fut, &cfft_inst_fut, \ |
||
| 50 | fftlen, \ |
||
| 51 | fftlen/2, \ |
||
| 52 | normalize); \ |
||
| 53 | \ |
||
| 54 | arm_dct4_init_##suffix( \ |
||
| 55 | &dct4_inst_ref, &rfft_inst_ref, &cfft_inst_ref, \ |
||
| 56 | fftlen, \ |
||
| 57 | fftlen/2, \ |
||
| 58 | normalize); \ |
||
| 59 | \ |
||
| 60 | memset( transform_fft_input_fut,0, \ |
||
| 61 | fftlen*sizeof(input_type)); \ |
||
| 62 | \ |
||
| 63 | TRANSFORM_PREPARE_INPLACE_INPUTS( \ |
||
| 64 | transform_fft_##suffix##_inputs, \ |
||
| 65 | fftlen * sizeof(input_type)); \ |
||
| 66 | \ |
||
| 67 | /* Display parameter values */ \ |
||
| 68 | JTEST_DUMP_STRF("Block Size: %d\n", \ |
||
| 69 | (int)fftlen); \ |
||
| 70 | \ |
||
| 71 | /* Input provided as a scratch buffer. Inplace input is \ |
||
| 72 | * actual input. Display cycle count and run test*/ \ |
||
| 73 | JTEST_COUNT_CYCLES( \ |
||
| 74 | arm_dct4_##suffix( \ |
||
| 75 | &dct4_inst_fut, \ |
||
| 76 | (void *) transform_fft_input_fut, \ |
||
| 77 | (void *) transform_fft_inplace_input_fut)); \ |
||
| 78 | \ |
||
| 79 | memset( transform_fft_input_ref,0, \ |
||
| 80 | fftlen*sizeof(input_type)); \ |
||
| 81 | \ |
||
| 82 | /* Input provided as a scratch buffer. Inplace input is */ \ |
||
| 83 | /* actual input. */ \ |
||
| 84 | ref_dct4_##suffix( \ |
||
| 85 | &dct4_inst_ref, \ |
||
| 86 | (void *) transform_fft_input_ref, \ |
||
| 87 | (void *) transform_fft_inplace_input_ref); \ |
||
| 88 | \ |
||
| 89 | /* Test correctness */ \ |
||
| 90 | DCT_TRANSFORM_SNR_COMPARE_INTERFACE( \ |
||
| 91 | fftlen, \ |
||
| 92 | input_type)); \ |
||
| 93 | \ |
||
| 94 | return JTEST_TEST_PASSED; \ |
||
| 95 | } |
||
| 96 | |||
| 97 | /* |
||
| 98 | DCT function test template for fixed point data. Arguments are: function |
||
| 99 | suffix (q7/q15/q31/f32), input type (q7_t/q15_t/q31_t/float32_t) and prefix |
||
| 100 | (dct_4) |
||
| 101 | */ |
||
| 102 | #define DCT4_FIXED_POINT_DEFINE_TEST(suffix, input_type, prefix) \ |
||
| 103 | JTEST_DEFINE_TEST(arm_dct4_##suffix##_test, arm_dct4_##suffix) \ |
||
| 104 | { \ |
||
| 105 | CONCAT(arm_dct4_instance_,suffix) dct4_inst_fut = {0}; \ |
||
| 106 | CONCAT(arm_rfft_instance_,suffix) rfft_inst_fut = {0}; \ |
||
| 107 | CONCAT(arm_cfft_radix4_instance_,suffix) cfft_inst_fut = {0}; \ |
||
| 108 | \ |
||
| 109 | CONCAT(arm_dct4_instance_,suffix) dct4_inst_ref = {0}; \ |
||
| 110 | CONCAT(arm_rfft_instance_,suffix) rfft_inst_ref = {0}; \ |
||
| 111 | CONCAT(arm_cfft_radix4_instance_,suffix) cfft_inst_ref = {0}; \ |
||
| 112 | \ |
||
| 113 | TEMPLATE_DO_ARR_DESC( \ |
||
| 114 | fftlen_idx, uint16_t, fftlen, transform_dct_fftlens \ |
||
| 115 | , \ |
||
| 116 | uint32_t i; \ |
||
| 117 | float32_t normalize_f32 = \ |
||
| 118 | ref_sqrt_f32((2.0f/(float32_t)fftlen)); \ |
||
| 119 | input_type normalize; \ |
||
| 120 | \ |
||
| 121 | /* Calculate normalized DCT4 value for input_type. */ \ |
||
| 122 | TEST_CONVERT_FLOAT_TO(&normalize_f32, &normalize, \ |
||
| 123 | 1, input_type); \ |
||
| 124 | \ |
||
| 125 | /* Initialize the DCT4, RFFT, and CFFT instances */ \ |
||
| 126 | arm_dct4_init_##suffix( \ |
||
| 127 | &dct4_inst_fut, &rfft_inst_fut, &cfft_inst_fut, \ |
||
| 128 | fftlen, \ |
||
| 129 | fftlen/2, \ |
||
| 130 | normalize); \ |
||
| 131 | \ |
||
| 132 | arm_dct4_init_##suffix( \ |
||
| 133 | &dct4_inst_ref, &rfft_inst_ref, &cfft_inst_ref, \ |
||
| 134 | fftlen, \ |
||
| 135 | fftlen/2, \ |
||
| 136 | normalize); \ |
||
| 137 | \ |
||
| 138 | /* Input samples need to be downscaled by 1 bit to \ |
||
| 139 | * avoid saturations in the Q31 DCT process, \ |
||
| 140 | * as the conversion from DCT2 to DCT4 involves \ |
||
| 141 | * one subtraction. \ |
||
| 142 | */ \ |
||
| 143 | for(i=0; i < fftlen; i++) \ |
||
| 144 | { \ |
||
| 145 | ((input_type*)transform_fft_inplace_input_fut)[i] = \ |
||
| 146 | prefix##transform_fft_##suffix##_inputs[i] >> 1; \ |
||
| 147 | ((input_type*)transform_fft_inplace_input_ref)[i] = \ |
||
| 148 | prefix##transform_fft_##suffix##_inputs[i] >> 1; \ |
||
| 149 | } \ |
||
| 150 | \ |
||
| 151 | memset( transform_fft_input_fut,0, \ |
||
| 152 | fftlen*sizeof(input_type)); \ |
||
| 153 | \ |
||
| 154 | /* Display test parameter values */ \ |
||
| 155 | JTEST_DUMP_STRF("Block Size: %d\n", \ |
||
| 156 | (int)fftlen); \ |
||
| 157 | \ |
||
| 158 | /* Input provided as a scratch buffer. Inplace input is \ |
||
| 159 | * actual input. */ \ |
||
| 160 | JTEST_COUNT_CYCLES( \ |
||
| 161 | arm_dct4_##suffix( \ |
||
| 162 | &dct4_inst_fut, \ |
||
| 163 | (void *) transform_fft_input_fut, \ |
||
| 164 | (void *) transform_fft_inplace_input_fut)); \ |
||
| 165 | \ |
||
| 166 | memset( transform_fft_input_ref,0, \ |
||
| 167 | fftlen*sizeof(input_type)); \ |
||
| 168 | \ |
||
| 169 | /* Input provided as a scratch buffer. Inplace input is */ \ |
||
| 170 | /* actual input. */ \ |
||
| 171 | ref_dct4_##suffix( \ |
||
| 172 | &dct4_inst_ref, \ |
||
| 173 | (void *) transform_fft_input_ref, \ |
||
| 174 | (void *) transform_fft_inplace_input_ref); \ |
||
| 175 | \ |
||
| 176 | /* Test correctness */ \ |
||
| 177 | DCT_TRANSFORM_SNR_COMPARE_INTERFACE( \ |
||
| 178 | fftlen, \ |
||
| 179 | input_type)); \ |
||
| 180 | \ |
||
| 181 | return JTEST_TEST_PASSED; \ |
||
| 182 | } |
||
| 183 | |||
| 184 | DCT4_DEFINE_TEST(f32, float32_t); |
||
| 185 | DCT4_FIXED_POINT_DEFINE_TEST(q31, q31_t,); |
||
| 186 | DCT4_FIXED_POINT_DEFINE_TEST(q15, q15_t, dct4_); |
||
| 187 | |||
| 188 | /*--------------------------------------------------------------------------------*/ |
||
| 189 | /* Collect all tests in a group */ |
||
| 190 | /*--------------------------------------------------------------------------------*/ |
||
| 191 | |||
| 192 | JTEST_DEFINE_GROUP(dct4_tests) |
||
| 193 | { |
||
| 194 | JTEST_TEST_CALL(arm_dct4_f32_test); |
||
| 195 | JTEST_TEST_CALL(arm_dct4_q31_test); |
||
| 196 | JTEST_TEST_CALL(arm_dct4_q15_test); |
||
| 197 | } |