DMIC: Add for format.h conversion from fractional to float

Note: Use with care since this generic macro is currently used only in
host test bench for debug print commands so there are no speed or
precision optimized versions yet.The cast to int64_t is not necessary
for all integer types. Also float restricts precision of a 64 bit
int.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
This commit is contained in:
Seppo Ingalsuo 2018-05-11 17:03:07 +03:00 committed by Liam Girdwood
parent 787b7d1a7b
commit 1b0fc77f83
1 changed files with 3 additions and 0 deletions

View File

@ -70,6 +70,9 @@
*/
#define Q_CONVERT_FLOAT(f, qy) ((int)((f) * (1 << qy) + 0.5)) /* f is float */
/* Convert fractional Qnx.ny number x to float */
#define Q_CONVERT_QTOF(x, ny) ((float)(x) / ((int64_t)1 << (ny)))
/* A more clever macro for Q-shifts */
#define Q_SHIFT(x, src_q, dst_q) ((x)>>((src_q)-(dst_q)))
#define Q_SHIFT_RND(x, src_q, dst_q) ((((x) >> ((src_q)-(dst_q) -1)) +1) >> 1)