1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_dct4_init_q15.c
4  * Description:  Initialization function of DCT-4 & IDCT4 Q15
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 DCT4Q15 DCT4 Q15
34  */
35 
36 /**
37   @ingroup DCT4_IDCT4
38  */
39 
40  /**
41   @addtogroup DCT4Q15
42   @{
43  */
44 
45 /**
46   @brief         Initialization function for the Q15 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 Q15 DCT4/IDCT4 structure
49   @param[in]     S_RFFT    points to an instance of Q15 RFFT/RIFFT structure
50   @param[in]     S_CFFT    points to an instance of Q15 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.15 format are mentioned in the table below for different DCT sizes:
61 
62 | DCT Size  | Normalizing factor value (hexadecimal)  |
63 | --------: | ---------------------------------------:|
64 | 2048      | 0x400                                   |
65 | 512       | 0x800                                   |
66 | 128       | 0x1000                                  |
67 
68  */
69 
arm_dct4_init_q15(arm_dct4_instance_q15 * S,arm_rfft_instance_q15 * S_RFFT,arm_cfft_radix4_instance_q15 * S_CFFT,uint16_t N,uint16_t Nby2,q15_t normalize)70 arm_status arm_dct4_init_q15(
71   arm_dct4_instance_q15 * S,
72   arm_rfft_instance_q15 * S_RFFT,
73   arm_cfft_radix4_instance_q15 * S_CFFT,
74   uint16_t N,
75   uint16_t Nby2,
76   q15_t normalize)
77 {
78   /*  Initialise 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 = WeightsQ15_8192;
101     S->pCosFactor = cos_factorsQ15_8192;
102     break;
103 
104   case 2048U:
105     S->pTwiddle = WeightsQ15_2048;
106     S->pCosFactor = cos_factorsQ15_2048;
107     break;
108 
109   case 512U:
110     S->pTwiddle = WeightsQ15_512;
111     S->pCosFactor = cos_factorsQ15_512;
112     break;
113 
114   case 128U:
115     S->pTwiddle = WeightsQ15_128;
116     S->pCosFactor = cos_factorsQ15_128;
117     break;
118 
119   default:
120     status = ARM_MATH_ARGUMENT_ERROR;
121   }
122 
123   /* Initialize the RFFT/RIFFT */
124   arm_rfft_init_q15(S->pRfft, S->N, 0U, 1U);
125 
126   /* return the status of DCT4 Init function */
127   return (status);
128 }
129 
130 /**
131   @} end of DCT4Q15 group
132  */
133