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

Commit 3989f649 authored by Andy Hung's avatar Andy Hung Committed by Android (Google) Code Review
Browse files

Merge "FLACExtractor: Fix 24-bit compressed to 16-bit raw handling"

parents 4c88a45c 6a746a4d
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -401,6 +401,7 @@ void FLACParser::errorCallback(FLAC__StreamDecoderErrorStatus status)

// Copy samples from FLAC native 32-bit non-interleaved to 16-bit signed
// or 32-bit float interleaved.
// TODO: Consider moving to audio_utils.
// These are candidates for optimization if needed.
static void copyTo16Signed(
        short *dst,
@@ -408,12 +409,21 @@ static void copyTo16Signed(
        unsigned nSamples,
        unsigned nChannels,
        unsigned bitsPerSample) {
    const unsigned leftShift = 16 - bitsPerSample;
    const int leftShift = 16 - (int)bitsPerSample; // cast to int to prevent unsigned overflow.
    if (leftShift >= 0) {
        for (unsigned i = 0; i < nSamples; ++i) {
            for (unsigned c = 0; c < nChannels; ++c) {
                *dst++ = src[c][i] << leftShift;
            }
        }
    } else {
        const int rightShift = -leftShift;
        for (unsigned i = 0; i < nSamples; ++i) {
            for (unsigned c = 0; c < nChannels; ++c) {
                *dst++ = src[c][i] >> rightShift;
            }
        }
    }
}

static void copyToFloat(