/ Drivers / CMSIS / DSP / Source / TransformFunctions / arm_dct4_init_q15.c
arm_dct4_init_q15.c
  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    @ingroup groupTransforms
 34   */
 35  
 36   /**
 37    @addtogroup DCT4_IDCT4
 38    @{
 39   */
 40  
 41  /**
 42    @brief         Initialization function for the Q15 DCT4/IDCT4.
 43    @param[in,out] S         points to an instance of Q15 DCT4/IDCT4 structure
 44    @param[in]     S_RFFT    points to an instance of Q15 RFFT/RIFFT structure
 45    @param[in]     S_CFFT    points to an instance of Q15 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.15 format are mentioned in the table below for different DCT sizes:
 56  
 57                     \image html dct4NormalizingQ15Table.gif
 58   */
 59  
 60  arm_status arm_dct4_init_q15(
 61    arm_dct4_instance_q15 * S,
 62    arm_rfft_instance_q15 * S_RFFT,
 63    arm_cfft_radix4_instance_q15 * S_CFFT,
 64    uint16_t N,
 65    uint16_t Nby2,
 66    q15_t normalize)
 67  {
 68    /*  Initialise 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_Q15_8192)
 89      /* Initialize the table modifier values */
 90    case 8192U:
 91      S->pTwiddle = WeightsQ15_8192;
 92      S->pCosFactor = cos_factorsQ15_8192;
 93      break;
 94    #endif
 95  
 96    #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q15_2048)
 97    case 2048U:
 98      S->pTwiddle = WeightsQ15_2048;
 99      S->pCosFactor = cos_factorsQ15_2048;
100      break;
101    #endif
102  
103    #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q15_512)
104    case 512U:
105      S->pTwiddle = WeightsQ15_512;
106      S->pCosFactor = cos_factorsQ15_512;
107      break;
108    #endif 
109  
110    #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q15_128)
111    case 128U:
112      S->pTwiddle = WeightsQ15_128;
113      S->pCosFactor = cos_factorsQ15_128;
114      break;
115    #endif 
116  
117    default:
118      status = ARM_MATH_ARGUMENT_ERROR;
119    }
120  
121    /* Initialize the RFFT/RIFFT */
122    arm_rfft_init_q15(S->pRfft, S->N, 0U, 1U);
123  
124    /* return the status of DCT4 Init function */
125    return (status);
126  }
127  
128  /**
129    @} end of DCT4_IDCT4 group
130   */