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

Commit 279dbc40 authored by Miller Liang's avatar Miller Liang Committed by Android (Google) Code Review
Browse files

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

parents b18cfd46 387458c9
Loading
Loading
Loading
Loading
+5 −21
Original line number Original line Diff line number Diff line
@@ -18,7 +18,7 @@
#include <utils/Log.h>
#include <utils/Log.h>


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


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


        const audio_format_t sourceFormat = getDeviceFormat();
        const audio_format_t sourceFormat = getDeviceFormat();
        const audio_format_t destinationFormat = getFormat();
        const audio_format_t destinationFormat = getFormat();
        // TODO factor this out into a utility function

        if (sourceFormat == destinationFormat) {
        memcpy_by_audio_format(destination, destinationFormat,
            memcpy(destination, wrappingBuffer.data[partIndex], numBytes);
                wrappingBuffer.data[partIndex], sourceFormat, numSamples);
        } 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;
        }
        destination += numBytes;
        destination += numBytes;
        framesLeft -= framesToProcess;
        framesLeft -= framesToProcess;
    }
    }