arm_dct4_init_q31.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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: 18. March 2019
  7. * $Revision: V1.6.0
  8. *
  9. * Target Processor: Cortex-M cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2019 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. #include "arm_math.h"
  29. #include "arm_common_tables.h"
  30. /**
  31. @ingroup DCT4_IDCT4
  32. */
  33. /**
  34. @addtogroup DCT4_IDCT4
  35. @{
  36. */
  37. /**
  38. @brief Initialization function for the Q31 DCT4/IDCT4.
  39. @param[in,out] S points to an instance of Q31 DCT4/IDCT4 structure.
  40. @param[in] S_RFFT points to an instance of Q31 RFFT/RIFFT structure
  41. @param[in] S_CFFT points to an instance of Q31 CFFT/CIFFT structure
  42. @param[in] N length of the DCT4.
  43. @param[in] Nby2 half of the length of the DCT4.
  44. @param[in] normalize normalizing factor.
  45. @return execution status
  46. - \ref ARM_MATH_SUCCESS : Operation successful
  47. - \ref ARM_MATH_ARGUMENT_ERROR : <code>N</code> is not a supported transform length
  48. @par Normalizing factor:
  49. The normalizing factor is <code>sqrt(2/N)</code>, which depends on the size of transform <code>N</code>.
  50. Normalizing factors in 1.31 format are mentioned in the table below for different DCT sizes:
  51. \image html dct4NormalizingQ31Table.gif
  52. */
  53. arm_status arm_dct4_init_q31(
  54. arm_dct4_instance_q31 * S,
  55. arm_rfft_instance_q31 * S_RFFT,
  56. arm_cfft_radix4_instance_q31 * S_CFFT,
  57. uint16_t N,
  58. uint16_t Nby2,
  59. q31_t normalize)
  60. {
  61. /* Initialize the default arm status */
  62. arm_status status = ARM_MATH_SUCCESS;
  63. /* Initialize the DCT4 length */
  64. S->N = N;
  65. /* Initialize the half of DCT4 length */
  66. S->Nby2 = Nby2;
  67. /* Initialize the DCT4 Normalizing factor */
  68. S->normalize = normalize;
  69. /* Initialize Real FFT Instance */
  70. S->pRfft = S_RFFT;
  71. /* Initialize Complex FFT Instance */
  72. S->pCfft = S_CFFT;
  73. switch (N)
  74. {
  75. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q31_8192)
  76. /* Initialize the table modifier values */
  77. case 8192U:
  78. S->pTwiddle = WeightsQ31_8192;
  79. S->pCosFactor = cos_factorsQ31_8192;
  80. break;
  81. #endif
  82. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q31_2048)
  83. case 2048U:
  84. S->pTwiddle = WeightsQ31_2048;
  85. S->pCosFactor = cos_factorsQ31_2048;
  86. break;
  87. #endif
  88. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q31_512)
  89. case 512U:
  90. S->pTwiddle = WeightsQ31_512;
  91. S->pCosFactor = cos_factorsQ31_512;
  92. break;
  93. #endif
  94. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q31_128)
  95. case 128U:
  96. S->pTwiddle = WeightsQ31_128;
  97. S->pCosFactor = cos_factorsQ31_128;
  98. break;
  99. #endif
  100. default:
  101. status = ARM_MATH_ARGUMENT_ERROR;
  102. }
  103. /* Initialize the RFFT/RIFFT Function */
  104. arm_rfft_init_q31(S->pRfft, S->N, 0U, 1U);
  105. /* return the status of DCT4 Init function */
  106. return (status);
  107. }
  108. /**
  109. @} end of DCT4_IDCT4 group
  110. */