blob: 9aa60eab60c6465c28f83281360f2ffb7e186dd9 [file] [log] [blame]
Shunkai Yaobd862b82022-12-20 00:11:41 +00001/*
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"
Shunkai Yaobd862b82022-12-20 00:11:41 +000025
26namespace aidl::android::hardware::audio::effect {
27
Shraddha Basantwani84ea32e2023-02-01 16:22:37 +053028class AutomaticGainControlV2SwContext final : public EffectContext {
Shunkai Yaobd862b82022-12-20 00:11:41 +000029 public:
Shraddha Basantwani84ea32e2023-02-01 16:22:37 +053030 AutomaticGainControlV2SwContext(int statusDepth, const Parameter::Common& common)
Shunkai Yaobd862b82022-12-20 00:11:41 +000031 : EffectContext(statusDepth, common) {
32 LOG(DEBUG) << __func__;
33 }
34
35 RetCode setDigitalGain(int gain);
36 int getDigitalGain();
Shraddha Basantwani84ea32e2023-02-01 16:22:37 +053037 RetCode setLevelEstimator(AutomaticGainControlV2::LevelEstimator levelEstimator);
38 AutomaticGainControlV2::LevelEstimator getLevelEstimator();
Shunkai Yaobd862b82022-12-20 00:11:41 +000039 RetCode setSaturationMargin(int margin);
40 int getSaturationMargin();
41
42 private:
Sham Rathodd7c6f322022-12-26 11:17:10 +053043 int mDigitalGain = 0;
Shraddha Basantwani84ea32e2023-02-01 16:22:37 +053044 AutomaticGainControlV2::LevelEstimator mLevelEstimator =
45 AutomaticGainControlV2::LevelEstimator::RMS;
Sham Rathodd7c6f322022-12-26 11:17:10 +053046 int mSaturationMargin = 0;
Shunkai Yaobd862b82022-12-20 00:11:41 +000047};
48
Shraddha Basantwani84ea32e2023-02-01 16:22:37 +053049class AutomaticGainControlV2Sw final : public EffectImpl {
Shunkai Yaobd862b82022-12-20 00:11:41 +000050 public:
51 static const std::string kEffectName;
52 static const bool kStrengthSupported;
Shunkai Yao87811022023-02-13 17:40:37 +000053 static const Capability kCapability;
Shunkai Yaobd862b82022-12-20 00:11:41 +000054 static const Descriptor kDescriptor;
Shraddha Basantwani84ea32e2023-02-01 16:22:37 +053055 AutomaticGainControlV2Sw() { LOG(DEBUG) << __func__; }
56 ~AutomaticGainControlV2Sw() {
Shunkai Yaobd862b82022-12-20 00:11:41 +000057 cleanUp();
58 LOG(DEBUG) << __func__;
59 }
60
61 ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override;
62 ndk::ScopedAStatus setParameterSpecific(const Parameter::Specific& specific) override;
63 ndk::ScopedAStatus getParameterSpecific(const Parameter::Id& id,
64 Parameter::Specific* specific) override;
65
66 std::shared_ptr<EffectContext> createContext(const Parameter::Common& common) override;
67 std::shared_ptr<EffectContext> getContext() override;
68 RetCode releaseContext() override;
69
70 std::string getEffectName() override { return kEffectName; };
71 IEffect::Status effectProcessImpl(float* in, float* out, int samples) override;
72
73 private:
Shraddha Basantwani84ea32e2023-02-01 16:22:37 +053074 static const std::vector<Range::AutomaticGainControlV2Range> kRanges;
75 std::shared_ptr<AutomaticGainControlV2SwContext> mContext;
76 ndk::ScopedAStatus getParameterAutomaticGainControlV2(const AutomaticGainControlV2::Tag& tag,
77 Parameter::Specific* specific);
Shunkai Yaobd862b82022-12-20 00:11:41 +000078};
79} // namespace aidl::android::hardware::audio::effect