OSDN Git Service

Add Q19.12 to float conversion
authorAndy Hung <hunga@google.com>
Tue, 25 Feb 2014 03:07:40 +0000 (19:07 -0800)
committerAndy Hung <hunga@google.com>
Thu, 27 Feb 2014 01:57:33 +0000 (17:57 -0800)
Change-Id: I4c9affada24da4a61afff83442fc74bb0db41549
Signed-off-by: Andy Hung <hunga@google.com>
audio_utils/include/audio_utils/primitives.h
audio_utils/primitives.c

index 656b9f0..dc1e4d9 100644 (file)
@@ -82,6 +82,19 @@ void memcpy_to_i16_from_i32(int16_t *dst, const int32_t *src, size_t count);
  */
 void memcpy_to_i16_from_float(int16_t *dst, const float *src, size_t count);
 
+/* Copy samples from signed fixed-point 32-bit Q19.12 to single-precision floating-point.
+ * The nominal output float range is [-1.0, 1.0] if the fixed-point range is
+ * [0xf8000000, 0x07ffffff].  The full float range is [-16.0, 16.0].  Note the closed range
+ * at 1.0 and 16.0 is due to rounding on conversion to float.
+ * Parameters:
+ *  dst     Destination buffer
+ *  src     Source buffer
+ *  count   Number of samples to copy
+ * The destination and source buffers must either be completely separate (non-overlapping), or
+ * they must both start at the same address.  Partially overlapping buffers are not supported.
+ */
+void memcpy_to_float_from_q19_12(float *dst, const int32_t *src, size_t c);
+
 /* Downmix pairs of interleaved stereo input 16-bit samples to mono output 16-bit samples.
  * Parameters:
  *  dst     Destination buffer
index e2d4abc..153f3a3 100644 (file)
@@ -60,6 +60,15 @@ void memcpy_to_i16_from_float(int16_t *dst, const float *src, size_t count)
     }
 }
 
+void memcpy_to_float_from_q19_12(float *dst, const int32_t *src, size_t c)
+{
+    size_t i;
+    static const float scale = 1. / (32768. * 4096.);
+    for (i = 0; i < c; ++i) {
+        *dst++ = *src++ * scale;
+    }
+}
+
 void downmix_to_mono_i16_from_stereo_i16(int16_t *dst, const int16_t *src, size_t count)
 {
     while (count--) {