Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 511754b5 authored by Glenn Kasten's avatar Glenn Kasten
Browse files

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
parent f237a30e
Loading
Loading
Loading
Loading
+5 −13
Original line number Original line Diff line number Diff line
@@ -43,6 +43,8 @@
#include <system/audio.h>
#include <system/audio.h>
#include <system/audio_policy.h>
#include <system/audio_policy.h>


#include <audio_utils/primitives.h>

namespace android {
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)) {
        if (mFormat == AUDIO_FORMAT_PCM_8_BIT && !(mFlags & AUDIO_POLICY_OUTPUT_FLAG_DIRECT)) {
            // Divide capacity by 2 to take expansion into account
            // Divide capacity by 2 to take expansion into account
            toWrite = audioBuffer.size>>1;
            toWrite = audioBuffer.size>>1;
            // 8 to 16 bit conversion
            memcpy_to_i16_from_u8(audioBuffer.i16, (const uint8_t *) src, toWrite);
            int count = toWrite;
            int16_t *dst = (int16_t *)(audioBuffer.i8);
            while(count--) {
                *dst++ = (int16_t)(*src++^0x80) << 8;
            }
        } else {
        } else {
            toWrite = audioBuffer.size;
            toWrite = audioBuffer.size;
            memcpy(audioBuffer.i8, src, toWrite);
            memcpy(audioBuffer.i8, src, toWrite);
@@ -1125,13 +1122,8 @@ bool AudioTrack::processAudioBuffer(const sp<AudioTrackThread>& thread)
        if (writtenSize > reqSize) writtenSize = reqSize;
        if (writtenSize > reqSize) writtenSize = reqSize;


        if (mFormat == AUDIO_FORMAT_PCM_8_BIT && !(mFlags & AUDIO_POLICY_OUTPUT_FLAG_DIRECT)) {
        if (mFormat == AUDIO_FORMAT_PCM_8_BIT && !(mFlags & AUDIO_POLICY_OUTPUT_FLAG_DIRECT)) {
            // 8 to 16 bit conversion
            // 8 to 16 bit conversion, note that source and destination are the same address
            const int8_t *src = audioBuffer.i8 + writtenSize-1;
            memcpy_to_i16_from_u8(audioBuffer.i16, (const uint8_t *) audioBuffer.i8, writtenSize);
            int count = writtenSize;
            int16_t *dst = audioBuffer.i16 + writtenSize-1;
            while(count--) {
                *dst-- = (int16_t)(*src--^0x80) << 8;
            }
            writtenSize <<= 1;
            writtenSize <<= 1;
        }
        }