[Sound-open-firmware] [PATCH 6/7] [v3]DMIC: Add for format.h conversion from fractional to float

Seppo Ingalsuo seppo.ingalsuo at linux.intel.com
Fri May 11 16:03:07 CEST 2018


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 at linux.intel.com>
---
 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 c9c23ec..f00b6f9 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)
-- 
2.14.1



More information about the Sound-open-firmware mailing list