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