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

Commit 05cae0cb authored by Miller Liang's avatar Miller Liang Committed by Automerger Merge Worker
Browse files

Merge "aaudio: factor the format converstion function" into sc-dev am: 279dbc40

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/av/+/14310034

Change-Id: I9aaab9b61d5e506b7495e17d54a0946ad726ae0e
parents 2161a411 279dbc40
Loading
Loading
Loading
Loading
+5 −21
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@
#include <utils/Log.h>

#include <algorithm>
#include <audio_utils/primitives.h>
#include <audio_utils/format.h>
#include <aaudio/AAudio.h>
#include <media/MediaMetricsItem.h>

@@ -188,26 +188,10 @@ aaudio_result_t AudioStreamInternalCapture::readNowWithConversion(void *buffer,

        const audio_format_t sourceFormat = getDeviceFormat();
        const audio_format_t destinationFormat = getFormat();
        // TODO factor this out into a utility function
        if (sourceFormat == destinationFormat) {
            memcpy(destination, wrappingBuffer.data[partIndex], numBytes);
        } else if (sourceFormat == AUDIO_FORMAT_PCM_16_BIT
                   && destinationFormat == AUDIO_FORMAT_PCM_FLOAT) {
            memcpy_to_float_from_i16(
                    (float *) destination,
                    (const int16_t *) wrappingBuffer.data[partIndex],
                    numSamples);
        } else if (sourceFormat == AUDIO_FORMAT_PCM_FLOAT
                   && destinationFormat == AUDIO_FORMAT_PCM_16_BIT) {
            memcpy_to_i16_from_float(
                    (int16_t *) destination,
                    (const float *) wrappingBuffer.data[partIndex],
                    numSamples);
        } else {
            ALOGE("%s() - Format conversion not supported! audio_format_t source = %u, dest = %u",
                __func__, sourceFormat, destinationFormat);
            return AAUDIO_ERROR_INVALID_FORMAT;
        }

        memcpy_by_audio_format(destination, destinationFormat,
                wrappingBuffer.data[partIndex], sourceFormat, numSamples);

        destination += numBytes;
        framesLeft -= framesToProcess;
    }