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

Commit b6e3cf89 authored by Andy Hung's avatar Andy Hung Committed by Automerger Merge Worker
Browse files

Merge "Reverb true mono changes : initial version" am: 1a5a9044

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

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I16b539d77132216df505beae73f1508da62252b6
parents 0e57afcf 1a5a9044
Loading
Loading
Loading
Loading
+6 −17
Original line number Diff line number Diff line
@@ -312,9 +312,6 @@ int main(int argc, const char* argv[]) {
    config.inputCfg.samplingRate = config.outputCfg.samplingRate = revConfigParams.sampleRate;
    config.inputCfg.channels = config.outputCfg.channels = revConfigParams.chMask;
    config.inputCfg.format = config.outputCfg.format = AUDIO_FORMAT_PCM_FLOAT;
    if (AUDIO_CHANNEL_OUT_MONO == revConfigParams.chMask) {
        config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
    }
    if (int status = reverbCreateEffect(&effectHandle, &config, sessionId, ioId,
                                        revConfigParams.auxiliary);
        status != 0) {
@@ -346,19 +343,11 @@ int main(int argc, const char* argv[]) {
    const int ioChannelCount = revConfigParams.fChannels;
    const int ioFrameSize = ioChannelCount * sizeof(short);
    const int maxChannelCount = std::max(channelCount, ioChannelCount);
    /*
     * Mono input will be converted to 2 channels internally in the process call
     * by copying the same data into the second channel.
     * Hence when channelCount is 1, output buffer should be allocated for
     * 2 channels. The outChannelCount takes care of allocation of sufficient
     * memory for the output buffer.
     */
    const int outChannelCount = (channelCount == 1 ? 2 : channelCount);

    std::vector<short> in(frameLength * maxChannelCount);
    std::vector<short> out(frameLength * outChannelCount);
    std::vector<short> out(frameLength * maxChannelCount);
    std::vector<float> floatIn(frameLength * channelCount);
    std::vector<float> floatOut(frameLength * outChannelCount);
    std::vector<float> floatOut(frameLength * channelCount);

    int frameCounter = 0;

@@ -392,11 +381,11 @@ int main(int argc, const char* argv[]) {
#else
        memcpy(floatOut.data(), floatIn.data(), frameLength * frameSize);
#endif
        memcpy_to_i16_from_float(out.data(), floatOut.data(), frameLength * outChannelCount);
        memcpy_to_i16_from_float(out.data(), floatOut.data(), frameLength * channelCount);

        if (ioChannelCount != outChannelCount) {
            adjust_channels(out.data(), outChannelCount, out.data(), ioChannelCount, sizeof(short),
                            frameLength * outChannelCount * sizeof(short));
        if (ioChannelCount != channelCount) {
            adjust_channels(out.data(), channelCount, out.data(), ioChannelCount, sizeof(short),
                            frameLength * channelCount * sizeof(short));
        }
        (void)fwrite(out.data(), ioFrameSize, frameLength, outputFp.get());
        frameCounter += frameLength;
+30 −12
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ typedef float LVM_FLOAT;
#include "EffectReverb.h"
// from Reverb/lib
#include "LVREV.h"
#include "VectorArithmetic.h"

// effect_handle_t interface implementation for reverb
extern "C" const struct effect_interface_s gReverbInterface;
@@ -332,6 +333,7 @@ extern "C" int EffectGetDescriptor(const effect_uuid_t* uuid, effect_descriptor_
//----------------------------------------------------------------------------
int process(effect_buffer_t* pIn, effect_buffer_t* pOut, int frameCount, ReverbContext* pContext) {
    int channels = audio_channel_count_from_out_mask(pContext->config.inputCfg.channels);
    int outChannels = audio_channel_count_from_out_mask(pContext->config.outputCfg.channels);
    LVREV_ReturnStatus_en LvmStatus = LVREV_SUCCESS; /* Function call status */

    // Reverb only effects the stereo channels in multichannel source.
@@ -454,33 +456,49 @@ int process(effect_buffer_t* pIn, effect_buffer_t* pOut, int frameCount, ReverbC
        }
    }

    if (channels > 2) {
    if (outChannels > 2) {
        // Accumulate if required
        if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE) {
            for (int i = 0; i < frameCount; i++) {
                pOut[channels * i] += pContext->OutFrames[FCC_2 * i];
                pOut[channels * i + 1] += pContext->OutFrames[FCC_2 * i + 1];
                pOut[outChannels * i] += pContext->OutFrames[FCC_2 * i];
                pOut[outChannels * i + 1] += pContext->OutFrames[FCC_2 * i + 1];
            }
        } else {
            for (int i = 0; i < frameCount; i++) {
                pOut[channels * i] = pContext->OutFrames[FCC_2 * i];
                pOut[channels * i + 1] = pContext->OutFrames[FCC_2 * i + 1];
                pOut[outChannels * i] = pContext->OutFrames[FCC_2 * i];
                pOut[outChannels * i + 1] = pContext->OutFrames[FCC_2 * i + 1];
            }
        }
        if (!pContext->auxiliary) {
            for (int i = 0; i < frameCount; i++) {
            for (int j = FCC_2; j < channels; j++) {
                pOut[channels * i + j] = pIn[channels * i + j];
                // channels and outChannels are expected to be same.
                for (int j = FCC_2; j < outChannels; j++) {
                    pOut[outChannels * i + j] = pIn[outChannels * i + j];
                }
            }
        }
    } else {
        if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE) {
            if (outChannels == FCC_1) {
                for (int i = 0; i < frameCount; i++) {
                    pOut[i] +=
                            ((pContext->OutFrames[i * FCC_2] + pContext->OutFrames[i * FCC_2 + 1]) *
                             0.5f);
                }
            } else {
                for (int i = 0; i < frameCount * FCC_2; i++) {
                    pOut[i] += pContext->OutFrames[i];
                }
            }
        } else {
            if (outChannels == FCC_1) {
                From2iToMono_Float((const process_buffer_t*)pContext->OutFrames, pOut, frameCount);
            } else {
                memcpy(pOut, pContext->OutFrames, frameCount * sizeof(*pOut) * FCC_2);
            }
        }
    }

    return 0;
} /* end process */

@@ -549,7 +567,7 @@ int Reverb_setConfig(ReverbContext* pContext, effect_config_t* pConfig) {
    CHECK_ARG((pContext->auxiliary && pConfig->inputCfg.channels == AUDIO_CHANNEL_OUT_MONO) ||
              ((!pContext->auxiliary) && (inputChannels <= LVM_MAX_CHANNELS)));
    int outputChannels = audio_channel_count_from_out_mask(pConfig->outputCfg.channels);
    CHECK_ARG(outputChannels >= FCC_2 && outputChannels <= LVM_MAX_CHANNELS);
    CHECK_ARG(outputChannels <= LVM_MAX_CHANNELS);
    CHECK_ARG(pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE ||
              pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE);
    CHECK_ARG(pConfig->inputCfg.format == EFFECT_BUFFER_FORMAT);