/ Drivers / CMSIS / DSP / Source / TransformFunctions / arm_dct4_init_f32.c
arm_dct4_init_f32.c
  1  /* ----------------------------------------------------------------------
  2   * Project:      CMSIS DSP Library
  3   * Title:        arm_dct4_init_f32.c
  4   * Description:  Initialization function of DCT-4 & IDCT4 F32
  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 floating-point DCT4/IDCT4.
 43    @param[in,out] S          points to an instance of floating-point DCT4/IDCT4 structure
 44    @param[in]     S_RFFT     points to an instance of floating-point RFFT/RIFFT structure
 45    @param[in]     S_CFFT     points to an instance of floating-point 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                     Floating-point normalizing factors are mentioned in the table below for different DCT sizes:
 56  
 57                     \image html dct4NormalizingF32Table.gif
 58   */
 59  
 60  arm_status arm_dct4_init_f32(
 61    arm_dct4_instance_f32 * S,
 62    arm_rfft_instance_f32 * S_RFFT,
 63    arm_cfft_radix4_instance_f32 * S_CFFT,
 64    uint16_t N,
 65    uint16_t Nby2,
 66    float32_t normalize)
 67  {
 68    /* Initialize the default arm status */
 69    arm_status status = ARM_MATH_SUCCESS;
 70  
 71  
 72    /* Initialize the DCT4 length */
 73    S->N = N;
 74  
 75    /* Initialize the half of DCT4 length */
 76    S->Nby2 = Nby2;
 77  
 78    /* Initialize the DCT4 Normalizing factor */
 79    S->normalize = normalize;
 80  
 81    /* Initialize Real FFT Instance */
 82    S->pRfft = S_RFFT;
 83  
 84    /* Initialize Complex FFT Instance */
 85    S->pCfft = S_CFFT;
 86  
 87    switch (N)
 88    {
 89    #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_F32_8192)
 90      /* Initialize the table modifier values */
 91    case 8192U:
 92      S->pTwiddle = Weights_8192;
 93      S->pCosFactor = cos_factors_8192;
 94      break;
 95    #endif
 96  
 97    #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_F32_2048)
 98    case 2048U:
 99      S->pTwiddle = Weights_2048;
100      S->pCosFactor = cos_factors_2048;
101      break;
102    #endif
103  
104    #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_F32_512)
105    case 512U:
106      S->pTwiddle = Weights_512;
107      S->pCosFactor = cos_factors_512;
108      break;
109    #endif
110  
111    #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_F32_128)
112    case 128U:
113      S->pTwiddle = Weights_128;
114      S->pCosFactor = cos_factors_128;
115      break;
116    #endif
117    default:
118      status = ARM_MATH_ARGUMENT_ERROR;
119    }
120  
121    /* Initialize the RFFT/RIFFT Function */
122    arm_rfft_init_f32(S->pRfft, S->pCfft, 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   */