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_f32.c    
9
*    
10
* Description:  Initialization function of DCT-4 & IDCT4 F32    
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
* In the tables below the real and imaginary values are placed alternatively, hence the    
72
* array length is <code>2*N</code>.    
73
*//**    
74
 
75
* cosFactor tables are generated using the formula : <pre>cos_factors[n] = 2 * cos((2n+1)*pi/(4*N))</pre>    
76
* \par    
77
* C command to generate the table    
78
* \par    
79
* <pre> for(i = 0; i< N; i++)    
80
* {    
81
*    cos_factors[i]= 2 * cos((2*i+1)*c/2);    
82
* } </pre>    
83
* \par    
84
* where <code>N</code> is the number of factors to generate and <code>c</code> is <code>pi/(2*N)</code>    
85
*//**    
86
 * @brief  Initialization function for the floating-point DCT4/IDCT4.  
87
 * @param[in,out] *S         points to an instance of floating-point DCT4/IDCT4 structure.  
88
 * @param[in]     *S_RFFT    points to an instance of floating-point RFFT/RIFFT structure.  
89
 * @param[in]     *S_CFFT    points to an instance of floating-point 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>fftLenReal</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
 * Floating-point normalizing factors are mentioned in the table below for different DCT sizes:    
97
 * \image html dct4NormalizingF32Table.gif    
98
 */
99
100
arm_status arm_dct4_init_f32(
101
  arm_dct4_instance_f32 * S,
102
  arm_rfft_instance_f32 * S_RFFT,
103
  arm_cfft_radix4_instance_f32 * S_CFFT,
104
  uint16_t N,
105
  uint16_t Nby2,
106
  float32_t normalize)
107
{
108
  /*  Initialize 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
  float32_t *twiddlePtr[4] =
113
    { (float32_t *) Weights_128, (float32_t *) Weights_512,
114
    (float32_t *) Weights_2048, (float32_t *) Weights_8192
115
  };
116
117
  /* Initializing the pointer array with the cos factor table base addresses of different lengths */
118
  float32_t *pCosFactor[4] =
119
    { (float32_t *) cos_factors_128, (float32_t *) cos_factors_512,
120
    (float32_t *) cos_factors_2048, (float32_t *) cos_factors_8192
121
  };
122
123
  /* Initialize the DCT4 length */
124
  S->N = N;
125
126
  /* Initialize the half of DCT4 length */
127
  S->Nby2 = Nby2;
128
129
  /* Initialize the DCT4 Normalizing factor */
130
  S->normalize = normalize;
131
132
  /* Initialize Real FFT Instance */
133
  S->pRfft = S_RFFT;
134
135
  /* Initialize Complex FFT Instance */
136
  S->pCfft = S_CFFT;
137
138
  switch (N)
139
  {
140
    /* Initialize the table modifier values */
141
  case 8192u:
142
    S->pTwiddle = twiddlePtr[3];
143
    S->pCosFactor = pCosFactor[3];
144
    break;
145
  case 2048u:
146
    S->pTwiddle = twiddlePtr[2];
147
    S->pCosFactor = pCosFactor[2];
148
    break;
149
  case 512u:
150
    S->pTwiddle = twiddlePtr[1];
151
    S->pCosFactor = pCosFactor[1];
152
    break;
153
  case 128u:
154
    S->pTwiddle = twiddlePtr[0];
155
    S->pCosFactor = pCosFactor[0];
156
    break;
157
  default:
158
    status = ARM_MATH_ARGUMENT_ERROR;
159
  }
160
161
  /* Initialize the RFFT/RIFFT */
162
  arm_rfft_init_f32(S->pRfft, S->pCfft, S->N, 0u, 1u);
163
164
  /* return the status of DCT4 Init function */
165
  return (status);
166
}
167
168
/**    
169
   * @} end of DCT4_IDCT4 group    
170
   */
171
 
172