From e46f5534fa219a760822c8b08bc81a3267b5ff2b Mon Sep 17 00:00:00 2001 From: Andy Hung Date: Tue, 18 Mar 2014 13:13:45 -0700 Subject: [PATCH] Add PCM_32_BIT and PCM_8_24_BIT to format conversion Change-Id: I533f0be84410117d1c31229bb80b8cabda430f99 Signed-off-by: Andy Hung --- audio_utils/format.c | 60 +++++++++++++++++++++++++++----- audio_utils/include/audio_utils/format.h | 15 ++++++-- 2 files changed, 64 insertions(+), 11 deletions(-) diff --git a/audio_utils/format.c b/audio_utils/format.c index fd02fb9c..caa354a4 100644 --- a/audio_utils/format.c +++ b/audio_utils/format.c @@ -14,7 +14,7 @@ * limitations under the License. */ -//#define LOG_NDEBUG 0 +/* #define LOG_NDEBUG 0 */ #define LOG_TAG "audio_utils_format" #include @@ -22,13 +22,21 @@ #include void memcpy_by_audio_format(void *dst, audio_format_t dst_format, - void *src, audio_format_t src_format, size_t count) { - if (dst_format == src_format - && (dst_format == AUDIO_FORMAT_PCM_16_BIT - || dst_format == AUDIO_FORMAT_PCM_FLOAT - || dst_format == AUDIO_FORMAT_PCM_24_BIT_PACKED)) { - memcpy(dst, src, count * audio_bytes_per_sample(dst_format)); - return; + void *src, audio_format_t src_format, size_t count) +{ + /* default cases for error falls through to fatal log below. */ + if (dst_format == src_format) { + switch (dst_format) { + case AUDIO_FORMAT_PCM_16_BIT: + case AUDIO_FORMAT_PCM_FLOAT: + case AUDIO_FORMAT_PCM_24_BIT_PACKED: + case AUDIO_FORMAT_PCM_32_BIT: + case AUDIO_FORMAT_PCM_8_24_BIT: + memcpy(dst, src, count * audio_bytes_per_sample(dst_format)); + return; + default: + break; + } } switch (dst_format) { case AUDIO_FORMAT_PCM_16_BIT: @@ -39,6 +47,12 @@ void memcpy_by_audio_format(void *dst, audio_format_t dst_format, case AUDIO_FORMAT_PCM_24_BIT_PACKED: memcpy_to_i16_from_p24((int16_t*)dst, (uint8_t*)src, count); return; + case AUDIO_FORMAT_PCM_32_BIT: + memcpy_to_i16_from_i32((int16_t*)dst, (int32_t*)src, count); + return; + case AUDIO_FORMAT_PCM_8_24_BIT: + memcpy_to_i16_from_q8_23((int16_t*)dst, (int32_t*)src, count); + return; default: break; } @@ -51,6 +65,12 @@ void memcpy_by_audio_format(void *dst, audio_format_t dst_format, case AUDIO_FORMAT_PCM_24_BIT_PACKED: memcpy_to_float_from_p24((float*)dst, (uint8_t*)src, count); return; + case AUDIO_FORMAT_PCM_32_BIT: + memcpy_to_float_from_i32((float*)dst, (int32_t*)src, count); + return; + case AUDIO_FORMAT_PCM_8_24_BIT: + memcpy_to_float_from_q8_23((float*)dst, (int32_t*)src, count); + return; default: break; } @@ -67,6 +87,30 @@ void memcpy_by_audio_format(void *dst, audio_format_t dst_format, break; } break; + case AUDIO_FORMAT_PCM_32_BIT: + switch (src_format) { + case AUDIO_FORMAT_PCM_16_BIT: + memcpy_to_i32_from_i16((int32_t*)dst, (int16_t*)src, count); + return; + case AUDIO_FORMAT_PCM_FLOAT: + memcpy_to_i32_from_float((int32_t*)dst, (float*)src, count); + return; + default: + break; + } + break; + case AUDIO_FORMAT_PCM_8_24_BIT: + switch (src_format) { + case AUDIO_FORMAT_PCM_16_BIT: + memcpy_to_q8_23_from_i16((int32_t*)dst, (int16_t*)src, count); + return; + case AUDIO_FORMAT_PCM_FLOAT: + memcpy_to_q8_23_from_float_with_clamp((int32_t*)dst, (float*)src, count); + return; + default: + break; + } + break; default: break; } diff --git a/audio_utils/include/audio_utils/format.h b/audio_utils/include/audio_utils/format.h index 7ae6226a..9a68fd29 100644 --- a/audio_utils/include/audio_utils/format.h +++ b/audio_utils/include/audio_utils/format.h @@ -31,16 +31,25 @@ __BEGIN_DECLS * src_format Source buffer format * count Number of samples to copy * - * Permitted format types for dst_format and src_format are as follows: + * Allowed format conversions are given by either case 1 or 2 below: + * + * 1) One of src_format or dst_format is AUDIO_FORMAT_PCM_16_BIT or + * AUDIO_FORMAT_PCM_FLOAT, and the other format type is one of: + * * AUDIO_FORMAT_PCM_16_BIT - * AUDIO_FORMAT_PCM_24_BIT_PACKED * AUDIO_FORMAT_PCM_FLOAT + * AUDIO_FORMAT_PCM_24_BIT_PACKED + * AUDIO_FORMAT_PCM_32_BIT + * AUDIO_FORMAT_PCM_8_24_BIT + * + * 2) Both dst_format and src_format are identical and of the list given + * in (1). This is a straight copy. * * The destination and source buffers must be completely separate if the destination * format size is larger than the source format size. These routines call functions * in primitives.h, so descriptions of detailed behavior can be reviewed there. * - * Logs a fatal error if dst or src format is not one of the permitted types. + * Logs a fatal error if dst or src format is not allowed by the conversion rules above. */ void memcpy_by_audio_format(void *dst, audio_format_t dst_format, void *src, audio_format_t src_format, size_t count); -- 2.11.0