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