/* * 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. */ #pragma once #include #include "effect-impl/EffectContext.h" #include #include #include #include namespace aidl::android::hardware::audio::effect { enum DynamicsProcessingState { DYNAMICS_PROCESSING_STATE_UNINITIALIZED, DYNAMICS_PROCESSING_STATE_INITIALIZED, DYNAMICS_PROCESSING_STATE_ACTIVE, }; class DynamicsProcessingContext final : public EffectContext { public: DynamicsProcessingContext(int statusDepth, const Parameter::Common& common); ~DynamicsProcessingContext() = default; RetCode enable(); RetCode disable(); void reset(); // override EffectContext::setCommon to update mChannelCount RetCode setCommon(const Parameter::Common& common) override; RetCode setVolumeStereo(const Parameter::VolumeStereo& volumeStereo) override; Parameter::VolumeStereo getVolumeStereo() override; RetCode setEngineArchitecture(const DynamicsProcessing::EngineArchitecture& engineArchitecture); RetCode setPreEq(const std::vector& eqChannels); RetCode setPostEq(const std::vector& eqChannels); RetCode setPreEqBand(const std::vector& eqBands); RetCode setPostEqBand(const std::vector& eqBands); RetCode setMbc(const std::vector& mbcChannels); RetCode setMbcBand(const std::vector& eqBands); RetCode setLimiter(const std::vector& limiters); RetCode setInputGain(const std::vector& gain); DynamicsProcessing::EngineArchitecture getEngineArchitecture(); std::vector getPreEq(); std::vector getPostEq(); std::vector getPreEqBand(); std::vector getPostEqBand(); std::vector getMbc(); std::vector getMbcBand(); std::vector getLimiter(); std::vector getInputGain(); IEffect::Status dpeProcess(float* in, float* out, int samples); private: static constexpr float kPreferredProcessingDurationMs = 10.0f; static constexpr int kBandCount = 5; int mChannelCount = 0; DynamicsProcessingState mState = DYNAMICS_PROCESSING_STATE_UNINITIALIZED; std::unique_ptr mDpFreq = nullptr; bool mEngineInited = false; DynamicsProcessing::EngineArchitecture mEngineArchitecture = { .resolutionPreference = DynamicsProcessing::ResolutionPreference::FAVOR_FREQUENCY_RESOLUTION, .preferredProcessingDurationMs = kPreferredProcessingDurationMs, .preEqStage = {.inUse = true, .bandCount = kBandCount}, .postEqStage = {.inUse = true, .bandCount = kBandCount}, .mbcStage = {.inUse = true, .bandCount = kBandCount}, .limiterInUse = true, }; enum class StageType { PREEQ, POSTEQ, MBC, LIMITER, INPUTGAIN }; void init(); void dpSetFreqDomainVariant_l(const DynamicsProcessing::EngineArchitecture& engine); dp_fx::DPChannel* getChannel_l(int ch); dp_fx::DPEq* getPreEq_l(int ch); dp_fx::DPEq* getPostEq_l(int ch); dp_fx::DPMbc* getMbc_l(int ch); dp_fx::DPLimiter* getLimiter_l(int ch); dp_fx::DPBandStage* getStageWithType_l(StageType type, int ch); dp_fx::DPEq* getEqWithType_l(StageType type, int ch); template RetCode setDpChannels_l(const std::vector& channels, StageType type); template RetCode setBands_l(const std::vector& bands, StageType type); RetCode setDpChannelBand_l(const std::any& anyConfig, StageType type, std::set>& chBandSet); std::vector getEqBandConfigs(StageType type); std::vector getChannelConfig(StageType type); template bool validateBandConfig(const std::vector& bands, int maxChannel, int maxBand); bool validateLimiterConfig(const std::vector& cfgs, int maxChannel); bool validateInputGainConfig(const std::vector& cfgs, int maxChannel); inline bool validateChannel(int ch, int maxCh) { return ch >= 0 && ch < maxCh; } inline bool validateBand(int band, int maxBand) { return band >= 0 && band < maxBand; } }; } // namespace aidl::android::hardware::audio::effect