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

Commit 214c86e5 authored by Jindong Yue's avatar Jindong Yue Committed by Mikhail Naganov
Browse files

audio: Add warning log for unmatched mixer values



Compare the mixer control values set by the user with the values
retrieved from the hardware, and log a warning if they do not match.

This check is meaningful because of the integer division involved in
converting between percentage and hardware values in tinyalsa, which
can lead to small discrepancies due to rounding.

Bug: 375030900
Test: build locally
Change-Id: If396a5cedc768f2bab5db055b5cf875143e3c23b
Signed-off-by: default avatarJindong Yue <jindong.yue@nxp.com>
parent 5c7e78b8
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -242,6 +242,14 @@ ndk::ScopedAStatus StreamInPrimary::setHwGain(const std::vector<float>& in_chann
        mHwGains = currentGains;
        return status;
    }
    float gain;
    RETURN_STATUS_IF_ERROR(primary::PrimaryMixer::getInstance().getMicGain(&gain));
    // Due to rounding errors, round trip conversions between percents and indexed values may not
    // match.
    if (gain != in_channelGains[0]) {
        LOG(WARNING) << __func__ << ": unmatched gain: set: " << in_channelGains[0]
                     << ", from mixer: " << gain;
    }
    return ndk::ScopedAStatus::ok();
}

@@ -275,6 +283,15 @@ ndk::ScopedAStatus StreamOutPrimary::setHwVolume(const std::vector<float>& in_ch
        mHwVolumes = currentVolumes;
        return status;
    }
    std::vector<float> volumes;
    RETURN_STATUS_IF_ERROR(primary::PrimaryMixer::getInstance().getVolumes(&volumes));
    // Due to rounding errors, round trip conversions between percents and indexed values may not
    // match.
    if (volumes != in_channelVolumes) {
        LOG(WARNING) << __func__ << ": unmatched volumes: set: "
                     << ::android::internal::ToString(in_channelVolumes)
                     << ", from mixer: " << ::android::internal::ToString(volumes);
    }
    return ndk::ScopedAStatus::ok();
}