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 <audio_effects/effect_loudnessenhancer.h>
20 
21 #include "dsp/core/dynamic_range_compression.h"
22 #include "effect-impl/EffectContext.h"
23 
24 namespace aidl::android::hardware::audio::effect {
25 
26 enum LoudnessEnhancerState {
27     LOUDNESS_ENHANCER_STATE_UNINITIALIZED,
28     LOUDNESS_ENHANCER_STATE_INITIALIZED,
29     LOUDNESS_ENHANCER_STATE_ACTIVE,
30 };
31 
32 class LoudnessEnhancerContext final : public EffectContext {
33   public:
34     LoudnessEnhancerContext(int statusDepth, const Parameter::Common& common);
35     ~LoudnessEnhancerContext() = default;
36 
37     RetCode enable();
38     RetCode disable();
39     void reset();
40 
41     RetCode setLeGain(int gainMb);
getLeGain()42     int getLeGain() const { return mGain; }
43 
44     IEffect::Status process(float* in, float* out, int samples);
45 
46   private:
47     LoudnessEnhancerState mState = LOUDNESS_ENHANCER_STATE_UNINITIALIZED;
48     int mGain = LOUDNESS_ENHANCER_DEFAULT_TARGET_GAIN_MB;
49     // In this implementation, there is no coupling between the compression on the left and right
50     // channels
51     std::unique_ptr<le_fx::AdaptiveDynamicRangeCompression> mCompressor;
52 
53     void init_params();
54 };
55 }  // namespace aidl::android::hardware::audio::effect
56