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

Commit 490e1ab6 authored by Jaideep Sharma's avatar Jaideep Sharma Committed by Cherrypicker Worker
Browse files

audio: change volume only if effect updates the volume

Incase of offload effects, setting unity gain leads to
full volume on enabling effects, as unity gain (volume
1.0f, 1.0f is set to audiohal).

Don't set volume always to unity gain, instead
check if effect interface has updated the volume
then only, change the value.

Bug: 296954124
Test: Start a offload effect and check volume.
(cherry picked from https://android-review.googlesource.com/q/commit:98eb34bdd87dd837c64b963b7d926568436d6da5)
Merged-In: I0c20e1235a90b77c0d6ad8fba586cdf006f37224
Change-Id: I0c20e1235a90b77c0d6ad8fba586cdf006f37224
parent 39184c44
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -354,14 +354,22 @@ status_t EffectConversionHelperAidl::handleSetVolume(uint32_t cmdSize, const voi
    }

    constexpr uint32_t unityGain = 1 << 24;
    Parameter::VolumeStereo volume = {.left = (float)(*(uint32_t*)pCmdData) / unityGain,
    Parameter::VolumeStereo requestedVolume = {.left = (float)(*(uint32_t*)pCmdData) / unityGain,
                                      .right = (float)(*(uint32_t*)pCmdData + 1) / unityGain};

    RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
            mEffect->setParameter(Parameter::make<Parameter::volumeStereo>(volume))));
            mEffect->setParameter(Parameter::make<Parameter::volumeStereo>(requestedVolume))));

    // get volume from effect and set if changed.
    Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::volumeStereo);
    Parameter volParam;
    RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &volParam)));
    Parameter::VolumeStereo appliedVolume = volParam.get<Parameter::volumeStereo>();

    // write unity gain back if volume was successfully set
    if (replySize && *replySize == 2 * sizeof(uint32_t) && pReplyData) {
        constexpr uint32_t vol_ret[2] = {unityGain, unityGain};
        uint32_t vl = (uint32_t)(appliedVolume.left * unityGain);
        uint32_t vr = (uint32_t)(appliedVolume.right * unityGain);
        uint32_t vol_ret[2] = {vl, vr};
        memcpy(pReplyData, vol_ret, sizeof(vol_ret));
    }
    return OK;