OSDN Git Service

Add floating point mono to stereo upmix and downmix
authorAndy Hung <hunga@google.com>
Tue, 21 Apr 2015 20:21:36 +0000 (13:21 -0700)
committerAndy Hung <hunga@google.com>
Tue, 21 Apr 2015 23:56:11 +0000 (16:56 -0700)
Change-Id: I89f501d6eb3a150a057eda5c0475bbb394bcd986

audio_utils/include/audio_utils/primitives.h
audio_utils/primitives.c

index b46d657..e2ea90c 100644 (file)
@@ -323,6 +323,27 @@ void downmix_to_mono_i16_from_stereo_i16(int16_t *dst, const int16_t *src, size_
  */
 void upmix_to_stereo_i16_from_mono_i16(int16_t *dst, const int16_t *src, size_t count);
 
+/* Downmix pairs of interleaved stereo input float samples to mono output float samples
+ * by averaging the stereo pair together.
+ * Parameters:
+ *  dst     Destination buffer
+ *  src     Source buffer
+ *  count   Number of stereo frames to downmix
+ * The destination and source buffers must be completely separate (non-overlapping),
+ * or they must both start at the same address.
+ */
+void downmix_to_mono_float_from_stereo_float(float *dst, const float *src, size_t count);
+
+/* Upmix mono input float samples to pairs of interleaved stereo output float samples by
+ * duplicating.
+ * Parameters:
+ *  dst     Destination buffer
+ *  src     Source buffer
+ *  count   Number of mono samples to upmix
+ * The destination and source buffers must be completely separate (non-overlapping).
+ */
+void upmix_to_stereo_float_from_mono_float(float *dst, const float *src, size_t count);
+
 /* Return the total number of non-zero 32-bit samples */
 size_t nonZeroMono32(const int32_t *samples, size_t count);
 
index 633faab..4bca07c 100644 (file)
@@ -245,6 +245,24 @@ void upmix_to_stereo_i16_from_mono_i16(int16_t *dst, const int16_t *src, size_t
     }
 }
 
+void downmix_to_mono_float_from_stereo_float(float *dst, const float *src, size_t frames)
+{
+    while (frames--) {
+        *dst++ = (src[0] + src[1]) * 0.5;
+        src += 2;
+    }
+}
+
+void upmix_to_stereo_float_from_mono_float(float *dst, const float *src, size_t frames)
+{
+    while (frames--) {
+        float temp = *src++;
+        dst[0] = temp;
+        dst[1] = temp;
+        dst += 2;
+    }
+}
+
 size_t nonZeroMono32(const int32_t *samples, size_t count)
 {
     size_t nonZero = 0;