Shunkai Yao | bd862b8 | 2022-12-20 00:11:41 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include <aidl/android/hardware/audio/effect/BnEffect.h> |
| 20 | #include <fmq/AidlMessageQueue.h> |
| 21 | #include <cstdlib> |
| 22 | #include <memory> |
| 23 | |
| 24 | #include "effect-impl/EffectImpl.h" |
| 25 | #include "effect-impl/EffectUUID.h" |
| 26 | |
| 27 | namespace aidl::android::hardware::audio::effect { |
| 28 | |
| 29 | class AutomaticGainControlSwContext final : public EffectContext { |
| 30 | public: |
| 31 | AutomaticGainControlSwContext(int statusDepth, const Parameter::Common& common) |
| 32 | : EffectContext(statusDepth, common) { |
| 33 | LOG(DEBUG) << __func__; |
| 34 | } |
| 35 | |
| 36 | RetCode setDigitalGain(int gain); |
| 37 | int getDigitalGain(); |
| 38 | RetCode setLevelEstimator(AutomaticGainControl::LevelEstimator levelEstimator); |
| 39 | AutomaticGainControl::LevelEstimator getLevelEstimator(); |
| 40 | RetCode setSaturationMargin(int margin); |
| 41 | int getSaturationMargin(); |
| 42 | |
| 43 | private: |
Sham Rathod | d7c6f32 | 2022-12-26 11:17:10 +0530 | [diff] [blame] | 44 | int mDigitalGain = 0; |
| 45 | AutomaticGainControl::LevelEstimator mLevelEstimator = |
| 46 | AutomaticGainControl::LevelEstimator::RMS; |
| 47 | int mSaturationMargin = 0; |
Shunkai Yao | bd862b8 | 2022-12-20 00:11:41 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | class AutomaticGainControlSw final : public EffectImpl { |
| 51 | public: |
| 52 | static const std::string kEffectName; |
| 53 | static const bool kStrengthSupported; |
Shunkai Yao | 8781102 | 2023-02-13 17:40:37 +0000 | [diff] [blame^] | 54 | static const Capability kCapability; |
Shunkai Yao | bd862b8 | 2022-12-20 00:11:41 +0000 | [diff] [blame] | 55 | static const Descriptor kDescriptor; |
| 56 | AutomaticGainControlSw() { LOG(DEBUG) << __func__; } |
| 57 | ~AutomaticGainControlSw() { |
| 58 | cleanUp(); |
| 59 | LOG(DEBUG) << __func__; |
| 60 | } |
| 61 | |
| 62 | ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override; |
| 63 | ndk::ScopedAStatus setParameterSpecific(const Parameter::Specific& specific) override; |
| 64 | ndk::ScopedAStatus getParameterSpecific(const Parameter::Id& id, |
| 65 | Parameter::Specific* specific) override; |
| 66 | |
| 67 | std::shared_ptr<EffectContext> createContext(const Parameter::Common& common) override; |
| 68 | std::shared_ptr<EffectContext> getContext() override; |
| 69 | RetCode releaseContext() override; |
| 70 | |
| 71 | std::string getEffectName() override { return kEffectName; }; |
| 72 | IEffect::Status effectProcessImpl(float* in, float* out, int samples) override; |
| 73 | |
| 74 | private: |
Shunkai Yao | 8781102 | 2023-02-13 17:40:37 +0000 | [diff] [blame^] | 75 | static const std::vector<Range::AutomaticGainControlRange> kRanges; |
Shunkai Yao | bd862b8 | 2022-12-20 00:11:41 +0000 | [diff] [blame] | 76 | std::shared_ptr<AutomaticGainControlSwContext> mContext; |
| 77 | ndk::ScopedAStatus getParameterAutomaticGainControl(const AutomaticGainControl::Tag& tag, |
| 78 | Parameter::Specific* specific); |
| 79 | }; |
| 80 | } // namespace aidl::android::hardware::audio::effect |