1 // SPDX-License-Identifier: BSD-3-Clause
2 //
3 // Copyright(c) 2021 Intel Corporation. All rights reserved.
4 //
5 // Author: Shriram Shastry <malladi.sastry@linux.intel.com>
6 //
7 //
8
9 #include <sof/math/log.h>
10 #include <sof/audio/format.h>
11 /**
12 * Base-e logarithm loge(x)
13 *
14 * loge = (u) computes the base-e logarithm of
15 * u using lookup table.
16 * input u must be scalar/real number and positive
17 *
18 * +------------------+-----------------+--------+--------+
19 * | inpfxp |loge (returntype)| inpfxp | loge |
20 * +----+-----+-------+----+----+-------+--------+--------+
21 * |WLen| FLen|Signbit|WLen|FLen|Signbit| Qformat| Qformat|
22 * +----+-----+-------+----+----+-------+--------+--------+
23 * | 32 | 0 | 0 | 32 | 27 | 0 | 32.0 | 5.27 |
24 * +------------------+-----------------+--------+--------+
25 *
26 * Arguments : uint32_t numerator [1 to 4294967295- Q32.0]
27 * Return Type : uint32_t UQ5.27 [ 0 to 22.1808076352]
28 */
ln_int32(uint32_t numerator)29 uint32_t ln_int32(uint32_t numerator)
30 {
31 return((uint32_t)Q_SHIFT_RND((int64_t)base2_logarithm(numerator) *
32 ONE_OVER_LOG2_E, 64, 32));
33 }
34