Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of dsp by
arm_float_to_q31.c
00001 /* ---------------------------------------------------------------------------- 00002 * Copyright (C) 2010 ARM Limited. All rights reserved. 00003 * 00004 * $Date: 29. November 2010 00005 * $Revision: V1.0.3 00006 * 00007 * Project: CMSIS DSP Library 00008 * Title: arm_float_to_q31.c 00009 * 00010 * Description: Processing function for the Conversion from float to Q31 00011 * 00012 * Target Processor: Cortex-M4/Cortex-M3 00013 * 00014 * Version 1.0.3 2010/11/29 00015 * Re-organized the CMSIS folders and updated documentation. 00016 * 00017 * Version 1.0.2 2010/11/11 00018 * Documentation updated. 00019 * 00020 * Version 1.0.1 2010/10/05 00021 * Production release and review comments incorporated. 00022 * 00023 * Version 1.0.0 2010/09/20 00024 * Production release and review comments incorporated. 00025 * ---------------------------------------------------------------------------- */ 00026 00027 #include "arm_math.h" 00028 00029 /** 00030 * @ingroup groupSupport 00031 */ 00032 00033 /** 00034 * @defgroup float_to_x Convert 32-bit floating point value 00035 */ 00036 00037 /** 00038 * @addtogroup float_to_x 00039 * @{ 00040 */ 00041 00042 /** 00043 * @brief Converts the elements of the floating-point vector to Q31 vector. 00044 * @param[in] *pSrc points to the floating-point input vector 00045 * @param[out] *pDst points to the Q31 output vector 00046 * @param[in] blockSize length of the input vector 00047 * @return none. 00048 * 00049 *\par Description: 00050 * \par 00051 * The equation used for the conversion process is: 00052 * 00053 * <pre> 00054 * pDst[n] = (q31_t)(pSrc[n] * 2147483648); 0 <= n < blockSize. 00055 * </pre> 00056 * <b>Scaling and Overflow Behavior:</b> 00057 * \par 00058 * The function uses saturating arithmetic. 00059 * Results outside of the allowable Q31 range[0x80000000 0x7FFFFFFF] will be saturated. 00060 * 00061 * \note In order to apply rounding, the library should be rebuilt with the ROUNDING macro 00062 * defined in the preprocessor section of project options. 00063 */ 00064 00065 00066 void arm_float_to_q31( 00067 float32_t * pSrc, 00068 q31_t * pDst, 00069 uint32_t blockSize) 00070 { 00071 float32_t *pIn = pSrc; /* Src pointer */ 00072 uint32_t blkCnt; /* loop counter */ 00073 00074 #ifdef ARM_MATH_ROUNDING 00075 00076 float32_t in; 00077 00078 #endif 00079 00080 00081 /*loop Unrolling */ 00082 blkCnt = blockSize >> 2u; 00083 00084 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00085 ** a second loop below computes the remaining 1 to 3 samples. */ 00086 while(blkCnt > 0u) 00087 { 00088 #ifdef ARM_MATH_ROUNDING 00089 /* C = A * 32768 */ 00090 /* convert from float to Q31 and then store the results in the destination buffer */ 00091 in = *pIn++; 00092 in = (in * 2147483648.0f); 00093 in += in > 0 ? 0.5 : -0.5; 00094 *pDst++ = clip_q63_to_q31((q63_t) (in)); 00095 00096 in = *pIn++; 00097 in = (in * 2147483648.0f); 00098 in += in > 0 ? 0.5 : -0.5; 00099 *pDst++ = clip_q63_to_q31((q63_t) (in)); 00100 00101 in = *pIn++; 00102 in = (in * 2147483648.0f); 00103 in += in > 0 ? 0.5 : -0.5; 00104 *pDst++ = clip_q63_to_q31((q63_t) (in)); 00105 00106 in = *pIn++; 00107 in = (in * 2147483648.0f); 00108 in += in > 0 ? 0.5 : -0.5; 00109 *pDst++ = clip_q63_to_q31((q63_t) (in)); 00110 00111 #else 00112 00113 /* C = A * 2147483648 */ 00114 /* convert from float to Q31 and then store the results in the destination buffer */ 00115 *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f)); 00116 *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f)); 00117 *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f)); 00118 *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f)); 00119 00120 #endif 00121 00122 /* Decrement the loop counter */ 00123 blkCnt--; 00124 } 00125 00126 /* If the blockSize is not a multiple of 4, compute any remaining output samples here. 00127 ** No loop unrolling is used. */ 00128 blkCnt = blockSize % 0x4u; 00129 00130 while(blkCnt > 0u) 00131 { 00132 #ifdef ARM_MATH_ROUNDING 00133 00134 /* C = A * 2147483648 */ 00135 /* convert from float to Q31 and then store the results in the destination buffer */ 00136 in = *pIn++; 00137 in = (in * 2147483648.0f); 00138 in += in > 0 ? 0.5 : -0.5; 00139 *pDst++ = clip_q63_to_q31((q63_t) (in)); 00140 00141 #else 00142 00143 /* C = A * 2147483648 */ 00144 /* convert from float to Q31 and then store the results in the destination buffer */ 00145 *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f)); 00146 00147 #endif 00148 00149 /* Decrement the loop counter */ 00150 blkCnt--; 00151 } 00152 } 00153 00154 /** 00155 * @} end of float_to_x group 00156 */
Generated on Tue Jul 12 2022 19:55:43 by
1.7.2
