arm_dct4_init_q31.c
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 @ingroup groupTransforms 34 */ 35 36 /** 37 @addtogroup DCT4_IDCT4 38 @{ 39 */ 40 41 /** 42 @brief Initialization function for the Q31 DCT4/IDCT4. 43 @param[in,out] S points to an instance of Q31 DCT4/IDCT4 structure. 44 @param[in] S_RFFT points to an instance of Q31 RFFT/RIFFT structure 45 @param[in] S_CFFT points to an instance of Q31 CFFT/CIFFT structure 46 @param[in] N length of the DCT4. 47 @param[in] Nby2 half of the length of the DCT4. 48 @param[in] normalize normalizing factor. 49 @return execution status 50 - \ref ARM_MATH_SUCCESS : Operation successful 51 - \ref ARM_MATH_ARGUMENT_ERROR : <code>N</code> is not a supported transform length 52 53 @par Normalizing factor: 54 The normalizing factor is <code>sqrt(2/N)</code>, which depends on the size of transform <code>N</code>. 55 Normalizing factors in 1.31 format are mentioned in the table below for different DCT sizes: 56 57 \image html dct4NormalizingQ31Table.gif 58 */ 59 60 arm_status arm_dct4_init_q31( 61 arm_dct4_instance_q31 * S, 62 arm_rfft_instance_q31 * S_RFFT, 63 arm_cfft_radix4_instance_q31 * S_CFFT, 64 uint16_t N, 65 uint16_t Nby2, 66 q31_t normalize) 67 { 68 /* Initialize the default arm status */ 69 arm_status status = ARM_MATH_SUCCESS; 70 71 /* Initialize the DCT4 length */ 72 S->N = N; 73 74 /* Initialize the half of DCT4 length */ 75 S->Nby2 = Nby2; 76 77 /* Initialize the DCT4 Normalizing factor */ 78 S->normalize = normalize; 79 80 /* Initialize Real FFT Instance */ 81 S->pRfft = S_RFFT; 82 83 /* Initialize Complex FFT Instance */ 84 S->pCfft = S_CFFT; 85 86 switch (N) 87 { 88 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q31_8192) 89 /* Initialize the table modifier values */ 90 case 8192U: 91 S->pTwiddle = WeightsQ31_8192; 92 S->pCosFactor = cos_factorsQ31_8192; 93 break; 94 #endif 95 96 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q31_2048) 97 case 2048U: 98 S->pTwiddle = WeightsQ31_2048; 99 S->pCosFactor = cos_factorsQ31_2048; 100 break; 101 #endif 102 103 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q31_512) 104 case 512U: 105 S->pTwiddle = WeightsQ31_512; 106 S->pCosFactor = cos_factorsQ31_512; 107 break; 108 #endif 109 110 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q31_128) 111 case 128U: 112 S->pTwiddle = WeightsQ31_128; 113 S->pCosFactor = cos_factorsQ31_128; 114 break; 115 #endif 116 default: 117 status = ARM_MATH_ARGUMENT_ERROR; 118 } 119 120 /* Initialize the RFFT/RIFFT Function */ 121 arm_rfft_init_q31(S->pRfft, S->N, 0U, 1U); 122 123 /* return the status of DCT4 Init function */ 124 return (status); 125 } 126 127 /** 128 @} end of DCT4_IDCT4 group 129 */