V4.0.1 of the ARM CMSIS DSP libraries. Note that arm_bitreversal2.s, arm_cfft_f32.c and arm_rfft_fast_f32.c had to be removed. arm_bitreversal2.s will not assemble with the online tools. So, the fast f32 FFT functions are not yet available. All the other FFT functions are available.
Dependents: MPU9150_Example fir_f32 fir_f32 MPU9150_nucleo_noni2cdev ... more
FilteringFunctions/arm_fir_sparse_q7.c@0:3d9c67d97d6f, 2014-07-28 (annotated)
- Committer:
- emh203
- Date:
- Mon Jul 28 15:03:15 2014 +0000
- Revision:
- 0:3d9c67d97d6f
1st working commit. Had to remove arm_bitreversal2.s arm_cfft_f32.c and arm_rfft_fast_f32.c. The .s will not assemble. For now I removed these functions so we could at least have a library for the other functions.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| emh203 | 0:3d9c67d97d6f | 1 | /* ---------------------------------------------------------------------- |
| emh203 | 0:3d9c67d97d6f | 2 | * Copyright (C) 2010-2014 ARM Limited. All rights reserved. |
| emh203 | 0:3d9c67d97d6f | 3 | * |
| emh203 | 0:3d9c67d97d6f | 4 | * $Date: 12. March 2014 |
| emh203 | 0:3d9c67d97d6f | 5 | * $Revision: V1.4.3 |
| emh203 | 0:3d9c67d97d6f | 6 | * |
| emh203 | 0:3d9c67d97d6f | 7 | * Project: CMSIS DSP Library |
| emh203 | 0:3d9c67d97d6f | 8 | * Title: arm_fir_sparse_q7.c |
| emh203 | 0:3d9c67d97d6f | 9 | * |
| emh203 | 0:3d9c67d97d6f | 10 | * Description: Q7 sparse FIR filter processing function. |
| emh203 | 0:3d9c67d97d6f | 11 | * |
| emh203 | 0:3d9c67d97d6f | 12 | * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0 |
| emh203 | 0:3d9c67d97d6f | 13 | * |
| emh203 | 0:3d9c67d97d6f | 14 | * Redistribution and use in source and binary forms, with or without |
| emh203 | 0:3d9c67d97d6f | 15 | * modification, are permitted provided that the following conditions |
| emh203 | 0:3d9c67d97d6f | 16 | * are met: |
| emh203 | 0:3d9c67d97d6f | 17 | * - Redistributions of source code must retain the above copyright |
| emh203 | 0:3d9c67d97d6f | 18 | * notice, this list of conditions and the following disclaimer. |
| emh203 | 0:3d9c67d97d6f | 19 | * - Redistributions in binary form must reproduce the above copyright |
| emh203 | 0:3d9c67d97d6f | 20 | * notice, this list of conditions and the following disclaimer in |
| emh203 | 0:3d9c67d97d6f | 21 | * the documentation and/or other materials provided with the |
| emh203 | 0:3d9c67d97d6f | 22 | * distribution. |
| emh203 | 0:3d9c67d97d6f | 23 | * - Neither the name of ARM LIMITED nor the names of its contributors |
| emh203 | 0:3d9c67d97d6f | 24 | * may be used to endorse or promote products derived from this |
| emh203 | 0:3d9c67d97d6f | 25 | * software without specific prior written permission. |
| emh203 | 0:3d9c67d97d6f | 26 | * |
| emh203 | 0:3d9c67d97d6f | 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| emh203 | 0:3d9c67d97d6f | 28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| emh203 | 0:3d9c67d97d6f | 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| emh203 | 0:3d9c67d97d6f | 30 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| emh203 | 0:3d9c67d97d6f | 31 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| emh203 | 0:3d9c67d97d6f | 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| emh203 | 0:3d9c67d97d6f | 33 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| emh203 | 0:3d9c67d97d6f | 34 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| emh203 | 0:3d9c67d97d6f | 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| emh203 | 0:3d9c67d97d6f | 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| emh203 | 0:3d9c67d97d6f | 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| emh203 | 0:3d9c67d97d6f | 38 | * POSSIBILITY OF SUCH DAMAGE. |
| emh203 | 0:3d9c67d97d6f | 39 | * ------------------------------------------------------------------- */ |
| emh203 | 0:3d9c67d97d6f | 40 | #include "arm_math.h" |
| emh203 | 0:3d9c67d97d6f | 41 | |
| emh203 | 0:3d9c67d97d6f | 42 | |
| emh203 | 0:3d9c67d97d6f | 43 | /** |
| emh203 | 0:3d9c67d97d6f | 44 | * @ingroup groupFilters |
| emh203 | 0:3d9c67d97d6f | 45 | */ |
| emh203 | 0:3d9c67d97d6f | 46 | |
| emh203 | 0:3d9c67d97d6f | 47 | /** |
| emh203 | 0:3d9c67d97d6f | 48 | * @addtogroup FIR_Sparse |
| emh203 | 0:3d9c67d97d6f | 49 | * @{ |
| emh203 | 0:3d9c67d97d6f | 50 | */ |
| emh203 | 0:3d9c67d97d6f | 51 | |
| emh203 | 0:3d9c67d97d6f | 52 | |
| emh203 | 0:3d9c67d97d6f | 53 | /** |
| emh203 | 0:3d9c67d97d6f | 54 | * @brief Processing function for the Q7 sparse FIR filter. |
| emh203 | 0:3d9c67d97d6f | 55 | * @param[in] *S points to an instance of the Q7 sparse FIR structure. |
| emh203 | 0:3d9c67d97d6f | 56 | * @param[in] *pSrc points to the block of input data. |
| emh203 | 0:3d9c67d97d6f | 57 | * @param[out] *pDst points to the block of output data |
| emh203 | 0:3d9c67d97d6f | 58 | * @param[in] *pScratchIn points to a temporary buffer of size blockSize. |
| emh203 | 0:3d9c67d97d6f | 59 | * @param[in] *pScratchOut points to a temporary buffer of size blockSize. |
| emh203 | 0:3d9c67d97d6f | 60 | * @param[in] blockSize number of input samples to process per call. |
| emh203 | 0:3d9c67d97d6f | 61 | * @return none. |
| emh203 | 0:3d9c67d97d6f | 62 | * |
| emh203 | 0:3d9c67d97d6f | 63 | * <b>Scaling and Overflow Behavior:</b> |
| emh203 | 0:3d9c67d97d6f | 64 | * \par |
| emh203 | 0:3d9c67d97d6f | 65 | * The function is implemented using a 32-bit internal accumulator. |
| emh203 | 0:3d9c67d97d6f | 66 | * Both coefficients and state variables are represented in 1.7 format and multiplications yield a 2.14 result. |
| emh203 | 0:3d9c67d97d6f | 67 | * The 2.14 intermediate results are accumulated in a 32-bit accumulator in 18.14 format. |
| emh203 | 0:3d9c67d97d6f | 68 | * There is no risk of internal overflow with this approach and the full precision of intermediate multiplications is preserved. |
| emh203 | 0:3d9c67d97d6f | 69 | * The accumulator is then converted to 18.7 format by discarding the low 7 bits. |
| emh203 | 0:3d9c67d97d6f | 70 | * Finally, the result is truncated to 1.7 format. |
| emh203 | 0:3d9c67d97d6f | 71 | */ |
| emh203 | 0:3d9c67d97d6f | 72 | |
| emh203 | 0:3d9c67d97d6f | 73 | void arm_fir_sparse_q7( |
| emh203 | 0:3d9c67d97d6f | 74 | arm_fir_sparse_instance_q7 * S, |
| emh203 | 0:3d9c67d97d6f | 75 | q7_t * pSrc, |
| emh203 | 0:3d9c67d97d6f | 76 | q7_t * pDst, |
| emh203 | 0:3d9c67d97d6f | 77 | q7_t * pScratchIn, |
| emh203 | 0:3d9c67d97d6f | 78 | q31_t * pScratchOut, |
| emh203 | 0:3d9c67d97d6f | 79 | uint32_t blockSize) |
| emh203 | 0:3d9c67d97d6f | 80 | { |
| emh203 | 0:3d9c67d97d6f | 81 | |
| emh203 | 0:3d9c67d97d6f | 82 | q7_t *pState = S->pState; /* State pointer */ |
| emh203 | 0:3d9c67d97d6f | 83 | q7_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ |
| emh203 | 0:3d9c67d97d6f | 84 | q7_t *px; /* Scratch buffer pointer */ |
| emh203 | 0:3d9c67d97d6f | 85 | q7_t *py = pState; /* Temporary pointers for state buffer */ |
| emh203 | 0:3d9c67d97d6f | 86 | q7_t *pb = pScratchIn; /* Temporary pointers for scratch buffer */ |
| emh203 | 0:3d9c67d97d6f | 87 | q7_t *pOut = pDst; /* Destination pointer */ |
| emh203 | 0:3d9c67d97d6f | 88 | int32_t *pTapDelay = S->pTapDelay; /* Pointer to the array containing offset of the non-zero tap values. */ |
| emh203 | 0:3d9c67d97d6f | 89 | uint32_t delaySize = S->maxDelay + blockSize; /* state length */ |
| emh203 | 0:3d9c67d97d6f | 90 | uint16_t numTaps = S->numTaps; /* Filter order */ |
| emh203 | 0:3d9c67d97d6f | 91 | int32_t readIndex; /* Read index of the state buffer */ |
| emh203 | 0:3d9c67d97d6f | 92 | uint32_t tapCnt, blkCnt; /* loop counters */ |
| emh203 | 0:3d9c67d97d6f | 93 | q7_t coeff = *pCoeffs++; /* Read the coefficient value */ |
| emh203 | 0:3d9c67d97d6f | 94 | q31_t *pScr2 = pScratchOut; /* Working pointer for scratch buffer of output values */ |
| emh203 | 0:3d9c67d97d6f | 95 | q31_t in; |
| emh203 | 0:3d9c67d97d6f | 96 | |
| emh203 | 0:3d9c67d97d6f | 97 | |
| emh203 | 0:3d9c67d97d6f | 98 | #ifndef ARM_MATH_CM0_FAMILY |
| emh203 | 0:3d9c67d97d6f | 99 | |
| emh203 | 0:3d9c67d97d6f | 100 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
| emh203 | 0:3d9c67d97d6f | 101 | |
| emh203 | 0:3d9c67d97d6f | 102 | q7_t in1, in2, in3, in4; |
| emh203 | 0:3d9c67d97d6f | 103 | |
| emh203 | 0:3d9c67d97d6f | 104 | /* BlockSize of Input samples are copied into the state buffer */ |
| emh203 | 0:3d9c67d97d6f | 105 | /* StateIndex points to the starting position to write in the state buffer */ |
| emh203 | 0:3d9c67d97d6f | 106 | arm_circularWrite_q7(py, (int32_t) delaySize, &S->stateIndex, 1, pSrc, 1, |
| emh203 | 0:3d9c67d97d6f | 107 | blockSize); |
| emh203 | 0:3d9c67d97d6f | 108 | |
| emh203 | 0:3d9c67d97d6f | 109 | /* Loop over the number of taps. */ |
| emh203 | 0:3d9c67d97d6f | 110 | tapCnt = numTaps; |
| emh203 | 0:3d9c67d97d6f | 111 | |
| emh203 | 0:3d9c67d97d6f | 112 | /* Read Index, from where the state buffer should be read, is calculated. */ |
| emh203 | 0:3d9c67d97d6f | 113 | readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++; |
| emh203 | 0:3d9c67d97d6f | 114 | |
| emh203 | 0:3d9c67d97d6f | 115 | /* Wraparound of readIndex */ |
| emh203 | 0:3d9c67d97d6f | 116 | if(readIndex < 0) |
| emh203 | 0:3d9c67d97d6f | 117 | { |
| emh203 | 0:3d9c67d97d6f | 118 | readIndex += (int32_t) delaySize; |
| emh203 | 0:3d9c67d97d6f | 119 | } |
| emh203 | 0:3d9c67d97d6f | 120 | |
| emh203 | 0:3d9c67d97d6f | 121 | /* Working pointer for state buffer is updated */ |
| emh203 | 0:3d9c67d97d6f | 122 | py = pState; |
| emh203 | 0:3d9c67d97d6f | 123 | |
| emh203 | 0:3d9c67d97d6f | 124 | /* blockSize samples are read from the state buffer */ |
| emh203 | 0:3d9c67d97d6f | 125 | arm_circularRead_q7(py, (int32_t) delaySize, &readIndex, 1, pb, pb, |
| emh203 | 0:3d9c67d97d6f | 126 | (int32_t) blockSize, 1, blockSize); |
| emh203 | 0:3d9c67d97d6f | 127 | |
| emh203 | 0:3d9c67d97d6f | 128 | /* Working pointer for the scratch buffer of state values */ |
| emh203 | 0:3d9c67d97d6f | 129 | px = pb; |
| emh203 | 0:3d9c67d97d6f | 130 | |
| emh203 | 0:3d9c67d97d6f | 131 | /* Working pointer for scratch buffer of output values */ |
| emh203 | 0:3d9c67d97d6f | 132 | pScratchOut = pScr2; |
| emh203 | 0:3d9c67d97d6f | 133 | |
| emh203 | 0:3d9c67d97d6f | 134 | /* Loop over the blockSize. Unroll by a factor of 4. |
| emh203 | 0:3d9c67d97d6f | 135 | * Compute 4 multiplications at a time. */ |
| emh203 | 0:3d9c67d97d6f | 136 | blkCnt = blockSize >> 2; |
| emh203 | 0:3d9c67d97d6f | 137 | |
| emh203 | 0:3d9c67d97d6f | 138 | while(blkCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 139 | { |
| emh203 | 0:3d9c67d97d6f | 140 | /* Perform multiplication and store in the scratch buffer */ |
| emh203 | 0:3d9c67d97d6f | 141 | *pScratchOut++ = ((q31_t) * px++ * coeff); |
| emh203 | 0:3d9c67d97d6f | 142 | *pScratchOut++ = ((q31_t) * px++ * coeff); |
| emh203 | 0:3d9c67d97d6f | 143 | *pScratchOut++ = ((q31_t) * px++ * coeff); |
| emh203 | 0:3d9c67d97d6f | 144 | *pScratchOut++ = ((q31_t) * px++ * coeff); |
| emh203 | 0:3d9c67d97d6f | 145 | |
| emh203 | 0:3d9c67d97d6f | 146 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 147 | blkCnt--; |
| emh203 | 0:3d9c67d97d6f | 148 | } |
| emh203 | 0:3d9c67d97d6f | 149 | |
| emh203 | 0:3d9c67d97d6f | 150 | /* If the blockSize is not a multiple of 4, |
| emh203 | 0:3d9c67d97d6f | 151 | * compute the remaining samples */ |
| emh203 | 0:3d9c67d97d6f | 152 | blkCnt = blockSize % 0x4u; |
| emh203 | 0:3d9c67d97d6f | 153 | |
| emh203 | 0:3d9c67d97d6f | 154 | while(blkCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 155 | { |
| emh203 | 0:3d9c67d97d6f | 156 | /* Perform multiplication and store in the scratch buffer */ |
| emh203 | 0:3d9c67d97d6f | 157 | *pScratchOut++ = ((q31_t) * px++ * coeff); |
| emh203 | 0:3d9c67d97d6f | 158 | |
| emh203 | 0:3d9c67d97d6f | 159 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 160 | blkCnt--; |
| emh203 | 0:3d9c67d97d6f | 161 | } |
| emh203 | 0:3d9c67d97d6f | 162 | |
| emh203 | 0:3d9c67d97d6f | 163 | /* Load the coefficient value and |
| emh203 | 0:3d9c67d97d6f | 164 | * increment the coefficient buffer for the next set of state values */ |
| emh203 | 0:3d9c67d97d6f | 165 | coeff = *pCoeffs++; |
| emh203 | 0:3d9c67d97d6f | 166 | |
| emh203 | 0:3d9c67d97d6f | 167 | /* Read Index, from where the state buffer should be read, is calculated. */ |
| emh203 | 0:3d9c67d97d6f | 168 | readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++; |
| emh203 | 0:3d9c67d97d6f | 169 | |
| emh203 | 0:3d9c67d97d6f | 170 | /* Wraparound of readIndex */ |
| emh203 | 0:3d9c67d97d6f | 171 | if(readIndex < 0) |
| emh203 | 0:3d9c67d97d6f | 172 | { |
| emh203 | 0:3d9c67d97d6f | 173 | readIndex += (int32_t) delaySize; |
| emh203 | 0:3d9c67d97d6f | 174 | } |
| emh203 | 0:3d9c67d97d6f | 175 | |
| emh203 | 0:3d9c67d97d6f | 176 | /* Loop over the number of taps. */ |
| emh203 | 0:3d9c67d97d6f | 177 | tapCnt = (uint32_t) numTaps - 1u; |
| emh203 | 0:3d9c67d97d6f | 178 | |
| emh203 | 0:3d9c67d97d6f | 179 | while(tapCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 180 | { |
| emh203 | 0:3d9c67d97d6f | 181 | /* Working pointer for state buffer is updated */ |
| emh203 | 0:3d9c67d97d6f | 182 | py = pState; |
| emh203 | 0:3d9c67d97d6f | 183 | |
| emh203 | 0:3d9c67d97d6f | 184 | /* blockSize samples are read from the state buffer */ |
| emh203 | 0:3d9c67d97d6f | 185 | arm_circularRead_q7(py, (int32_t) delaySize, &readIndex, 1, pb, pb, |
| emh203 | 0:3d9c67d97d6f | 186 | (int32_t) blockSize, 1, blockSize); |
| emh203 | 0:3d9c67d97d6f | 187 | |
| emh203 | 0:3d9c67d97d6f | 188 | /* Working pointer for the scratch buffer of state values */ |
| emh203 | 0:3d9c67d97d6f | 189 | px = pb; |
| emh203 | 0:3d9c67d97d6f | 190 | |
| emh203 | 0:3d9c67d97d6f | 191 | /* Working pointer for scratch buffer of output values */ |
| emh203 | 0:3d9c67d97d6f | 192 | pScratchOut = pScr2; |
| emh203 | 0:3d9c67d97d6f | 193 | |
| emh203 | 0:3d9c67d97d6f | 194 | /* Loop over the blockSize. Unroll by a factor of 4. |
| emh203 | 0:3d9c67d97d6f | 195 | * Compute 4 MACS at a time. */ |
| emh203 | 0:3d9c67d97d6f | 196 | blkCnt = blockSize >> 2; |
| emh203 | 0:3d9c67d97d6f | 197 | |
| emh203 | 0:3d9c67d97d6f | 198 | while(blkCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 199 | { |
| emh203 | 0:3d9c67d97d6f | 200 | /* Perform Multiply-Accumulate */ |
| emh203 | 0:3d9c67d97d6f | 201 | in = *pScratchOut + ((q31_t) * px++ * coeff); |
| emh203 | 0:3d9c67d97d6f | 202 | *pScratchOut++ = in; |
| emh203 | 0:3d9c67d97d6f | 203 | in = *pScratchOut + ((q31_t) * px++ * coeff); |
| emh203 | 0:3d9c67d97d6f | 204 | *pScratchOut++ = in; |
| emh203 | 0:3d9c67d97d6f | 205 | in = *pScratchOut + ((q31_t) * px++ * coeff); |
| emh203 | 0:3d9c67d97d6f | 206 | *pScratchOut++ = in; |
| emh203 | 0:3d9c67d97d6f | 207 | in = *pScratchOut + ((q31_t) * px++ * coeff); |
| emh203 | 0:3d9c67d97d6f | 208 | *pScratchOut++ = in; |
| emh203 | 0:3d9c67d97d6f | 209 | |
| emh203 | 0:3d9c67d97d6f | 210 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 211 | blkCnt--; |
| emh203 | 0:3d9c67d97d6f | 212 | } |
| emh203 | 0:3d9c67d97d6f | 213 | |
| emh203 | 0:3d9c67d97d6f | 214 | /* If the blockSize is not a multiple of 4, |
| emh203 | 0:3d9c67d97d6f | 215 | * compute the remaining samples */ |
| emh203 | 0:3d9c67d97d6f | 216 | blkCnt = blockSize % 0x4u; |
| emh203 | 0:3d9c67d97d6f | 217 | |
| emh203 | 0:3d9c67d97d6f | 218 | while(blkCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 219 | { |
| emh203 | 0:3d9c67d97d6f | 220 | /* Perform Multiply-Accumulate */ |
| emh203 | 0:3d9c67d97d6f | 221 | in = *pScratchOut + ((q31_t) * px++ * coeff); |
| emh203 | 0:3d9c67d97d6f | 222 | *pScratchOut++ = in; |
| emh203 | 0:3d9c67d97d6f | 223 | |
| emh203 | 0:3d9c67d97d6f | 224 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 225 | blkCnt--; |
| emh203 | 0:3d9c67d97d6f | 226 | } |
| emh203 | 0:3d9c67d97d6f | 227 | |
| emh203 | 0:3d9c67d97d6f | 228 | /* Load the coefficient value and |
| emh203 | 0:3d9c67d97d6f | 229 | * increment the coefficient buffer for the next set of state values */ |
| emh203 | 0:3d9c67d97d6f | 230 | coeff = *pCoeffs++; |
| emh203 | 0:3d9c67d97d6f | 231 | |
| emh203 | 0:3d9c67d97d6f | 232 | /* Read Index, from where the state buffer should be read, is calculated. */ |
| emh203 | 0:3d9c67d97d6f | 233 | readIndex = ((int32_t) S->stateIndex - |
| emh203 | 0:3d9c67d97d6f | 234 | (int32_t) blockSize) - *pTapDelay++; |
| emh203 | 0:3d9c67d97d6f | 235 | |
| emh203 | 0:3d9c67d97d6f | 236 | /* Wraparound of readIndex */ |
| emh203 | 0:3d9c67d97d6f | 237 | if(readIndex < 0) |
| emh203 | 0:3d9c67d97d6f | 238 | { |
| emh203 | 0:3d9c67d97d6f | 239 | readIndex += (int32_t) delaySize; |
| emh203 | 0:3d9c67d97d6f | 240 | } |
| emh203 | 0:3d9c67d97d6f | 241 | |
| emh203 | 0:3d9c67d97d6f | 242 | /* Decrement the tap loop counter */ |
| emh203 | 0:3d9c67d97d6f | 243 | tapCnt--; |
| emh203 | 0:3d9c67d97d6f | 244 | } |
| emh203 | 0:3d9c67d97d6f | 245 | |
| emh203 | 0:3d9c67d97d6f | 246 | /* All the output values are in pScratchOut buffer. |
| emh203 | 0:3d9c67d97d6f | 247 | Convert them into 1.15 format, saturate and store in the destination buffer. */ |
| emh203 | 0:3d9c67d97d6f | 248 | /* Loop over the blockSize. */ |
| emh203 | 0:3d9c67d97d6f | 249 | blkCnt = blockSize >> 2; |
| emh203 | 0:3d9c67d97d6f | 250 | |
| emh203 | 0:3d9c67d97d6f | 251 | while(blkCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 252 | { |
| emh203 | 0:3d9c67d97d6f | 253 | in1 = (q7_t) __SSAT(*pScr2++ >> 7, 8); |
| emh203 | 0:3d9c67d97d6f | 254 | in2 = (q7_t) __SSAT(*pScr2++ >> 7, 8); |
| emh203 | 0:3d9c67d97d6f | 255 | in3 = (q7_t) __SSAT(*pScr2++ >> 7, 8); |
| emh203 | 0:3d9c67d97d6f | 256 | in4 = (q7_t) __SSAT(*pScr2++ >> 7, 8); |
| emh203 | 0:3d9c67d97d6f | 257 | |
| emh203 | 0:3d9c67d97d6f | 258 | *__SIMD32(pOut)++ = __PACKq7(in1, in2, in3, in4); |
| emh203 | 0:3d9c67d97d6f | 259 | |
| emh203 | 0:3d9c67d97d6f | 260 | /* Decrement the blockSize loop counter */ |
| emh203 | 0:3d9c67d97d6f | 261 | blkCnt--; |
| emh203 | 0:3d9c67d97d6f | 262 | } |
| emh203 | 0:3d9c67d97d6f | 263 | |
| emh203 | 0:3d9c67d97d6f | 264 | /* If the blockSize is not a multiple of 4, |
| emh203 | 0:3d9c67d97d6f | 265 | remaining samples are processed in the below loop */ |
| emh203 | 0:3d9c67d97d6f | 266 | blkCnt = blockSize % 0x4u; |
| emh203 | 0:3d9c67d97d6f | 267 | |
| emh203 | 0:3d9c67d97d6f | 268 | while(blkCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 269 | { |
| emh203 | 0:3d9c67d97d6f | 270 | *pOut++ = (q7_t) __SSAT(*pScr2++ >> 7, 8); |
| emh203 | 0:3d9c67d97d6f | 271 | |
| emh203 | 0:3d9c67d97d6f | 272 | /* Decrement the blockSize loop counter */ |
| emh203 | 0:3d9c67d97d6f | 273 | blkCnt--; |
| emh203 | 0:3d9c67d97d6f | 274 | } |
| emh203 | 0:3d9c67d97d6f | 275 | |
| emh203 | 0:3d9c67d97d6f | 276 | #else |
| emh203 | 0:3d9c67d97d6f | 277 | |
| emh203 | 0:3d9c67d97d6f | 278 | /* Run the below code for Cortex-M0 */ |
| emh203 | 0:3d9c67d97d6f | 279 | |
| emh203 | 0:3d9c67d97d6f | 280 | /* BlockSize of Input samples are copied into the state buffer */ |
| emh203 | 0:3d9c67d97d6f | 281 | /* StateIndex points to the starting position to write in the state buffer */ |
| emh203 | 0:3d9c67d97d6f | 282 | arm_circularWrite_q7(py, (int32_t) delaySize, &S->stateIndex, 1, pSrc, 1, |
| emh203 | 0:3d9c67d97d6f | 283 | blockSize); |
| emh203 | 0:3d9c67d97d6f | 284 | |
| emh203 | 0:3d9c67d97d6f | 285 | /* Loop over the number of taps. */ |
| emh203 | 0:3d9c67d97d6f | 286 | tapCnt = numTaps; |
| emh203 | 0:3d9c67d97d6f | 287 | |
| emh203 | 0:3d9c67d97d6f | 288 | /* Read Index, from where the state buffer should be read, is calculated. */ |
| emh203 | 0:3d9c67d97d6f | 289 | readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++; |
| emh203 | 0:3d9c67d97d6f | 290 | |
| emh203 | 0:3d9c67d97d6f | 291 | /* Wraparound of readIndex */ |
| emh203 | 0:3d9c67d97d6f | 292 | if(readIndex < 0) |
| emh203 | 0:3d9c67d97d6f | 293 | { |
| emh203 | 0:3d9c67d97d6f | 294 | readIndex += (int32_t) delaySize; |
| emh203 | 0:3d9c67d97d6f | 295 | } |
| emh203 | 0:3d9c67d97d6f | 296 | |
| emh203 | 0:3d9c67d97d6f | 297 | /* Working pointer for state buffer is updated */ |
| emh203 | 0:3d9c67d97d6f | 298 | py = pState; |
| emh203 | 0:3d9c67d97d6f | 299 | |
| emh203 | 0:3d9c67d97d6f | 300 | /* blockSize samples are read from the state buffer */ |
| emh203 | 0:3d9c67d97d6f | 301 | arm_circularRead_q7(py, (int32_t) delaySize, &readIndex, 1, pb, pb, |
| emh203 | 0:3d9c67d97d6f | 302 | (int32_t) blockSize, 1, blockSize); |
| emh203 | 0:3d9c67d97d6f | 303 | |
| emh203 | 0:3d9c67d97d6f | 304 | /* Working pointer for the scratch buffer of state values */ |
| emh203 | 0:3d9c67d97d6f | 305 | px = pb; |
| emh203 | 0:3d9c67d97d6f | 306 | |
| emh203 | 0:3d9c67d97d6f | 307 | /* Working pointer for scratch buffer of output values */ |
| emh203 | 0:3d9c67d97d6f | 308 | pScratchOut = pScr2; |
| emh203 | 0:3d9c67d97d6f | 309 | |
| emh203 | 0:3d9c67d97d6f | 310 | /* Loop over the blockSize */ |
| emh203 | 0:3d9c67d97d6f | 311 | blkCnt = blockSize; |
| emh203 | 0:3d9c67d97d6f | 312 | |
| emh203 | 0:3d9c67d97d6f | 313 | while(blkCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 314 | { |
| emh203 | 0:3d9c67d97d6f | 315 | /* Perform multiplication and store in the scratch buffer */ |
| emh203 | 0:3d9c67d97d6f | 316 | *pScratchOut++ = ((q31_t) * px++ * coeff); |
| emh203 | 0:3d9c67d97d6f | 317 | |
| emh203 | 0:3d9c67d97d6f | 318 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 319 | blkCnt--; |
| emh203 | 0:3d9c67d97d6f | 320 | } |
| emh203 | 0:3d9c67d97d6f | 321 | |
| emh203 | 0:3d9c67d97d6f | 322 | /* Load the coefficient value and |
| emh203 | 0:3d9c67d97d6f | 323 | * increment the coefficient buffer for the next set of state values */ |
| emh203 | 0:3d9c67d97d6f | 324 | coeff = *pCoeffs++; |
| emh203 | 0:3d9c67d97d6f | 325 | |
| emh203 | 0:3d9c67d97d6f | 326 | /* Read Index, from where the state buffer should be read, is calculated. */ |
| emh203 | 0:3d9c67d97d6f | 327 | readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++; |
| emh203 | 0:3d9c67d97d6f | 328 | |
| emh203 | 0:3d9c67d97d6f | 329 | /* Wraparound of readIndex */ |
| emh203 | 0:3d9c67d97d6f | 330 | if(readIndex < 0) |
| emh203 | 0:3d9c67d97d6f | 331 | { |
| emh203 | 0:3d9c67d97d6f | 332 | readIndex += (int32_t) delaySize; |
| emh203 | 0:3d9c67d97d6f | 333 | } |
| emh203 | 0:3d9c67d97d6f | 334 | |
| emh203 | 0:3d9c67d97d6f | 335 | /* Loop over the number of taps. */ |
| emh203 | 0:3d9c67d97d6f | 336 | tapCnt = (uint32_t) numTaps - 1u; |
| emh203 | 0:3d9c67d97d6f | 337 | |
| emh203 | 0:3d9c67d97d6f | 338 | while(tapCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 339 | { |
| emh203 | 0:3d9c67d97d6f | 340 | /* Working pointer for state buffer is updated */ |
| emh203 | 0:3d9c67d97d6f | 341 | py = pState; |
| emh203 | 0:3d9c67d97d6f | 342 | |
| emh203 | 0:3d9c67d97d6f | 343 | /* blockSize samples are read from the state buffer */ |
| emh203 | 0:3d9c67d97d6f | 344 | arm_circularRead_q7(py, (int32_t) delaySize, &readIndex, 1, pb, pb, |
| emh203 | 0:3d9c67d97d6f | 345 | (int32_t) blockSize, 1, blockSize); |
| emh203 | 0:3d9c67d97d6f | 346 | |
| emh203 | 0:3d9c67d97d6f | 347 | /* Working pointer for the scratch buffer of state values */ |
| emh203 | 0:3d9c67d97d6f | 348 | px = pb; |
| emh203 | 0:3d9c67d97d6f | 349 | |
| emh203 | 0:3d9c67d97d6f | 350 | /* Working pointer for scratch buffer of output values */ |
| emh203 | 0:3d9c67d97d6f | 351 | pScratchOut = pScr2; |
| emh203 | 0:3d9c67d97d6f | 352 | |
| emh203 | 0:3d9c67d97d6f | 353 | /* Loop over the blockSize */ |
| emh203 | 0:3d9c67d97d6f | 354 | blkCnt = blockSize; |
| emh203 | 0:3d9c67d97d6f | 355 | |
| emh203 | 0:3d9c67d97d6f | 356 | while(blkCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 357 | { |
| emh203 | 0:3d9c67d97d6f | 358 | /* Perform Multiply-Accumulate */ |
| emh203 | 0:3d9c67d97d6f | 359 | in = *pScratchOut + ((q31_t) * px++ * coeff); |
| emh203 | 0:3d9c67d97d6f | 360 | *pScratchOut++ = in; |
| emh203 | 0:3d9c67d97d6f | 361 | |
| emh203 | 0:3d9c67d97d6f | 362 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 363 | blkCnt--; |
| emh203 | 0:3d9c67d97d6f | 364 | } |
| emh203 | 0:3d9c67d97d6f | 365 | |
| emh203 | 0:3d9c67d97d6f | 366 | /* Load the coefficient value and |
| emh203 | 0:3d9c67d97d6f | 367 | * increment the coefficient buffer for the next set of state values */ |
| emh203 | 0:3d9c67d97d6f | 368 | coeff = *pCoeffs++; |
| emh203 | 0:3d9c67d97d6f | 369 | |
| emh203 | 0:3d9c67d97d6f | 370 | /* Read Index, from where the state buffer should be read, is calculated. */ |
| emh203 | 0:3d9c67d97d6f | 371 | readIndex = |
| emh203 | 0:3d9c67d97d6f | 372 | ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++; |
| emh203 | 0:3d9c67d97d6f | 373 | |
| emh203 | 0:3d9c67d97d6f | 374 | /* Wraparound of readIndex */ |
| emh203 | 0:3d9c67d97d6f | 375 | if(readIndex < 0) |
| emh203 | 0:3d9c67d97d6f | 376 | { |
| emh203 | 0:3d9c67d97d6f | 377 | readIndex += (int32_t) delaySize; |
| emh203 | 0:3d9c67d97d6f | 378 | } |
| emh203 | 0:3d9c67d97d6f | 379 | |
| emh203 | 0:3d9c67d97d6f | 380 | /* Decrement the tap loop counter */ |
| emh203 | 0:3d9c67d97d6f | 381 | tapCnt--; |
| emh203 | 0:3d9c67d97d6f | 382 | } |
| emh203 | 0:3d9c67d97d6f | 383 | |
| emh203 | 0:3d9c67d97d6f | 384 | /* All the output values are in pScratchOut buffer. |
| emh203 | 0:3d9c67d97d6f | 385 | Convert them into 1.15 format, saturate and store in the destination buffer. */ |
| emh203 | 0:3d9c67d97d6f | 386 | /* Loop over the blockSize. */ |
| emh203 | 0:3d9c67d97d6f | 387 | blkCnt = blockSize; |
| emh203 | 0:3d9c67d97d6f | 388 | |
| emh203 | 0:3d9c67d97d6f | 389 | while(blkCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 390 | { |
| emh203 | 0:3d9c67d97d6f | 391 | *pOut++ = (q7_t) __SSAT(*pScr2++ >> 7, 8); |
| emh203 | 0:3d9c67d97d6f | 392 | |
| emh203 | 0:3d9c67d97d6f | 393 | /* Decrement the blockSize loop counter */ |
| emh203 | 0:3d9c67d97d6f | 394 | blkCnt--; |
| emh203 | 0:3d9c67d97d6f | 395 | } |
| emh203 | 0:3d9c67d97d6f | 396 | |
| emh203 | 0:3d9c67d97d6f | 397 | #endif /* #ifndef ARM_MATH_CM0_FAMILY */ |
| emh203 | 0:3d9c67d97d6f | 398 | |
| emh203 | 0:3d9c67d97d6f | 399 | } |
| emh203 | 0:3d9c67d97d6f | 400 | |
| emh203 | 0:3d9c67d97d6f | 401 | /** |
| emh203 | 0:3d9c67d97d6f | 402 | * @} end of FIR_Sparse group |
| emh203 | 0:3d9c67d97d6f | 403 | */ |
Eli Hughes