From 1b0fc77f831a4da901fdfcb9082e21c92468a79a Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 11 May 2018 17:03:07 +0300 Subject: [PATCH] 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 --- src/include/sof/audio/format.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/include/sof/audio/format.h b/src/include/sof/audio/format.h index c9c23ec76..f00b6f93f 100644 --- a/src/include/sof/audio/format.h +++ b/src/include/sof/audio/format.h @@ -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)