CMSIS DSP library

Dependents:   KL25Z_FFT_Demo Hat_Board_v5_1 KL25Z_FFT_Demo_tony KL25Z_FFT_Demo_tony ... more

Fork of mbed-dsp by mbed official

Committer:
mbed_official
Date:
Fri Nov 08 13:45:10 2013 +0000
Revision:
3:7a284390b0ce
Parent:
2:da51fb522205
Synchronized with git revision e69956aba2f68a2a26ac26b051f8d349deaa1ce8

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:fdd22bb7aa52 1 /* ----------------------------------------------------------------------
mbed_official 3:7a284390b0ce 2 * Copyright (C) 2010-2013 ARM Limited. All rights reserved.
emilmont 1:fdd22bb7aa52 3 *
mbed_official 3:7a284390b0ce 4 * $Date: 17. January 2013
mbed_official 3:7a284390b0ce 5 * $Revision: V1.4.1
emilmont 1:fdd22bb7aa52 6 *
emilmont 2:da51fb522205 7 * Project: CMSIS DSP Library
emilmont 2:da51fb522205 8 * Title: arm_fir_sparse_q31.c
emilmont 1:fdd22bb7aa52 9 *
emilmont 2:da51fb522205 10 * Description: Q31 sparse FIR filter processing function.
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 #include "arm_math.h"
emilmont 1:fdd22bb7aa52 41
emilmont 1:fdd22bb7aa52 42
emilmont 1:fdd22bb7aa52 43 /**
emilmont 1:fdd22bb7aa52 44 * @addtogroup FIR_Sparse
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 sparse FIR filter.
emilmont 1:fdd22bb7aa52 50 * @param[in] *S points to an instance of the Q31 sparse FIR structure.
emilmont 1:fdd22bb7aa52 51 * @param[in] *pSrc points to the block of input data.
emilmont 1:fdd22bb7aa52 52 * @param[out] *pDst points to the block of output data
emilmont 1:fdd22bb7aa52 53 * @param[in] *pScratchIn points to a temporary buffer of size blockSize.
emilmont 1:fdd22bb7aa52 54 * @param[in] blockSize number of input samples to process per call.
emilmont 1:fdd22bb7aa52 55 * @return none.
emilmont 1:fdd22bb7aa52 56 *
emilmont 1:fdd22bb7aa52 57 * <b>Scaling and Overflow Behavior:</b>
emilmont 1:fdd22bb7aa52 58 * \par
emilmont 1:fdd22bb7aa52 59 * The function is implemented using an internal 32-bit accumulator.
emilmont 1:fdd22bb7aa52 60 * The 1.31 x 1.31 multiplications are truncated to 2.30 format.
emilmont 1:fdd22bb7aa52 61 * This leads to loss of precision on the intermediate multiplications and provides only a single guard bit.
emilmont 1:fdd22bb7aa52 62 * If the accumulator result overflows, it wraps around rather than saturate.
emilmont 1:fdd22bb7aa52 63 * In order to avoid overflows the input signal or coefficients must be scaled down by log2(numTaps) bits.
emilmont 1:fdd22bb7aa52 64 */
emilmont 1:fdd22bb7aa52 65
emilmont 1:fdd22bb7aa52 66 void arm_fir_sparse_q31(
emilmont 1:fdd22bb7aa52 67 arm_fir_sparse_instance_q31 * S,
emilmont 1:fdd22bb7aa52 68 q31_t * pSrc,
emilmont 1:fdd22bb7aa52 69 q31_t * pDst,
emilmont 1:fdd22bb7aa52 70 q31_t * pScratchIn,
emilmont 1:fdd22bb7aa52 71 uint32_t blockSize)
emilmont 1:fdd22bb7aa52 72 {
emilmont 1:fdd22bb7aa52 73
emilmont 1:fdd22bb7aa52 74 q31_t *pState = S->pState; /* State pointer */
emilmont 1:fdd22bb7aa52 75 q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */
emilmont 1:fdd22bb7aa52 76 q31_t *px; /* Scratch buffer pointer */
emilmont 1:fdd22bb7aa52 77 q31_t *py = pState; /* Temporary pointers for state buffer */
emilmont 1:fdd22bb7aa52 78 q31_t *pb = pScratchIn; /* Temporary pointers for scratch buffer */
emilmont 1:fdd22bb7aa52 79 q31_t *pOut; /* Destination pointer */
emilmont 1:fdd22bb7aa52 80 q63_t out; /* Temporary output variable */
emilmont 1:fdd22bb7aa52 81 int32_t *pTapDelay = S->pTapDelay; /* Pointer to the array containing offset of the non-zero tap values. */
emilmont 1:fdd22bb7aa52 82 uint32_t delaySize = S->maxDelay + blockSize; /* state length */
emilmont 1:fdd22bb7aa52 83 uint16_t numTaps = S->numTaps; /* Filter order */
emilmont 1:fdd22bb7aa52 84 int32_t readIndex; /* Read index of the state buffer */
emilmont 1:fdd22bb7aa52 85 uint32_t tapCnt, blkCnt; /* loop counters */
emilmont 1:fdd22bb7aa52 86 q31_t coeff = *pCoeffs++; /* Read the first coefficient value */
emilmont 1:fdd22bb7aa52 87 q31_t in;
emilmont 1:fdd22bb7aa52 88
emilmont 1:fdd22bb7aa52 89
emilmont 1:fdd22bb7aa52 90 /* BlockSize of Input samples are copied into the state buffer */
emilmont 1:fdd22bb7aa52 91 /* StateIndex points to the starting position to write in the state buffer */
emilmont 1:fdd22bb7aa52 92 arm_circularWrite_f32((int32_t *) py, delaySize, &S->stateIndex, 1,
emilmont 1:fdd22bb7aa52 93 (int32_t *) pSrc, 1, blockSize);
emilmont 1:fdd22bb7aa52 94
emilmont 1:fdd22bb7aa52 95 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 96 readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 97
emilmont 1:fdd22bb7aa52 98 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 99 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 100 {
emilmont 1:fdd22bb7aa52 101 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 102 }
emilmont 1:fdd22bb7aa52 103
emilmont 1:fdd22bb7aa52 104 /* Working pointer for state buffer is updated */
emilmont 1:fdd22bb7aa52 105 py = pState;
emilmont 1:fdd22bb7aa52 106
emilmont 1:fdd22bb7aa52 107 /* blockSize samples are read from the state buffer */
emilmont 1:fdd22bb7aa52 108 arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1,
emilmont 1:fdd22bb7aa52 109 (int32_t *) pb, (int32_t *) pb, blockSize, 1,
emilmont 1:fdd22bb7aa52 110 blockSize);
emilmont 1:fdd22bb7aa52 111
emilmont 1:fdd22bb7aa52 112 /* Working pointer for the scratch buffer of state values */
emilmont 1:fdd22bb7aa52 113 px = pb;
emilmont 1:fdd22bb7aa52 114
emilmont 1:fdd22bb7aa52 115 /* Working pointer for scratch buffer of output values */
emilmont 1:fdd22bb7aa52 116 pOut = pDst;
emilmont 1:fdd22bb7aa52 117
emilmont 1:fdd22bb7aa52 118
mbed_official 3:7a284390b0ce 119 #ifndef ARM_MATH_CM0_FAMILY
emilmont 1:fdd22bb7aa52 120
emilmont 1:fdd22bb7aa52 121 /* Run the below code for Cortex-M4 and Cortex-M3 */
emilmont 1:fdd22bb7aa52 122
emilmont 1:fdd22bb7aa52 123 /* Loop over the blockSize. Unroll by a factor of 4.
emilmont 1:fdd22bb7aa52 124 * Compute 4 Multiplications at a time. */
emilmont 1:fdd22bb7aa52 125 blkCnt = blockSize >> 2;
emilmont 1:fdd22bb7aa52 126
emilmont 1:fdd22bb7aa52 127 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 128 {
emilmont 1:fdd22bb7aa52 129 /* Perform Multiplications and store in the destination buffer */
emilmont 1:fdd22bb7aa52 130 *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32);
emilmont 1:fdd22bb7aa52 131 *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32);
emilmont 1:fdd22bb7aa52 132 *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32);
emilmont 1:fdd22bb7aa52 133 *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32);
emilmont 1:fdd22bb7aa52 134
emilmont 1:fdd22bb7aa52 135 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 136 blkCnt--;
emilmont 1:fdd22bb7aa52 137 }
emilmont 1:fdd22bb7aa52 138
emilmont 1:fdd22bb7aa52 139 /* If the blockSize is not a multiple of 4,
emilmont 1:fdd22bb7aa52 140 * compute the remaining samples */
emilmont 1:fdd22bb7aa52 141 blkCnt = blockSize % 0x4u;
emilmont 1:fdd22bb7aa52 142
emilmont 1:fdd22bb7aa52 143 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 144 {
emilmont 1:fdd22bb7aa52 145 /* Perform Multiplications and store in the destination buffer */
emilmont 1:fdd22bb7aa52 146 *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32);
emilmont 1:fdd22bb7aa52 147
emilmont 1:fdd22bb7aa52 148 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 149 blkCnt--;
emilmont 1:fdd22bb7aa52 150 }
emilmont 1:fdd22bb7aa52 151
emilmont 1:fdd22bb7aa52 152 /* Load the coefficient value and
emilmont 1:fdd22bb7aa52 153 * increment the coefficient buffer for the next set of state values */
emilmont 1:fdd22bb7aa52 154 coeff = *pCoeffs++;
emilmont 1:fdd22bb7aa52 155
emilmont 1:fdd22bb7aa52 156 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 157 readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 158
emilmont 1:fdd22bb7aa52 159 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 160 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 161 {
emilmont 1:fdd22bb7aa52 162 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 163 }
emilmont 1:fdd22bb7aa52 164
emilmont 1:fdd22bb7aa52 165 /* Loop over the number of taps. */
emilmont 1:fdd22bb7aa52 166 tapCnt = (uint32_t) numTaps - 1u;
emilmont 1:fdd22bb7aa52 167
emilmont 1:fdd22bb7aa52 168 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 169 {
emilmont 1:fdd22bb7aa52 170 /* Working pointer for state buffer is updated */
emilmont 1:fdd22bb7aa52 171 py = pState;
emilmont 1:fdd22bb7aa52 172
emilmont 1:fdd22bb7aa52 173 /* blockSize samples are read from the state buffer */
emilmont 1:fdd22bb7aa52 174 arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1,
emilmont 1:fdd22bb7aa52 175 (int32_t *) pb, (int32_t *) pb, blockSize, 1,
emilmont 1:fdd22bb7aa52 176 blockSize);
emilmont 1:fdd22bb7aa52 177
emilmont 1:fdd22bb7aa52 178 /* Working pointer for the scratch buffer of state values */
emilmont 1:fdd22bb7aa52 179 px = pb;
emilmont 1:fdd22bb7aa52 180
emilmont 1:fdd22bb7aa52 181 /* Working pointer for scratch buffer of output values */
emilmont 1:fdd22bb7aa52 182 pOut = pDst;
emilmont 1:fdd22bb7aa52 183
emilmont 1:fdd22bb7aa52 184 /* Loop over the blockSize. Unroll by a factor of 4.
emilmont 1:fdd22bb7aa52 185 * Compute 4 MACS at a time. */
emilmont 1:fdd22bb7aa52 186 blkCnt = blockSize >> 2;
emilmont 1:fdd22bb7aa52 187
emilmont 1:fdd22bb7aa52 188 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 189 {
emilmont 1:fdd22bb7aa52 190 out = *pOut;
emilmont 1:fdd22bb7aa52 191 out += ((q63_t) * px++ * coeff) >> 32;
emilmont 1:fdd22bb7aa52 192 *pOut++ = (q31_t) (out);
emilmont 1:fdd22bb7aa52 193
emilmont 1:fdd22bb7aa52 194 out = *pOut;
emilmont 1:fdd22bb7aa52 195 out += ((q63_t) * px++ * coeff) >> 32;
emilmont 1:fdd22bb7aa52 196 *pOut++ = (q31_t) (out);
emilmont 1:fdd22bb7aa52 197
emilmont 1:fdd22bb7aa52 198 out = *pOut;
emilmont 1:fdd22bb7aa52 199 out += ((q63_t) * px++ * coeff) >> 32;
emilmont 1:fdd22bb7aa52 200 *pOut++ = (q31_t) (out);
emilmont 1:fdd22bb7aa52 201
emilmont 1:fdd22bb7aa52 202 out = *pOut;
emilmont 1:fdd22bb7aa52 203 out += ((q63_t) * px++ * coeff) >> 32;
emilmont 1:fdd22bb7aa52 204 *pOut++ = (q31_t) (out);
emilmont 1:fdd22bb7aa52 205
emilmont 1:fdd22bb7aa52 206 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 207 blkCnt--;
emilmont 1:fdd22bb7aa52 208 }
emilmont 1:fdd22bb7aa52 209
emilmont 1:fdd22bb7aa52 210 /* If the blockSize is not a multiple of 4,
emilmont 1:fdd22bb7aa52 211 * compute the remaining samples */
emilmont 1:fdd22bb7aa52 212 blkCnt = blockSize % 0x4u;
emilmont 1:fdd22bb7aa52 213
emilmont 1:fdd22bb7aa52 214 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 215 {
emilmont 1:fdd22bb7aa52 216 /* Perform Multiply-Accumulate */
emilmont 1:fdd22bb7aa52 217 out = *pOut;
emilmont 1:fdd22bb7aa52 218 out += ((q63_t) * px++ * coeff) >> 32;
emilmont 1:fdd22bb7aa52 219 *pOut++ = (q31_t) (out);
emilmont 1:fdd22bb7aa52 220
emilmont 1:fdd22bb7aa52 221 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 222 blkCnt--;
emilmont 1:fdd22bb7aa52 223 }
emilmont 1:fdd22bb7aa52 224
emilmont 1:fdd22bb7aa52 225 /* Load the coefficient value and
emilmont 1:fdd22bb7aa52 226 * increment the coefficient buffer for the next set of state values */
emilmont 1:fdd22bb7aa52 227 coeff = *pCoeffs++;
emilmont 1:fdd22bb7aa52 228
emilmont 1:fdd22bb7aa52 229 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 230 readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 231
emilmont 1:fdd22bb7aa52 232 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 233 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 234 {
emilmont 1:fdd22bb7aa52 235 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 236 }
emilmont 1:fdd22bb7aa52 237
emilmont 1:fdd22bb7aa52 238 /* Decrement the tap loop counter */
emilmont 1:fdd22bb7aa52 239 tapCnt--;
emilmont 1:fdd22bb7aa52 240 }
emilmont 1:fdd22bb7aa52 241
emilmont 1:fdd22bb7aa52 242 /* Working output pointer is updated */
emilmont 1:fdd22bb7aa52 243 pOut = pDst;
emilmont 1:fdd22bb7aa52 244
emilmont 1:fdd22bb7aa52 245 /* Output is converted into 1.31 format. */
emilmont 1:fdd22bb7aa52 246 /* Loop over the blockSize. Unroll by a factor of 4.
emilmont 1:fdd22bb7aa52 247 * process 4 output samples at a time. */
emilmont 1:fdd22bb7aa52 248 blkCnt = blockSize >> 2;
emilmont 1:fdd22bb7aa52 249
emilmont 1:fdd22bb7aa52 250 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 251 {
emilmont 1:fdd22bb7aa52 252 in = *pOut << 1;
emilmont 1:fdd22bb7aa52 253 *pOut++ = in;
emilmont 1:fdd22bb7aa52 254 in = *pOut << 1;
emilmont 1:fdd22bb7aa52 255 *pOut++ = in;
emilmont 1:fdd22bb7aa52 256 in = *pOut << 1;
emilmont 1:fdd22bb7aa52 257 *pOut++ = in;
emilmont 1:fdd22bb7aa52 258 in = *pOut << 1;
emilmont 1:fdd22bb7aa52 259 *pOut++ = in;
emilmont 1:fdd22bb7aa52 260
emilmont 1:fdd22bb7aa52 261 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 262 blkCnt--;
emilmont 1:fdd22bb7aa52 263 }
emilmont 1:fdd22bb7aa52 264
emilmont 1:fdd22bb7aa52 265 /* If the blockSize is not a multiple of 4,
emilmont 1:fdd22bb7aa52 266 * process the remaining output samples */
emilmont 1:fdd22bb7aa52 267 blkCnt = blockSize % 0x4u;
emilmont 1:fdd22bb7aa52 268
emilmont 1:fdd22bb7aa52 269 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 270 {
emilmont 1:fdd22bb7aa52 271 in = *pOut << 1;
emilmont 1:fdd22bb7aa52 272 *pOut++ = in;
emilmont 1:fdd22bb7aa52 273
emilmont 1:fdd22bb7aa52 274 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 275 blkCnt--;
emilmont 1:fdd22bb7aa52 276 }
emilmont 1:fdd22bb7aa52 277
emilmont 1:fdd22bb7aa52 278 #else
emilmont 1:fdd22bb7aa52 279
emilmont 1:fdd22bb7aa52 280 /* Run the below code for Cortex-M0 */
emilmont 1:fdd22bb7aa52 281 blkCnt = blockSize;
emilmont 1:fdd22bb7aa52 282
emilmont 1:fdd22bb7aa52 283 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 284 {
emilmont 1:fdd22bb7aa52 285 /* Perform Multiplications and store in the destination buffer */
emilmont 1:fdd22bb7aa52 286 *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32);
emilmont 1:fdd22bb7aa52 287
emilmont 1:fdd22bb7aa52 288 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 289 blkCnt--;
emilmont 1:fdd22bb7aa52 290 }
emilmont 1:fdd22bb7aa52 291
emilmont 1:fdd22bb7aa52 292 /* Load the coefficient value and
emilmont 1:fdd22bb7aa52 293 * increment the coefficient buffer for the next set of state values */
emilmont 1:fdd22bb7aa52 294 coeff = *pCoeffs++;
emilmont 1:fdd22bb7aa52 295
emilmont 1:fdd22bb7aa52 296 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 297 readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 298
emilmont 1:fdd22bb7aa52 299 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 300 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 301 {
emilmont 1:fdd22bb7aa52 302 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 303 }
emilmont 1:fdd22bb7aa52 304
emilmont 1:fdd22bb7aa52 305 /* Loop over the number of taps. */
emilmont 1:fdd22bb7aa52 306 tapCnt = (uint32_t) numTaps - 1u;
emilmont 1:fdd22bb7aa52 307
emilmont 1:fdd22bb7aa52 308 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 309 {
emilmont 1:fdd22bb7aa52 310 /* Working pointer for state buffer is updated */
emilmont 1:fdd22bb7aa52 311 py = pState;
emilmont 1:fdd22bb7aa52 312
emilmont 1:fdd22bb7aa52 313 /* blockSize samples are read from the state buffer */
emilmont 1:fdd22bb7aa52 314 arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1,
emilmont 1:fdd22bb7aa52 315 (int32_t *) pb, (int32_t *) pb, blockSize, 1,
emilmont 1:fdd22bb7aa52 316 blockSize);
emilmont 1:fdd22bb7aa52 317
emilmont 1:fdd22bb7aa52 318 /* Working pointer for the scratch buffer of state values */
emilmont 1:fdd22bb7aa52 319 px = pb;
emilmont 1:fdd22bb7aa52 320
emilmont 1:fdd22bb7aa52 321 /* Working pointer for scratch buffer of output values */
emilmont 1:fdd22bb7aa52 322 pOut = pDst;
emilmont 1:fdd22bb7aa52 323
emilmont 1:fdd22bb7aa52 324 blkCnt = blockSize;
emilmont 1:fdd22bb7aa52 325
emilmont 1:fdd22bb7aa52 326 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 327 {
emilmont 1:fdd22bb7aa52 328 /* Perform Multiply-Accumulate */
emilmont 1:fdd22bb7aa52 329 out = *pOut;
emilmont 1:fdd22bb7aa52 330 out += ((q63_t) * px++ * coeff) >> 32;
emilmont 1:fdd22bb7aa52 331 *pOut++ = (q31_t) (out);
emilmont 1:fdd22bb7aa52 332
emilmont 1:fdd22bb7aa52 333 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 334 blkCnt--;
emilmont 1:fdd22bb7aa52 335 }
emilmont 1:fdd22bb7aa52 336
emilmont 1:fdd22bb7aa52 337 /* Load the coefficient value and
emilmont 1:fdd22bb7aa52 338 * increment the coefficient buffer for the next set of state values */
emilmont 1:fdd22bb7aa52 339 coeff = *pCoeffs++;
emilmont 1:fdd22bb7aa52 340
emilmont 1:fdd22bb7aa52 341 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 342 readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 343
emilmont 1:fdd22bb7aa52 344 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 345 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 346 {
emilmont 1:fdd22bb7aa52 347 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 348 }
emilmont 1:fdd22bb7aa52 349
emilmont 1:fdd22bb7aa52 350 /* Decrement the tap loop counter */
emilmont 1:fdd22bb7aa52 351 tapCnt--;
emilmont 1:fdd22bb7aa52 352 }
emilmont 1:fdd22bb7aa52 353
emilmont 1:fdd22bb7aa52 354 /* Working output pointer is updated */
emilmont 1:fdd22bb7aa52 355 pOut = pDst;
emilmont 1:fdd22bb7aa52 356
emilmont 1:fdd22bb7aa52 357 /* Output is converted into 1.31 format. */
emilmont 1:fdd22bb7aa52 358 blkCnt = blockSize;
emilmont 1:fdd22bb7aa52 359
emilmont 1:fdd22bb7aa52 360 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 361 {
emilmont 1:fdd22bb7aa52 362 in = *pOut << 1;
emilmont 1:fdd22bb7aa52 363 *pOut++ = in;
emilmont 1:fdd22bb7aa52 364
emilmont 1:fdd22bb7aa52 365 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 366 blkCnt--;
emilmont 1:fdd22bb7aa52 367 }
emilmont 1:fdd22bb7aa52 368
mbed_official 3:7a284390b0ce 369 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
emilmont 1:fdd22bb7aa52 370
emilmont 1:fdd22bb7aa52 371 }
emilmont 1:fdd22bb7aa52 372
emilmont 1:fdd22bb7aa52 373 /**
emilmont 1:fdd22bb7aa52 374 * @} end of FIR_Sparse group
emilmont 1:fdd22bb7aa52 375 */