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_sparse_f32.c
emilmont 1:fdd22bb7aa52 9 *
emilmont 2:da51fb522205 10 * Description: Floating-point 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 * @ingroup groupFilters
emilmont 1:fdd22bb7aa52 44 */
emilmont 1:fdd22bb7aa52 45
emilmont 1:fdd22bb7aa52 46 /**
emilmont 1:fdd22bb7aa52 47 * @defgroup FIR_Sparse Finite Impulse Response (FIR) Sparse Filters
emilmont 1:fdd22bb7aa52 48 *
emilmont 1:fdd22bb7aa52 49 * This group of functions implements sparse FIR filters.
emilmont 1:fdd22bb7aa52 50 * Sparse FIR filters are equivalent to standard FIR filters except that most of the coefficients are equal to zero.
emilmont 1:fdd22bb7aa52 51 * Sparse filters are used for simulating reflections in communications and audio applications.
emilmont 1:fdd22bb7aa52 52 *
emilmont 1:fdd22bb7aa52 53 * There are separate functions for Q7, Q15, Q31, and floating-point data types.
emilmont 1:fdd22bb7aa52 54 * The functions operate on blocks of input and output data and each call to the function processes
emilmont 1:fdd22bb7aa52 55 * <code>blockSize</code> samples through the filter. <code>pSrc</code> and
emilmont 1:fdd22bb7aa52 56 * <code>pDst</code> points to input and output arrays respectively containing <code>blockSize</code> values.
emilmont 1:fdd22bb7aa52 57 *
emilmont 1:fdd22bb7aa52 58 * \par Algorithm:
emilmont 1:fdd22bb7aa52 59 * The sparse filter instant structure contains an array of tap indices <code>pTapDelay</code> which specifies the locations of the non-zero coefficients.
emilmont 1:fdd22bb7aa52 60 * This is in addition to the coefficient array <code>b</code>.
emilmont 1:fdd22bb7aa52 61 * The implementation essentially skips the multiplications by zero and leads to an efficient realization.
emilmont 1:fdd22bb7aa52 62 * <pre>
emilmont 1:fdd22bb7aa52 63 * y[n] = b[0] * x[n-pTapDelay[0]] + b[1] * x[n-pTapDelay[1]] + b[2] * x[n-pTapDelay[2]] + ...+ b[numTaps-1] * x[n-pTapDelay[numTaps-1]]
emilmont 1:fdd22bb7aa52 64 * </pre>
emilmont 1:fdd22bb7aa52 65 * \par
emilmont 1:fdd22bb7aa52 66 * \image html FIRSparse.gif "Sparse FIR filter. b[n] represents the filter coefficients"
emilmont 1:fdd22bb7aa52 67 * \par
emilmont 1:fdd22bb7aa52 68 * <code>pCoeffs</code> points to a coefficient array of size <code>numTaps</code>;
emilmont 1:fdd22bb7aa52 69 * <code>pTapDelay</code> points to an array of nonzero indices and is also of size <code>numTaps</code>;
emilmont 1:fdd22bb7aa52 70 * <code>pState</code> points to a state array of size <code>maxDelay + blockSize</code>, where
emilmont 1:fdd22bb7aa52 71 * <code>maxDelay</code> is the largest offset value that is ever used in the <code>pTapDelay</code> array.
emilmont 1:fdd22bb7aa52 72 * Some of the processing functions also require temporary working buffers.
emilmont 1:fdd22bb7aa52 73 *
emilmont 1:fdd22bb7aa52 74 * \par Instance Structure
emilmont 1:fdd22bb7aa52 75 * The coefficients and state variables for a filter are stored together in an instance data structure.
emilmont 1:fdd22bb7aa52 76 * A separate instance structure must be defined for each filter.
emilmont 1:fdd22bb7aa52 77 * Coefficient and offset arrays may be shared among several instances while state variable arrays cannot be shared.
emilmont 1:fdd22bb7aa52 78 * There are separate instance structure declarations for each of the 4 supported data types.
emilmont 1:fdd22bb7aa52 79 *
emilmont 1:fdd22bb7aa52 80 * \par Initialization Functions
emilmont 1:fdd22bb7aa52 81 * There is also an associated initialization function for each data type.
emilmont 1:fdd22bb7aa52 82 * The initialization function performs the following operations:
emilmont 1:fdd22bb7aa52 83 * - Sets the values of the internal structure fields.
emilmont 1:fdd22bb7aa52 84 * - Zeros out the values in the state buffer.
mbed_official 3:7a284390b0ce 85 * To do this manually without calling the init function, assign the follow subfields of the instance structure:
mbed_official 3:7a284390b0ce 86 * numTaps, pCoeffs, pTapDelay, maxDelay, stateIndex, pState. Also set all of the values in pState to zero.
emilmont 1:fdd22bb7aa52 87 *
emilmont 1:fdd22bb7aa52 88 * \par
emilmont 1:fdd22bb7aa52 89 * Use of the initialization function is optional.
emilmont 1:fdd22bb7aa52 90 * However, if the initialization function is used, then the instance structure cannot be placed into a const data section.
emilmont 1:fdd22bb7aa52 91 * To place an instance structure into a const data section, the instance structure must be manually initialized.
emilmont 1:fdd22bb7aa52 92 * Set the values in the state buffer to zeros before static initialization.
emilmont 1:fdd22bb7aa52 93 * The code below statically initializes each of the 4 different data type filter instance structures
emilmont 1:fdd22bb7aa52 94 * <pre>
emilmont 1:fdd22bb7aa52 95 *arm_fir_sparse_instance_f32 S = {numTaps, 0, pState, pCoeffs, maxDelay, pTapDelay};
emilmont 1:fdd22bb7aa52 96 *arm_fir_sparse_instance_q31 S = {numTaps, 0, pState, pCoeffs, maxDelay, pTapDelay};
emilmont 1:fdd22bb7aa52 97 *arm_fir_sparse_instance_q15 S = {numTaps, 0, pState, pCoeffs, maxDelay, pTapDelay};
emilmont 1:fdd22bb7aa52 98 *arm_fir_sparse_instance_q7 S = {numTaps, 0, pState, pCoeffs, maxDelay, pTapDelay};
emilmont 1:fdd22bb7aa52 99 * </pre>
emilmont 1:fdd22bb7aa52 100 * \par
emilmont 1:fdd22bb7aa52 101 *
emilmont 1:fdd22bb7aa52 102 * \par Fixed-Point Behavior
emilmont 1:fdd22bb7aa52 103 * Care must be taken when using the fixed-point versions of the sparse FIR filter functions.
emilmont 1:fdd22bb7aa52 104 * In particular, the overflow and saturation behavior of the accumulator used in each function must be considered.
emilmont 1:fdd22bb7aa52 105 * Refer to the function specific documentation below for usage guidelines.
emilmont 1:fdd22bb7aa52 106 */
emilmont 1:fdd22bb7aa52 107
emilmont 1:fdd22bb7aa52 108 /**
emilmont 1:fdd22bb7aa52 109 * @addtogroup FIR_Sparse
emilmont 1:fdd22bb7aa52 110 * @{
emilmont 1:fdd22bb7aa52 111 */
emilmont 1:fdd22bb7aa52 112
emilmont 1:fdd22bb7aa52 113 /**
emilmont 1:fdd22bb7aa52 114 * @brief Processing function for the floating-point sparse FIR filter.
emilmont 1:fdd22bb7aa52 115 * @param[in] *S points to an instance of the floating-point sparse FIR structure.
emilmont 1:fdd22bb7aa52 116 * @param[in] *pSrc points to the block of input data.
emilmont 1:fdd22bb7aa52 117 * @param[out] *pDst points to the block of output data
emilmont 1:fdd22bb7aa52 118 * @param[in] *pScratchIn points to a temporary buffer of size blockSize.
emilmont 1:fdd22bb7aa52 119 * @param[in] blockSize number of input samples to process per call.
emilmont 1:fdd22bb7aa52 120 * @return none.
emilmont 1:fdd22bb7aa52 121 */
emilmont 1:fdd22bb7aa52 122
emilmont 1:fdd22bb7aa52 123 void arm_fir_sparse_f32(
emilmont 1:fdd22bb7aa52 124 arm_fir_sparse_instance_f32 * S,
emilmont 1:fdd22bb7aa52 125 float32_t * pSrc,
emilmont 1:fdd22bb7aa52 126 float32_t * pDst,
emilmont 1:fdd22bb7aa52 127 float32_t * pScratchIn,
emilmont 1:fdd22bb7aa52 128 uint32_t blockSize)
emilmont 1:fdd22bb7aa52 129 {
emilmont 1:fdd22bb7aa52 130
emilmont 1:fdd22bb7aa52 131 float32_t *pState = S->pState; /* State pointer */
emilmont 1:fdd22bb7aa52 132 float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */
emilmont 1:fdd22bb7aa52 133 float32_t *px; /* Scratch buffer pointer */
emilmont 1:fdd22bb7aa52 134 float32_t *py = pState; /* Temporary pointers for state buffer */
emilmont 1:fdd22bb7aa52 135 float32_t *pb = pScratchIn; /* Temporary pointers for scratch buffer */
emilmont 1:fdd22bb7aa52 136 float32_t *pOut; /* Destination pointer */
emilmont 1:fdd22bb7aa52 137 int32_t *pTapDelay = S->pTapDelay; /* Pointer to the array containing offset of the non-zero tap values. */
emilmont 1:fdd22bb7aa52 138 uint32_t delaySize = S->maxDelay + blockSize; /* state length */
emilmont 1:fdd22bb7aa52 139 uint16_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */
emilmont 1:fdd22bb7aa52 140 int32_t readIndex; /* Read index of the state buffer */
emilmont 1:fdd22bb7aa52 141 uint32_t tapCnt, blkCnt; /* loop counters */
emilmont 1:fdd22bb7aa52 142 float32_t coeff = *pCoeffs++; /* Read the first coefficient value */
emilmont 1:fdd22bb7aa52 143
emilmont 1:fdd22bb7aa52 144
emilmont 1:fdd22bb7aa52 145
emilmont 1:fdd22bb7aa52 146 /* BlockSize of Input samples are copied into the state buffer */
emilmont 1:fdd22bb7aa52 147 /* StateIndex points to the starting position to write in the state buffer */
emilmont 1:fdd22bb7aa52 148 arm_circularWrite_f32((int32_t *) py, delaySize, &S->stateIndex, 1,
emilmont 1:fdd22bb7aa52 149 (int32_t *) pSrc, 1, blockSize);
emilmont 1:fdd22bb7aa52 150
emilmont 1:fdd22bb7aa52 151
emilmont 1:fdd22bb7aa52 152 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 153 readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 154
emilmont 1:fdd22bb7aa52 155 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 156 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 157 {
emilmont 1:fdd22bb7aa52 158 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 159 }
emilmont 1:fdd22bb7aa52 160
emilmont 1:fdd22bb7aa52 161 /* Working pointer for state buffer is updated */
emilmont 1:fdd22bb7aa52 162 py = pState;
emilmont 1:fdd22bb7aa52 163
emilmont 1:fdd22bb7aa52 164 /* blockSize samples are read from the state buffer */
emilmont 1:fdd22bb7aa52 165 arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1,
emilmont 1:fdd22bb7aa52 166 (int32_t *) pb, (int32_t *) pb, blockSize, 1,
emilmont 1:fdd22bb7aa52 167 blockSize);
emilmont 1:fdd22bb7aa52 168
emilmont 1:fdd22bb7aa52 169 /* Working pointer for the scratch buffer */
emilmont 1:fdd22bb7aa52 170 px = pb;
emilmont 1:fdd22bb7aa52 171
emilmont 1:fdd22bb7aa52 172 /* Working pointer for destination buffer */
emilmont 1:fdd22bb7aa52 173 pOut = pDst;
emilmont 1:fdd22bb7aa52 174
emilmont 1:fdd22bb7aa52 175
mbed_official 3:7a284390b0ce 176 #ifndef ARM_MATH_CM0_FAMILY
emilmont 1:fdd22bb7aa52 177
emilmont 1:fdd22bb7aa52 178 /* Run the below code for Cortex-M4 and Cortex-M3 */
emilmont 1:fdd22bb7aa52 179
emilmont 1:fdd22bb7aa52 180 /* Loop over the blockSize. Unroll by a factor of 4.
emilmont 1:fdd22bb7aa52 181 * Compute 4 Multiplications at a time. */
emilmont 1:fdd22bb7aa52 182 blkCnt = blockSize >> 2u;
emilmont 1:fdd22bb7aa52 183
emilmont 1:fdd22bb7aa52 184 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 185 {
emilmont 1:fdd22bb7aa52 186 /* Perform Multiplications and store in destination buffer */
emilmont 1:fdd22bb7aa52 187 *pOut++ = *px++ * coeff;
emilmont 1:fdd22bb7aa52 188 *pOut++ = *px++ * coeff;
emilmont 1:fdd22bb7aa52 189 *pOut++ = *px++ * coeff;
emilmont 1:fdd22bb7aa52 190 *pOut++ = *px++ * coeff;
emilmont 1:fdd22bb7aa52 191
emilmont 1:fdd22bb7aa52 192 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 193 blkCnt--;
emilmont 1:fdd22bb7aa52 194 }
emilmont 1:fdd22bb7aa52 195
emilmont 1:fdd22bb7aa52 196 /* If the blockSize is not a multiple of 4,
emilmont 1:fdd22bb7aa52 197 * compute the remaining samples */
emilmont 1:fdd22bb7aa52 198 blkCnt = blockSize % 0x4u;
emilmont 1:fdd22bb7aa52 199
emilmont 1:fdd22bb7aa52 200 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 201 {
emilmont 1:fdd22bb7aa52 202 /* Perform Multiplications and store in destination buffer */
emilmont 1:fdd22bb7aa52 203 *pOut++ = *px++ * coeff;
emilmont 1:fdd22bb7aa52 204
emilmont 1:fdd22bb7aa52 205 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 206 blkCnt--;
emilmont 1:fdd22bb7aa52 207 }
emilmont 1:fdd22bb7aa52 208
emilmont 1:fdd22bb7aa52 209 /* Load the coefficient value and
emilmont 1:fdd22bb7aa52 210 * increment the coefficient buffer for the next set of state values */
emilmont 1:fdd22bb7aa52 211 coeff = *pCoeffs++;
emilmont 1:fdd22bb7aa52 212
emilmont 1:fdd22bb7aa52 213 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 214 readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 215
emilmont 1:fdd22bb7aa52 216 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 217 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 218 {
emilmont 1:fdd22bb7aa52 219 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 220 }
emilmont 1:fdd22bb7aa52 221
emilmont 1:fdd22bb7aa52 222 /* Loop over the number of taps. */
mbed_official 5:3762170b6d4d 223 tapCnt = (uint32_t) numTaps - 2u;
emilmont 1:fdd22bb7aa52 224
emilmont 1:fdd22bb7aa52 225 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 226 {
emilmont 1:fdd22bb7aa52 227
emilmont 1:fdd22bb7aa52 228 /* Working pointer for state buffer is updated */
emilmont 1:fdd22bb7aa52 229 py = pState;
emilmont 1:fdd22bb7aa52 230
emilmont 1:fdd22bb7aa52 231 /* blockSize samples are read from the state buffer */
emilmont 1:fdd22bb7aa52 232 arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1,
emilmont 1:fdd22bb7aa52 233 (int32_t *) pb, (int32_t *) pb, blockSize, 1,
emilmont 1:fdd22bb7aa52 234 blockSize);
emilmont 1:fdd22bb7aa52 235
emilmont 1:fdd22bb7aa52 236 /* Working pointer for the scratch buffer */
emilmont 1:fdd22bb7aa52 237 px = pb;
emilmont 1:fdd22bb7aa52 238
emilmont 1:fdd22bb7aa52 239 /* Working pointer for destination buffer */
emilmont 1:fdd22bb7aa52 240 pOut = pDst;
emilmont 1:fdd22bb7aa52 241
emilmont 1:fdd22bb7aa52 242 /* Loop over the blockSize. Unroll by a factor of 4.
emilmont 1:fdd22bb7aa52 243 * Compute 4 MACS at a time. */
emilmont 1:fdd22bb7aa52 244 blkCnt = blockSize >> 2u;
emilmont 1:fdd22bb7aa52 245
emilmont 1:fdd22bb7aa52 246 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 247 {
emilmont 1:fdd22bb7aa52 248 /* Perform Multiply-Accumulate */
emilmont 1:fdd22bb7aa52 249 *pOut++ += *px++ * coeff;
emilmont 1:fdd22bb7aa52 250 *pOut++ += *px++ * coeff;
emilmont 1:fdd22bb7aa52 251 *pOut++ += *px++ * coeff;
emilmont 1:fdd22bb7aa52 252 *pOut++ += *px++ * coeff;
emilmont 1:fdd22bb7aa52 253
emilmont 1:fdd22bb7aa52 254 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 255 blkCnt--;
emilmont 1:fdd22bb7aa52 256 }
emilmont 1:fdd22bb7aa52 257
emilmont 1:fdd22bb7aa52 258 /* If the blockSize is not a multiple of 4,
emilmont 1:fdd22bb7aa52 259 * compute the remaining samples */
emilmont 1:fdd22bb7aa52 260 blkCnt = blockSize % 0x4u;
emilmont 1:fdd22bb7aa52 261
emilmont 1:fdd22bb7aa52 262 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 263 {
emilmont 1:fdd22bb7aa52 264 /* Perform Multiply-Accumulate */
emilmont 1:fdd22bb7aa52 265 *pOut++ += *px++ * coeff;
emilmont 1:fdd22bb7aa52 266
emilmont 1:fdd22bb7aa52 267 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 268 blkCnt--;
emilmont 1:fdd22bb7aa52 269 }
emilmont 1:fdd22bb7aa52 270
emilmont 1:fdd22bb7aa52 271 /* Load the coefficient value and
emilmont 1:fdd22bb7aa52 272 * increment the coefficient buffer for the next set of state values */
emilmont 1:fdd22bb7aa52 273 coeff = *pCoeffs++;
emilmont 1:fdd22bb7aa52 274
emilmont 1:fdd22bb7aa52 275 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 276 readIndex = ((int32_t) S->stateIndex -
emilmont 1:fdd22bb7aa52 277 (int32_t) blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 278
emilmont 1:fdd22bb7aa52 279 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 280 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 281 {
emilmont 1:fdd22bb7aa52 282 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 283 }
emilmont 1:fdd22bb7aa52 284
emilmont 1:fdd22bb7aa52 285 /* Decrement the tap loop counter */
emilmont 1:fdd22bb7aa52 286 tapCnt--;
emilmont 1:fdd22bb7aa52 287 }
mbed_official 5:3762170b6d4d 288
mbed_official 5:3762170b6d4d 289 /* Compute last tap without the final read of pTapDelay */
mbed_official 5:3762170b6d4d 290
mbed_official 5:3762170b6d4d 291 /* Working pointer for state buffer is updated */
mbed_official 5:3762170b6d4d 292 py = pState;
mbed_official 5:3762170b6d4d 293
mbed_official 5:3762170b6d4d 294 /* blockSize samples are read from the state buffer */
mbed_official 5:3762170b6d4d 295 arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1,
mbed_official 5:3762170b6d4d 296 (int32_t *) pb, (int32_t *) pb, blockSize, 1,
mbed_official 5:3762170b6d4d 297 blockSize);
mbed_official 5:3762170b6d4d 298
mbed_official 5:3762170b6d4d 299 /* Working pointer for the scratch buffer */
mbed_official 5:3762170b6d4d 300 px = pb;
mbed_official 5:3762170b6d4d 301
mbed_official 5:3762170b6d4d 302 /* Working pointer for destination buffer */
mbed_official 5:3762170b6d4d 303 pOut = pDst;
mbed_official 5:3762170b6d4d 304
mbed_official 5:3762170b6d4d 305 /* Loop over the blockSize. Unroll by a factor of 4.
mbed_official 5:3762170b6d4d 306 * Compute 4 MACS at a time. */
mbed_official 5:3762170b6d4d 307 blkCnt = blockSize >> 2u;
mbed_official 5:3762170b6d4d 308
mbed_official 5:3762170b6d4d 309 while(blkCnt > 0u)
mbed_official 5:3762170b6d4d 310 {
mbed_official 5:3762170b6d4d 311 /* Perform Multiply-Accumulate */
mbed_official 5:3762170b6d4d 312 *pOut++ += *px++ * coeff;
mbed_official 5:3762170b6d4d 313 *pOut++ += *px++ * coeff;
mbed_official 5:3762170b6d4d 314 *pOut++ += *px++ * coeff;
mbed_official 5:3762170b6d4d 315 *pOut++ += *px++ * coeff;
mbed_official 5:3762170b6d4d 316
mbed_official 5:3762170b6d4d 317 /* Decrement the loop counter */
mbed_official 5:3762170b6d4d 318 blkCnt--;
mbed_official 5:3762170b6d4d 319 }
mbed_official 5:3762170b6d4d 320
mbed_official 5:3762170b6d4d 321 /* If the blockSize is not a multiple of 4,
mbed_official 5:3762170b6d4d 322 * compute the remaining samples */
mbed_official 5:3762170b6d4d 323 blkCnt = blockSize % 0x4u;
mbed_official 5:3762170b6d4d 324
mbed_official 5:3762170b6d4d 325 while(blkCnt > 0u)
mbed_official 5:3762170b6d4d 326 {
mbed_official 5:3762170b6d4d 327 /* Perform Multiply-Accumulate */
mbed_official 5:3762170b6d4d 328 *pOut++ += *px++ * coeff;
mbed_official 5:3762170b6d4d 329
mbed_official 5:3762170b6d4d 330 /* Decrement the loop counter */
mbed_official 5:3762170b6d4d 331 blkCnt--;
mbed_official 5:3762170b6d4d 332 }
emilmont 1:fdd22bb7aa52 333
emilmont 1:fdd22bb7aa52 334 #else
emilmont 1:fdd22bb7aa52 335
emilmont 1:fdd22bb7aa52 336 /* Run the below code for Cortex-M0 */
emilmont 1:fdd22bb7aa52 337
emilmont 1:fdd22bb7aa52 338 blkCnt = blockSize;
emilmont 1:fdd22bb7aa52 339
emilmont 1:fdd22bb7aa52 340 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 341 {
emilmont 1:fdd22bb7aa52 342 /* Perform Multiplications and store in destination buffer */
emilmont 1:fdd22bb7aa52 343 *pOut++ = *px++ * coeff;
emilmont 1:fdd22bb7aa52 344
emilmont 1:fdd22bb7aa52 345 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 346 blkCnt--;
emilmont 1:fdd22bb7aa52 347 }
emilmont 1:fdd22bb7aa52 348
emilmont 1:fdd22bb7aa52 349 /* Load the coefficient value and
emilmont 1:fdd22bb7aa52 350 * increment the coefficient buffer for the next set of state values */
emilmont 1:fdd22bb7aa52 351 coeff = *pCoeffs++;
emilmont 1:fdd22bb7aa52 352
emilmont 1:fdd22bb7aa52 353 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 354 readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 355
emilmont 1:fdd22bb7aa52 356 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 357 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 358 {
emilmont 1:fdd22bb7aa52 359 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 360 }
emilmont 1:fdd22bb7aa52 361
emilmont 1:fdd22bb7aa52 362 /* Loop over the number of taps. */
mbed_official 5:3762170b6d4d 363 tapCnt = (uint32_t) numTaps - 2u;
emilmont 1:fdd22bb7aa52 364
emilmont 1:fdd22bb7aa52 365 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 366 {
emilmont 1:fdd22bb7aa52 367
emilmont 1:fdd22bb7aa52 368 /* Working pointer for state buffer is updated */
emilmont 1:fdd22bb7aa52 369 py = pState;
emilmont 1:fdd22bb7aa52 370
emilmont 1:fdd22bb7aa52 371 /* blockSize samples are read from the state buffer */
emilmont 1:fdd22bb7aa52 372 arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1,
emilmont 1:fdd22bb7aa52 373 (int32_t *) pb, (int32_t *) pb, blockSize, 1,
emilmont 1:fdd22bb7aa52 374 blockSize);
emilmont 1:fdd22bb7aa52 375
emilmont 1:fdd22bb7aa52 376 /* Working pointer for the scratch buffer */
emilmont 1:fdd22bb7aa52 377 px = pb;
emilmont 1:fdd22bb7aa52 378
emilmont 1:fdd22bb7aa52 379 /* Working pointer for destination buffer */
emilmont 1:fdd22bb7aa52 380 pOut = pDst;
emilmont 1:fdd22bb7aa52 381
emilmont 1:fdd22bb7aa52 382 blkCnt = blockSize;
emilmont 1:fdd22bb7aa52 383
emilmont 1:fdd22bb7aa52 384 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 385 {
emilmont 1:fdd22bb7aa52 386 /* Perform Multiply-Accumulate */
emilmont 1:fdd22bb7aa52 387 *pOut++ += *px++ * coeff;
emilmont 1:fdd22bb7aa52 388
emilmont 1:fdd22bb7aa52 389 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 390 blkCnt--;
emilmont 1:fdd22bb7aa52 391 }
emilmont 1:fdd22bb7aa52 392
emilmont 1:fdd22bb7aa52 393 /* Load the coefficient value and
emilmont 1:fdd22bb7aa52 394 * increment the coefficient buffer for the next set of state values */
emilmont 1:fdd22bb7aa52 395 coeff = *pCoeffs++;
emilmont 1:fdd22bb7aa52 396
emilmont 1:fdd22bb7aa52 397 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 398 readIndex =
emilmont 1:fdd22bb7aa52 399 ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 400
emilmont 1:fdd22bb7aa52 401 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 402 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 403 {
emilmont 1:fdd22bb7aa52 404 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 405 }
emilmont 1:fdd22bb7aa52 406
emilmont 1:fdd22bb7aa52 407 /* Decrement the tap loop counter */
emilmont 1:fdd22bb7aa52 408 tapCnt--;
emilmont 1:fdd22bb7aa52 409 }
mbed_official 5:3762170b6d4d 410
mbed_official 5:3762170b6d4d 411 /* Compute last tap without the final read of pTapDelay */
mbed_official 5:3762170b6d4d 412
mbed_official 5:3762170b6d4d 413 /* Working pointer for state buffer is updated */
mbed_official 5:3762170b6d4d 414 py = pState;
mbed_official 5:3762170b6d4d 415
mbed_official 5:3762170b6d4d 416 /* blockSize samples are read from the state buffer */
mbed_official 5:3762170b6d4d 417 arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1,
mbed_official 5:3762170b6d4d 418 (int32_t *) pb, (int32_t *) pb, blockSize, 1,
mbed_official 5:3762170b6d4d 419 blockSize);
mbed_official 5:3762170b6d4d 420
mbed_official 5:3762170b6d4d 421 /* Working pointer for the scratch buffer */
mbed_official 5:3762170b6d4d 422 px = pb;
mbed_official 5:3762170b6d4d 423
mbed_official 5:3762170b6d4d 424 /* Working pointer for destination buffer */
mbed_official 5:3762170b6d4d 425 pOut = pDst;
mbed_official 5:3762170b6d4d 426
mbed_official 5:3762170b6d4d 427 blkCnt = blockSize;
mbed_official 5:3762170b6d4d 428
mbed_official 5:3762170b6d4d 429 while(blkCnt > 0u)
mbed_official 5:3762170b6d4d 430 {
mbed_official 5:3762170b6d4d 431 /* Perform Multiply-Accumulate */
mbed_official 5:3762170b6d4d 432 *pOut++ += *px++ * coeff;
mbed_official 5:3762170b6d4d 433
mbed_official 5:3762170b6d4d 434 /* Decrement the loop counter */
mbed_official 5:3762170b6d4d 435 blkCnt--;
mbed_official 5:3762170b6d4d 436 }
emilmont 1:fdd22bb7aa52 437
mbed_official 3:7a284390b0ce 438 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
emilmont 1:fdd22bb7aa52 439
emilmont 1:fdd22bb7aa52 440 }
emilmont 1:fdd22bb7aa52 441
emilmont 1:fdd22bb7aa52 442 /**
emilmont 1:fdd22bb7aa52 443 * @} end of FIR_Sparse group
emilmont 1:fdd22bb7aa52 444 */