The CMSIS DSP 5 library

Dependents:   Nucleo-Heart-Rate ejercicioVrms2 PROYECTOFINAL ejercicioVrms ... more

Committer:
xorjoep
Date:
Thu Jun 21 11:56:27 2018 +0000
Revision:
3:4098b9d3d571
Parent:
1:24714b45cd1b
headers is a folder not a library

Who changed what in which revision?

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