blob: 5e31e2f8b248edc7cfd94ac51ea5af81814084ac [file] [log] [blame]
Shunkai Yao6afc8552022-10-26 22:47:20 +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 Yao6afc8552022-10-26 22:47:20 +000025
26namespace aidl::android::hardware::audio::effect {
27
Shunkai Yao812d5b42022-11-16 18:08:50 +000028class EnvReverbSwContext final : public EffectContext {
Shunkai Yao6afc8552022-10-26 22:47:20 +000029 public:
Shunkai Yao812d5b42022-11-16 18:08:50 +000030 EnvReverbSwContext(int statusDepth, const Parameter::Common& common)
Shunkai Yao6afc8552022-10-26 22:47:20 +000031 : EffectContext(statusDepth, common) {
32 LOG(DEBUG) << __func__;
33 }
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053034
Sham Rathode362a462023-01-05 18:46:21 +053035 RetCode setErRoomLevel(int roomLevel);
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053036 int getErRoomLevel() const { return mRoomLevel; }
37
Sham Rathode362a462023-01-05 18:46:21 +053038 RetCode setErRoomHfLevel(int roomHfLevel);
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053039 int getErRoomHfLevel() const { return mRoomHfLevel; }
40
Sham Rathode362a462023-01-05 18:46:21 +053041 RetCode setErDecayTime(int decayTime);
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053042 int getErDecayTime() const { return mDecayTime; }
43
Sham Rathode362a462023-01-05 18:46:21 +053044 RetCode setErDecayHfRatio(int decayHfRatio);
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053045 int getErDecayHfRatio() const { return mDecayHfRatio; }
46
Sham Rathode362a462023-01-05 18:46:21 +053047 RetCode setErLevel(int level);
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053048 int getErLevel() const { return mLevel; }
49
Sham Rathode362a462023-01-05 18:46:21 +053050 RetCode setErDelay(int delay);
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053051 int getErDelay() const { return mDelay; }
52
Sham Rathode362a462023-01-05 18:46:21 +053053 RetCode setErDiffusion(int diffusion);
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053054 int getErDiffusion() const { return mDiffusion; }
55
Sham Rathode362a462023-01-05 18:46:21 +053056 RetCode setErDensity(int density);
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053057 int getErDensity() const { return mDensity; }
58
59 RetCode setErBypass(bool bypass) {
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053060 mBypass = bypass;
61 return RetCode::SUCCESS;
62 }
63 bool getErBypass() const { return mBypass; }
64
Shunkai Yao2ddafc22023-02-21 18:02:10 +000065 RetCode setErReflectionsDelay(int delay) {
66 mReflectionsDelayMs = delay;
67 return RetCode::SUCCESS;
68 }
69 bool getErReflectionsDelay() const { return mReflectionsDelayMs; }
70
71 RetCode setErReflectionsLevel(int level) {
72 mReflectionsLevelMb = level;
73 return RetCode::SUCCESS;
74 }
75 bool getErReflectionsLevel() const { return mReflectionsLevelMb; }
76
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053077 private:
Sham Rathode362a462023-01-05 18:46:21 +053078 int mRoomLevel = -6000; // Default room level
79 int mRoomHfLevel = 0; // Default room hf level
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053080 int mDecayTime = 1000; // Default decay time
81 int mDecayHfRatio = 500; // Default decay hf ratio
Sham Rathode362a462023-01-05 18:46:21 +053082 int mLevel = -6000; // Default level
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053083 int mDelay = 40; // Default delay
Shunkai Yao2ddafc22023-02-21 18:02:10 +000084 int mReflectionsLevelMb = 0;
85 int mReflectionsDelayMs = 0;
Sham Rathode362a462023-01-05 18:46:21 +053086 int mDiffusion = 1000; // Default diffusion
87 int mDensity = 1000; // Default density
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053088 bool mBypass = false; // Default bypass
Shunkai Yao6afc8552022-10-26 22:47:20 +000089};
90
Shunkai Yao812d5b42022-11-16 18:08:50 +000091class EnvReverbSw final : public EffectImpl {
Shunkai Yao6afc8552022-10-26 22:47:20 +000092 public:
Shunkai Yaoc12e0822022-12-12 07:13:58 +000093 static const std::string kEffectName;
Shunkai Yao87811022023-02-13 17:40:37 +000094 static const Capability kCapability;
Shunkai Yaoc12e0822022-12-12 07:13:58 +000095 static const Descriptor kDescriptor;
Shunkai Yao812d5b42022-11-16 18:08:50 +000096 EnvReverbSw() { LOG(DEBUG) << __func__; }
97 ~EnvReverbSw() {
98 cleanUp();
Shunkai Yao6afc8552022-10-26 22:47:20 +000099 LOG(DEBUG) << __func__;
Shunkai Yao6afc8552022-10-26 22:47:20 +0000100 }
101
102 ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override;
103 ndk::ScopedAStatus setParameterSpecific(const Parameter::Specific& specific) override;
104 ndk::ScopedAStatus getParameterSpecific(const Parameter::Id& id,
105 Parameter::Specific* specific) override;
Shraddha Basantwanif627d802022-11-08 14:45:07 +0530106
Shunkai Yao6afc8552022-10-26 22:47:20 +0000107 std::shared_ptr<EffectContext> createContext(const Parameter::Common& common) override;
Shraddha Basantwanif627d802022-11-08 14:45:07 +0530108 std::shared_ptr<EffectContext> getContext() override;
Shunkai Yao6afc8552022-10-26 22:47:20 +0000109 RetCode releaseContext() override;
110
Shraddha Basantwanif627d802022-11-08 14:45:07 +0530111 IEffect::Status effectProcessImpl(float* in, float* out, int samples) override;
112 std::string getEffectName() override { return kEffectName; }
113
Shunkai Yao6afc8552022-10-26 22:47:20 +0000114 private:
Shunkai Yao87811022023-02-13 17:40:37 +0000115 static const std::vector<Range::EnvironmentalReverbRange> kRanges;
Shunkai Yao812d5b42022-11-16 18:08:50 +0000116 std::shared_ptr<EnvReverbSwContext> mContext;
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +0530117 ndk::ScopedAStatus getParameterEnvironmentalReverb(const EnvironmentalReverb::Tag& tag,
118 Parameter::Specific* specific);
Shunkai Yao6afc8552022-10-26 22:47:20 +0000119};
120} // namespace aidl::android::hardware::audio::effect