Subversion Repositories DashDisplay

Rev

Rev 49 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 mjames 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_q31.c    
9
*    
10
* Description:  Initialization function of DCT-4 & IDCT4 Q31    
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
* Convert the output to q31 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
 
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 q31 format by multiplying with 2^31 and saturated if required.    
89
*//**    
90
 * @brief  Initialization function for the Q31 DCT4/IDCT4.  
91
 * @param[in,out] *S         points to an instance of Q31 DCT4/IDCT4 structure.  
92
 * @param[in]     *S_RFFT    points to an instance of Q31 RFFT/RIFFT structure  
93
 * @param[in]     *S_CFFT    points to an instance of Q31 CFFT/CIFFT structure  
94
 * @param[in]     N          length of the DCT4.  
95
 * @param[in]     Nby2       half of the length of the DCT4.  
96
 * @param[in]     normalize  normalizing factor.  
97
 * @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.  
98
 * \par Normalizing factor:    
99
 * The normalizing factor is <code>sqrt(2/N)</code>, which depends on the size of transform <code>N</code>.    
100
 * Normalizing factors in 1.31 format are mentioned in the table below for different DCT sizes:    
101
 * \image html dct4NormalizingQ31Table.gif    
102
 */
103
104
arm_status arm_dct4_init_q31(
105
  arm_dct4_instance_q31 * S,
106
  arm_rfft_instance_q31 * S_RFFT,
107
  arm_cfft_radix4_instance_q31 * S_CFFT,
108
  uint16_t N,
109
  uint16_t Nby2,
110
  q31_t normalize)
111
{
112
  /*  Initialise the default arm status */
113
  arm_status status = ARM_MATH_SUCCESS;
114
115
  /* Initializing the pointer array with the weight table base addresses of different lengths */
116
  q31_t *twiddlePtr[4] = { (q31_t *) WeightsQ31_128, (q31_t *) WeightsQ31_512,
117
    (q31_t *) WeightsQ31_2048, (q31_t *) WeightsQ31_8192
118
  };
119
120
  /* Initializing the pointer array with the cos factor table base addresses of different lengths */
121
  q31_t *pCosFactor[4] =
122
    { (q31_t *) cos_factorsQ31_128, (q31_t *) cos_factorsQ31_512,
123
    (q31_t *) cos_factorsQ31_2048, (q31_t *) cos_factorsQ31_8192
124
  };
125
126
  /* Initialize the DCT4 length */
127
  S->N = N;
128
129
  /* Initialize the half of DCT4 length */
130
  S->Nby2 = Nby2;
131
132
  /* Initialize the DCT4 Normalizing factor */
133
  S->normalize = normalize;
134
135
  /* Initialize Real FFT Instance */
136
  S->pRfft = S_RFFT;
137
138
  /* Initialize Complex FFT Instance */
139
  S->pCfft = S_CFFT;
140
141
  switch (N)
142
  {
143
 
144
  case 8192u:
145
    S->pTwiddle = twiddlePtr[3];
146
    S->pCosFactor = pCosFactor[3];
147
    break;
148
  case 2048u:
149
    S->pTwiddle = twiddlePtr[2];
150
    S->pCosFactor = pCosFactor[2];
151
    break;
152
  case 512u:
153
    S->pTwiddle = twiddlePtr[1];
154
    S->pCosFactor = pCosFactor[1];
155
    break;
156
  case 128u:
157
    S->pTwiddle = twiddlePtr[0];
158
    S->pCosFactor = pCosFactor[0];
159
    break;
160
  default:
161
    status = ARM_MATH_ARGUMENT_ERROR;
162
  }
163
164
  /* Initialize the RFFT/RIFFT Function */
165
  arm_rfft_init_q31(S->pRfft,  S->N, 0, 1);
166
167
  /* return the status of DCT4 Init function */
168
  return (status);
169
}
170
171
/**    
172
   * @} end of DCT4_IDCT4 group    
173
   */
174
 
175