CMSIS DSP library

Dependents:   performance_timer Surfboard_ gps2rtty Capstone ... more

Legacy Warning

This is an mbed 2 library. To learn more about mbed OS 5, visit the docs.

Committer:
emilmont
Date:
Wed Nov 28 12:30:09 2012 +0000
Revision:
1:fdd22bb7aa52
Child:
2:da51fb522205
DSP library code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:fdd22bb7aa52 1 /* ----------------------------------------------------------------------
emilmont 1:fdd22bb7aa52 2 * Copyright (C) 2010 ARM Limited. All rights reserved.
emilmont 1:fdd22bb7aa52 3 *
emilmont 1:fdd22bb7aa52 4 * $Date: 15. February 2012
emilmont 1:fdd22bb7aa52 5 * $Revision: V1.1.0
emilmont 1:fdd22bb7aa52 6 *
emilmont 1:fdd22bb7aa52 7 * Project: CMSIS DSP Library
emilmont 1:fdd22bb7aa52 8 * Title: arm_dct4_q31.c
emilmont 1:fdd22bb7aa52 9 *
emilmont 1:fdd22bb7aa52 10 * Description: Processing function of DCT4 & IDCT4 Q31.
emilmont 1:fdd22bb7aa52 11 *
emilmont 1:fdd22bb7aa52 12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
emilmont 1:fdd22bb7aa52 13 *
emilmont 1:fdd22bb7aa52 14 * Version 1.1.0 2012/02/15
emilmont 1:fdd22bb7aa52 15 * Updated with more optimizations, bug fixes and minor API changes.
emilmont 1:fdd22bb7aa52 16 *
emilmont 1:fdd22bb7aa52 17 * Version 1.0.10 2011/7/15
emilmont 1:fdd22bb7aa52 18 * Big Endian support added and Merged M0 and M3/M4 Source code.
emilmont 1:fdd22bb7aa52 19 *
emilmont 1:fdd22bb7aa52 20 * Version 1.0.3 2010/11/29
emilmont 1:fdd22bb7aa52 21 * Re-organized the CMSIS folders and updated documentation.
emilmont 1:fdd22bb7aa52 22 *
emilmont 1:fdd22bb7aa52 23 * Version 1.0.2 2010/11/11
emilmont 1:fdd22bb7aa52 24 * Documentation updated.
emilmont 1:fdd22bb7aa52 25 *
emilmont 1:fdd22bb7aa52 26 * Version 1.0.1 2010/10/05
emilmont 1:fdd22bb7aa52 27 * Production release and review comments incorporated.
emilmont 1:fdd22bb7aa52 28 *
emilmont 1:fdd22bb7aa52 29 * Version 1.0.0 2010/09/20
emilmont 1:fdd22bb7aa52 30 * Production release and review comments incorporated.
emilmont 1:fdd22bb7aa52 31 * -------------------------------------------------------------------- */
emilmont 1:fdd22bb7aa52 32
emilmont 1:fdd22bb7aa52 33 #include "arm_math.h"
emilmont 1:fdd22bb7aa52 34
emilmont 1:fdd22bb7aa52 35 /**
emilmont 1:fdd22bb7aa52 36 * @addtogroup DCT4_IDCT4
emilmont 1:fdd22bb7aa52 37 * @{
emilmont 1:fdd22bb7aa52 38 */
emilmont 1:fdd22bb7aa52 39
emilmont 1:fdd22bb7aa52 40 /**
emilmont 1:fdd22bb7aa52 41 * @brief Processing function for the Q31 DCT4/IDCT4.
emilmont 1:fdd22bb7aa52 42 * @param[in] *S points to an instance of the Q31 DCT4 structure.
emilmont 1:fdd22bb7aa52 43 * @param[in] *pState points to state buffer.
emilmont 1:fdd22bb7aa52 44 * @param[in,out] *pInlineBuffer points to the in-place input and output buffer.
emilmont 1:fdd22bb7aa52 45 * @return none.
emilmont 1:fdd22bb7aa52 46 * \par Input an output formats:
emilmont 1:fdd22bb7aa52 47 * Input samples need to be downscaled by 1 bit to avoid saturations in the Q31 DCT process,
emilmont 1:fdd22bb7aa52 48 * as the conversion from DCT2 to DCT4 involves one subtraction.
emilmont 1:fdd22bb7aa52 49 * Internally inputs are downscaled in the RFFT process function to avoid overflows.
emilmont 1:fdd22bb7aa52 50 * Number of bits downscaled, depends on the size of the transform.
emilmont 1:fdd22bb7aa52 51 * The input and output formats for different DCT sizes and number of bits to upscale are mentioned in the table below:
emilmont 1:fdd22bb7aa52 52 *
emilmont 1:fdd22bb7aa52 53 * \image html dct4FormatsQ31Table.gif
emilmont 1:fdd22bb7aa52 54 */
emilmont 1:fdd22bb7aa52 55
emilmont 1:fdd22bb7aa52 56 void arm_dct4_q31(
emilmont 1:fdd22bb7aa52 57 const arm_dct4_instance_q31 * S,
emilmont 1:fdd22bb7aa52 58 q31_t * pState,
emilmont 1:fdd22bb7aa52 59 q31_t * pInlineBuffer)
emilmont 1:fdd22bb7aa52 60 {
emilmont 1:fdd22bb7aa52 61 uint16_t i; /* Loop counter */
emilmont 1:fdd22bb7aa52 62 q31_t *weights = S->pTwiddle; /* Pointer to the Weights table */
emilmont 1:fdd22bb7aa52 63 q31_t *cosFact = S->pCosFactor; /* Pointer to the cos factors table */
emilmont 1:fdd22bb7aa52 64 q31_t *pS1, *pS2, *pbuff; /* Temporary pointers for input buffer and pState buffer */
emilmont 1:fdd22bb7aa52 65 q31_t in; /* Temporary variable */
emilmont 1:fdd22bb7aa52 66
emilmont 1:fdd22bb7aa52 67
emilmont 1:fdd22bb7aa52 68 /* DCT4 computation involves DCT2 (which is calculated using RFFT)
emilmont 1:fdd22bb7aa52 69 * along with some pre-processing and post-processing.
emilmont 1:fdd22bb7aa52 70 * Computational procedure is explained as follows:
emilmont 1:fdd22bb7aa52 71 * (a) Pre-processing involves multiplying input with cos factor,
emilmont 1:fdd22bb7aa52 72 * r(n) = 2 * u(n) * cos(pi*(2*n+1)/(4*n))
emilmont 1:fdd22bb7aa52 73 * where,
emilmont 1:fdd22bb7aa52 74 * r(n) -- output of preprocessing
emilmont 1:fdd22bb7aa52 75 * u(n) -- input to preprocessing(actual Source buffer)
emilmont 1:fdd22bb7aa52 76 * (b) Calculation of DCT2 using FFT is divided into three steps:
emilmont 1:fdd22bb7aa52 77 * Step1: Re-ordering of even and odd elements of input.
emilmont 1:fdd22bb7aa52 78 * Step2: Calculating FFT of the re-ordered input.
emilmont 1:fdd22bb7aa52 79 * Step3: Taking the real part of the product of FFT output and weights.
emilmont 1:fdd22bb7aa52 80 * (c) Post-processing - DCT4 can be obtained from DCT2 output using the following equation:
emilmont 1:fdd22bb7aa52 81 * Y4(k) = Y2(k) - Y4(k-1) and Y4(-1) = Y4(0)
emilmont 1:fdd22bb7aa52 82 * where,
emilmont 1:fdd22bb7aa52 83 * Y4 -- DCT4 output, Y2 -- DCT2 output
emilmont 1:fdd22bb7aa52 84 * (d) Multiplying the output with the normalizing factor sqrt(2/N).
emilmont 1:fdd22bb7aa52 85 */
emilmont 1:fdd22bb7aa52 86
emilmont 1:fdd22bb7aa52 87 /*-------- Pre-processing ------------*/
emilmont 1:fdd22bb7aa52 88 /* Multiplying input with cos factor i.e. r(n) = 2 * x(n) * cos(pi*(2*n+1)/(4*n)) */
emilmont 1:fdd22bb7aa52 89 arm_mult_q31(pInlineBuffer, cosFact, pInlineBuffer, S->N);
emilmont 1:fdd22bb7aa52 90 arm_shift_q31(pInlineBuffer, 1, pInlineBuffer, S->N);
emilmont 1:fdd22bb7aa52 91
emilmont 1:fdd22bb7aa52 92 /* ----------------------------------------------------------------
emilmont 1:fdd22bb7aa52 93 * Step1: Re-ordering of even and odd elements as
emilmont 1:fdd22bb7aa52 94 * pState[i] = pInlineBuffer[2*i] and
emilmont 1:fdd22bb7aa52 95 * pState[N-i-1] = pInlineBuffer[2*i+1] where i = 0 to N/2
emilmont 1:fdd22bb7aa52 96 ---------------------------------------------------------------------*/
emilmont 1:fdd22bb7aa52 97
emilmont 1:fdd22bb7aa52 98 /* pS1 initialized to pState */
emilmont 1:fdd22bb7aa52 99 pS1 = pState;
emilmont 1:fdd22bb7aa52 100
emilmont 1:fdd22bb7aa52 101 /* pS2 initialized to pState+N-1, so that it points to the end of the state buffer */
emilmont 1:fdd22bb7aa52 102 pS2 = pState + (S->N - 1u);
emilmont 1:fdd22bb7aa52 103
emilmont 1:fdd22bb7aa52 104 /* pbuff initialized to input buffer */
emilmont 1:fdd22bb7aa52 105 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 106
emilmont 1:fdd22bb7aa52 107 #ifndef ARM_MATH_CM0
emilmont 1:fdd22bb7aa52 108
emilmont 1:fdd22bb7aa52 109 /* Run the below code for Cortex-M4 and Cortex-M3 */
emilmont 1:fdd22bb7aa52 110
emilmont 1:fdd22bb7aa52 111 /* Initializing the loop counter to N/2 >> 2 for loop unrolling by 4 */
emilmont 1:fdd22bb7aa52 112 i = S->Nby2 >> 2u;
emilmont 1:fdd22bb7aa52 113
emilmont 1:fdd22bb7aa52 114 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
emilmont 1:fdd22bb7aa52 115 ** a second loop below computes the remaining 1 to 3 samples. */
emilmont 1:fdd22bb7aa52 116 do
emilmont 1:fdd22bb7aa52 117 {
emilmont 1:fdd22bb7aa52 118 /* Re-ordering of even and odd elements */
emilmont 1:fdd22bb7aa52 119 /* pState[i] = pInlineBuffer[2*i] */
emilmont 1:fdd22bb7aa52 120 *pS1++ = *pbuff++;
emilmont 1:fdd22bb7aa52 121 /* pState[N-i-1] = pInlineBuffer[2*i+1] */
emilmont 1:fdd22bb7aa52 122 *pS2-- = *pbuff++;
emilmont 1:fdd22bb7aa52 123
emilmont 1:fdd22bb7aa52 124 *pS1++ = *pbuff++;
emilmont 1:fdd22bb7aa52 125 *pS2-- = *pbuff++;
emilmont 1:fdd22bb7aa52 126
emilmont 1:fdd22bb7aa52 127 *pS1++ = *pbuff++;
emilmont 1:fdd22bb7aa52 128 *pS2-- = *pbuff++;
emilmont 1:fdd22bb7aa52 129
emilmont 1:fdd22bb7aa52 130 *pS1++ = *pbuff++;
emilmont 1:fdd22bb7aa52 131 *pS2-- = *pbuff++;
emilmont 1:fdd22bb7aa52 132
emilmont 1:fdd22bb7aa52 133 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 134 i--;
emilmont 1:fdd22bb7aa52 135 } while(i > 0u);
emilmont 1:fdd22bb7aa52 136
emilmont 1:fdd22bb7aa52 137 /* pbuff initialized to input buffer */
emilmont 1:fdd22bb7aa52 138 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 139
emilmont 1:fdd22bb7aa52 140 /* pS1 initialized to pState */
emilmont 1:fdd22bb7aa52 141 pS1 = pState;
emilmont 1:fdd22bb7aa52 142
emilmont 1:fdd22bb7aa52 143 /* Initializing the loop counter to N/4 instead of N for loop unrolling */
emilmont 1:fdd22bb7aa52 144 i = S->N >> 2u;
emilmont 1:fdd22bb7aa52 145
emilmont 1:fdd22bb7aa52 146 /* Processing with loop unrolling 4 times as N is always multiple of 4.
emilmont 1:fdd22bb7aa52 147 * Compute 4 outputs at a time */
emilmont 1:fdd22bb7aa52 148 do
emilmont 1:fdd22bb7aa52 149 {
emilmont 1:fdd22bb7aa52 150 /* Writing the re-ordered output back to inplace input buffer */
emilmont 1:fdd22bb7aa52 151 *pbuff++ = *pS1++;
emilmont 1:fdd22bb7aa52 152 *pbuff++ = *pS1++;
emilmont 1:fdd22bb7aa52 153 *pbuff++ = *pS1++;
emilmont 1:fdd22bb7aa52 154 *pbuff++ = *pS1++;
emilmont 1:fdd22bb7aa52 155
emilmont 1:fdd22bb7aa52 156 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 157 i--;
emilmont 1:fdd22bb7aa52 158 } while(i > 0u);
emilmont 1:fdd22bb7aa52 159
emilmont 1:fdd22bb7aa52 160
emilmont 1:fdd22bb7aa52 161 /* ---------------------------------------------------------
emilmont 1:fdd22bb7aa52 162 * Step2: Calculate RFFT for N-point input
emilmont 1:fdd22bb7aa52 163 * ---------------------------------------------------------- */
emilmont 1:fdd22bb7aa52 164 /* pInlineBuffer is real input of length N , pState is the complex output of length 2N */
emilmont 1:fdd22bb7aa52 165 arm_rfft_q31(S->pRfft, pInlineBuffer, pState);
emilmont 1:fdd22bb7aa52 166
emilmont 1:fdd22bb7aa52 167 /*----------------------------------------------------------------------
emilmont 1:fdd22bb7aa52 168 * Step3: Multiply the FFT output with the weights.
emilmont 1:fdd22bb7aa52 169 *----------------------------------------------------------------------*/
emilmont 1:fdd22bb7aa52 170 arm_cmplx_mult_cmplx_q31(pState, weights, pState, S->N);
emilmont 1:fdd22bb7aa52 171
emilmont 1:fdd22bb7aa52 172 /* The output of complex multiplication is in 3.29 format.
emilmont 1:fdd22bb7aa52 173 * Hence changing the format of N (i.e. 2*N elements) complex numbers to 1.31 format by shifting left by 2 bits. */
emilmont 1:fdd22bb7aa52 174 arm_shift_q31(pState, 2, pState, S->N * 2);
emilmont 1:fdd22bb7aa52 175
emilmont 1:fdd22bb7aa52 176 /* ----------- Post-processing ---------- */
emilmont 1:fdd22bb7aa52 177 /* DCT-IV can be obtained from DCT-II by the equation,
emilmont 1:fdd22bb7aa52 178 * Y4(k) = Y2(k) - Y4(k-1) and Y4(-1) = Y4(0)
emilmont 1:fdd22bb7aa52 179 * Hence, Y4(0) = Y2(0)/2 */
emilmont 1:fdd22bb7aa52 180 /* Getting only real part from the output and Converting to DCT-IV */
emilmont 1:fdd22bb7aa52 181
emilmont 1:fdd22bb7aa52 182 /* Initializing the loop counter to N >> 2 for loop unrolling by 4 */
emilmont 1:fdd22bb7aa52 183 i = (S->N - 1u) >> 2u;
emilmont 1:fdd22bb7aa52 184
emilmont 1:fdd22bb7aa52 185 /* pbuff initialized to input buffer. */
emilmont 1:fdd22bb7aa52 186 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 187
emilmont 1:fdd22bb7aa52 188 /* pS1 initialized to pState */
emilmont 1:fdd22bb7aa52 189 pS1 = pState;
emilmont 1:fdd22bb7aa52 190
emilmont 1:fdd22bb7aa52 191 /* Calculating Y4(0) from Y2(0) using Y4(0) = Y2(0)/2 */
emilmont 1:fdd22bb7aa52 192 in = *pS1++ >> 1u;
emilmont 1:fdd22bb7aa52 193 /* input buffer acts as inplace, so output values are stored in the input itself. */
emilmont 1:fdd22bb7aa52 194 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 195
emilmont 1:fdd22bb7aa52 196 /* pState pointer is incremented twice as the real values are located alternatively in the array */
emilmont 1:fdd22bb7aa52 197 pS1++;
emilmont 1:fdd22bb7aa52 198
emilmont 1:fdd22bb7aa52 199 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
emilmont 1:fdd22bb7aa52 200 ** a second loop below computes the remaining 1 to 3 samples. */
emilmont 1:fdd22bb7aa52 201 do
emilmont 1:fdd22bb7aa52 202 {
emilmont 1:fdd22bb7aa52 203 /* Calculating Y4(1) to Y4(N-1) from Y2 using equation Y4(k) = Y2(k) - Y4(k-1) */
emilmont 1:fdd22bb7aa52 204 /* pState pointer (pS1) is incremented twice as the real values are located alternatively in the array */
emilmont 1:fdd22bb7aa52 205 in = *pS1++ - in;
emilmont 1:fdd22bb7aa52 206 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 207 /* points to the next real value */
emilmont 1:fdd22bb7aa52 208 pS1++;
emilmont 1:fdd22bb7aa52 209
emilmont 1:fdd22bb7aa52 210 in = *pS1++ - in;
emilmont 1:fdd22bb7aa52 211 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 212 pS1++;
emilmont 1:fdd22bb7aa52 213
emilmont 1:fdd22bb7aa52 214 in = *pS1++ - in;
emilmont 1:fdd22bb7aa52 215 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 216 pS1++;
emilmont 1:fdd22bb7aa52 217
emilmont 1:fdd22bb7aa52 218 in = *pS1++ - in;
emilmont 1:fdd22bb7aa52 219 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 220 pS1++;
emilmont 1:fdd22bb7aa52 221
emilmont 1:fdd22bb7aa52 222 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 223 i--;
emilmont 1:fdd22bb7aa52 224 } while(i > 0u);
emilmont 1:fdd22bb7aa52 225
emilmont 1:fdd22bb7aa52 226 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
emilmont 1:fdd22bb7aa52 227 ** No loop unrolling is used. */
emilmont 1:fdd22bb7aa52 228 i = (S->N - 1u) % 0x4u;
emilmont 1:fdd22bb7aa52 229
emilmont 1:fdd22bb7aa52 230 while(i > 0u)
emilmont 1:fdd22bb7aa52 231 {
emilmont 1:fdd22bb7aa52 232 /* Calculating Y4(1) to Y4(N-1) from Y2 using equation Y4(k) = Y2(k) - Y4(k-1) */
emilmont 1:fdd22bb7aa52 233 /* pState pointer (pS1) is incremented twice as the real values are located alternatively in the array */
emilmont 1:fdd22bb7aa52 234 in = *pS1++ - in;
emilmont 1:fdd22bb7aa52 235 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 236 /* points to the next real value */
emilmont 1:fdd22bb7aa52 237 pS1++;
emilmont 1:fdd22bb7aa52 238
emilmont 1:fdd22bb7aa52 239 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 240 i--;
emilmont 1:fdd22bb7aa52 241 }
emilmont 1:fdd22bb7aa52 242
emilmont 1:fdd22bb7aa52 243
emilmont 1:fdd22bb7aa52 244 /*------------ Normalizing the output by multiplying with the normalizing factor ----------*/
emilmont 1:fdd22bb7aa52 245
emilmont 1:fdd22bb7aa52 246 /* Initializing the loop counter to N/4 instead of N for loop unrolling */
emilmont 1:fdd22bb7aa52 247 i = S->N >> 2u;
emilmont 1:fdd22bb7aa52 248
emilmont 1:fdd22bb7aa52 249 /* pbuff initialized to the pInlineBuffer(now contains the output values) */
emilmont 1:fdd22bb7aa52 250 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 251
emilmont 1:fdd22bb7aa52 252 /* Processing with loop unrolling 4 times as N is always multiple of 4. Compute 4 outputs at a time */
emilmont 1:fdd22bb7aa52 253 do
emilmont 1:fdd22bb7aa52 254 {
emilmont 1:fdd22bb7aa52 255 /* Multiplying pInlineBuffer with the normalizing factor sqrt(2/N) */
emilmont 1:fdd22bb7aa52 256 in = *pbuff;
emilmont 1:fdd22bb7aa52 257 *pbuff++ = ((q31_t) (((q63_t) in * S->normalize) >> 31));
emilmont 1:fdd22bb7aa52 258
emilmont 1:fdd22bb7aa52 259 in = *pbuff;
emilmont 1:fdd22bb7aa52 260 *pbuff++ = ((q31_t) (((q63_t) in * S->normalize) >> 31));
emilmont 1:fdd22bb7aa52 261
emilmont 1:fdd22bb7aa52 262 in = *pbuff;
emilmont 1:fdd22bb7aa52 263 *pbuff++ = ((q31_t) (((q63_t) in * S->normalize) >> 31));
emilmont 1:fdd22bb7aa52 264
emilmont 1:fdd22bb7aa52 265 in = *pbuff;
emilmont 1:fdd22bb7aa52 266 *pbuff++ = ((q31_t) (((q63_t) in * S->normalize) >> 31));
emilmont 1:fdd22bb7aa52 267
emilmont 1:fdd22bb7aa52 268 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 269 i--;
emilmont 1:fdd22bb7aa52 270 } while(i > 0u);
emilmont 1:fdd22bb7aa52 271
emilmont 1:fdd22bb7aa52 272
emilmont 1:fdd22bb7aa52 273 #else
emilmont 1:fdd22bb7aa52 274
emilmont 1:fdd22bb7aa52 275 /* Run the below code for Cortex-M0 */
emilmont 1:fdd22bb7aa52 276
emilmont 1:fdd22bb7aa52 277 /* Initializing the loop counter to N/2 */
emilmont 1:fdd22bb7aa52 278 i = S->Nby2;
emilmont 1:fdd22bb7aa52 279
emilmont 1:fdd22bb7aa52 280 do
emilmont 1:fdd22bb7aa52 281 {
emilmont 1:fdd22bb7aa52 282 /* Re-ordering of even and odd elements */
emilmont 1:fdd22bb7aa52 283 /* pState[i] = pInlineBuffer[2*i] */
emilmont 1:fdd22bb7aa52 284 *pS1++ = *pbuff++;
emilmont 1:fdd22bb7aa52 285 /* pState[N-i-1] = pInlineBuffer[2*i+1] */
emilmont 1:fdd22bb7aa52 286 *pS2-- = *pbuff++;
emilmont 1:fdd22bb7aa52 287
emilmont 1:fdd22bb7aa52 288 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 289 i--;
emilmont 1:fdd22bb7aa52 290 } while(i > 0u);
emilmont 1:fdd22bb7aa52 291
emilmont 1:fdd22bb7aa52 292 /* pbuff initialized to input buffer */
emilmont 1:fdd22bb7aa52 293 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 294
emilmont 1:fdd22bb7aa52 295 /* pS1 initialized to pState */
emilmont 1:fdd22bb7aa52 296 pS1 = pState;
emilmont 1:fdd22bb7aa52 297
emilmont 1:fdd22bb7aa52 298 /* Initializing the loop counter */
emilmont 1:fdd22bb7aa52 299 i = S->N;
emilmont 1:fdd22bb7aa52 300
emilmont 1:fdd22bb7aa52 301 do
emilmont 1:fdd22bb7aa52 302 {
emilmont 1:fdd22bb7aa52 303 /* Writing the re-ordered output back to inplace input buffer */
emilmont 1:fdd22bb7aa52 304 *pbuff++ = *pS1++;
emilmont 1:fdd22bb7aa52 305
emilmont 1:fdd22bb7aa52 306 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 307 i--;
emilmont 1:fdd22bb7aa52 308 } while(i > 0u);
emilmont 1:fdd22bb7aa52 309
emilmont 1:fdd22bb7aa52 310
emilmont 1:fdd22bb7aa52 311 /* ---------------------------------------------------------
emilmont 1:fdd22bb7aa52 312 * Step2: Calculate RFFT for N-point input
emilmont 1:fdd22bb7aa52 313 * ---------------------------------------------------------- */
emilmont 1:fdd22bb7aa52 314 /* pInlineBuffer is real input of length N , pState is the complex output of length 2N */
emilmont 1:fdd22bb7aa52 315 arm_rfft_q31(S->pRfft, pInlineBuffer, pState);
emilmont 1:fdd22bb7aa52 316
emilmont 1:fdd22bb7aa52 317 /*----------------------------------------------------------------------
emilmont 1:fdd22bb7aa52 318 * Step3: Multiply the FFT output with the weights.
emilmont 1:fdd22bb7aa52 319 *----------------------------------------------------------------------*/
emilmont 1:fdd22bb7aa52 320 arm_cmplx_mult_cmplx_q31(pState, weights, pState, S->N);
emilmont 1:fdd22bb7aa52 321
emilmont 1:fdd22bb7aa52 322 /* The output of complex multiplication is in 3.29 format.
emilmont 1:fdd22bb7aa52 323 * Hence changing the format of N (i.e. 2*N elements) complex numbers to 1.31 format by shifting left by 2 bits. */
emilmont 1:fdd22bb7aa52 324 arm_shift_q31(pState, 2, pState, S->N * 2);
emilmont 1:fdd22bb7aa52 325
emilmont 1:fdd22bb7aa52 326 /* ----------- Post-processing ---------- */
emilmont 1:fdd22bb7aa52 327 /* DCT-IV can be obtained from DCT-II by the equation,
emilmont 1:fdd22bb7aa52 328 * Y4(k) = Y2(k) - Y4(k-1) and Y4(-1) = Y4(0)
emilmont 1:fdd22bb7aa52 329 * Hence, Y4(0) = Y2(0)/2 */
emilmont 1:fdd22bb7aa52 330 /* Getting only real part from the output and Converting to DCT-IV */
emilmont 1:fdd22bb7aa52 331
emilmont 1:fdd22bb7aa52 332 /* pbuff initialized to input buffer. */
emilmont 1:fdd22bb7aa52 333 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 334
emilmont 1:fdd22bb7aa52 335 /* pS1 initialized to pState */
emilmont 1:fdd22bb7aa52 336 pS1 = pState;
emilmont 1:fdd22bb7aa52 337
emilmont 1:fdd22bb7aa52 338 /* Calculating Y4(0) from Y2(0) using Y4(0) = Y2(0)/2 */
emilmont 1:fdd22bb7aa52 339 in = *pS1++ >> 1u;
emilmont 1:fdd22bb7aa52 340 /* input buffer acts as inplace, so output values are stored in the input itself. */
emilmont 1:fdd22bb7aa52 341 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 342
emilmont 1:fdd22bb7aa52 343 /* pState pointer is incremented twice as the real values are located alternatively in the array */
emilmont 1:fdd22bb7aa52 344 pS1++;
emilmont 1:fdd22bb7aa52 345
emilmont 1:fdd22bb7aa52 346 /* Initializing the loop counter */
emilmont 1:fdd22bb7aa52 347 i = (S->N - 1u);
emilmont 1:fdd22bb7aa52 348
emilmont 1:fdd22bb7aa52 349 while(i > 0u)
emilmont 1:fdd22bb7aa52 350 {
emilmont 1:fdd22bb7aa52 351 /* Calculating Y4(1) to Y4(N-1) from Y2 using equation Y4(k) = Y2(k) - Y4(k-1) */
emilmont 1:fdd22bb7aa52 352 /* pState pointer (pS1) is incremented twice as the real values are located alternatively in the array */
emilmont 1:fdd22bb7aa52 353 in = *pS1++ - in;
emilmont 1:fdd22bb7aa52 354 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 355 /* points to the next real value */
emilmont 1:fdd22bb7aa52 356 pS1++;
emilmont 1:fdd22bb7aa52 357
emilmont 1:fdd22bb7aa52 358 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 359 i--;
emilmont 1:fdd22bb7aa52 360 }
emilmont 1:fdd22bb7aa52 361
emilmont 1:fdd22bb7aa52 362
emilmont 1:fdd22bb7aa52 363 /*------------ Normalizing the output by multiplying with the normalizing factor ----------*/
emilmont 1:fdd22bb7aa52 364
emilmont 1:fdd22bb7aa52 365 /* Initializing the loop counter */
emilmont 1:fdd22bb7aa52 366 i = S->N;
emilmont 1:fdd22bb7aa52 367
emilmont 1:fdd22bb7aa52 368 /* pbuff initialized to the pInlineBuffer(now contains the output values) */
emilmont 1:fdd22bb7aa52 369 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 370
emilmont 1:fdd22bb7aa52 371 do
emilmont 1:fdd22bb7aa52 372 {
emilmont 1:fdd22bb7aa52 373 /* Multiplying pInlineBuffer with the normalizing factor sqrt(2/N) */
emilmont 1:fdd22bb7aa52 374 in = *pbuff;
emilmont 1:fdd22bb7aa52 375 *pbuff++ = ((q31_t) (((q63_t) in * S->normalize) >> 31));
emilmont 1:fdd22bb7aa52 376
emilmont 1:fdd22bb7aa52 377 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 378 i--;
emilmont 1:fdd22bb7aa52 379 } while(i > 0u);
emilmont 1:fdd22bb7aa52 380
emilmont 1:fdd22bb7aa52 381 #endif /* #ifndef ARM_MATH_CM0 */
emilmont 1:fdd22bb7aa52 382
emilmont 1:fdd22bb7aa52 383 }
emilmont 1:fdd22bb7aa52 384
emilmont 1:fdd22bb7aa52 385 /**
emilmont 1:fdd22bb7aa52 386 * @} end of DCT4_IDCT4 group
emilmont 1:fdd22bb7aa52 387 */