summaryrefslogtreecommitdiff
path: root/midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/Common/src/transform_tests/cfft_tests.c
blob: f26c6f629fa159d8e38ac074eb357d9d6d18b6f8 (plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "jtest.h"
#include "ref.h"
#include "arr_desc.h"
#include "transform_templates.h"
#include "transform_test_data.h"

#define CFFT_SNR_THRESHOLD 120

/*
  CFFT function test template. Arguments are: inverse-transform flag, function
  suffix (q7/q15/q31/f32) and the output type (q7_t, q15_t, q31_t, float32_t)
*/
#define CFFT_TEST_BODY(ifft_flag, suffix, output_type)                                  \
    do                                                                                  \
    {                                                                                   \
        /* Go through all arm_cfft_instances */                                         \
        TEMPLATE_DO_ARR_DESC(                                                           \
            cfft_inst_idx, const arm_cfft_instance_##suffix *, cfft_inst_ptr,           \
            transform_cfft_##suffix##_structs                                           \
            ,                                                                           \
                                                                                        \
            TRANSFORM_PREPARE_INPLACE_INPUTS(                                           \
                transform_fft_##suffix##_inputs,                                        \
                cfft_inst_ptr->fftLen *                                                 \
                sizeof(output_type) *                                                   \
                2 /*complex_inputs*/);                                                  \
                                                                                        \
                /* Display parameter values */                                          \
                JTEST_DUMP_STRF("Block Size: %d\n"                                      \
                                "Inverse-transform flag: %d\n",                         \
                                (int)cfft_inst_ptr->fftLen,                             \
                                (int)ifft_flag);                                        \
                                                                                        \
            /* Display cycle count and run test */                                      \
            JTEST_COUNT_CYCLES(                                                         \
                arm_cfft_##suffix(cfft_inst_ptr,                                        \
                             (void *) transform_fft_inplace_input_fut,                  \
                             ifft_flag,              /* IFFT Flag */                    \
                             1));            /* Bitreverse flag */                      \
            ref_cfft_##suffix(cfft_inst_ptr,                                            \
                         (void *) transform_fft_inplace_input_ref,                      \
                         ifft_flag,         /* IFFT Flag */                             \
                         1);        /* Bitreverse flag */                               \
                                                                                        \
            /* Test correctness */                                                      \
            TRANSFORM_SNR_COMPARE_CMPLX_INTERFACE(                                      \
                cfft_inst_ptr->fftLen,                                                  \
                output_type));                                                          \
                                                                                        \
        return JTEST_TEST_PASSED;                                                       \
    } while (0)


/*
  CFFT function with downshift test template. Arguments are: inverse-transform flag,
  function suffix (q7/q15/q31/f32) and the output type (q7_t, q15_t, q31_t, float32_t)
*/
#define CFFT_DOWNSHIFT_INPUT_TEST_BODY(ifft_flag, suffix, output_type)                  \
    do                                                                                  \
    {                                                                                   \
        /* Go through all arm_cfft_instances */                                         \
        TEMPLATE_DO_ARR_DESC(                                                           \
            cfft_inst_idx, const arm_cfft_instance_##suffix *, cfft_inst_ptr,           \
            transform_cfft_##suffix##_structs                                           \
            ,                                                                           \
                                                                                        \
            TRANSFORM_PREPARE_INPLACE_INPUTS_DOWNSHIFT(                                 \
                transform_fft_##suffix##_inputs,                                        \
                cfft_inst_ptr->fftLen *                                                 \
                sizeof(output_type) *                                                   \
                2 /*complex_inputs*/, output_type);                                     \
                                                                                        \
            /* Display parameter values */                                              \
            JTEST_DUMP_STRF("Block Size: %d\n"                                          \
                            "Inverse-transform flag: %d\n",                             \
                            (int)cfft_inst_ptr->fftLen,                                 \
                            (int)ifft_flag);                                            \
                                                                                        \
            /* Display cycle count and run test */                                      \
            JTEST_COUNT_CYCLES(                                                         \
                arm_cfft_##suffix(cfft_inst_ptr,                                        \
                             (void *) transform_fft_inplace_input_fut,                  \
                             ifft_flag,              /* IFFT Flag */                    \
                             1));            /* Bitreverse flag */                      \
            ref_cfft_##suffix(cfft_inst_ptr,                                            \
                         (void *) transform_fft_inplace_input_ref,                      \
                         ifft_flag,         /* IFFT Flag */                             \
                         1);        /* Bitreverse flag */                               \
                                                                                        \
            /* Test correctness */                                                      \
            TRANSFORM_SNR_COMPARE_CMPLX_INTERFACE(                                      \
                cfft_inst_ptr->fftLen,                                                  \
                output_type));                                                          \
                                                                                        \
        return JTEST_TEST_PASSED;                                                       \
    } while (0)


/* Test declarations */
JTEST_DEFINE_TEST(cfft_f32_test, cfft_f32)
{
    CFFT_TEST_BODY((uint8_t) 0, f32, float32_t);
}

JTEST_DEFINE_TEST(cfft_f32_ifft_test, cfft_f32)
{
    CFFT_TEST_BODY((uint8_t) 1, f32, float32_t);
}

JTEST_DEFINE_TEST(cfft_q31_test, cfft_q31)
{
    CFFT_TEST_BODY((uint8_t) 0, q31, q31_t);
}

JTEST_DEFINE_TEST(cfft_q31_ifft_test, cfft_q31)
{
    CFFT_TEST_BODY((uint8_t) 1, q31, q31_t);
}

JTEST_DEFINE_TEST(cfft_q15_test, cfft_q15)
{
    CFFT_TEST_BODY((uint8_t) 0, q15, q15_t);
}

JTEST_DEFINE_TEST(cfft_q15_ifft_test, cfft_q15)
{
    CFFT_TEST_BODY((uint8_t) 1, q15, q15_t);
}

/*--------------------------------------------------------------------------------*/
/* Collect all tests in a group */
/*--------------------------------------------------------------------------------*/

JTEST_DEFINE_GROUP(cfft_tests)
{
    JTEST_TEST_CALL(cfft_f32_test);
    JTEST_TEST_CALL(cfft_f32_ifft_test);

    JTEST_TEST_CALL(cfft_q31_test);
    JTEST_TEST_CALL(cfft_q31_ifft_test);

    JTEST_TEST_CALL(cfft_q15_test);
    JTEST_TEST_CALL(cfft_q15_ifft_test);
}