OSDN Git Service

audio_utils: Add support for one more format conversion
authorHaynes Mathew George <hgeorge@codeaurora.org>
Thu, 9 Apr 2015 20:50:13 +0000 (13:50 -0700)
committerGlenn Kasten <gkasten@google.com>
Tue, 14 Apr 2015 00:24:16 +0000 (17:24 -0700)
Support conversion from packed 24 bit to padded 24 bit (8_24)

Change-Id: Ibc6535f6e2bf7d53900edcb45b0056c02597f727

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

index 4ac862a..a6b2033 100644 (file)
@@ -126,6 +126,10 @@ void memcpy_by_audio_format(void *dst, audio_format_t dst_format,
         case AUDIO_FORMAT_PCM_FLOAT:
             memcpy_to_q8_23_from_float_with_clamp((int32_t*)dst, (float*)src, count);
             return;
+        case AUDIO_FORMAT_PCM_24_BIT_PACKED: {
+            memcpy_to_q8_23_from_p24((int32_t *)dst, (uint8_t *)src, count);
+            return;
+        }
         default:
             break;
         }
index e852894..6fef295 100644 (file)
@@ -221,6 +221,16 @@ void memcpy_to_q8_23_from_i16(int32_t *dst, const int16_t *src, size_t count);
  */
 void memcpy_to_q8_23_from_float_with_clamp(int32_t *dst, const float *src, size_t count);
 
+/* Copy samples from signed fixed point packed 24-bit Q0.23 to signed fixed-point 32-bit Q8.23.
+ * The output data range is [0xff800000, 0x007fffff].
+ * Parameters:
+ *  dst     Destination buffer
+ *  src     Source buffer
+ *  count   Number of samples to copy
+ * The destination and source buffers must be completely separate.
+ */
+void memcpy_to_q8_23_from_p24(int32_t *dst, const uint8_t *src, size_t count);
+
 /* Copy samples from single-precision floating-point to signed fixed-point 32-bit Q4.27.
  * The conversion will use the full available Q4.27 range, including guard bits.
  * Fractional lsb is rounded to nearest, ties away from zero.
index fb4df97..f3a5a50 100644 (file)
@@ -173,6 +173,18 @@ void memcpy_to_q8_23_from_float_with_clamp(int32_t *dst, const float *src, size_
     }
 }
 
+void memcpy_to_q8_23_from_p24(int32_t *dst, const uint8_t *src, size_t count)
+{
+    while (count--) {
+#ifdef HAVE_BIG_ENDIAN
+        *dst++ = (int8_t)src[0] << 16 | src[1] << 8 | src[2];
+#else
+        *dst++ = (int8_t)src[2] << 16 | src[1] << 8 | src[0];
+#endif
+        src += 3;
+    }
+}
+
 void memcpy_to_q4_27_from_float(int32_t *dst, const float *src, size_t count)
 {
     while (count--) {