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:
mbed_official
Date:
Fri Nov 20 08:45:18 2015 +0000
Revision:
5:3762170b6d4d
Parent:
3:7a284390b0ce
Synchronized with git revision 2eb940b9a73af188d3004a2575fdfbb05febe62b

Full URL: https://github.com/mbedmicro/mbed/commit/2eb940b9a73af188d3004a2575fdfbb05febe62b/

Added option to build rpc library. closes #1426

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:fdd22bb7aa52 1 /* ----------------------------------------------------------------------
mbed_official 5:3762170b6d4d 2 * Copyright (C) 2010-2014 ARM Limited. All rights reserved.
emilmont 1:fdd22bb7aa52 3 *
mbed_official 5:3762170b6d4d 4 * $Date: 19. March 2015
mbed_official 5:3762170b6d4d 5 * $Revision: V.1.4.5
emilmont 1:fdd22bb7aa52 6 *
emilmont 2:da51fb522205 7 * Project: CMSIS DSP Library
emilmont 2:da51fb522205 8 * Title: arm_dct4_q31.c
emilmont 1:fdd22bb7aa52 9 *
emilmont 2:da51fb522205 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 *
mbed_official 3:7a284390b0ce 14 * Redistribution and use in source and binary forms, with or without
mbed_official 3:7a284390b0ce 15 * modification, are permitted provided that the following conditions
mbed_official 3:7a284390b0ce 16 * are met:
mbed_official 3:7a284390b0ce 17 * - Redistributions of source code must retain the above copyright
mbed_official 3:7a284390b0ce 18 * notice, this list of conditions and the following disclaimer.
mbed_official 3:7a284390b0ce 19 * - Redistributions in binary form must reproduce the above copyright
mbed_official 3:7a284390b0ce 20 * notice, this list of conditions and the following disclaimer in
mbed_official 3:7a284390b0ce 21 * the documentation and/or other materials provided with the
mbed_official 3:7a284390b0ce 22 * distribution.
mbed_official 3:7a284390b0ce 23 * - Neither the name of ARM LIMITED nor the names of its contributors
mbed_official 3:7a284390b0ce 24 * may be used to endorse or promote products derived from this
mbed_official 3:7a284390b0ce 25 * software without specific prior written permission.
mbed_official 3:7a284390b0ce 26 *
mbed_official 3:7a284390b0ce 27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
mbed_official 3:7a284390b0ce 28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
mbed_official 3:7a284390b0ce 29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
mbed_official 3:7a284390b0ce 30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
mbed_official 3:7a284390b0ce 31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
mbed_official 3:7a284390b0ce 32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
mbed_official 3:7a284390b0ce 33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
mbed_official 3:7a284390b0ce 34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 3:7a284390b0ce 35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
mbed_official 3:7a284390b0ce 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
mbed_official 3:7a284390b0ce 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbed_official 3:7a284390b0ce 38 * POSSIBILITY OF SUCH DAMAGE.
emilmont 1:fdd22bb7aa52 39 * -------------------------------------------------------------------- */
emilmont 1:fdd22bb7aa52 40
emilmont 1:fdd22bb7aa52 41 #include "arm_math.h"
emilmont 1:fdd22bb7aa52 42
emilmont 1:fdd22bb7aa52 43 /**
emilmont 1:fdd22bb7aa52 44 * @addtogroup DCT4_IDCT4
emilmont 1:fdd22bb7aa52 45 * @{
emilmont 1:fdd22bb7aa52 46 */
emilmont 1:fdd22bb7aa52 47
emilmont 1:fdd22bb7aa52 48 /**
emilmont 1:fdd22bb7aa52 49 * @brief Processing function for the Q31 DCT4/IDCT4.
emilmont 1:fdd22bb7aa52 50 * @param[in] *S points to an instance of the Q31 DCT4 structure.
emilmont 1:fdd22bb7aa52 51 * @param[in] *pState points to state buffer.
emilmont 1:fdd22bb7aa52 52 * @param[in,out] *pInlineBuffer points to the in-place input and output buffer.
emilmont 1:fdd22bb7aa52 53 * @return none.
emilmont 1:fdd22bb7aa52 54 * \par Input an output formats:
emilmont 1:fdd22bb7aa52 55 * Input samples need to be downscaled by 1 bit to avoid saturations in the Q31 DCT process,
emilmont 1:fdd22bb7aa52 56 * as the conversion from DCT2 to DCT4 involves one subtraction.
emilmont 1:fdd22bb7aa52 57 * Internally inputs are downscaled in the RFFT process function to avoid overflows.
emilmont 1:fdd22bb7aa52 58 * Number of bits downscaled, depends on the size of the transform.
emilmont 1:fdd22bb7aa52 59 * The input and output formats for different DCT sizes and number of bits to upscale are mentioned in the table below:
emilmont 1:fdd22bb7aa52 60 *
emilmont 1:fdd22bb7aa52 61 * \image html dct4FormatsQ31Table.gif
emilmont 1:fdd22bb7aa52 62 */
emilmont 1:fdd22bb7aa52 63
emilmont 1:fdd22bb7aa52 64 void arm_dct4_q31(
emilmont 1:fdd22bb7aa52 65 const arm_dct4_instance_q31 * S,
emilmont 1:fdd22bb7aa52 66 q31_t * pState,
emilmont 1:fdd22bb7aa52 67 q31_t * pInlineBuffer)
emilmont 1:fdd22bb7aa52 68 {
emilmont 1:fdd22bb7aa52 69 uint16_t i; /* Loop counter */
emilmont 1:fdd22bb7aa52 70 q31_t *weights = S->pTwiddle; /* Pointer to the Weights table */
emilmont 1:fdd22bb7aa52 71 q31_t *cosFact = S->pCosFactor; /* Pointer to the cos factors table */
emilmont 1:fdd22bb7aa52 72 q31_t *pS1, *pS2, *pbuff; /* Temporary pointers for input buffer and pState buffer */
emilmont 1:fdd22bb7aa52 73 q31_t in; /* Temporary variable */
emilmont 1:fdd22bb7aa52 74
emilmont 1:fdd22bb7aa52 75
emilmont 1:fdd22bb7aa52 76 /* DCT4 computation involves DCT2 (which is calculated using RFFT)
emilmont 1:fdd22bb7aa52 77 * along with some pre-processing and post-processing.
emilmont 1:fdd22bb7aa52 78 * Computational procedure is explained as follows:
emilmont 1:fdd22bb7aa52 79 * (a) Pre-processing involves multiplying input with cos factor,
emilmont 1:fdd22bb7aa52 80 * r(n) = 2 * u(n) * cos(pi*(2*n+1)/(4*n))
emilmont 1:fdd22bb7aa52 81 * where,
emilmont 1:fdd22bb7aa52 82 * r(n) -- output of preprocessing
emilmont 1:fdd22bb7aa52 83 * u(n) -- input to preprocessing(actual Source buffer)
emilmont 1:fdd22bb7aa52 84 * (b) Calculation of DCT2 using FFT is divided into three steps:
emilmont 1:fdd22bb7aa52 85 * Step1: Re-ordering of even and odd elements of input.
emilmont 1:fdd22bb7aa52 86 * Step2: Calculating FFT of the re-ordered input.
emilmont 1:fdd22bb7aa52 87 * Step3: Taking the real part of the product of FFT output and weights.
emilmont 1:fdd22bb7aa52 88 * (c) Post-processing - DCT4 can be obtained from DCT2 output using the following equation:
emilmont 1:fdd22bb7aa52 89 * Y4(k) = Y2(k) - Y4(k-1) and Y4(-1) = Y4(0)
emilmont 1:fdd22bb7aa52 90 * where,
emilmont 1:fdd22bb7aa52 91 * Y4 -- DCT4 output, Y2 -- DCT2 output
emilmont 1:fdd22bb7aa52 92 * (d) Multiplying the output with the normalizing factor sqrt(2/N).
emilmont 1:fdd22bb7aa52 93 */
emilmont 1:fdd22bb7aa52 94
emilmont 1:fdd22bb7aa52 95 /*-------- Pre-processing ------------*/
emilmont 1:fdd22bb7aa52 96 /* Multiplying input with cos factor i.e. r(n) = 2 * x(n) * cos(pi*(2*n+1)/(4*n)) */
emilmont 1:fdd22bb7aa52 97 arm_mult_q31(pInlineBuffer, cosFact, pInlineBuffer, S->N);
emilmont 1:fdd22bb7aa52 98 arm_shift_q31(pInlineBuffer, 1, pInlineBuffer, S->N);
emilmont 1:fdd22bb7aa52 99
emilmont 1:fdd22bb7aa52 100 /* ----------------------------------------------------------------
emilmont 1:fdd22bb7aa52 101 * Step1: Re-ordering of even and odd elements as
emilmont 1:fdd22bb7aa52 102 * pState[i] = pInlineBuffer[2*i] and
emilmont 1:fdd22bb7aa52 103 * pState[N-i-1] = pInlineBuffer[2*i+1] where i = 0 to N/2
emilmont 1:fdd22bb7aa52 104 ---------------------------------------------------------------------*/
emilmont 1:fdd22bb7aa52 105
emilmont 1:fdd22bb7aa52 106 /* pS1 initialized to pState */
emilmont 1:fdd22bb7aa52 107 pS1 = pState;
emilmont 1:fdd22bb7aa52 108
emilmont 1:fdd22bb7aa52 109 /* pS2 initialized to pState+N-1, so that it points to the end of the state buffer */
emilmont 1:fdd22bb7aa52 110 pS2 = pState + (S->N - 1u);
emilmont 1:fdd22bb7aa52 111
emilmont 1:fdd22bb7aa52 112 /* pbuff initialized to input buffer */
emilmont 1:fdd22bb7aa52 113 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 114
mbed_official 3:7a284390b0ce 115 #ifndef ARM_MATH_CM0_FAMILY
emilmont 1:fdd22bb7aa52 116
emilmont 1:fdd22bb7aa52 117 /* Run the below code for Cortex-M4 and Cortex-M3 */
emilmont 1:fdd22bb7aa52 118
emilmont 1:fdd22bb7aa52 119 /* Initializing the loop counter to N/2 >> 2 for loop unrolling by 4 */
emilmont 1:fdd22bb7aa52 120 i = S->Nby2 >> 2u;
emilmont 1:fdd22bb7aa52 121
emilmont 1:fdd22bb7aa52 122 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
emilmont 1:fdd22bb7aa52 123 ** a second loop below computes the remaining 1 to 3 samples. */
emilmont 1:fdd22bb7aa52 124 do
emilmont 1:fdd22bb7aa52 125 {
emilmont 1:fdd22bb7aa52 126 /* Re-ordering of even and odd elements */
emilmont 1:fdd22bb7aa52 127 /* pState[i] = pInlineBuffer[2*i] */
emilmont 1:fdd22bb7aa52 128 *pS1++ = *pbuff++;
emilmont 1:fdd22bb7aa52 129 /* pState[N-i-1] = pInlineBuffer[2*i+1] */
emilmont 1:fdd22bb7aa52 130 *pS2-- = *pbuff++;
emilmont 1:fdd22bb7aa52 131
emilmont 1:fdd22bb7aa52 132 *pS1++ = *pbuff++;
emilmont 1:fdd22bb7aa52 133 *pS2-- = *pbuff++;
emilmont 1:fdd22bb7aa52 134
emilmont 1:fdd22bb7aa52 135 *pS1++ = *pbuff++;
emilmont 1:fdd22bb7aa52 136 *pS2-- = *pbuff++;
emilmont 1:fdd22bb7aa52 137
emilmont 1:fdd22bb7aa52 138 *pS1++ = *pbuff++;
emilmont 1:fdd22bb7aa52 139 *pS2-- = *pbuff++;
emilmont 1:fdd22bb7aa52 140
emilmont 1:fdd22bb7aa52 141 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 142 i--;
emilmont 1:fdd22bb7aa52 143 } while(i > 0u);
emilmont 1:fdd22bb7aa52 144
emilmont 1:fdd22bb7aa52 145 /* pbuff initialized to input buffer */
emilmont 1:fdd22bb7aa52 146 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 147
emilmont 1:fdd22bb7aa52 148 /* pS1 initialized to pState */
emilmont 1:fdd22bb7aa52 149 pS1 = pState;
emilmont 1:fdd22bb7aa52 150
emilmont 1:fdd22bb7aa52 151 /* Initializing the loop counter to N/4 instead of N for loop unrolling */
emilmont 1:fdd22bb7aa52 152 i = S->N >> 2u;
emilmont 1:fdd22bb7aa52 153
emilmont 1:fdd22bb7aa52 154 /* Processing with loop unrolling 4 times as N is always multiple of 4.
emilmont 1:fdd22bb7aa52 155 * Compute 4 outputs at a time */
emilmont 1:fdd22bb7aa52 156 do
emilmont 1:fdd22bb7aa52 157 {
emilmont 1:fdd22bb7aa52 158 /* Writing the re-ordered output back to inplace input buffer */
emilmont 1:fdd22bb7aa52 159 *pbuff++ = *pS1++;
emilmont 1:fdd22bb7aa52 160 *pbuff++ = *pS1++;
emilmont 1:fdd22bb7aa52 161 *pbuff++ = *pS1++;
emilmont 1:fdd22bb7aa52 162 *pbuff++ = *pS1++;
emilmont 1:fdd22bb7aa52 163
emilmont 1:fdd22bb7aa52 164 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 165 i--;
emilmont 1:fdd22bb7aa52 166 } while(i > 0u);
emilmont 1:fdd22bb7aa52 167
emilmont 1:fdd22bb7aa52 168
emilmont 1:fdd22bb7aa52 169 /* ---------------------------------------------------------
emilmont 1:fdd22bb7aa52 170 * Step2: Calculate RFFT for N-point input
emilmont 1:fdd22bb7aa52 171 * ---------------------------------------------------------- */
emilmont 1:fdd22bb7aa52 172 /* pInlineBuffer is real input of length N , pState is the complex output of length 2N */
emilmont 1:fdd22bb7aa52 173 arm_rfft_q31(S->pRfft, pInlineBuffer, pState);
emilmont 1:fdd22bb7aa52 174
emilmont 1:fdd22bb7aa52 175 /*----------------------------------------------------------------------
emilmont 1:fdd22bb7aa52 176 * Step3: Multiply the FFT output with the weights.
emilmont 1:fdd22bb7aa52 177 *----------------------------------------------------------------------*/
emilmont 1:fdd22bb7aa52 178 arm_cmplx_mult_cmplx_q31(pState, weights, pState, S->N);
emilmont 1:fdd22bb7aa52 179
emilmont 1:fdd22bb7aa52 180 /* The output of complex multiplication is in 3.29 format.
emilmont 1:fdd22bb7aa52 181 * 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 182 arm_shift_q31(pState, 2, pState, S->N * 2);
emilmont 1:fdd22bb7aa52 183
emilmont 1:fdd22bb7aa52 184 /* ----------- Post-processing ---------- */
emilmont 1:fdd22bb7aa52 185 /* DCT-IV can be obtained from DCT-II by the equation,
emilmont 1:fdd22bb7aa52 186 * Y4(k) = Y2(k) - Y4(k-1) and Y4(-1) = Y4(0)
emilmont 1:fdd22bb7aa52 187 * Hence, Y4(0) = Y2(0)/2 */
emilmont 1:fdd22bb7aa52 188 /* Getting only real part from the output and Converting to DCT-IV */
emilmont 1:fdd22bb7aa52 189
emilmont 1:fdd22bb7aa52 190 /* Initializing the loop counter to N >> 2 for loop unrolling by 4 */
emilmont 1:fdd22bb7aa52 191 i = (S->N - 1u) >> 2u;
emilmont 1:fdd22bb7aa52 192
emilmont 1:fdd22bb7aa52 193 /* pbuff initialized to input buffer. */
emilmont 1:fdd22bb7aa52 194 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 195
emilmont 1:fdd22bb7aa52 196 /* pS1 initialized to pState */
emilmont 1:fdd22bb7aa52 197 pS1 = pState;
emilmont 1:fdd22bb7aa52 198
emilmont 1:fdd22bb7aa52 199 /* Calculating Y4(0) from Y2(0) using Y4(0) = Y2(0)/2 */
emilmont 1:fdd22bb7aa52 200 in = *pS1++ >> 1u;
emilmont 1:fdd22bb7aa52 201 /* input buffer acts as inplace, so output values are stored in the input itself. */
emilmont 1:fdd22bb7aa52 202 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 203
emilmont 1:fdd22bb7aa52 204 /* pState pointer is incremented twice as the real values are located alternatively in the array */
emilmont 1:fdd22bb7aa52 205 pS1++;
emilmont 1:fdd22bb7aa52 206
emilmont 1:fdd22bb7aa52 207 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
emilmont 1:fdd22bb7aa52 208 ** a second loop below computes the remaining 1 to 3 samples. */
emilmont 1:fdd22bb7aa52 209 do
emilmont 1:fdd22bb7aa52 210 {
emilmont 1:fdd22bb7aa52 211 /* Calculating Y4(1) to Y4(N-1) from Y2 using equation Y4(k) = Y2(k) - Y4(k-1) */
emilmont 1:fdd22bb7aa52 212 /* pState pointer (pS1) is incremented twice as the real values are located alternatively in the array */
emilmont 1:fdd22bb7aa52 213 in = *pS1++ - in;
emilmont 1:fdd22bb7aa52 214 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 215 /* points to the next real value */
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 in = *pS1++ - in;
emilmont 1:fdd22bb7aa52 223 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 224 pS1++;
emilmont 1:fdd22bb7aa52 225
emilmont 1:fdd22bb7aa52 226 in = *pS1++ - in;
emilmont 1:fdd22bb7aa52 227 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 228 pS1++;
emilmont 1:fdd22bb7aa52 229
emilmont 1:fdd22bb7aa52 230 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 231 i--;
emilmont 1:fdd22bb7aa52 232 } while(i > 0u);
emilmont 1:fdd22bb7aa52 233
emilmont 1:fdd22bb7aa52 234 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
emilmont 1:fdd22bb7aa52 235 ** No loop unrolling is used. */
emilmont 1:fdd22bb7aa52 236 i = (S->N - 1u) % 0x4u;
emilmont 1:fdd22bb7aa52 237
emilmont 1:fdd22bb7aa52 238 while(i > 0u)
emilmont 1:fdd22bb7aa52 239 {
emilmont 1:fdd22bb7aa52 240 /* Calculating Y4(1) to Y4(N-1) from Y2 using equation Y4(k) = Y2(k) - Y4(k-1) */
emilmont 1:fdd22bb7aa52 241 /* pState pointer (pS1) is incremented twice as the real values are located alternatively in the array */
emilmont 1:fdd22bb7aa52 242 in = *pS1++ - in;
emilmont 1:fdd22bb7aa52 243 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 244 /* points to the next real value */
emilmont 1:fdd22bb7aa52 245 pS1++;
emilmont 1:fdd22bb7aa52 246
emilmont 1:fdd22bb7aa52 247 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 248 i--;
emilmont 1:fdd22bb7aa52 249 }
emilmont 1:fdd22bb7aa52 250
emilmont 1:fdd22bb7aa52 251
emilmont 1:fdd22bb7aa52 252 /*------------ Normalizing the output by multiplying with the normalizing factor ----------*/
emilmont 1:fdd22bb7aa52 253
emilmont 1:fdd22bb7aa52 254 /* Initializing the loop counter to N/4 instead of N for loop unrolling */
emilmont 1:fdd22bb7aa52 255 i = S->N >> 2u;
emilmont 1:fdd22bb7aa52 256
emilmont 1:fdd22bb7aa52 257 /* pbuff initialized to the pInlineBuffer(now contains the output values) */
emilmont 1:fdd22bb7aa52 258 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 259
emilmont 1:fdd22bb7aa52 260 /* Processing with loop unrolling 4 times as N is always multiple of 4. Compute 4 outputs at a time */
emilmont 1:fdd22bb7aa52 261 do
emilmont 1:fdd22bb7aa52 262 {
emilmont 1:fdd22bb7aa52 263 /* Multiplying pInlineBuffer with the normalizing factor sqrt(2/N) */
emilmont 1:fdd22bb7aa52 264 in = *pbuff;
emilmont 1:fdd22bb7aa52 265 *pbuff++ = ((q31_t) (((q63_t) in * S->normalize) >> 31));
emilmont 1:fdd22bb7aa52 266
emilmont 1:fdd22bb7aa52 267 in = *pbuff;
emilmont 1:fdd22bb7aa52 268 *pbuff++ = ((q31_t) (((q63_t) in * S->normalize) >> 31));
emilmont 1:fdd22bb7aa52 269
emilmont 1:fdd22bb7aa52 270 in = *pbuff;
emilmont 1:fdd22bb7aa52 271 *pbuff++ = ((q31_t) (((q63_t) in * S->normalize) >> 31));
emilmont 1:fdd22bb7aa52 272
emilmont 1:fdd22bb7aa52 273 in = *pbuff;
emilmont 1:fdd22bb7aa52 274 *pbuff++ = ((q31_t) (((q63_t) in * S->normalize) >> 31));
emilmont 1:fdd22bb7aa52 275
emilmont 1:fdd22bb7aa52 276 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 277 i--;
emilmont 1:fdd22bb7aa52 278 } while(i > 0u);
emilmont 1:fdd22bb7aa52 279
emilmont 1:fdd22bb7aa52 280
emilmont 1:fdd22bb7aa52 281 #else
emilmont 1:fdd22bb7aa52 282
emilmont 1:fdd22bb7aa52 283 /* Run the below code for Cortex-M0 */
emilmont 1:fdd22bb7aa52 284
emilmont 1:fdd22bb7aa52 285 /* Initializing the loop counter to N/2 */
emilmont 1:fdd22bb7aa52 286 i = S->Nby2;
emilmont 1:fdd22bb7aa52 287
emilmont 1:fdd22bb7aa52 288 do
emilmont 1:fdd22bb7aa52 289 {
emilmont 1:fdd22bb7aa52 290 /* Re-ordering of even and odd elements */
emilmont 1:fdd22bb7aa52 291 /* pState[i] = pInlineBuffer[2*i] */
emilmont 1:fdd22bb7aa52 292 *pS1++ = *pbuff++;
emilmont 1:fdd22bb7aa52 293 /* pState[N-i-1] = pInlineBuffer[2*i+1] */
emilmont 1:fdd22bb7aa52 294 *pS2-- = *pbuff++;
emilmont 1:fdd22bb7aa52 295
emilmont 1:fdd22bb7aa52 296 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 297 i--;
emilmont 1:fdd22bb7aa52 298 } while(i > 0u);
emilmont 1:fdd22bb7aa52 299
emilmont 1:fdd22bb7aa52 300 /* pbuff initialized to input buffer */
emilmont 1:fdd22bb7aa52 301 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 302
emilmont 1:fdd22bb7aa52 303 /* pS1 initialized to pState */
emilmont 1:fdd22bb7aa52 304 pS1 = pState;
emilmont 1:fdd22bb7aa52 305
emilmont 1:fdd22bb7aa52 306 /* Initializing the loop counter */
emilmont 1:fdd22bb7aa52 307 i = S->N;
emilmont 1:fdd22bb7aa52 308
emilmont 1:fdd22bb7aa52 309 do
emilmont 1:fdd22bb7aa52 310 {
emilmont 1:fdd22bb7aa52 311 /* Writing the re-ordered output back to inplace input buffer */
emilmont 1:fdd22bb7aa52 312 *pbuff++ = *pS1++;
emilmont 1:fdd22bb7aa52 313
emilmont 1:fdd22bb7aa52 314 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 315 i--;
emilmont 1:fdd22bb7aa52 316 } while(i > 0u);
emilmont 1:fdd22bb7aa52 317
emilmont 1:fdd22bb7aa52 318
emilmont 1:fdd22bb7aa52 319 /* ---------------------------------------------------------
emilmont 1:fdd22bb7aa52 320 * Step2: Calculate RFFT for N-point input
emilmont 1:fdd22bb7aa52 321 * ---------------------------------------------------------- */
emilmont 1:fdd22bb7aa52 322 /* pInlineBuffer is real input of length N , pState is the complex output of length 2N */
emilmont 1:fdd22bb7aa52 323 arm_rfft_q31(S->pRfft, pInlineBuffer, pState);
emilmont 1:fdd22bb7aa52 324
emilmont 1:fdd22bb7aa52 325 /*----------------------------------------------------------------------
emilmont 1:fdd22bb7aa52 326 * Step3: Multiply the FFT output with the weights.
emilmont 1:fdd22bb7aa52 327 *----------------------------------------------------------------------*/
emilmont 1:fdd22bb7aa52 328 arm_cmplx_mult_cmplx_q31(pState, weights, pState, S->N);
emilmont 1:fdd22bb7aa52 329
emilmont 1:fdd22bb7aa52 330 /* The output of complex multiplication is in 3.29 format.
emilmont 1:fdd22bb7aa52 331 * 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 332 arm_shift_q31(pState, 2, pState, S->N * 2);
emilmont 1:fdd22bb7aa52 333
emilmont 1:fdd22bb7aa52 334 /* ----------- Post-processing ---------- */
emilmont 1:fdd22bb7aa52 335 /* DCT-IV can be obtained from DCT-II by the equation,
emilmont 1:fdd22bb7aa52 336 * Y4(k) = Y2(k) - Y4(k-1) and Y4(-1) = Y4(0)
emilmont 1:fdd22bb7aa52 337 * Hence, Y4(0) = Y2(0)/2 */
emilmont 1:fdd22bb7aa52 338 /* Getting only real part from the output and Converting to DCT-IV */
emilmont 1:fdd22bb7aa52 339
emilmont 1:fdd22bb7aa52 340 /* pbuff initialized to input buffer. */
emilmont 1:fdd22bb7aa52 341 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 342
emilmont 1:fdd22bb7aa52 343 /* pS1 initialized to pState */
emilmont 1:fdd22bb7aa52 344 pS1 = pState;
emilmont 1:fdd22bb7aa52 345
emilmont 1:fdd22bb7aa52 346 /* Calculating Y4(0) from Y2(0) using Y4(0) = Y2(0)/2 */
emilmont 1:fdd22bb7aa52 347 in = *pS1++ >> 1u;
emilmont 1:fdd22bb7aa52 348 /* input buffer acts as inplace, so output values are stored in the input itself. */
emilmont 1:fdd22bb7aa52 349 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 350
emilmont 1:fdd22bb7aa52 351 /* pState pointer is incremented twice as the real values are located alternatively in the array */
emilmont 1:fdd22bb7aa52 352 pS1++;
emilmont 1:fdd22bb7aa52 353
emilmont 1:fdd22bb7aa52 354 /* Initializing the loop counter */
emilmont 1:fdd22bb7aa52 355 i = (S->N - 1u);
emilmont 1:fdd22bb7aa52 356
emilmont 1:fdd22bb7aa52 357 while(i > 0u)
emilmont 1:fdd22bb7aa52 358 {
emilmont 1:fdd22bb7aa52 359 /* Calculating Y4(1) to Y4(N-1) from Y2 using equation Y4(k) = Y2(k) - Y4(k-1) */
emilmont 1:fdd22bb7aa52 360 /* pState pointer (pS1) is incremented twice as the real values are located alternatively in the array */
emilmont 1:fdd22bb7aa52 361 in = *pS1++ - in;
emilmont 1:fdd22bb7aa52 362 *pbuff++ = in;
emilmont 1:fdd22bb7aa52 363 /* points to the next real value */
emilmont 1:fdd22bb7aa52 364 pS1++;
emilmont 1:fdd22bb7aa52 365
emilmont 1:fdd22bb7aa52 366 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 367 i--;
emilmont 1:fdd22bb7aa52 368 }
emilmont 1:fdd22bb7aa52 369
emilmont 1:fdd22bb7aa52 370
emilmont 1:fdd22bb7aa52 371 /*------------ Normalizing the output by multiplying with the normalizing factor ----------*/
emilmont 1:fdd22bb7aa52 372
emilmont 1:fdd22bb7aa52 373 /* Initializing the loop counter */
emilmont 1:fdd22bb7aa52 374 i = S->N;
emilmont 1:fdd22bb7aa52 375
emilmont 1:fdd22bb7aa52 376 /* pbuff initialized to the pInlineBuffer(now contains the output values) */
emilmont 1:fdd22bb7aa52 377 pbuff = pInlineBuffer;
emilmont 1:fdd22bb7aa52 378
emilmont 1:fdd22bb7aa52 379 do
emilmont 1:fdd22bb7aa52 380 {
emilmont 1:fdd22bb7aa52 381 /* Multiplying pInlineBuffer with the normalizing factor sqrt(2/N) */
emilmont 1:fdd22bb7aa52 382 in = *pbuff;
emilmont 1:fdd22bb7aa52 383 *pbuff++ = ((q31_t) (((q63_t) in * S->normalize) >> 31));
emilmont 1:fdd22bb7aa52 384
emilmont 1:fdd22bb7aa52 385 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 386 i--;
emilmont 1:fdd22bb7aa52 387 } while(i > 0u);
emilmont 1:fdd22bb7aa52 388
mbed_official 3:7a284390b0ce 389 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
emilmont 1:fdd22bb7aa52 390
emilmont 1:fdd22bb7aa52 391 }
emilmont 1:fdd22bb7aa52 392
emilmont 1:fdd22bb7aa52 393 /**
emilmont 1:fdd22bb7aa52 394 * @} end of DCT4_IDCT4 group
emilmont 1:fdd22bb7aa52 395 */