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

Commit 8dc22baa authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Virtualizer : Add minimum and maximum capabilities for params." am: 98c73f7a

parents aeea8c3d 98c73f7a
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -36,8 +36,6 @@ package android.hardware.audio.effect;
union Virtualizer {
  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 Virtualizer {
  @VintfStability
  parcelable Capability {
    android.hardware.audio.effect.VendorExtension extension;
    int maxStrengthPm;
    boolean strengthSupported;
  }
}
+6 −11
Original line number Diff line number Diff line
@@ -52,6 +52,10 @@ union Virtualizer {
         * capability definition not enough.
         */
        VendorExtension 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 always return EX_ILLEGAL_ARGUMENT.
@@ -59,16 +63,6 @@ union Virtualizer {
        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 virtualizer effect.
     *
@@ -76,7 +70,8 @@ union Virtualizer {
     * 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 −2
Original line number Diff line number Diff line
@@ -61,8 +61,8 @@ namespace aidl::android::hardware::audio::effect {

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

RetCode VirtualizerSwContext::setVrStrength(int strength) {
    if (strength < 0 || strength > VirtualizerSw::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
@@ -32,16 +32,7 @@ class VirtualizerSwContext final : public EffectContext {
        : EffectContext(statusDepth, common) {
        LOG(DEBUG) << __func__;
    }
    RetCode setVrStrength(int strength) {
        if (strength < Virtualizer::MIN_PER_MILLE_STRENGTH ||
            strength > Virtualizer::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 setVrStrength(int strength);
    int getVrStrength() const { return mStrength; }

  private:
+28 −11
Original line number Diff line number Diff line
@@ -44,11 +44,6 @@ using VirtualizerParamTestParam = std::tuple<std::pair<std::shared_ptr<IFactory>
 * otherwise expect EX_ILLEGAL_ARGUMENT.
 */

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

class VirtualizerParamTest : public ::testing::TestWithParam<VirtualizerParamTestParam>,
                             public EffectHelper {
  public:
@@ -75,8 +70,7 @@ class VirtualizerParamTest : public ::testing::TestWithParam<VirtualizerParamTes
    }

    Parameter::Specific getDefaultParamSpecific() {
        Virtualizer vr =
                Virtualizer::make<Virtualizer::strengthPm>(Virtualizer::MIN_PER_MILLE_STRENGTH);
        Virtualizer vr = Virtualizer::make<Virtualizer::strengthPm>(0);
        Parameter::Specific specific =
                Parameter::Specific::make<Parameter::Specific::virtualizer>(vr);
        return specific;
@@ -86,7 +80,7 @@ class VirtualizerParamTest : public ::testing::TestWithParam<VirtualizerParamTes
    std::shared_ptr<IFactory> mFactory;
    std::shared_ptr<IEffect> mEffect;
    Descriptor mDescriptor;
    int mParamStrength = Virtualizer::MIN_PER_MILLE_STRENGTH;
    int mParamStrength = 0;

    void SetAndGetVirtualizerParameters() {
        for (auto& it : mTags) {
@@ -141,8 +135,29 @@ class VirtualizerParamTest : public ::testing::TestWithParam<VirtualizerParamTes
    }

    bool isStrengthInRange(const Virtualizer::Capability& cap, int strength) const {
        return cap.strengthSupported && strength >= Virtualizer::MIN_PER_MILLE_STRENGTH &&
               strength <= Virtualizer::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::virtualizer>().maxStrengthPm <
                           b.second.capability.get<Capability::virtualizer>().maxStrengthPm;
                });
        if (max == kFactoryDescList.end()) {
            return {0};
        }
        int maxStrength = max->second.capability.get<Capability::virtualizer>().maxStrengthPm;
        return {std::numeric_limits<int>::min(),
                -1,
                0,
                maxStrength >> 1,
                maxStrength,
                maxStrength + 1,
                std::numeric_limits<int>::max()};
    }

  private:
@@ -159,7 +174,9 @@ INSTANTIATE_TEST_SUITE_P(
        VirtualizerTest, VirtualizerParamTest,
        ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
                                   IFactory::descriptor, kVirtualizerTypeUUID)),
                           testing::ValuesIn(kStrengthValues)),
                           testing::ValuesIn(VirtualizerParamTest::getStrengthTestValues(
                                   EffectFactoryHelper::getAllEffectDescriptors(
                                           IFactory::descriptor, kVirtualizerTypeUUID)))),
        [](const testing::TestParamInfo<VirtualizerParamTest::ParamType>& info) {
            auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
            std::string strength = std::to_string(std::get<PARAM_STRENGTH>(info.param));