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 08 13:45:10 2013 +0000
Revision:
3:7a284390b0ce
Parent:
2:da51fb522205
Child:
5:3762170b6d4d
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_q7.c
emilmont 1:fdd22bb7aa52 9 *
emilmont 2:da51fb522205 10 * Description: Q7 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 * @ingroup groupFilters
emilmont 1:fdd22bb7aa52 45 */
emilmont 1:fdd22bb7aa52 46
emilmont 1:fdd22bb7aa52 47 /**
emilmont 1:fdd22bb7aa52 48 * @addtogroup FIR_Sparse
emilmont 1:fdd22bb7aa52 49 * @{
emilmont 1:fdd22bb7aa52 50 */
emilmont 1:fdd22bb7aa52 51
emilmont 1:fdd22bb7aa52 52
emilmont 1:fdd22bb7aa52 53 /**
emilmont 1:fdd22bb7aa52 54 * @brief Processing function for the Q7 sparse FIR filter.
emilmont 1:fdd22bb7aa52 55 * @param[in] *S points to an instance of the Q7 sparse FIR structure.
emilmont 1:fdd22bb7aa52 56 * @param[in] *pSrc points to the block of input data.
emilmont 1:fdd22bb7aa52 57 * @param[out] *pDst points to the block of output data
emilmont 1:fdd22bb7aa52 58 * @param[in] *pScratchIn points to a temporary buffer of size blockSize.
emilmont 1:fdd22bb7aa52 59 * @param[in] *pScratchOut points to a temporary buffer of size blockSize.
emilmont 1:fdd22bb7aa52 60 * @param[in] blockSize number of input samples to process per call.
emilmont 1:fdd22bb7aa52 61 * @return none.
emilmont 1:fdd22bb7aa52 62 *
emilmont 1:fdd22bb7aa52 63 * <b>Scaling and Overflow Behavior:</b>
emilmont 1:fdd22bb7aa52 64 * \par
emilmont 1:fdd22bb7aa52 65 * The function is implemented using a 32-bit internal accumulator.
emilmont 1:fdd22bb7aa52 66 * Both coefficients and state variables are represented in 1.7 format and multiplications yield a 2.14 result.
emilmont 1:fdd22bb7aa52 67 * The 2.14 intermediate results are accumulated in a 32-bit accumulator in 18.14 format.
emilmont 1:fdd22bb7aa52 68 * There is no risk of internal overflow with this approach and the full precision of intermediate multiplications is preserved.
emilmont 1:fdd22bb7aa52 69 * The accumulator is then converted to 18.7 format by discarding the low 7 bits.
emilmont 1:fdd22bb7aa52 70 * Finally, the result is truncated to 1.7 format.
emilmont 1:fdd22bb7aa52 71 */
emilmont 1:fdd22bb7aa52 72
emilmont 1:fdd22bb7aa52 73 void arm_fir_sparse_q7(
emilmont 1:fdd22bb7aa52 74 arm_fir_sparse_instance_q7 * S,
emilmont 1:fdd22bb7aa52 75 q7_t * pSrc,
emilmont 1:fdd22bb7aa52 76 q7_t * pDst,
emilmont 1:fdd22bb7aa52 77 q7_t * pScratchIn,
emilmont 1:fdd22bb7aa52 78 q31_t * pScratchOut,
emilmont 1:fdd22bb7aa52 79 uint32_t blockSize)
emilmont 1:fdd22bb7aa52 80 {
emilmont 1:fdd22bb7aa52 81
emilmont 1:fdd22bb7aa52 82 q7_t *pState = S->pState; /* State pointer */
emilmont 1:fdd22bb7aa52 83 q7_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */
emilmont 1:fdd22bb7aa52 84 q7_t *px; /* Scratch buffer pointer */
emilmont 1:fdd22bb7aa52 85 q7_t *py = pState; /* Temporary pointers for state buffer */
emilmont 1:fdd22bb7aa52 86 q7_t *pb = pScratchIn; /* Temporary pointers for scratch buffer */
emilmont 1:fdd22bb7aa52 87 q7_t *pOut = pDst; /* Destination pointer */
emilmont 1:fdd22bb7aa52 88 int32_t *pTapDelay = S->pTapDelay; /* Pointer to the array containing offset of the non-zero tap values. */
emilmont 1:fdd22bb7aa52 89 uint32_t delaySize = S->maxDelay + blockSize; /* state length */
emilmont 1:fdd22bb7aa52 90 uint16_t numTaps = S->numTaps; /* Filter order */
emilmont 1:fdd22bb7aa52 91 int32_t readIndex; /* Read index of the state buffer */
emilmont 1:fdd22bb7aa52 92 uint32_t tapCnt, blkCnt; /* loop counters */
emilmont 1:fdd22bb7aa52 93 q7_t coeff = *pCoeffs++; /* Read the coefficient value */
emilmont 1:fdd22bb7aa52 94 q31_t *pScr2 = pScratchOut; /* Working pointer for scratch buffer of output values */
emilmont 1:fdd22bb7aa52 95 q31_t in;
emilmont 1:fdd22bb7aa52 96
emilmont 1:fdd22bb7aa52 97
mbed_official 3:7a284390b0ce 98 #ifndef ARM_MATH_CM0_FAMILY
emilmont 1:fdd22bb7aa52 99
emilmont 1:fdd22bb7aa52 100 /* Run the below code for Cortex-M4 and Cortex-M3 */
emilmont 1:fdd22bb7aa52 101
emilmont 1:fdd22bb7aa52 102 q7_t in1, in2, in3, in4;
emilmont 1:fdd22bb7aa52 103
emilmont 1:fdd22bb7aa52 104 /* BlockSize of Input samples are copied into the state buffer */
emilmont 1:fdd22bb7aa52 105 /* StateIndex points to the starting position to write in the state buffer */
emilmont 1:fdd22bb7aa52 106 arm_circularWrite_q7(py, (int32_t) delaySize, &S->stateIndex, 1, pSrc, 1,
emilmont 1:fdd22bb7aa52 107 blockSize);
emilmont 1:fdd22bb7aa52 108
emilmont 1:fdd22bb7aa52 109 /* Loop over the number of taps. */
emilmont 1:fdd22bb7aa52 110 tapCnt = numTaps;
emilmont 1:fdd22bb7aa52 111
emilmont 1:fdd22bb7aa52 112 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 113 readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 114
emilmont 1:fdd22bb7aa52 115 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 116 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 117 {
emilmont 1:fdd22bb7aa52 118 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 119 }
emilmont 1:fdd22bb7aa52 120
emilmont 1:fdd22bb7aa52 121 /* Working pointer for state buffer is updated */
emilmont 1:fdd22bb7aa52 122 py = pState;
emilmont 1:fdd22bb7aa52 123
emilmont 1:fdd22bb7aa52 124 /* blockSize samples are read from the state buffer */
emilmont 1:fdd22bb7aa52 125 arm_circularRead_q7(py, (int32_t) delaySize, &readIndex, 1, pb, pb,
emilmont 1:fdd22bb7aa52 126 (int32_t) blockSize, 1, blockSize);
emilmont 1:fdd22bb7aa52 127
emilmont 1:fdd22bb7aa52 128 /* Working pointer for the scratch buffer of state values */
emilmont 1:fdd22bb7aa52 129 px = pb;
emilmont 1:fdd22bb7aa52 130
emilmont 1:fdd22bb7aa52 131 /* Working pointer for scratch buffer of output values */
emilmont 1:fdd22bb7aa52 132 pScratchOut = pScr2;
emilmont 1:fdd22bb7aa52 133
emilmont 1:fdd22bb7aa52 134 /* Loop over the blockSize. Unroll by a factor of 4.
emilmont 1:fdd22bb7aa52 135 * Compute 4 multiplications at a time. */
emilmont 1:fdd22bb7aa52 136 blkCnt = blockSize >> 2;
emilmont 1:fdd22bb7aa52 137
emilmont 1:fdd22bb7aa52 138 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 139 {
emilmont 1:fdd22bb7aa52 140 /* Perform multiplication and store in the scratch buffer */
emilmont 1:fdd22bb7aa52 141 *pScratchOut++ = ((q31_t) * px++ * coeff);
emilmont 1:fdd22bb7aa52 142 *pScratchOut++ = ((q31_t) * px++ * coeff);
emilmont 1:fdd22bb7aa52 143 *pScratchOut++ = ((q31_t) * px++ * coeff);
emilmont 1:fdd22bb7aa52 144 *pScratchOut++ = ((q31_t) * px++ * coeff);
emilmont 1:fdd22bb7aa52 145
emilmont 1:fdd22bb7aa52 146 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 147 blkCnt--;
emilmont 1:fdd22bb7aa52 148 }
emilmont 1:fdd22bb7aa52 149
emilmont 1:fdd22bb7aa52 150 /* If the blockSize is not a multiple of 4,
emilmont 1:fdd22bb7aa52 151 * compute the remaining samples */
emilmont 1:fdd22bb7aa52 152 blkCnt = blockSize % 0x4u;
emilmont 1:fdd22bb7aa52 153
emilmont 1:fdd22bb7aa52 154 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 155 {
emilmont 1:fdd22bb7aa52 156 /* Perform multiplication and store in the scratch buffer */
emilmont 1:fdd22bb7aa52 157 *pScratchOut++ = ((q31_t) * px++ * coeff);
emilmont 1:fdd22bb7aa52 158
emilmont 1:fdd22bb7aa52 159 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 160 blkCnt--;
emilmont 1:fdd22bb7aa52 161 }
emilmont 1:fdd22bb7aa52 162
emilmont 1:fdd22bb7aa52 163 /* Load the coefficient value and
emilmont 1:fdd22bb7aa52 164 * increment the coefficient buffer for the next set of state values */
emilmont 1:fdd22bb7aa52 165 coeff = *pCoeffs++;
emilmont 1:fdd22bb7aa52 166
emilmont 1:fdd22bb7aa52 167 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 168 readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 169
emilmont 1:fdd22bb7aa52 170 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 171 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 172 {
emilmont 1:fdd22bb7aa52 173 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 174 }
emilmont 1:fdd22bb7aa52 175
emilmont 1:fdd22bb7aa52 176 /* Loop over the number of taps. */
emilmont 1:fdd22bb7aa52 177 tapCnt = (uint32_t) numTaps - 1u;
emilmont 1:fdd22bb7aa52 178
emilmont 1:fdd22bb7aa52 179 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 180 {
emilmont 1:fdd22bb7aa52 181 /* Working pointer for state buffer is updated */
emilmont 1:fdd22bb7aa52 182 py = pState;
emilmont 1:fdd22bb7aa52 183
emilmont 1:fdd22bb7aa52 184 /* blockSize samples are read from the state buffer */
emilmont 1:fdd22bb7aa52 185 arm_circularRead_q7(py, (int32_t) delaySize, &readIndex, 1, pb, pb,
emilmont 1:fdd22bb7aa52 186 (int32_t) blockSize, 1, blockSize);
emilmont 1:fdd22bb7aa52 187
emilmont 1:fdd22bb7aa52 188 /* Working pointer for the scratch buffer of state values */
emilmont 1:fdd22bb7aa52 189 px = pb;
emilmont 1:fdd22bb7aa52 190
emilmont 1:fdd22bb7aa52 191 /* Working pointer for scratch buffer of output values */
emilmont 1:fdd22bb7aa52 192 pScratchOut = pScr2;
emilmont 1:fdd22bb7aa52 193
emilmont 1:fdd22bb7aa52 194 /* Loop over the blockSize. Unroll by a factor of 4.
emilmont 1:fdd22bb7aa52 195 * Compute 4 MACS at a time. */
emilmont 1:fdd22bb7aa52 196 blkCnt = blockSize >> 2;
emilmont 1:fdd22bb7aa52 197
emilmont 1:fdd22bb7aa52 198 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 199 {
emilmont 1:fdd22bb7aa52 200 /* Perform Multiply-Accumulate */
emilmont 1:fdd22bb7aa52 201 in = *pScratchOut + ((q31_t) * px++ * coeff);
emilmont 1:fdd22bb7aa52 202 *pScratchOut++ = in;
emilmont 1:fdd22bb7aa52 203 in = *pScratchOut + ((q31_t) * px++ * coeff);
emilmont 1:fdd22bb7aa52 204 *pScratchOut++ = in;
emilmont 1:fdd22bb7aa52 205 in = *pScratchOut + ((q31_t) * px++ * coeff);
emilmont 1:fdd22bb7aa52 206 *pScratchOut++ = in;
emilmont 1:fdd22bb7aa52 207 in = *pScratchOut + ((q31_t) * px++ * coeff);
emilmont 1:fdd22bb7aa52 208 *pScratchOut++ = in;
emilmont 1:fdd22bb7aa52 209
emilmont 1:fdd22bb7aa52 210 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 211 blkCnt--;
emilmont 1:fdd22bb7aa52 212 }
emilmont 1:fdd22bb7aa52 213
emilmont 1:fdd22bb7aa52 214 /* If the blockSize is not a multiple of 4,
emilmont 1:fdd22bb7aa52 215 * compute the remaining samples */
emilmont 1:fdd22bb7aa52 216 blkCnt = blockSize % 0x4u;
emilmont 1:fdd22bb7aa52 217
emilmont 1:fdd22bb7aa52 218 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 219 {
emilmont 1:fdd22bb7aa52 220 /* Perform Multiply-Accumulate */
emilmont 1:fdd22bb7aa52 221 in = *pScratchOut + ((q31_t) * px++ * coeff);
emilmont 1:fdd22bb7aa52 222 *pScratchOut++ = in;
emilmont 1:fdd22bb7aa52 223
emilmont 1:fdd22bb7aa52 224 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 225 blkCnt--;
emilmont 1:fdd22bb7aa52 226 }
emilmont 1:fdd22bb7aa52 227
emilmont 1:fdd22bb7aa52 228 /* Load the coefficient value and
emilmont 1:fdd22bb7aa52 229 * increment the coefficient buffer for the next set of state values */
emilmont 1:fdd22bb7aa52 230 coeff = *pCoeffs++;
emilmont 1:fdd22bb7aa52 231
emilmont 1:fdd22bb7aa52 232 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 233 readIndex = ((int32_t) S->stateIndex -
emilmont 1:fdd22bb7aa52 234 (int32_t) blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 235
emilmont 1:fdd22bb7aa52 236 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 237 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 238 {
emilmont 1:fdd22bb7aa52 239 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 240 }
emilmont 1:fdd22bb7aa52 241
emilmont 1:fdd22bb7aa52 242 /* Decrement the tap loop counter */
emilmont 1:fdd22bb7aa52 243 tapCnt--;
emilmont 1:fdd22bb7aa52 244 }
emilmont 1:fdd22bb7aa52 245
emilmont 1:fdd22bb7aa52 246 /* All the output values are in pScratchOut buffer.
emilmont 1:fdd22bb7aa52 247 Convert them into 1.15 format, saturate and store in the destination buffer. */
emilmont 1:fdd22bb7aa52 248 /* Loop over the blockSize. */
emilmont 1:fdd22bb7aa52 249 blkCnt = blockSize >> 2;
emilmont 1:fdd22bb7aa52 250
emilmont 1:fdd22bb7aa52 251 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 252 {
emilmont 1:fdd22bb7aa52 253 in1 = (q7_t) __SSAT(*pScr2++ >> 7, 8);
emilmont 1:fdd22bb7aa52 254 in2 = (q7_t) __SSAT(*pScr2++ >> 7, 8);
emilmont 1:fdd22bb7aa52 255 in3 = (q7_t) __SSAT(*pScr2++ >> 7, 8);
emilmont 1:fdd22bb7aa52 256 in4 = (q7_t) __SSAT(*pScr2++ >> 7, 8);
emilmont 1:fdd22bb7aa52 257
emilmont 1:fdd22bb7aa52 258 *__SIMD32(pOut)++ = __PACKq7(in1, in2, in3, in4);
emilmont 1:fdd22bb7aa52 259
emilmont 1:fdd22bb7aa52 260 /* Decrement the blockSize loop counter */
emilmont 1:fdd22bb7aa52 261 blkCnt--;
emilmont 1:fdd22bb7aa52 262 }
emilmont 1:fdd22bb7aa52 263
emilmont 1:fdd22bb7aa52 264 /* If the blockSize is not a multiple of 4,
emilmont 1:fdd22bb7aa52 265 remaining samples are processed in the below loop */
emilmont 1:fdd22bb7aa52 266 blkCnt = blockSize % 0x4u;
emilmont 1:fdd22bb7aa52 267
emilmont 1:fdd22bb7aa52 268 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 269 {
emilmont 1:fdd22bb7aa52 270 *pOut++ = (q7_t) __SSAT(*pScr2++ >> 7, 8);
emilmont 1:fdd22bb7aa52 271
emilmont 1:fdd22bb7aa52 272 /* Decrement the blockSize loop counter */
emilmont 1:fdd22bb7aa52 273 blkCnt--;
emilmont 1:fdd22bb7aa52 274 }
emilmont 1:fdd22bb7aa52 275
emilmont 1:fdd22bb7aa52 276 #else
emilmont 1:fdd22bb7aa52 277
emilmont 1:fdd22bb7aa52 278 /* Run the below code for Cortex-M0 */
emilmont 1:fdd22bb7aa52 279
emilmont 1:fdd22bb7aa52 280 /* BlockSize of Input samples are copied into the state buffer */
emilmont 1:fdd22bb7aa52 281 /* StateIndex points to the starting position to write in the state buffer */
emilmont 1:fdd22bb7aa52 282 arm_circularWrite_q7(py, (int32_t) delaySize, &S->stateIndex, 1, pSrc, 1,
emilmont 1:fdd22bb7aa52 283 blockSize);
emilmont 1:fdd22bb7aa52 284
emilmont 1:fdd22bb7aa52 285 /* Loop over the number of taps. */
emilmont 1:fdd22bb7aa52 286 tapCnt = numTaps;
emilmont 1:fdd22bb7aa52 287
emilmont 1:fdd22bb7aa52 288 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 289 readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 290
emilmont 1:fdd22bb7aa52 291 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 292 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 293 {
emilmont 1:fdd22bb7aa52 294 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 295 }
emilmont 1:fdd22bb7aa52 296
emilmont 1:fdd22bb7aa52 297 /* Working pointer for state buffer is updated */
emilmont 1:fdd22bb7aa52 298 py = pState;
emilmont 1:fdd22bb7aa52 299
emilmont 1:fdd22bb7aa52 300 /* blockSize samples are read from the state buffer */
emilmont 1:fdd22bb7aa52 301 arm_circularRead_q7(py, (int32_t) delaySize, &readIndex, 1, pb, pb,
emilmont 1:fdd22bb7aa52 302 (int32_t) blockSize, 1, blockSize);
emilmont 1:fdd22bb7aa52 303
emilmont 1:fdd22bb7aa52 304 /* Working pointer for the scratch buffer of state values */
emilmont 1:fdd22bb7aa52 305 px = pb;
emilmont 1:fdd22bb7aa52 306
emilmont 1:fdd22bb7aa52 307 /* Working pointer for scratch buffer of output values */
emilmont 1:fdd22bb7aa52 308 pScratchOut = pScr2;
emilmont 1:fdd22bb7aa52 309
emilmont 1:fdd22bb7aa52 310 /* Loop over the blockSize */
emilmont 1:fdd22bb7aa52 311 blkCnt = blockSize;
emilmont 1:fdd22bb7aa52 312
emilmont 1:fdd22bb7aa52 313 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 314 {
emilmont 1:fdd22bb7aa52 315 /* Perform multiplication and store in the scratch buffer */
emilmont 1:fdd22bb7aa52 316 *pScratchOut++ = ((q31_t) * px++ * coeff);
emilmont 1:fdd22bb7aa52 317
emilmont 1:fdd22bb7aa52 318 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 319 blkCnt--;
emilmont 1:fdd22bb7aa52 320 }
emilmont 1:fdd22bb7aa52 321
emilmont 1:fdd22bb7aa52 322 /* Load the coefficient value and
emilmont 1:fdd22bb7aa52 323 * increment the coefficient buffer for the next set of state values */
emilmont 1:fdd22bb7aa52 324 coeff = *pCoeffs++;
emilmont 1:fdd22bb7aa52 325
emilmont 1:fdd22bb7aa52 326 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 327 readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 328
emilmont 1:fdd22bb7aa52 329 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 330 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 331 {
emilmont 1:fdd22bb7aa52 332 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 333 }
emilmont 1:fdd22bb7aa52 334
emilmont 1:fdd22bb7aa52 335 /* Loop over the number of taps. */
emilmont 1:fdd22bb7aa52 336 tapCnt = (uint32_t) numTaps - 1u;
emilmont 1:fdd22bb7aa52 337
emilmont 1:fdd22bb7aa52 338 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 339 {
emilmont 1:fdd22bb7aa52 340 /* Working pointer for state buffer is updated */
emilmont 1:fdd22bb7aa52 341 py = pState;
emilmont 1:fdd22bb7aa52 342
emilmont 1:fdd22bb7aa52 343 /* blockSize samples are read from the state buffer */
emilmont 1:fdd22bb7aa52 344 arm_circularRead_q7(py, (int32_t) delaySize, &readIndex, 1, pb, pb,
emilmont 1:fdd22bb7aa52 345 (int32_t) blockSize, 1, blockSize);
emilmont 1:fdd22bb7aa52 346
emilmont 1:fdd22bb7aa52 347 /* Working pointer for the scratch buffer of state values */
emilmont 1:fdd22bb7aa52 348 px = pb;
emilmont 1:fdd22bb7aa52 349
emilmont 1:fdd22bb7aa52 350 /* Working pointer for scratch buffer of output values */
emilmont 1:fdd22bb7aa52 351 pScratchOut = pScr2;
emilmont 1:fdd22bb7aa52 352
emilmont 1:fdd22bb7aa52 353 /* Loop over the blockSize */
emilmont 1:fdd22bb7aa52 354 blkCnt = blockSize;
emilmont 1:fdd22bb7aa52 355
emilmont 1:fdd22bb7aa52 356 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 357 {
emilmont 1:fdd22bb7aa52 358 /* Perform Multiply-Accumulate */
emilmont 1:fdd22bb7aa52 359 in = *pScratchOut + ((q31_t) * px++ * coeff);
emilmont 1:fdd22bb7aa52 360 *pScratchOut++ = in;
emilmont 1:fdd22bb7aa52 361
emilmont 1:fdd22bb7aa52 362 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 363 blkCnt--;
emilmont 1:fdd22bb7aa52 364 }
emilmont 1:fdd22bb7aa52 365
emilmont 1:fdd22bb7aa52 366 /* Load the coefficient value and
emilmont 1:fdd22bb7aa52 367 * increment the coefficient buffer for the next set of state values */
emilmont 1:fdd22bb7aa52 368 coeff = *pCoeffs++;
emilmont 1:fdd22bb7aa52 369
emilmont 1:fdd22bb7aa52 370 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 371 readIndex =
emilmont 1:fdd22bb7aa52 372 ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 373
emilmont 1:fdd22bb7aa52 374 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 375 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 376 {
emilmont 1:fdd22bb7aa52 377 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 378 }
emilmont 1:fdd22bb7aa52 379
emilmont 1:fdd22bb7aa52 380 /* Decrement the tap loop counter */
emilmont 1:fdd22bb7aa52 381 tapCnt--;
emilmont 1:fdd22bb7aa52 382 }
emilmont 1:fdd22bb7aa52 383
emilmont 1:fdd22bb7aa52 384 /* All the output values are in pScratchOut buffer.
emilmont 1:fdd22bb7aa52 385 Convert them into 1.15 format, saturate and store in the destination buffer. */
emilmont 1:fdd22bb7aa52 386 /* Loop over the blockSize. */
emilmont 1:fdd22bb7aa52 387 blkCnt = blockSize;
emilmont 1:fdd22bb7aa52 388
emilmont 1:fdd22bb7aa52 389 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 390 {
emilmont 1:fdd22bb7aa52 391 *pOut++ = (q7_t) __SSAT(*pScr2++ >> 7, 8);
emilmont 1:fdd22bb7aa52 392
emilmont 1:fdd22bb7aa52 393 /* Decrement the blockSize loop counter */
emilmont 1:fdd22bb7aa52 394 blkCnt--;
emilmont 1:fdd22bb7aa52 395 }
emilmont 1:fdd22bb7aa52 396
mbed_official 3:7a284390b0ce 397 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
emilmont 1:fdd22bb7aa52 398
emilmont 1:fdd22bb7aa52 399 }
emilmont 1:fdd22bb7aa52 400
emilmont 1:fdd22bb7aa52 401 /**
emilmont 1:fdd22bb7aa52 402 * @} end of FIR_Sparse group
emilmont 1:fdd22bb7aa52 403 */