Subversion Repositories AFRtranscoder

Rev

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

  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:        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.  * In the tables below the real and imaginary values are placed alternatively, hence the
  59.  * array length is <code>2*N</code>.
  60.  *//**
  61. * \par
  62. * cosFactor tables are generated using the formula : <pre>cos_factors[n] = 2 * cos((2n+1)*pi/(4*N))</pre>
  63. * \par
  64. * C command to generate the table
  65. * \par
  66. * <pre> for(i = 0; i< N; i++)
  67. * {
  68. *    cos_factors[i]= 2 * cos((2*i+1)*c/2);
  69. * } </pre>
  70. * \par
  71. * where <code>N</code> is the number of factors to generate and <code>c</code> is <code>pi/(2*N)</code>
  72. *//**
  73.  * @} end of DCT4_IDCT4_Table group
  74.  */
  75.  
  76. /**
  77.  * @addtogroup DCT4_IDCT4
  78.  * @{
  79.  */
  80.  
  81. /**
  82.  * @brief  Initialization function for the floating-point DCT4/IDCT4.
  83.  * @param[in,out] *S         points to an instance of floating-point DCT4/IDCT4 structure.
  84.  * @param[in]     *S_RFFT    points to an instance of floating-point RFFT/RIFFT structure.
  85.  * @param[in]     *S_CFFT    points to an instance of floating-point CFFT/CIFFT structure.
  86.  * @param[in]     N                      length of the DCT4.
  87.  * @param[in]     Nby2       half of the length of the DCT4.
  88.  * @param[in]     normalize  normalizing factor.
  89.  * @return        arm_status function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if <code>fftLenReal</code> is not a supported transform length.
  90.  * \par Normalizing factor:
  91.  * The normalizing factor is <code>sqrt(2/N)</code>, which depends on the size of transform <code>N</code>.
  92.  * Floating-point normalizing factors are mentioned in the table below for different DCT sizes:
  93.  * \image html dct4NormalizingF32Table.gif
  94.  */
  95.  
  96. arm_status arm_dct4_init_f32(
  97.   arm_dct4_instance_f32 * S,
  98.   arm_rfft_instance_f32 * S_RFFT,
  99.   arm_cfft_radix4_instance_f32 * S_CFFT,
  100.   uint16_t N,
  101.   uint16_t Nby2,
  102.   float32_t normalize)
  103. {
  104.   /*  Initialize the default arm status */
  105.   arm_status status = ARM_MATH_SUCCESS;
  106.  
  107.   /* Initializing the pointer array with the weight table base addresses of different lengths */
  108.   float32_t *twiddlePtr[4] =
  109.     { (float32_t *) Weights_128, (float32_t *) Weights_512,
  110.     (float32_t *) Weights_2048, (float32_t *) Weights_8192
  111.   };
  112.  
  113.   /* Initializing the pointer array with the cos factor table base addresses of different lengths */
  114.   float32_t *pCosFactor[4] =
  115.     { (float32_t *) cos_factors_128, (float32_t *) cos_factors_512,
  116.     (float32_t *) cos_factors_2048, (float32_t *) cos_factors_8192
  117.   };
  118.  
  119.   /* Initialize the DCT4 length */
  120.   S->N = N;
  121.  
  122.   /* Initialize the half of DCT4 length */
  123.   S->Nby2 = Nby2;
  124.  
  125.   /* Initialize the DCT4 Normalizing factor */
  126.   S->normalize = normalize;
  127.  
  128.   /* Initialize Real FFT Instance */
  129.   S->pRfft = S_RFFT;
  130.  
  131.   /* Initialize Complex FFT Instance */
  132.   S->pCfft = S_CFFT;
  133.  
  134.   switch (N)
  135.   {
  136.     /* Initialize the table modifier values */
  137.   case 8192U:
  138.     S->pTwiddle = twiddlePtr[3];
  139.     S->pCosFactor = pCosFactor[3];
  140.     break;
  141.   case 2048U:
  142.     S->pTwiddle = twiddlePtr[2];
  143.     S->pCosFactor = pCosFactor[2];
  144.     break;
  145.   case 512U:
  146.     S->pTwiddle = twiddlePtr[1];
  147.     S->pCosFactor = pCosFactor[1];
  148.     break;
  149.   case 128U:
  150.     S->pTwiddle = twiddlePtr[0];
  151.     S->pCosFactor = pCosFactor[0];
  152.     break;
  153.   default:
  154.     status = ARM_MATH_ARGUMENT_ERROR;
  155.   }
  156.  
  157.   /* Initialize the RFFT/RIFFT */
  158.   arm_rfft_init_f32(S->pRfft, S->pCfft, S->N, 0U, 1U);
  159.  
  160.   /* return the status of DCT4 Init function */
  161.   return (status);
  162. }
  163.  
  164. /**
  165.  * @} end of DCT4_IDCT4 group
  166.  */
  167.