summaryrefslogtreecommitdiffstats
path: root/audio_utils
diff options
context:
space:
mode:
Diffstat (limited to 'audio_utils')
-rw-r--r--audio_utils/format.c3
-rw-r--r--audio_utils/tests/Android.mk21
-rw-r--r--audio_utils/tests/primitives_tests.cpp33
3 files changed, 52 insertions, 5 deletions
diff --git a/audio_utils/format.c b/audio_utils/format.c
index 4e61321..3eda484 100644
--- a/audio_utils/format.c
+++ b/audio_utils/format.c
@@ -120,6 +120,9 @@ void memcpy_by_audio_format(void *dst, audio_format_t dst_format,
case AUDIO_FORMAT_PCM_FLOAT:
memcpy_to_i32_from_float((int32_t*)dst, (float*)src, count);
return;
+ case AUDIO_FORMAT_PCM_24_BIT_PACKED:
+ memcpy_to_i32_from_p24((int32_t*)dst, (uint8_t *)src, count);
+ return;
default:
break;
}
diff --git a/audio_utils/tests/Android.mk b/audio_utils/tests/Android.mk
index 0db09dc..cd76cf0 100644
--- a/audio_utils/tests/Android.mk
+++ b/audio_utils/tests/Android.mk
@@ -1,26 +1,37 @@
# Build the unit tests for audio_utils
LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
+include $(CLEAR_VARS)
LOCAL_SHARED_LIBRARIES := \
liblog \
libcutils \
libaudioutils
-
LOCAL_C_INCLUDES := \
$(call include-path-for, audio-utils)
-
LOCAL_SRC_FILES := \
primitives_tests.cpp
-
LOCAL_MODULE := primitives_tests
LOCAL_MODULE_TAGS := tests
-
LOCAL_CFLAGS := -Werror -Wall
include $(BUILD_NATIVE_TEST)
include $(CLEAR_VARS)
+LOCAL_SHARED_LIBRARIES := \
+ liblog \
+ libcutils
+LOCAL_STATIC_LIBRARIES := \
+ libaudioutils
+LOCAL_C_INCLUDES := \
+ $(call include-path-for, audio-utils)
+LOCAL_SRC_FILES := \
+ primitives_tests.cpp
+LOCAL_MODULE := primitives_tests
+LOCAL_MODULE_TAGS := tests
+LOCAL_CFLAGS := -Werror -Wall
+include $(BUILD_HOST_NATIVE_TEST)
+
+include $(CLEAR_VARS)
LOCAL_SRC_FILES := fifo_tests.cpp
LOCAL_MODULE := fifo_tests
LOCAL_C_INCLUDES := $(call include-path-for, audio-utils)
diff --git a/audio_utils/tests/primitives_tests.cpp b/audio_utils/tests/primitives_tests.cpp
index 5b3cd2d..178490b 100644
--- a/audio_utils/tests/primitives_tests.cpp
+++ b/audio_utils/tests/primitives_tests.cpp
@@ -103,6 +103,14 @@ void checkMonotone(const T *ary, size_t size)
}
}
+void checkMonotonep24(uint8_t * pary, size_t size)
+{
+ size_t frames = size/3;
+ for (size_t i = 1; i < frames; ++i) {
+ EXPECT_LT(i32_from_p24(pary + 3*(i-1)), i32_from_p24(pary + 3*i));
+ }
+}
+
TEST(audio_utils_primitives, clamp_to_int) {
static const float testArray[] = {
-NAN, -INFINITY,
@@ -256,6 +264,31 @@ TEST(audio_utils_primitives, memcpy) {
memset(i32ary, 0, 65536 * sizeof(i32ary[0]));
checkMonotone(i16ary, 65536);
+ // do round-trip test i16 -> p24 -> i32 -> p24 -> q8_23 -> p24 -> i16
+ memcpy_to_p24_from_i16(pary, i16ary, 65536);
+ memset(i16ary, 0, 65536 * sizeof(i16ary[0]));
+ checkMonotonep24(pary, 65536 * 3);
+
+ memcpy_to_i32_from_p24(i32ary, pary, 65536);
+ memset(pary, 0, 65536 * 3 * sizeof(pary[0]));
+ checkMonotone(i32ary, 65536);
+
+ memcpy_to_p24_from_i32(pary, i32ary, 65536);
+ memset(i32ary, 0, 65536 * sizeof(i32ary[0]));
+ checkMonotonep24(pary, 65536 * 3);
+
+ memcpy_to_q8_23_from_p24(i32ary, pary, 65536);
+ memset(pary, 0, 65536 * 3 * sizeof(pary[0]));
+ checkMonotone(i32ary, 65536);
+
+ memcpy_to_p24_from_q8_23(pary, i32ary, 65536);
+ memset(i32ary, 0, 65536 * sizeof(i32ary[0]));
+ checkMonotonep24(pary, 65536 * 3);
+
+ memcpy_to_i16_from_p24(i16ary, pary, 65536);
+ memset(pary, 0, 65536 * 3 * sizeof(pary[0]));
+ checkMonotone(i16ary, 65536);
+
// do partial round-trip testing q4_27 to i16 and float
memcpy_to_float_from_i16(fary, i16ary, 65536);
//memset(i16ary, 0, 65536 * sizeof(i16ary[0])); // not cleared: we don't do full roundtrip