From 511754b5839fd9b09fc56b89ae007fbc39084a33 Mon Sep 17 00:00:00 2001 From: Glenn Kasten Date: Wed, 11 Jan 2012 09:52:19 -0800 Subject: [PATCH] Move memcpy_to_i16_from_u8 to audio_utils This will make it easier for this kind of code to be optimized for each target architecture. Change-Id: I9efd27d6c0175b00b9a784353244805cec63c0b8 --- media/libmedia/AudioTrack.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp index 97b2312009..b22c25bd37 100644 --- a/media/libmedia/AudioTrack.cpp +++ b/media/libmedia/AudioTrack.cpp @@ -43,6 +43,8 @@ #include #include +#include + namespace android { // --------------------------------------------------------------------------- @@ -999,12 +1001,7 @@ ssize_t AudioTrack::write(const void* buffer, size_t userSize) if (mFormat == AUDIO_FORMAT_PCM_8_BIT && !(mFlags & AUDIO_POLICY_OUTPUT_FLAG_DIRECT)) { // Divide capacity by 2 to take expansion into account toWrite = audioBuffer.size>>1; - // 8 to 16 bit conversion - int count = toWrite; - int16_t *dst = (int16_t *)(audioBuffer.i8); - while(count--) { - *dst++ = (int16_t)(*src++^0x80) << 8; - } + memcpy_to_i16_from_u8(audioBuffer.i16, (const uint8_t *) src, toWrite); } else { toWrite = audioBuffer.size; memcpy(audioBuffer.i8, src, toWrite); @@ -1125,13 +1122,8 @@ bool AudioTrack::processAudioBuffer(const sp& thread) if (writtenSize > reqSize) writtenSize = reqSize; if (mFormat == AUDIO_FORMAT_PCM_8_BIT && !(mFlags & AUDIO_POLICY_OUTPUT_FLAG_DIRECT)) { - // 8 to 16 bit conversion - const int8_t *src = audioBuffer.i8 + writtenSize-1; - int count = writtenSize; - int16_t *dst = audioBuffer.i16 + writtenSize-1; - while(count--) { - *dst-- = (int16_t)(*src--^0x80) << 8; - } + // 8 to 16 bit conversion, note that source and destination are the same address + memcpy_to_i16_from_u8(audioBuffer.i16, (const uint8_t *) audioBuffer.i8, writtenSize); writtenSize <<= 1; } -- 2.11.0