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

Commit 6c1368fb authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "BassBoost : Add minimum and maximum capabilities for params."

parents 0179b6a9 8411fd2e
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -36,8 +36,6 @@ package android.hardware.audio.effect;
union BassBoost {
  android.hardware.audio.effect.VendorExtension vendor;
  int strengthPm;
  const int MIN_PER_MILLE_STRENGTH = 0;
  const int MAX_PER_MILLE_STRENGTH = 1000;
  @VintfStability
  union Id {
    int vendorExtensionTag;
@@ -46,6 +44,7 @@ union BassBoost {
  @VintfStability
  parcelable Capability {
    ParcelableHolder extension;
    int maxStrengthPm;
    boolean strengthSupported;
  }
}
+6 −11
Original line number Diff line number Diff line
@@ -51,6 +51,10 @@ union BassBoost {
         * definition not enough.
         */
        ParcelableHolder extension;
        /**
         * Maximum possible per mille strength.
         */
        int maxStrengthPm;
        /**
         * Indicates whether setting strength is supported. False value indicates only one strength
         * is supported and setParameter() method will return EX_ILLEGAL_ARGUMENT.
@@ -58,16 +62,6 @@ union BassBoost {
        boolean strengthSupported;
    }

    /**
     * Minimal possible per mille strength.
     */
    const int MIN_PER_MILLE_STRENGTH = 0;

    /**
     * Maximum possible per mille strength.
     */
    const int MAX_PER_MILLE_STRENGTH = 1000;

    /**
     * The per mille strength of the bass boost effect.
     *
@@ -75,7 +69,8 @@ union BassBoost {
     * allowed to round the given strength to the nearest supported value. In this case {@link
     * #IEffect.getParameter()} method should return the rounded value that was actually set.
     *
     * The valid range for strength is [0, 1000].
     * The value of the strength must be non-negative and not exceed the value specified by
     * the 'maxStrengthPm' capability.
     */
    int strengthPm;
}
+12 −1
Original line number Diff line number Diff line
@@ -62,7 +62,8 @@ namespace aidl::android::hardware::audio::effect {

const std::string BassBoostSw::kEffectName = "BassBoostSw";
const bool BassBoostSw::kStrengthSupported = true;
const BassBoost::Capability BassBoostSw::kCapability = {.strengthSupported = kStrengthSupported};
const BassBoost::Capability BassBoostSw::kCapability = {.maxStrengthPm = 1000,
                                                        .strengthSupported = kStrengthSupported};
const Descriptor BassBoostSw::kDescriptor = {
        .common = {.id = {.type = kBassBoostTypeUUID,
                          .uuid = kBassBoostSwImplUUID,
@@ -171,4 +172,14 @@ IEffect::Status BassBoostSw::effectProcessImpl(float* in, float* out, int sample
    return {STATUS_OK, samples, samples};
}

RetCode BassBoostSwContext::setBbStrengthPm(int strength) {
    if (strength < 0 || strength > BassBoostSw::kCapability.maxStrengthPm) {
        LOG(ERROR) << __func__ << " invalid strength: " << strength;
        return RetCode::ERROR_ILLEGAL_PARAMETER;
    }
    // TODO : Add implementation to apply new strength
    mStrength = strength;
    return RetCode::SUCCESS;
}

}  // namespace aidl::android::hardware::audio::effect
+1 −10
Original line number Diff line number Diff line
@@ -33,16 +33,7 @@ class BassBoostSwContext final : public EffectContext {
        LOG(DEBUG) << __func__;
    }

    RetCode setBbStrengthPm(int strength) {
        if (strength < BassBoost::MIN_PER_MILLE_STRENGTH ||
            strength > BassBoost::MAX_PER_MILLE_STRENGTH) {
            LOG(ERROR) << __func__ << " invalid strength: " << strength;
            return RetCode::ERROR_ILLEGAL_PARAMETER;
        }
        // TODO : Add implementation to apply new strength
        mStrength = strength;
        return RetCode::SUCCESS;
    }
    RetCode setBbStrengthPm(int strength);
    int getBbStrengthPm() const { return mStrength; }

  private:
+31 −16
Original line number Diff line number Diff line
@@ -46,15 +46,6 @@ using BassBoostParamTestParam = std::tuple<std::pair<std::shared_ptr<IFactory>,
 * otherwise expect EX_ILLEGAL_ARGUMENT.
 */

const std::vector<int> kStrengthValues = {
        std::numeric_limits<int>::min(),
        BassBoost::MIN_PER_MILLE_STRENGTH - 1,
        BassBoost::MIN_PER_MILLE_STRENGTH,
        (BassBoost::MIN_PER_MILLE_STRENGTH + BassBoost::MAX_PER_MILLE_STRENGTH) >> 1,
        BassBoost::MAX_PER_MILLE_STRENGTH,
        BassBoost::MAX_PER_MILLE_STRENGTH + 2,
        std::numeric_limits<int>::max()};

class BassBoostParamTest : public ::testing::TestWithParam<BassBoostParamTestParam>,
                           public EffectHelper {
  public:
@@ -81,7 +72,7 @@ class BassBoostParamTest : public ::testing::TestWithParam<BassBoostParamTestPar
    }

    Parameter::Specific getDefaultParamSpecific() {
        BassBoost bb = BassBoost::make<BassBoost::strengthPm>(BassBoost::MIN_PER_MILLE_STRENGTH);
        BassBoost bb = BassBoost::make<BassBoost::strengthPm>(0);
        Parameter::Specific specific =
                Parameter::Specific::make<Parameter::Specific::bassBoost>(bb);
        return specific;
@@ -91,7 +82,7 @@ class BassBoostParamTest : public ::testing::TestWithParam<BassBoostParamTestPar
    std::shared_ptr<IFactory> mFactory;
    std::shared_ptr<IEffect> mEffect;
    Descriptor mDescriptor;
    int mParamStrength = BassBoost::MIN_PER_MILLE_STRENGTH;
    int mParamStrength = 0;

    void SetAndGetBassBoostParameters() {
        for (auto& it : mTags) {
@@ -146,8 +137,29 @@ class BassBoostParamTest : public ::testing::TestWithParam<BassBoostParamTestPar
    }

    bool isStrengthInRange(const BassBoost::Capability& cap, int strength) const {
        return cap.strengthSupported && strength >= BassBoost::MIN_PER_MILLE_STRENGTH &&
               strength <= BassBoost::MAX_PER_MILLE_STRENGTH;
        return cap.strengthSupported && strength >= 0 && strength <= cap.maxStrengthPm;
    }

    static std::vector<int> getStrengthTestValues(
            std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> kFactoryDescList) {
        const auto max = std::max_element(
                kFactoryDescList.begin(), kFactoryDescList.end(),
                [](const std::pair<std::shared_ptr<IFactory>, Descriptor>& a,
                   const std::pair<std::shared_ptr<IFactory>, Descriptor>& b) {
                    return a.second.capability.get<Capability::bassBoost>().maxStrengthPm <
                           b.second.capability.get<Capability::bassBoost>().maxStrengthPm;
                });
        if (max == kFactoryDescList.end()) {
            return {0};
        }
        int maxStrength = max->second.capability.get<Capability::bassBoost>().maxStrengthPm;
        return {std::numeric_limits<int>::min(),
                -1,
                0,
                maxStrength >> 1,
                maxStrength,
                maxStrength + 1,
                std::numeric_limits<int>::max()};
    }

  private:
@@ -162,9 +174,12 @@ TEST_P(BassBoostParamTest, SetAndGetStrength) {

INSTANTIATE_TEST_SUITE_P(
        BassBoostTest, BassBoostParamTest,
        ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
                                   IFactory::descriptor, kBassBoostTypeUUID)),
                           testing::ValuesIn(kStrengthValues)),
        ::testing::Combine(
                testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
                                                                               kBassBoostTypeUUID)),
                testing::ValuesIn(BassBoostParamTest::getStrengthTestValues(
                        EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
                                                                     kBassBoostTypeUUID)))),
        [](const testing::TestParamInfo<BassBoostParamTest::ParamType>& info) {
            auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
            std::string strength = std::to_string(std::get<PARAM_STRENGTH>(info.param));