Set blackbox file handler to NULL after closing file
[inav.git] / lib / main / CMSIS / DSP / Source / FastMathFunctions / arm_sin_q15.c
blob7c8f627b5214b881c4c98c2c9c9f6d97b233d6e4
1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_sin_q15.c
4 * Description: Fast sine calculation for Q15 values
6 * $Date: 27. January 2017
7 * $Revision: V.1.5.1
9 * Target Processor: Cortex-M cores
10 * -------------------------------------------------------------------- */
12 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
14 * SPDX-License-Identifier: Apache-2.0
16 * Licensed under the Apache License, Version 2.0 (the License); you may
17 * not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
20 * www.apache.org/licenses/LICENSE-2.0
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
29 #include "arm_math.h"
30 #include "arm_common_tables.h"
32 /**
33 * @ingroup groupFastMath
36 /**
37 * @addtogroup sin
38 * @{
41 /**
42 * @brief Fast approximation to the trigonometric sine function for Q15 data.
43 * @param[in] x Scaled input value in radians.
44 * @return sin(x).
46 * The Q15 input value is in the range [0 +0.9999] and is mapped to a radian value in the range [0 2*pi).
49 q15_t arm_sin_q15(
50 q15_t x)
52 q15_t sinVal; /* Temporary variables for input, output */
53 int32_t index; /* Index variables */
54 q15_t a, b; /* Four nearest output values */
55 q15_t fract; /* Temporary values for fractional values */
57 /* Calculate the nearest index */
58 index = (uint32_t)x >> FAST_MATH_Q15_SHIFT;
60 /* Calculation of fractional value */
61 fract = (x - (index << FAST_MATH_Q15_SHIFT)) << 9;
63 /* Read two nearest values of input value from the sin table */
64 a = sinTable_q15[index];
65 b = sinTable_q15[index+1];
67 /* Linear interpolation process */
68 sinVal = (q31_t)(0x8000-fract)*a >> 16;
69 sinVal = (q15_t)((((q31_t)sinVal << 16) + ((q31_t)fract*b)) >> 16);
71 return sinVal << 1;
74 /**
75 * @} end of sin group