diff --git a/audio/aidl/aidl_api/android.hardware.audio.effect/current/android/hardware/audio/effect/Virtualizer.aidl b/audio/aidl/aidl_api/android.hardware.audio.effect/current/android/hardware/audio/effect/Virtualizer.aidl index deaff9059e..9fdd69227c 100644 --- a/audio/aidl/aidl_api/android.hardware.audio.effect/current/android/hardware/audio/effect/Virtualizer.aidl +++ b/audio/aidl/aidl_api/android.hardware.audio.effect/current/android/hardware/audio/effect/Virtualizer.aidl @@ -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; } } diff --git a/audio/aidl/android/hardware/audio/effect/Virtualizer.aidl b/audio/aidl/android/hardware/audio/effect/Virtualizer.aidl index 90ec6f8352..5f385a65f9 100644 --- a/audio/aidl/android/hardware/audio/effect/Virtualizer.aidl +++ b/audio/aidl/android/hardware/audio/effect/Virtualizer.aidl @@ -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; } diff --git a/audio/aidl/default/virtualizer/VirtualizerSw.cpp b/audio/aidl/default/virtualizer/VirtualizerSw.cpp index f4aa67cb1e..cc51937495 100644 --- a/audio/aidl/default/virtualizer/VirtualizerSw.cpp +++ b/audio/aidl/default/virtualizer/VirtualizerSw.cpp @@ -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 diff --git a/audio/aidl/default/virtualizer/VirtualizerSw.h b/audio/aidl/default/virtualizer/VirtualizerSw.h index b4482da909..0f294cdf4f 100644 --- a/audio/aidl/default/virtualizer/VirtualizerSw.h +++ b/audio/aidl/default/virtualizer/VirtualizerSw.h @@ -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: diff --git a/audio/aidl/vts/VtsHalVirtualizerTargetTest.cpp b/audio/aidl/vts/VtsHalVirtualizerTargetTest.cpp index 61776b2b6e..090de17b96 100644 --- a/audio/aidl/vts/VtsHalVirtualizerTargetTest.cpp +++ b/audio/aidl/vts/VtsHalVirtualizerTargetTest.cpp @@ -44,11 +44,6 @@ using VirtualizerParamTestParam = std::tuple * otherwise expect EX_ILLEGAL_ARGUMENT. */ -const std::vector kStrengthValues = { - std::numeric_limits::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::max()}; - class VirtualizerParamTest : public ::testing::TestWithParam, public EffectHelper { public: @@ -75,8 +70,7 @@ class VirtualizerParamTest : public ::testing::TestWithParam(Virtualizer::MIN_PER_MILLE_STRENGTH); + Virtualizer vr = Virtualizer::make(0); Parameter::Specific specific = Parameter::Specific::make(vr); return specific; @@ -86,7 +80,7 @@ class VirtualizerParamTest : public ::testing::TestWithParam mFactory; std::shared_ptr 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= Virtualizer::MIN_PER_MILLE_STRENGTH && - strength <= Virtualizer::MAX_PER_MILLE_STRENGTH; + return cap.strengthSupported && strength >= 0 && strength <= cap.maxStrengthPm; + } + + static std::vector getStrengthTestValues( + std::vector, Descriptor>> kFactoryDescList) { + const auto max = std::max_element( + kFactoryDescList.begin(), kFactoryDescList.end(), + [](const std::pair, Descriptor>& a, + const std::pair, Descriptor>& b) { + return a.second.capability.get().maxStrengthPm < + b.second.capability.get().maxStrengthPm; + }); + if (max == kFactoryDescList.end()) { + return {0}; + } + int maxStrength = max->second.capability.get().maxStrengthPm; + return {std::numeric_limits::min(), + -1, + 0, + maxStrength >> 1, + maxStrength, + maxStrength + 1, + std::numeric_limits::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& info) { auto descriptor = std::get(info.param).second; std::string strength = std::to_string(std::get(info.param));