Subversion Repositories AFRtranscoder

Rev

Blame | Last modification | View Log | Download | RSS feed

  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:        27. January 2017
  7.  * $Revision:    V.1.5.1
  8.  *
  9.  * Target Processor: Cortex-M cores
  10.  * -------------------------------------------------------------------- */
  11. /*
  12.  * Copyright (C) 2010-2017 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 "arm_math.h"
  30.  
  31. /**
  32.  * @ingroup DCT4_IDCT4
  33.  */
  34.  
  35. /**
  36.  * @addtogroup DCT4_IDCT4_Table DCT Type IV Tables
  37.  * @{
  38.  */
  39.  
  40. /*
  41. * @brief  Weights Table
  42. */
  43.  
  44. /**
  45.  * \par
  46.  * Weights tables are generated using the formula : <pre>weights[n] = e^(-j*n*pi/(2*N))</pre>
  47.  * \par
  48.  * C command to generate the table
  49.  * <pre>
  50.  * for(i = 0; i< N; i++)
  51.  * {
  52.  *   weights[2*i]= cos(i*c);
  53.  *   weights[(2*i)+1]= -sin(i * c);
  54.  * } </pre>
  55.  * \par
  56.  * where <code>N</code> is the Number of weights to be calculated and <code>c</code> is <code>pi/(2*N)</code>
  57.  * \par
  58.  * Convert the output to q31 format by multiplying with 2^31 and saturated if required.
  59.  * \par
  60.  * In the tables below the real and imaginary values are placed alternatively, hence the
  61.  * array length is <code>2*N</code>.
  62.  *//**
  63. * \par
  64. * cosFactor tables are generated using the formula : <pre>cos_factors[n] = 2 * cos((2n+1)*pi/(4*N))</pre>
  65. * \par
  66. * C command to generate the table
  67. * <pre>
  68. * for(i = 0; i< N; i++)
  69. * {
  70. *   cos_factors[i]= 2 * cos((2*i+1)*c/2);
  71. * } </pre>
  72. * \par
  73. * where <code>N</code> is the number of factors to generate and <code>c</code> is <code>pi/(2*N)</code>
  74. * \par
  75. * Then converted to q31 format by multiplying with 2^31 and saturated if required.
  76. *//**
  77.  * @} end of DCT4_IDCT4_Table group
  78.  */
  79.  
  80. /**
  81.  * @addtogroup DCT4_IDCT4
  82.  * @{
  83.  */
  84.  
  85. /**
  86.  * @brief  Initialization function for the Q31 DCT4/IDCT4.
  87.  * @param[in,out] *S         points to an instance of Q31 DCT4/IDCT4 structure.
  88.  * @param[in]     *S_RFFT    points to an instance of Q31 RFFT/RIFFT structure
  89.  * @param[in]     *S_CFFT    points to an instance of Q31 CFFT/CIFFT structure
  90.  * @param[in]     N          length of the DCT4.
  91.  * @param[in]     Nby2       half of the length of the DCT4.
  92.  * @param[in]     normalize  normalizing factor.
  93.  * @return                arm_status function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if <code>N</code> is not a supported transform length.
  94.  * \par Normalizing factor:
  95.  * The normalizing factor is <code>sqrt(2/N)</code>, which depends on the size of transform <code>N</code>.
  96.  * Normalizing factors in 1.31 format are mentioned in the table below for different DCT sizes:
  97.  * \image html dct4NormalizingQ31Table.gif
  98.  */
  99.  
  100. arm_status arm_dct4_init_q31(
  101.   arm_dct4_instance_q31 * S,
  102.   arm_rfft_instance_q31 * S_RFFT,
  103.   arm_cfft_radix4_instance_q31 * S_CFFT,
  104.   uint16_t N,
  105.   uint16_t Nby2,
  106.   q31_t normalize)
  107. {
  108.   /*  Initialise the default arm status */
  109.   arm_status status = ARM_MATH_SUCCESS;
  110.  
  111.   /* Initializing the pointer array with the weight table base addresses of different lengths */
  112.   q31_t *twiddlePtr[4] = { (q31_t *) WeightsQ31_128, (q31_t *) WeightsQ31_512,
  113.     (q31_t *) WeightsQ31_2048, (q31_t *) WeightsQ31_8192
  114.   };
  115.  
  116.   /* Initializing the pointer array with the cos factor table base addresses of different lengths */
  117.   q31_t *pCosFactor[4] =
  118.     { (q31_t *) cos_factorsQ31_128, (q31_t *) cos_factorsQ31_512,
  119.     (q31_t *) cos_factorsQ31_2048, (q31_t *) cos_factorsQ31_8192
  120.   };
  121.  
  122.   /* Initialize the DCT4 length */
  123.   S->N = N;
  124.  
  125.   /* Initialize the half of DCT4 length */
  126.   S->Nby2 = Nby2;
  127.  
  128.   /* Initialize the DCT4 Normalizing factor */
  129.   S->normalize = normalize;
  130.  
  131.   /* Initialize Real FFT Instance */
  132.   S->pRfft = S_RFFT;
  133.  
  134.   /* Initialize Complex FFT Instance */
  135.   S->pCfft = S_CFFT;
  136.  
  137.   switch (N)
  138.   {
  139.     /* Initialize the table modifier values */
  140.   case 8192U:
  141.     S->pTwiddle = twiddlePtr[3];
  142.     S->pCosFactor = pCosFactor[3];
  143.     break;
  144.   case 2048U:
  145.     S->pTwiddle = twiddlePtr[2];
  146.     S->pCosFactor = pCosFactor[2];
  147.     break;
  148.   case 512U:
  149.     S->pTwiddle = twiddlePtr[1];
  150.     S->pCosFactor = pCosFactor[1];
  151.     break;
  152.   case 128U:
  153.     S->pTwiddle = twiddlePtr[0];
  154.     S->pCosFactor = pCosFactor[0];
  155.     break;
  156.   default:
  157.     status = ARM_MATH_ARGUMENT_ERROR;
  158.   }
  159.  
  160.   /* Initialize the RFFT/RIFFT Function */
  161.   arm_rfft_init_q31(S->pRfft,  S->N, 0, 1);
  162.  
  163.   /* return the status of DCT4 Init function */
  164.   return (status);
  165. }
  166.  
  167. /**
  168.  * @} end of DCT4_IDCT4 group
  169.  */
  170.