Add memcpy_to_i16_from_i32 and memcpy_to_i16_from_float

Change-Id: I0c74d99f3201dbd7f51ba0a6e85c51c207c1db1f
diff --git a/audio_utils/primitives.c b/audio_utils/primitives.c
index 074f071..90ad75a 100644
--- a/audio_utils/primitives.c
+++ b/audio_utils/primitives.c
@@ -46,6 +46,30 @@
     }
 }
 
+void memcpy_to_i16_from_i32(int16_t *dst, const int32_t *src, size_t count)
+{
+    while (count--) {
+        *dst++ = *src++ >> 16;
+    }
+}
+
+void memcpy_to_i16_from_float(int16_t *dst, const float *src, size_t count)
+{
+    while (count--) {
+        float f = *src++;
+        int16_t i;
+        if (f > 1.0) {
+            i = 32767;
+        } else if (f < -1.0) {
+            i = -32768;
+        } else {
+            // does not specifically handle NaN
+            i = f * 32767.0;
+        }
+        *dst++ = i;
+    }
+}
+
 void downmix_to_mono_i16_from_stereo_i16(int16_t *dst, const int16_t *src, size_t count)
 {
     while (count--) {