Subversion Repositories DashDisplay

Rev

Rev 28 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /* ----------------------------------------------------------------------    
  2. * Copyright (C) 2010-2014 ARM Limited. All rights reserved.    
  3. *    
  4. * $Date:        19. March 2015
  5. * $Revision:    V.1.4.5  
  6. *    
  7. * Project:          CMSIS DSP Library    
  8. * Title:            arm_dct4_init_q15.c    
  9. *    
  10. * Description:  Initialization function of DCT-4 & IDCT4 Q15    
  11. *    
  12. * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
  13. *  
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions
  16. * are met:
  17. *   - Redistributions of source code must retain the above copyright
  18. *     notice, this list of conditions and the following disclaimer.
  19. *   - Redistributions in binary form must reproduce the above copyright
  20. *     notice, this list of conditions and the following disclaimer in
  21. *     the documentation and/or other materials provided with the
  22. *     distribution.
  23. *   - Neither the name of ARM LIMITED nor the names of its contributors
  24. *     may be used to endorse or promote products derived from this
  25. *     software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  30. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  31. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  32. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  33. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  34. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  35. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  37. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. * POSSIBILITY OF SUCH DAMAGE.    
  39. * -------------------------------------------------------------------- */
  40.  
  41.  
  42. #include "arm_math.h"
  43.  
  44. /**    
  45.  * @ingroup groupTransforms    
  46.  */
  47.  
  48. /**    
  49.  * @addtogroup DCT4_IDCT4    
  50.  * @{    
  51.  */
  52.  
  53. /*    
  54. * @brief  Weights Table    
  55. */
  56.  
  57. /**    
  58. * \par    
  59. * Weights tables are generated using the formula : <pre>weights[n] = e^(-j*n*pi/(2*N))</pre>    
  60. * \par    
  61. * C command to generate the table    
  62. * <pre>    
  63. * for(i = 0; i< N; i++)    
  64. * {    
  65. *   weights[2*i]= cos(i*c);    
  66. *   weights[(2*i)+1]= -sin(i * c);    
  67. * } </pre>    
  68. * \par    
  69. * where <code>N</code> is the Number of weights to be calculated and <code>c</code> is <code>pi/(2*N)</code>    
  70. * \par    
  71. * Converted the output to q15 format by multiplying with 2^31 and saturated if required.    
  72. * \par    
  73. * In the tables below the real and imaginary values are placed alternatively, hence the    
  74. * array length is <code>2*N</code>.    
  75. *//**    
  76. * \par    
  77. * cosFactor tables are generated using the formula : <pre> cos_factors[n] = 2 * cos((2n+1)*pi/(4*N)) </pre>    
  78. * \par    
  79. * C command to generate the table    
  80. * <pre>    
  81. * for(i = 0; i< N; i++)    
  82. * {    
  83. *   cos_factors[i]= 2 * cos((2*i+1)*c/2);    
  84. * } </pre>    
  85. * \par    
  86. * where <code>N</code> is the number of factors to generate and <code>c</code> is <code>pi/(2*N)</code>    
  87. * \par    
  88. * Then converted to q15 format by multiplying with 2^31 and saturated if required.    
  89.    
  90. *//**    
  91.  * @brief  Initialization function for the Q15 DCT4/IDCT4.  
  92.  * @param[in,out] *S         points to an instance of Q15 DCT4/IDCT4 structure.  
  93.  * @param[in]     *S_RFFT    points to an instance of Q15 RFFT/RIFFT structure.  
  94.  * @param[in]     *S_CFFT    points to an instance of Q15 CFFT/CIFFT structure.  
  95.  * @param[in]     N          length of the DCT4.  
  96.  * @param[in]     Nby2       half of the length of the DCT4.  
  97.  * @param[in]     normalize  normalizing factor.  
  98.  * @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.  
  99.  * \par Normalizing factor:    
  100.  * The normalizing factor is <code>sqrt(2/N)</code>, which depends on the size of transform <code>N</code>.    
  101.  * Normalizing factors in 1.15 format are mentioned in the table below for different DCT sizes:    
  102.  * \image html dct4NormalizingQ15Table.gif    
  103.  */
  104.  
  105. arm_status arm_dct4_init_q15(
  106.   arm_dct4_instance_q15 * S,
  107.   arm_rfft_instance_q15 * S_RFFT,
  108.   arm_cfft_radix4_instance_q15 * S_CFFT,
  109.   uint16_t N,
  110.   uint16_t Nby2,
  111.   q15_t normalize)
  112. {
  113.   /*  Initialise the default arm status */
  114.   arm_status status = ARM_MATH_SUCCESS;
  115.  
  116.   /* Initializing the pointer array with the weight table base addresses of different lengths */
  117.   q15_t *twiddlePtr[4] = { (q15_t *) WeightsQ15_128, (q15_t *) WeightsQ15_512,
  118.     (q15_t *) WeightsQ15_2048, (q15_t *) WeightsQ15_8192
  119.   };
  120.  
  121.   /* Initializing the pointer array with the cos factor table base addresses of different lengths */
  122.   q15_t *pCosFactor[4] =
  123.     { (q15_t *) cos_factorsQ15_128, (q15_t *) cos_factorsQ15_512,
  124.     (q15_t *) cos_factorsQ15_2048, (q15_t *) cos_factorsQ15_8192
  125.   };
  126.  
  127.   /* Initialize the DCT4 length */
  128.   S->N = N;
  129.  
  130.   /* Initialize the half of DCT4 length */
  131.   S->Nby2 = Nby2;
  132.  
  133.   /* Initialize the DCT4 Normalizing factor */
  134.   S->normalize = normalize;
  135.  
  136.   /* Initialize Real FFT Instance */
  137.   S->pRfft = S_RFFT;
  138.  
  139.   /* Initialize Complex FFT Instance */
  140.   S->pCfft = S_CFFT;
  141.  
  142.   switch (N)
  143.   {
  144.     /* Initialize the table modifier values */
  145.   case 8192u:
  146.     S->pTwiddle = twiddlePtr[3];
  147.     S->pCosFactor = pCosFactor[3];
  148.     break;
  149.   case 2048u:
  150.     S->pTwiddle = twiddlePtr[2];
  151.     S->pCosFactor = pCosFactor[2];
  152.     break;
  153.   case 512u:
  154.     S->pTwiddle = twiddlePtr[1];
  155.     S->pCosFactor = pCosFactor[1];
  156.     break;
  157.   case 128u:
  158.     S->pTwiddle = twiddlePtr[0];
  159.     S->pCosFactor = pCosFactor[0];
  160.     break;
  161.   default:
  162.     status = ARM_MATH_ARGUMENT_ERROR;
  163.   }
  164.  
  165.   /* Initialize the RFFT/RIFFT */
  166.   arm_rfft_init_q15(S->pRfft, S->N, 0u, 1u);
  167.  
  168.   /* return the status of DCT4 Init function */
  169.   return (status);
  170. }
  171.  
  172. /**    
  173.    * @} end of DCT4_IDCT4 group    
  174.    */
  175.