1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_dct4_init_q31.c
4 * Description: Initialization function of DCT-4 & IDCT4 Q31
5 *
6 * $Date: 23 April 2021
7 * $Revision: V1.9.0
8 *
9 * Target Processor: Cortex-M and Cortex-A cores
10 * -------------------------------------------------------------------- */
11 /*
12 * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
13 *
14 * SPDX-License-Identifier: Apache-2.0
15 *
16 * Licensed under the Apache License, Version 2.0 (the License); you may
17 * not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
19 *
20 * www.apache.org/licenses/LICENSE-2.0
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
27 */
28
29 #include "dsp/transform_functions.h"
30 #include "arm_common_tables.h"
31
32 /**
33 * @defgroup DCT4Q31 DCT4 Q31
34 */
35
36 /**
37 @ingroup DCT4_IDCT4
38 */
39
40 /**
41 @addtogroup DCT4Q31
42 @{
43 */
44
45 /**
46 @brief Initialization function for the Q31 DCT4/IDCT4.
47 @deprecated Do not use this function. It will be removed in future versions.
48 @param[in,out] S points to an instance of Q31 DCT4/IDCT4 structure.
49 @param[in] S_RFFT points to an instance of Q31 RFFT/RIFFT structure
50 @param[in] S_CFFT points to an instance of Q31 CFFT/CIFFT structure
51 @param[in] N length of the DCT4.
52 @param[in] Nby2 half of the length of the DCT4.
53 @param[in] normalize normalizing factor.
54 @return execution status
55 - \ref ARM_MATH_SUCCESS : Operation successful
56 - \ref ARM_MATH_ARGUMENT_ERROR : <code>N</code> is not a supported transform length
57
58 @par Normalizing factor:
59 The normalizing factor is <code>sqrt(2/N)</code>, which depends on the size of transform <code>N</code>.
60 Normalizing factors in 1.31 format are mentioned in the table below for different DCT sizes:
61
62 | DCT Size | Normalizing factor value (hexadecimal) |
63 | --------: | ---------------------------------------:|
64 | 2048 | 0x4000000 |
65 | 512 | 0x8000000 |
66 | 128 | 0x10000000 |
67
68 */
69
arm_dct4_init_q31(arm_dct4_instance_q31 * S,arm_rfft_instance_q31 * S_RFFT,arm_cfft_radix4_instance_q31 * S_CFFT,uint16_t N,uint16_t Nby2,q31_t normalize)70 arm_status arm_dct4_init_q31(
71 arm_dct4_instance_q31 * S,
72 arm_rfft_instance_q31 * S_RFFT,
73 arm_cfft_radix4_instance_q31 * S_CFFT,
74 uint16_t N,
75 uint16_t Nby2,
76 q31_t normalize)
77 {
78 /* Initialize the default arm status */
79 arm_status status = ARM_MATH_SUCCESS;
80
81 /* Initialize the DCT4 length */
82 S->N = N;
83
84 /* Initialize the half of DCT4 length */
85 S->Nby2 = Nby2;
86
87 /* Initialize the DCT4 Normalizing factor */
88 S->normalize = normalize;
89
90 /* Initialize Real FFT Instance */
91 S->pRfft = S_RFFT;
92
93 /* Initialize Complex FFT Instance */
94 S->pCfft = S_CFFT;
95
96 switch (N)
97 {
98 /* Initialize the table modifier values */
99 case 8192U:
100 S->pTwiddle = WeightsQ31_8192;
101 S->pCosFactor = cos_factorsQ31_8192;
102 break;
103
104 case 2048U:
105 S->pTwiddle = WeightsQ31_2048;
106 S->pCosFactor = cos_factorsQ31_2048;
107 break;
108
109 case 512U:
110 S->pTwiddle = WeightsQ31_512;
111 S->pCosFactor = cos_factorsQ31_512;
112 break;
113
114 case 128U:
115 S->pTwiddle = WeightsQ31_128;
116 S->pCosFactor = cos_factorsQ31_128;
117 break;
118 default:
119 status = ARM_MATH_ARGUMENT_ERROR;
120 }
121
122 /* Initialize the RFFT/RIFFT Function */
123 arm_rfft_init_q31(S->pRfft, S->N, 0U, 1U);
124
125 /* return the status of DCT4 Init function */
126 return (status);
127 }
128
129 /**
130 @} end of DCT4Q31 group
131 */
132