Subversion Repositories AFRtranscoder

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 mjames 1
/* ----------------------------------------------------------------------
2
 * Project:      CMSIS DSP Library
3
 * Title:        arm_dct4_init_q15.c
4
 * Description:  Initialization function of DCT-4 & IDCT4 Q15
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
 * Converted the output to q15 format by multiplying with 2^31 and saturated if required.
59
 * \par
60
 * In the tables below the real and imaginary values are placed alternatively, hence the
61
 * array length is <code>2*N</code>.
62
 *//**
63
 
64
* cosFactor tables are generated using the formula : <pre> cos_factors[n] = 2 * cos((2n+1)*pi/(4*N)) </pre>
65
* \par
66
* C command to generate the table
67
* <pre>
68
* for(i = 0; i< N; i++)
69
* {
70
*   cos_factors[i]= 2 * cos((2*i+1)*c/2);
71
* } </pre>
72
* \par
73
* where <code>N</code> is the number of factors to generate and <code>c</code> is <code>pi/(2*N)</code>
74
* \par
75
* Then converted to q15 format by multiplying with 2^31 and saturated if required.
76
77
*//**
78
 * @} end of DCT4_IDCT4_Table group
79
 */
80
81
/**
82
 * @addtogroup DCT4_IDCT4
83
 * @{
84
 */
85
86
/**
87
 * @brief  Initialization function for the Q15 DCT4/IDCT4.
88
 * @param[in,out] *S         points to an instance of Q15 DCT4/IDCT4 structure.
89
 * @param[in]     *S_RFFT    points to an instance of Q15 RFFT/RIFFT structure.
90
 * @param[in]     *S_CFFT    points to an instance of Q15 CFFT/CIFFT structure.
91
 * @param[in]     N          length of the DCT4.
92
 * @param[in]     Nby2       half of the length of the DCT4.
93
 * @param[in]     normalize  normalizing factor.
94
 * @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.
95
 * \par Normalizing factor:
96
 * The normalizing factor is <code>sqrt(2/N)</code>, which depends on the size of transform <code>N</code>.
97
 * Normalizing factors in 1.15 format are mentioned in the table below for different DCT sizes:
98
 
99
 */
100
101
arm_status arm_dct4_init_q15(
102
  arm_dct4_instance_q15 * S,
103
  arm_rfft_instance_q15 * S_RFFT,
104
  arm_cfft_radix4_instance_q15 * S_CFFT,
105
  uint16_t N,
106
  uint16_t Nby2,
107
  q15_t normalize)
108
{
109
  /*  Initialise the default arm status */
110
  arm_status status = ARM_MATH_SUCCESS;
111
112
  /* Initializing the pointer array with the weight table base addresses of different lengths */
113
  q15_t *twiddlePtr[4] = { (q15_t *) WeightsQ15_128, (q15_t *) WeightsQ15_512,
114
    (q15_t *) WeightsQ15_2048, (q15_t *) WeightsQ15_8192
115
  };
116
117
  /* Initializing the pointer array with the cos factor table base addresses of different lengths */
118
  q15_t *pCosFactor[4] =
119
    { (q15_t *) cos_factorsQ15_128, (q15_t *) cos_factorsQ15_512,
120
    (q15_t *) cos_factorsQ15_2048, (q15_t *) cos_factorsQ15_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_q15(S->pRfft, 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