/* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include "EffectRangeSpecific.h" #include "effect-impl/EffectRange.h" namespace aidl::android::hardware::audio::effect { namespace DynamicsProcessingRanges { static bool isInputGainConfigInRange(const std::vector& cfgs, const DynamicsProcessing::InputGain& min, const DynamicsProcessing::InputGain& max) { auto func = [](const DynamicsProcessing::InputGain& arg) { return std::make_tuple(arg.channel, arg.gainDb); }; return isTupleInRange(cfgs, min, max, func); } static bool isLimiterConfigInRange(const std::vector& cfgs, const DynamicsProcessing::LimiterConfig& min, const DynamicsProcessing::LimiterConfig& max) { auto func = [](const DynamicsProcessing::LimiterConfig& arg) { return std::make_tuple(arg.channel, arg.enable, arg.linkGroup, arg.attackTimeMs, arg.releaseTimeMs, arg.ratio, arg.thresholdDb, arg.postGainDb); }; return isTupleInRange(cfgs, min, max, func); } static bool isMbcBandConfigInRange(const std::vector& cfgs, const DynamicsProcessing::MbcBandConfig& min, const DynamicsProcessing::MbcBandConfig& max) { auto func = [](const DynamicsProcessing::MbcBandConfig& arg) { return std::make_tuple(arg.channel, arg.band, arg.enable, arg.cutoffFrequencyHz, arg.attackTimeMs, arg.releaseTimeMs, arg.ratio, arg.thresholdDb, arg.kneeWidthDb, arg.noiseGateThresholdDb, arg.expanderRatio, arg.preGainDb, arg.postGainDb); }; return isTupleInRange(cfgs, min, max, func); } static bool isEqBandConfigInRange(const std::vector& cfgs, const DynamicsProcessing::EqBandConfig& min, const DynamicsProcessing::EqBandConfig& max) { auto func = [](const DynamicsProcessing::EqBandConfig& arg) { return std::make_tuple(arg.channel, arg.band, arg.enable, arg.cutoffFrequencyHz, arg.gainDb); }; return isTupleInRange(cfgs, min, max, func); } static bool isChannelConfigInRange(const std::vector& cfgs, const DynamicsProcessing::ChannelConfig& min, const DynamicsProcessing::ChannelConfig& max) { auto func = [](const DynamicsProcessing::ChannelConfig& arg) { return std::make_tuple(arg.channel, arg.enable); }; return isTupleInRange(cfgs, min, max, func); } static bool isEngineConfigInRange(const DynamicsProcessing::EngineArchitecture& cfg, const DynamicsProcessing::EngineArchitecture& min, const DynamicsProcessing::EngineArchitecture& max) { auto func = [](const DynamicsProcessing::EngineArchitecture& arg) { return std::make_tuple(arg.resolutionPreference, arg.preferredProcessingDurationMs, arg.preEqStage.inUse, arg.preEqStage.bandCount, arg.postEqStage.inUse, arg.postEqStage.bandCount, arg.mbcStage.inUse, arg.mbcStage.bandCount, arg.limiterInUse); }; return isTupleInRange(func(cfg), func(min), func(max)); } static int locateMinMaxForTag(DynamicsProcessing::Tag tag, const std::vector& ranges) { for (int i = 0; i < (int)ranges.size(); i++) { if (tag == ranges[i].min.getTag() && tag == ranges[i].max.getTag()) { return i; } } return -1; } bool isParamInRange(const DynamicsProcessing& dp, const std::vector& ranges) { auto tag = dp.getTag(); int i = locateMinMaxForTag(tag, ranges); if (i == -1) return true; switch (tag) { case DynamicsProcessing::engineArchitecture: { return isEngineConfigInRange( dp.get(), ranges[i].min.get(), ranges[i].max.get()); } case DynamicsProcessing::preEq: { return isChannelConfigInRange(dp.get(), ranges[i].min.get()[0], ranges[i].max.get()[0]); } case DynamicsProcessing::postEq: { return isChannelConfigInRange(dp.get(), ranges[i].min.get()[0], ranges[i].max.get()[0]); } case DynamicsProcessing::mbc: { return isChannelConfigInRange(dp.get(), ranges[i].min.get()[0], ranges[i].max.get()[0]); } case DynamicsProcessing::preEqBand: { return isEqBandConfigInRange(dp.get(), ranges[i].min.get()[0], ranges[i].max.get()[0]); } case DynamicsProcessing::postEqBand: { return isEqBandConfigInRange(dp.get(), ranges[i].min.get()[0], ranges[i].max.get()[0]); } case DynamicsProcessing::mbcBand: { return isMbcBandConfigInRange(dp.get(), ranges[i].min.get()[0], ranges[i].max.get()[0]); } case DynamicsProcessing::limiter: { return isLimiterConfigInRange(dp.get(), ranges[i].min.get()[0], ranges[i].max.get()[0]); } case DynamicsProcessing::inputGain: { return isInputGainConfigInRange(dp.get(), ranges[i].min.get()[0], ranges[i].max.get()[0]); } default: { return true; } } return true; } } // namespace DynamicsProcessingRanges } // namespace aidl::android::hardware::audio::effect