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_fir_interpolate_q31.c
emilmont 1:fdd22bb7aa52 9 *
emilmont 1:fdd22bb7aa52 10 * Description: Q31 FIR interpolation.
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 * Version 0.0.7 2010/06/10
emilmont 1:fdd22bb7aa52 33 * Misra-C changes done
emilmont 1:fdd22bb7aa52 34 * ---------------------------------------------------------------------------*/
emilmont 1:fdd22bb7aa52 35
emilmont 1:fdd22bb7aa52 36 #include "arm_math.h"
emilmont 1:fdd22bb7aa52 37
emilmont 1:fdd22bb7aa52 38 /**
emilmont 1:fdd22bb7aa52 39 * @ingroup groupFilters
emilmont 1:fdd22bb7aa52 40 */
emilmont 1:fdd22bb7aa52 41
emilmont 1:fdd22bb7aa52 42 /**
emilmont 1:fdd22bb7aa52 43 * @addtogroup FIR_Interpolate
emilmont 1:fdd22bb7aa52 44 * @{
emilmont 1:fdd22bb7aa52 45 */
emilmont 1:fdd22bb7aa52 46
emilmont 1:fdd22bb7aa52 47 /**
emilmont 1:fdd22bb7aa52 48 * @brief Processing function for the Q31 FIR interpolator.
emilmont 1:fdd22bb7aa52 49 * @param[in] *S points to an instance of the Q31 FIR interpolator structure.
emilmont 1:fdd22bb7aa52 50 * @param[in] *pSrc points to the block of input data.
emilmont 1:fdd22bb7aa52 51 * @param[out] *pDst points to the block of output data.
emilmont 1:fdd22bb7aa52 52 * @param[in] blockSize number of input samples to process per call.
emilmont 1:fdd22bb7aa52 53 * @return none.
emilmont 1:fdd22bb7aa52 54 *
emilmont 1:fdd22bb7aa52 55 * <b>Scaling and Overflow Behavior:</b>
emilmont 1:fdd22bb7aa52 56 * \par
emilmont 1:fdd22bb7aa52 57 * The function is implemented using an internal 64-bit accumulator.
emilmont 1:fdd22bb7aa52 58 * The accumulator has a 2.62 format and maintains full precision of the intermediate multiplication results but provides only a single guard bit.
emilmont 1:fdd22bb7aa52 59 * Thus, if the accumulator result overflows it wraps around rather than clip.
emilmont 1:fdd22bb7aa52 60 * In order to avoid overflows completely the input signal must be scaled down by <code>1/(numTaps/L)</code>.
emilmont 1:fdd22bb7aa52 61 * since <code>numTaps/L</code> additions occur per output sample.
emilmont 1:fdd22bb7aa52 62 * After all multiply-accumulates are performed, the 2.62 accumulator is truncated to 1.32 format and then saturated to 1.31 format.
emilmont 1:fdd22bb7aa52 63 */
emilmont 1:fdd22bb7aa52 64
emilmont 1:fdd22bb7aa52 65 #ifndef ARM_MATH_CM0
emilmont 1:fdd22bb7aa52 66
emilmont 1:fdd22bb7aa52 67 /* Run the below code for Cortex-M4 and Cortex-M3 */
emilmont 1:fdd22bb7aa52 68
emilmont 1:fdd22bb7aa52 69 void arm_fir_interpolate_q31(
emilmont 1:fdd22bb7aa52 70 const arm_fir_interpolate_instance_q31 * S,
emilmont 1:fdd22bb7aa52 71 q31_t * pSrc,
emilmont 1:fdd22bb7aa52 72 q31_t * pDst,
emilmont 1:fdd22bb7aa52 73 uint32_t blockSize)
emilmont 1:fdd22bb7aa52 74 {
emilmont 1:fdd22bb7aa52 75 q31_t *pState = S->pState; /* State pointer */
emilmont 1:fdd22bb7aa52 76 q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */
emilmont 1:fdd22bb7aa52 77 q31_t *pStateCurnt; /* Points to the current sample of the state */
emilmont 1:fdd22bb7aa52 78 q31_t *ptr1, *ptr2; /* Temporary pointers for state and coefficient buffers */
emilmont 1:fdd22bb7aa52 79 q63_t sum0; /* Accumulators */
emilmont 1:fdd22bb7aa52 80 q31_t x0, c0; /* Temporary variables to hold state and coefficient values */
emilmont 1:fdd22bb7aa52 81 uint32_t i, blkCnt, j; /* Loop counters */
emilmont 1:fdd22bb7aa52 82 uint16_t phaseLen = S->phaseLength, tapCnt; /* Length of each polyphase filter component */
emilmont 1:fdd22bb7aa52 83
emilmont 1:fdd22bb7aa52 84 uint32_t blkCntN2;
emilmont 1:fdd22bb7aa52 85 q63_t acc0, acc1;
emilmont 1:fdd22bb7aa52 86 q31_t x1;
emilmont 1:fdd22bb7aa52 87
emilmont 1:fdd22bb7aa52 88 /* S->pState buffer contains previous frame (phaseLen - 1) samples */
emilmont 1:fdd22bb7aa52 89 /* pStateCurnt points to the location where the new input data should be written */
emilmont 1:fdd22bb7aa52 90 pStateCurnt = S->pState + ((q31_t) phaseLen - 1);
emilmont 1:fdd22bb7aa52 91
emilmont 1:fdd22bb7aa52 92 /* Initialise blkCnt */
emilmont 1:fdd22bb7aa52 93 blkCnt = blockSize / 2;
emilmont 1:fdd22bb7aa52 94 blkCntN2 = blockSize - (2 * blkCnt);
emilmont 1:fdd22bb7aa52 95
emilmont 1:fdd22bb7aa52 96 /* Samples loop unrolled by 2 */
emilmont 1:fdd22bb7aa52 97 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 98 {
emilmont 1:fdd22bb7aa52 99 /* Copy new input sample into the state buffer */
emilmont 1:fdd22bb7aa52 100 *pStateCurnt++ = *pSrc++;
emilmont 1:fdd22bb7aa52 101 *pStateCurnt++ = *pSrc++;
emilmont 1:fdd22bb7aa52 102
emilmont 1:fdd22bb7aa52 103 /* Address modifier index of coefficient buffer */
emilmont 1:fdd22bb7aa52 104 j = 1u;
emilmont 1:fdd22bb7aa52 105
emilmont 1:fdd22bb7aa52 106 /* Loop over the Interpolation factor. */
emilmont 1:fdd22bb7aa52 107 i = (S->L);
emilmont 1:fdd22bb7aa52 108
emilmont 1:fdd22bb7aa52 109 while(i > 0u)
emilmont 1:fdd22bb7aa52 110 {
emilmont 1:fdd22bb7aa52 111 /* Set accumulator to zero */
emilmont 1:fdd22bb7aa52 112 acc0 = 0;
emilmont 1:fdd22bb7aa52 113 acc1 = 0;
emilmont 1:fdd22bb7aa52 114
emilmont 1:fdd22bb7aa52 115 /* Initialize state pointer */
emilmont 1:fdd22bb7aa52 116 ptr1 = pState;
emilmont 1:fdd22bb7aa52 117
emilmont 1:fdd22bb7aa52 118 /* Initialize coefficient pointer */
emilmont 1:fdd22bb7aa52 119 ptr2 = pCoeffs + (S->L - j);
emilmont 1:fdd22bb7aa52 120
emilmont 1:fdd22bb7aa52 121 /* Loop over the polyPhase length. Unroll by a factor of 4.
emilmont 1:fdd22bb7aa52 122 ** Repeat until we've computed numTaps-(4*S->L) coefficients. */
emilmont 1:fdd22bb7aa52 123 tapCnt = phaseLen >> 2u;
emilmont 1:fdd22bb7aa52 124
emilmont 1:fdd22bb7aa52 125 x0 = *(ptr1++);
emilmont 1:fdd22bb7aa52 126
emilmont 1:fdd22bb7aa52 127 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 128 {
emilmont 1:fdd22bb7aa52 129
emilmont 1:fdd22bb7aa52 130 /* Read the input sample */
emilmont 1:fdd22bb7aa52 131 x1 = *(ptr1++);
emilmont 1:fdd22bb7aa52 132
emilmont 1:fdd22bb7aa52 133 /* Read the coefficient */
emilmont 1:fdd22bb7aa52 134 c0 = *(ptr2);
emilmont 1:fdd22bb7aa52 135
emilmont 1:fdd22bb7aa52 136 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 137 acc0 += (q63_t) x0 *c0;
emilmont 1:fdd22bb7aa52 138 acc1 += (q63_t) x1 *c0;
emilmont 1:fdd22bb7aa52 139
emilmont 1:fdd22bb7aa52 140
emilmont 1:fdd22bb7aa52 141 /* Read the coefficient */
emilmont 1:fdd22bb7aa52 142 c0 = *(ptr2 + S->L);
emilmont 1:fdd22bb7aa52 143
emilmont 1:fdd22bb7aa52 144 /* Read the input sample */
emilmont 1:fdd22bb7aa52 145 x0 = *(ptr1++);
emilmont 1:fdd22bb7aa52 146
emilmont 1:fdd22bb7aa52 147 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 148 acc0 += (q63_t) x1 *c0;
emilmont 1:fdd22bb7aa52 149 acc1 += (q63_t) x0 *c0;
emilmont 1:fdd22bb7aa52 150
emilmont 1:fdd22bb7aa52 151
emilmont 1:fdd22bb7aa52 152 /* Read the coefficient */
emilmont 1:fdd22bb7aa52 153 c0 = *(ptr2 + S->L * 2);
emilmont 1:fdd22bb7aa52 154
emilmont 1:fdd22bb7aa52 155 /* Read the input sample */
emilmont 1:fdd22bb7aa52 156 x1 = *(ptr1++);
emilmont 1:fdd22bb7aa52 157
emilmont 1:fdd22bb7aa52 158 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 159 acc0 += (q63_t) x0 *c0;
emilmont 1:fdd22bb7aa52 160 acc1 += (q63_t) x1 *c0;
emilmont 1:fdd22bb7aa52 161
emilmont 1:fdd22bb7aa52 162 /* Read the coefficient */
emilmont 1:fdd22bb7aa52 163 c0 = *(ptr2 + S->L * 3);
emilmont 1:fdd22bb7aa52 164
emilmont 1:fdd22bb7aa52 165 /* Read the input sample */
emilmont 1:fdd22bb7aa52 166 x0 = *(ptr1++);
emilmont 1:fdd22bb7aa52 167
emilmont 1:fdd22bb7aa52 168 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 169 acc0 += (q63_t) x1 *c0;
emilmont 1:fdd22bb7aa52 170 acc1 += (q63_t) x0 *c0;
emilmont 1:fdd22bb7aa52 171
emilmont 1:fdd22bb7aa52 172
emilmont 1:fdd22bb7aa52 173 /* Upsampling is done by stuffing L-1 zeros between each sample.
emilmont 1:fdd22bb7aa52 174 * So instead of multiplying zeros with coefficients,
emilmont 1:fdd22bb7aa52 175 * Increment the coefficient pointer by interpolation factor times. */
emilmont 1:fdd22bb7aa52 176 ptr2 += 4 * S->L;
emilmont 1:fdd22bb7aa52 177
emilmont 1:fdd22bb7aa52 178 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 179 tapCnt--;
emilmont 1:fdd22bb7aa52 180 }
emilmont 1:fdd22bb7aa52 181
emilmont 1:fdd22bb7aa52 182 /* If the polyPhase length is not a multiple of 4, compute the remaining filter taps */
emilmont 1:fdd22bb7aa52 183 tapCnt = phaseLen % 0x4u;
emilmont 1:fdd22bb7aa52 184
emilmont 1:fdd22bb7aa52 185 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 186 {
emilmont 1:fdd22bb7aa52 187
emilmont 1:fdd22bb7aa52 188 /* Read the input sample */
emilmont 1:fdd22bb7aa52 189 x1 = *(ptr1++);
emilmont 1:fdd22bb7aa52 190
emilmont 1:fdd22bb7aa52 191 /* Read the coefficient */
emilmont 1:fdd22bb7aa52 192 c0 = *(ptr2);
emilmont 1:fdd22bb7aa52 193
emilmont 1:fdd22bb7aa52 194 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 195 acc0 += (q63_t) x0 *c0;
emilmont 1:fdd22bb7aa52 196 acc1 += (q63_t) x1 *c0;
emilmont 1:fdd22bb7aa52 197
emilmont 1:fdd22bb7aa52 198 /* Increment the coefficient pointer by interpolation factor times. */
emilmont 1:fdd22bb7aa52 199 ptr2 += S->L;
emilmont 1:fdd22bb7aa52 200
emilmont 1:fdd22bb7aa52 201 /* update states for next sample processing */
emilmont 1:fdd22bb7aa52 202 x0 = x1;
emilmont 1:fdd22bb7aa52 203
emilmont 1:fdd22bb7aa52 204 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 205 tapCnt--;
emilmont 1:fdd22bb7aa52 206 }
emilmont 1:fdd22bb7aa52 207
emilmont 1:fdd22bb7aa52 208 /* The result is in the accumulator, store in the destination buffer. */
emilmont 1:fdd22bb7aa52 209 *pDst = (q31_t) (acc0 >> 31);
emilmont 1:fdd22bb7aa52 210 *(pDst + S->L) = (q31_t) (acc1 >> 31);
emilmont 1:fdd22bb7aa52 211
emilmont 1:fdd22bb7aa52 212
emilmont 1:fdd22bb7aa52 213 pDst++;
emilmont 1:fdd22bb7aa52 214
emilmont 1:fdd22bb7aa52 215 /* Increment the address modifier index of coefficient buffer */
emilmont 1:fdd22bb7aa52 216 j++;
emilmont 1:fdd22bb7aa52 217
emilmont 1:fdd22bb7aa52 218 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 219 i--;
emilmont 1:fdd22bb7aa52 220 }
emilmont 1:fdd22bb7aa52 221
emilmont 1:fdd22bb7aa52 222 /* Advance the state pointer by 1
emilmont 1:fdd22bb7aa52 223 * to process the next group of interpolation factor number samples */
emilmont 1:fdd22bb7aa52 224 pState = pState + 2;
emilmont 1:fdd22bb7aa52 225
emilmont 1:fdd22bb7aa52 226 pDst += S->L;
emilmont 1:fdd22bb7aa52 227
emilmont 1:fdd22bb7aa52 228 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 229 blkCnt--;
emilmont 1:fdd22bb7aa52 230 }
emilmont 1:fdd22bb7aa52 231
emilmont 1:fdd22bb7aa52 232 /* If the blockSize is not a multiple of 2, compute any remaining output samples here.
emilmont 1:fdd22bb7aa52 233 ** No loop unrolling is used. */
emilmont 1:fdd22bb7aa52 234 blkCnt = blkCntN2;
emilmont 1:fdd22bb7aa52 235
emilmont 1:fdd22bb7aa52 236 /* Loop over the blockSize. */
emilmont 1:fdd22bb7aa52 237 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 238 {
emilmont 1:fdd22bb7aa52 239 /* Copy new input sample into the state buffer */
emilmont 1:fdd22bb7aa52 240 *pStateCurnt++ = *pSrc++;
emilmont 1:fdd22bb7aa52 241
emilmont 1:fdd22bb7aa52 242 /* Address modifier index of coefficient buffer */
emilmont 1:fdd22bb7aa52 243 j = 1u;
emilmont 1:fdd22bb7aa52 244
emilmont 1:fdd22bb7aa52 245 /* Loop over the Interpolation factor. */
emilmont 1:fdd22bb7aa52 246 i = S->L;
emilmont 1:fdd22bb7aa52 247 while(i > 0u)
emilmont 1:fdd22bb7aa52 248 {
emilmont 1:fdd22bb7aa52 249 /* Set accumulator to zero */
emilmont 1:fdd22bb7aa52 250 sum0 = 0;
emilmont 1:fdd22bb7aa52 251
emilmont 1:fdd22bb7aa52 252 /* Initialize state pointer */
emilmont 1:fdd22bb7aa52 253 ptr1 = pState;
emilmont 1:fdd22bb7aa52 254
emilmont 1:fdd22bb7aa52 255 /* Initialize coefficient pointer */
emilmont 1:fdd22bb7aa52 256 ptr2 = pCoeffs + (S->L - j);
emilmont 1:fdd22bb7aa52 257
emilmont 1:fdd22bb7aa52 258 /* Loop over the polyPhase length. Unroll by a factor of 4.
emilmont 1:fdd22bb7aa52 259 ** Repeat until we've computed numTaps-(4*S->L) coefficients. */
emilmont 1:fdd22bb7aa52 260 tapCnt = phaseLen >> 2;
emilmont 1:fdd22bb7aa52 261 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 262 {
emilmont 1:fdd22bb7aa52 263
emilmont 1:fdd22bb7aa52 264 /* Read the coefficient */
emilmont 1:fdd22bb7aa52 265 c0 = *(ptr2);
emilmont 1:fdd22bb7aa52 266
emilmont 1:fdd22bb7aa52 267 /* Upsampling is done by stuffing L-1 zeros between each sample.
emilmont 1:fdd22bb7aa52 268 * So instead of multiplying zeros with coefficients,
emilmont 1:fdd22bb7aa52 269 * Increment the coefficient pointer by interpolation factor times. */
emilmont 1:fdd22bb7aa52 270 ptr2 += S->L;
emilmont 1:fdd22bb7aa52 271
emilmont 1:fdd22bb7aa52 272 /* Read the input sample */
emilmont 1:fdd22bb7aa52 273 x0 = *(ptr1++);
emilmont 1:fdd22bb7aa52 274
emilmont 1:fdd22bb7aa52 275 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 276 sum0 += (q63_t) x0 *c0;
emilmont 1:fdd22bb7aa52 277
emilmont 1:fdd22bb7aa52 278 /* Read the coefficient */
emilmont 1:fdd22bb7aa52 279 c0 = *(ptr2);
emilmont 1:fdd22bb7aa52 280
emilmont 1:fdd22bb7aa52 281 /* Increment the coefficient pointer by interpolation factor times. */
emilmont 1:fdd22bb7aa52 282 ptr2 += S->L;
emilmont 1:fdd22bb7aa52 283
emilmont 1:fdd22bb7aa52 284 /* Read the input sample */
emilmont 1:fdd22bb7aa52 285 x0 = *(ptr1++);
emilmont 1:fdd22bb7aa52 286
emilmont 1:fdd22bb7aa52 287 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 288 sum0 += (q63_t) x0 *c0;
emilmont 1:fdd22bb7aa52 289
emilmont 1:fdd22bb7aa52 290 /* Read the coefficient */
emilmont 1:fdd22bb7aa52 291 c0 = *(ptr2);
emilmont 1:fdd22bb7aa52 292
emilmont 1:fdd22bb7aa52 293 /* Increment the coefficient pointer by interpolation factor times. */
emilmont 1:fdd22bb7aa52 294 ptr2 += S->L;
emilmont 1:fdd22bb7aa52 295
emilmont 1:fdd22bb7aa52 296 /* Read the input sample */
emilmont 1:fdd22bb7aa52 297 x0 = *(ptr1++);
emilmont 1:fdd22bb7aa52 298
emilmont 1:fdd22bb7aa52 299 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 300 sum0 += (q63_t) x0 *c0;
emilmont 1:fdd22bb7aa52 301
emilmont 1:fdd22bb7aa52 302 /* Read the coefficient */
emilmont 1:fdd22bb7aa52 303 c0 = *(ptr2);
emilmont 1:fdd22bb7aa52 304
emilmont 1:fdd22bb7aa52 305 /* Increment the coefficient pointer by interpolation factor times. */
emilmont 1:fdd22bb7aa52 306 ptr2 += S->L;
emilmont 1:fdd22bb7aa52 307
emilmont 1:fdd22bb7aa52 308 /* Read the input sample */
emilmont 1:fdd22bb7aa52 309 x0 = *(ptr1++);
emilmont 1:fdd22bb7aa52 310
emilmont 1:fdd22bb7aa52 311 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 312 sum0 += (q63_t) x0 *c0;
emilmont 1:fdd22bb7aa52 313
emilmont 1:fdd22bb7aa52 314 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 315 tapCnt--;
emilmont 1:fdd22bb7aa52 316 }
emilmont 1:fdd22bb7aa52 317
emilmont 1:fdd22bb7aa52 318 /* If the polyPhase length is not a multiple of 4, compute the remaining filter taps */
emilmont 1:fdd22bb7aa52 319 tapCnt = phaseLen & 0x3u;
emilmont 1:fdd22bb7aa52 320
emilmont 1:fdd22bb7aa52 321 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 322 {
emilmont 1:fdd22bb7aa52 323 /* Read the coefficient */
emilmont 1:fdd22bb7aa52 324 c0 = *(ptr2);
emilmont 1:fdd22bb7aa52 325
emilmont 1:fdd22bb7aa52 326 /* Increment the coefficient pointer by interpolation factor times. */
emilmont 1:fdd22bb7aa52 327 ptr2 += S->L;
emilmont 1:fdd22bb7aa52 328
emilmont 1:fdd22bb7aa52 329 /* Read the input sample */
emilmont 1:fdd22bb7aa52 330 x0 = *(ptr1++);
emilmont 1:fdd22bb7aa52 331
emilmont 1:fdd22bb7aa52 332 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 333 sum0 += (q63_t) x0 *c0;
emilmont 1:fdd22bb7aa52 334
emilmont 1:fdd22bb7aa52 335 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 336 tapCnt--;
emilmont 1:fdd22bb7aa52 337 }
emilmont 1:fdd22bb7aa52 338
emilmont 1:fdd22bb7aa52 339 /* The result is in the accumulator, store in the destination buffer. */
emilmont 1:fdd22bb7aa52 340 *pDst++ = (q31_t) (sum0 >> 31);
emilmont 1:fdd22bb7aa52 341
emilmont 1:fdd22bb7aa52 342 /* Increment the address modifier index of coefficient buffer */
emilmont 1:fdd22bb7aa52 343 j++;
emilmont 1:fdd22bb7aa52 344
emilmont 1:fdd22bb7aa52 345 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 346 i--;
emilmont 1:fdd22bb7aa52 347 }
emilmont 1:fdd22bb7aa52 348
emilmont 1:fdd22bb7aa52 349 /* Advance the state pointer by 1
emilmont 1:fdd22bb7aa52 350 * to process the next group of interpolation factor number samples */
emilmont 1:fdd22bb7aa52 351 pState = pState + 1;
emilmont 1:fdd22bb7aa52 352
emilmont 1:fdd22bb7aa52 353 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 354 blkCnt--;
emilmont 1:fdd22bb7aa52 355 }
emilmont 1:fdd22bb7aa52 356
emilmont 1:fdd22bb7aa52 357 /* Processing is complete.
emilmont 1:fdd22bb7aa52 358 ** Now copy the last phaseLen - 1 samples to the satrt of the state buffer.
emilmont 1:fdd22bb7aa52 359 ** This prepares the state buffer for the next function call. */
emilmont 1:fdd22bb7aa52 360
emilmont 1:fdd22bb7aa52 361 /* Points to the start of the state buffer */
emilmont 1:fdd22bb7aa52 362 pStateCurnt = S->pState;
emilmont 1:fdd22bb7aa52 363
emilmont 1:fdd22bb7aa52 364 tapCnt = (phaseLen - 1u) >> 2u;
emilmont 1:fdd22bb7aa52 365
emilmont 1:fdd22bb7aa52 366 /* copy data */
emilmont 1:fdd22bb7aa52 367 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 368 {
emilmont 1:fdd22bb7aa52 369 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 370 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 371 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 372 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 373
emilmont 1:fdd22bb7aa52 374 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 375 tapCnt--;
emilmont 1:fdd22bb7aa52 376 }
emilmont 1:fdd22bb7aa52 377
emilmont 1:fdd22bb7aa52 378 tapCnt = (phaseLen - 1u) % 0x04u;
emilmont 1:fdd22bb7aa52 379
emilmont 1:fdd22bb7aa52 380 /* copy data */
emilmont 1:fdd22bb7aa52 381 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 382 {
emilmont 1:fdd22bb7aa52 383 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 384
emilmont 1:fdd22bb7aa52 385 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 386 tapCnt--;
emilmont 1:fdd22bb7aa52 387 }
emilmont 1:fdd22bb7aa52 388
emilmont 1:fdd22bb7aa52 389 }
emilmont 1:fdd22bb7aa52 390
emilmont 1:fdd22bb7aa52 391
emilmont 1:fdd22bb7aa52 392 #else
emilmont 1:fdd22bb7aa52 393
emilmont 1:fdd22bb7aa52 394 void arm_fir_interpolate_q31(
emilmont 1:fdd22bb7aa52 395 const arm_fir_interpolate_instance_q31 * S,
emilmont 1:fdd22bb7aa52 396 q31_t * pSrc,
emilmont 1:fdd22bb7aa52 397 q31_t * pDst,
emilmont 1:fdd22bb7aa52 398 uint32_t blockSize)
emilmont 1:fdd22bb7aa52 399 {
emilmont 1:fdd22bb7aa52 400 q31_t *pState = S->pState; /* State pointer */
emilmont 1:fdd22bb7aa52 401 q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */
emilmont 1:fdd22bb7aa52 402 q31_t *pStateCurnt; /* Points to the current sample of the state */
emilmont 1:fdd22bb7aa52 403 q31_t *ptr1, *ptr2; /* Temporary pointers for state and coefficient buffers */
emilmont 1:fdd22bb7aa52 404
emilmont 1:fdd22bb7aa52 405 /* Run the below code for Cortex-M0 */
emilmont 1:fdd22bb7aa52 406
emilmont 1:fdd22bb7aa52 407 q63_t sum; /* Accumulator */
emilmont 1:fdd22bb7aa52 408 q31_t x0, c0; /* Temporary variables to hold state and coefficient values */
emilmont 1:fdd22bb7aa52 409 uint32_t i, blkCnt; /* Loop counters */
emilmont 1:fdd22bb7aa52 410 uint16_t phaseLen = S->phaseLength, tapCnt; /* Length of each polyphase filter component */
emilmont 1:fdd22bb7aa52 411
emilmont 1:fdd22bb7aa52 412
emilmont 1:fdd22bb7aa52 413 /* S->pState buffer contains previous frame (phaseLen - 1) samples */
emilmont 1:fdd22bb7aa52 414 /* pStateCurnt points to the location where the new input data should be written */
emilmont 1:fdd22bb7aa52 415 pStateCurnt = S->pState + ((q31_t) phaseLen - 1);
emilmont 1:fdd22bb7aa52 416
emilmont 1:fdd22bb7aa52 417 /* Total number of intput samples */
emilmont 1:fdd22bb7aa52 418 blkCnt = blockSize;
emilmont 1:fdd22bb7aa52 419
emilmont 1:fdd22bb7aa52 420 /* Loop over the blockSize. */
emilmont 1:fdd22bb7aa52 421 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 422 {
emilmont 1:fdd22bb7aa52 423 /* Copy new input sample into the state buffer */
emilmont 1:fdd22bb7aa52 424 *pStateCurnt++ = *pSrc++;
emilmont 1:fdd22bb7aa52 425
emilmont 1:fdd22bb7aa52 426 /* Loop over the Interpolation factor. */
emilmont 1:fdd22bb7aa52 427 i = S->L;
emilmont 1:fdd22bb7aa52 428
emilmont 1:fdd22bb7aa52 429 while(i > 0u)
emilmont 1:fdd22bb7aa52 430 {
emilmont 1:fdd22bb7aa52 431 /* Set accumulator to zero */
emilmont 1:fdd22bb7aa52 432 sum = 0;
emilmont 1:fdd22bb7aa52 433
emilmont 1:fdd22bb7aa52 434 /* Initialize state pointer */
emilmont 1:fdd22bb7aa52 435 ptr1 = pState;
emilmont 1:fdd22bb7aa52 436
emilmont 1:fdd22bb7aa52 437 /* Initialize coefficient pointer */
emilmont 1:fdd22bb7aa52 438 ptr2 = pCoeffs + (i - 1u);
emilmont 1:fdd22bb7aa52 439
emilmont 1:fdd22bb7aa52 440 tapCnt = phaseLen;
emilmont 1:fdd22bb7aa52 441
emilmont 1:fdd22bb7aa52 442 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 443 {
emilmont 1:fdd22bb7aa52 444 /* Read the coefficient */
emilmont 1:fdd22bb7aa52 445 c0 = *(ptr2);
emilmont 1:fdd22bb7aa52 446
emilmont 1:fdd22bb7aa52 447 /* Increment the coefficient pointer by interpolation factor times. */
emilmont 1:fdd22bb7aa52 448 ptr2 += S->L;
emilmont 1:fdd22bb7aa52 449
emilmont 1:fdd22bb7aa52 450 /* Read the input sample */
emilmont 1:fdd22bb7aa52 451 x0 = *ptr1++;
emilmont 1:fdd22bb7aa52 452
emilmont 1:fdd22bb7aa52 453 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 454 sum += (q63_t) x0 *c0;
emilmont 1:fdd22bb7aa52 455
emilmont 1:fdd22bb7aa52 456 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 457 tapCnt--;
emilmont 1:fdd22bb7aa52 458 }
emilmont 1:fdd22bb7aa52 459
emilmont 1:fdd22bb7aa52 460 /* The result is in the accumulator, store in the destination buffer. */
emilmont 1:fdd22bb7aa52 461 *pDst++ = (q31_t) (sum >> 31);
emilmont 1:fdd22bb7aa52 462
emilmont 1:fdd22bb7aa52 463 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 464 i--;
emilmont 1:fdd22bb7aa52 465 }
emilmont 1:fdd22bb7aa52 466
emilmont 1:fdd22bb7aa52 467 /* Advance the state pointer by 1
emilmont 1:fdd22bb7aa52 468 * to process the next group of interpolation factor number samples */
emilmont 1:fdd22bb7aa52 469 pState = pState + 1;
emilmont 1:fdd22bb7aa52 470
emilmont 1:fdd22bb7aa52 471 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 472 blkCnt--;
emilmont 1:fdd22bb7aa52 473 }
emilmont 1:fdd22bb7aa52 474
emilmont 1:fdd22bb7aa52 475 /* Processing is complete.
emilmont 1:fdd22bb7aa52 476 ** Now copy the last phaseLen - 1 samples to the satrt of the state buffer.
emilmont 1:fdd22bb7aa52 477 ** This prepares the state buffer for the next function call. */
emilmont 1:fdd22bb7aa52 478
emilmont 1:fdd22bb7aa52 479 /* Points to the start of the state buffer */
emilmont 1:fdd22bb7aa52 480 pStateCurnt = S->pState;
emilmont 1:fdd22bb7aa52 481
emilmont 1:fdd22bb7aa52 482 tapCnt = phaseLen - 1u;
emilmont 1:fdd22bb7aa52 483
emilmont 1:fdd22bb7aa52 484 /* copy data */
emilmont 1:fdd22bb7aa52 485 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 486 {
emilmont 1:fdd22bb7aa52 487 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 488
emilmont 1:fdd22bb7aa52 489 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 490 tapCnt--;
emilmont 1:fdd22bb7aa52 491 }
emilmont 1:fdd22bb7aa52 492
emilmont 1:fdd22bb7aa52 493 }
emilmont 1:fdd22bb7aa52 494
emilmont 1:fdd22bb7aa52 495 #endif /* #ifndef ARM_MATH_CM0 */
emilmont 1:fdd22bb7aa52 496
emilmont 1:fdd22bb7aa52 497 /**
emilmont 1:fdd22bb7aa52 498 * @} end of FIR_Interpolate group
emilmont 1:fdd22bb7aa52 499 */