xref: /aosp_15_r20/hardware/interfaces/audio/aidl/default/envReverb/EnvReverbSw.h (revision 4d7e907c777eeecc4c5bd7cf640a754fac206ff7)
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 
26 namespace aidl::android::hardware::audio::effect {
27 
28 class EnvReverbSwContext final : public EffectContext {
29   public:
EnvReverbSwContext(int statusDepth,const Parameter::Common & common)30     EnvReverbSwContext(int statusDepth, const Parameter::Common& common)
31         : EffectContext(statusDepth, common) {
32         LOG(DEBUG) << __func__;
33     }
34 
35     RetCode setErRoomLevel(int roomLevel);
getErRoomLevel()36     int getErRoomLevel() const { return mRoomLevel; }
37 
38     RetCode setErRoomHfLevel(int roomHfLevel);
getErRoomHfLevel()39     int getErRoomHfLevel() const { return mRoomHfLevel; }
40 
41     RetCode setErDecayTime(int decayTime);
getErDecayTime()42     int getErDecayTime() const { return mDecayTime; }
43 
44     RetCode setErDecayHfRatio(int decayHfRatio);
getErDecayHfRatio()45     int getErDecayHfRatio() const { return mDecayHfRatio; }
46 
47     RetCode setErLevel(int level);
getErLevel()48     int getErLevel() const { return mLevel; }
49 
50     RetCode setErDelay(int delay);
getErDelay()51     int getErDelay() const { return mDelay; }
52 
53     RetCode setErDiffusion(int diffusion);
getErDiffusion()54     int getErDiffusion() const { return mDiffusion; }
55 
56     RetCode setErDensity(int density);
getErDensity()57     int getErDensity() const { return mDensity; }
58 
setErBypass(bool bypass)59     RetCode setErBypass(bool bypass) {
60         mBypass = bypass;
61         return RetCode::SUCCESS;
62     }
getErBypass()63     bool getErBypass() const { return mBypass; }
64 
setErReflectionsDelay(int delay)65     RetCode setErReflectionsDelay(int delay) {
66         mReflectionsDelayMs = delay;
67         return RetCode::SUCCESS;
68     }
getErReflectionsDelay()69     bool getErReflectionsDelay() const { return mReflectionsDelayMs; }
70 
setErReflectionsLevel(int level)71     RetCode setErReflectionsLevel(int level) {
72         mReflectionsLevelMb = level;
73         return RetCode::SUCCESS;
74     }
getErReflectionsLevel()75     bool getErReflectionsLevel() const { return mReflectionsLevelMb; }
76 
77   private:
78     int mRoomLevel = -6000;                                        // Default room level
79     int mRoomHfLevel = 0;                                          // Default room hf level
80     int mDecayTime = 1000;                                         // Default decay time
81     int mDecayHfRatio = 500;                                       // Default decay hf ratio
82     int mLevel = -6000;                                            // Default level
83     int mDelay = 40;                                               // Default delay
84     int mReflectionsLevelMb = 0;
85     int mReflectionsDelayMs = 0;
86     int mDiffusion = 1000;                                         // Default diffusion
87     int mDensity = 1000;                                           // Default density
88     bool mBypass = false;                                          // Default bypass
89 };
90 
91 class EnvReverbSw final : public EffectImpl {
92   public:
93     static const std::string kEffectName;
94     static const Capability kCapability;
95     static const Descriptor kDescriptor;
EnvReverbSw()96     EnvReverbSw() { LOG(DEBUG) << __func__; }
~EnvReverbSw()97     ~EnvReverbSw() {
98         cleanUp();
99         LOG(DEBUG) << __func__;
100     }
101 
102     ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override;
103     ndk::ScopedAStatus setParameterSpecific(const Parameter::Specific& specific)
104             REQUIRES(mImplMutex) override;
105     ndk::ScopedAStatus getParameterSpecific(const Parameter::Id& id, Parameter::Specific* specific)
106             REQUIRES(mImplMutex) override;
107 
108     std::shared_ptr<EffectContext> createContext(const Parameter::Common& common)
109             REQUIRES(mImplMutex) override;
110     RetCode releaseContext() REQUIRES(mImplMutex) override;
111 
112     IEffect::Status effectProcessImpl(float* in, float* out, int samples) override;
getEffectName()113     std::string getEffectName() override { return kEffectName; }
114 
115   private:
116     static const std::vector<Range::EnvironmentalReverbRange> kRanges;
117     std::shared_ptr<EnvReverbSwContext> mContext GUARDED_BY(mImplMutex);
118     ndk::ScopedAStatus getParameterEnvironmentalReverb(const EnvironmentalReverb::Tag& tag,
119                                                        Parameter::Specific* specific)
120             REQUIRES(mImplMutex);
121 };
122 }  // namespace aidl::android::hardware::audio::effect
123