blob: dd2cf5deb2ba8489cdf86614990db5a12b99d869 [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"
25#include "effect-impl/EffectUUID.h"
26
27namespace aidl::android::hardware::audio::effect {
28
Shunkai Yao812d5b42022-11-16 18:08:50 +000029class EnvReverbSwContext final : public EffectContext {
Shunkai Yao6afc8552022-10-26 22:47:20 +000030 public:
Shunkai Yao812d5b42022-11-16 18:08:50 +000031 EnvReverbSwContext(int statusDepth, const Parameter::Common& common)
Shunkai Yao6afc8552022-10-26 22:47:20 +000032 : EffectContext(statusDepth, common) {
33 LOG(DEBUG) << __func__;
34 }
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053035
Sham Rathode362a462023-01-05 18:46:21 +053036 RetCode setErRoomLevel(int roomLevel);
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053037 int getErRoomLevel() const { return mRoomLevel; }
38
Sham Rathode362a462023-01-05 18:46:21 +053039 RetCode setErRoomHfLevel(int roomHfLevel);
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053040 int getErRoomHfLevel() const { return mRoomHfLevel; }
41
Sham Rathode362a462023-01-05 18:46:21 +053042 RetCode setErDecayTime(int decayTime);
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053043 int getErDecayTime() const { return mDecayTime; }
44
Sham Rathode362a462023-01-05 18:46:21 +053045 RetCode setErDecayHfRatio(int decayHfRatio);
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053046 int getErDecayHfRatio() const { return mDecayHfRatio; }
47
Sham Rathode362a462023-01-05 18:46:21 +053048 RetCode setErLevel(int level);
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053049 int getErLevel() const { return mLevel; }
50
Sham Rathode362a462023-01-05 18:46:21 +053051 RetCode setErDelay(int delay);
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053052 int getErDelay() const { return mDelay; }
53
Sham Rathode362a462023-01-05 18:46:21 +053054 RetCode setErDiffusion(int diffusion);
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053055 int getErDiffusion() const { return mDiffusion; }
56
Sham Rathode362a462023-01-05 18:46:21 +053057 RetCode setErDensity(int density);
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053058 int getErDensity() const { return mDensity; }
59
60 RetCode setErBypass(bool bypass) {
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053061 mBypass = bypass;
62 return RetCode::SUCCESS;
63 }
64 bool getErBypass() const { return mBypass; }
65
Shunkai Yao2ddafc22023-02-21 18:02:10 +000066 RetCode setErReflectionsDelay(int delay) {
67 mReflectionsDelayMs = delay;
68 return RetCode::SUCCESS;
69 }
70 bool getErReflectionsDelay() const { return mReflectionsDelayMs; }
71
72 RetCode setErReflectionsLevel(int level) {
73 mReflectionsLevelMb = level;
74 return RetCode::SUCCESS;
75 }
76 bool getErReflectionsLevel() const { return mReflectionsLevelMb; }
77
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053078 private:
Sham Rathode362a462023-01-05 18:46:21 +053079 int mRoomLevel = -6000; // Default room level
80 int mRoomHfLevel = 0; // Default room hf level
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053081 int mDecayTime = 1000; // Default decay time
82 int mDecayHfRatio = 500; // Default decay hf ratio
Sham Rathode362a462023-01-05 18:46:21 +053083 int mLevel = -6000; // Default level
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053084 int mDelay = 40; // Default delay
Shunkai Yao2ddafc22023-02-21 18:02:10 +000085 int mReflectionsLevelMb = 0;
86 int mReflectionsDelayMs = 0;
Sham Rathode362a462023-01-05 18:46:21 +053087 int mDiffusion = 1000; // Default diffusion
88 int mDensity = 1000; // Default density
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053089 bool mBypass = false; // Default bypass
Shunkai Yao6afc8552022-10-26 22:47:20 +000090};
91
Shunkai Yao812d5b42022-11-16 18:08:50 +000092class EnvReverbSw final : public EffectImpl {
Shunkai Yao6afc8552022-10-26 22:47:20 +000093 public:
Shunkai Yaoc12e0822022-12-12 07:13:58 +000094 static const std::string kEffectName;
Shunkai Yao87811022023-02-13 17:40:37 +000095 static const Capability kCapability;
Shunkai Yaoc12e0822022-12-12 07:13:58 +000096 static const Descriptor kDescriptor;
Shunkai Yao812d5b42022-11-16 18:08:50 +000097 EnvReverbSw() { LOG(DEBUG) << __func__; }
98 ~EnvReverbSw() {
99 cleanUp();
Shunkai Yao6afc8552022-10-26 22:47:20 +0000100 LOG(DEBUG) << __func__;
Shunkai Yao6afc8552022-10-26 22:47:20 +0000101 }
102
103 ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override;
104 ndk::ScopedAStatus setParameterSpecific(const Parameter::Specific& specific) override;
105 ndk::ScopedAStatus getParameterSpecific(const Parameter::Id& id,
106 Parameter::Specific* specific) override;
Shraddha Basantwanif627d802022-11-08 14:45:07 +0530107
Shunkai Yao6afc8552022-10-26 22:47:20 +0000108 std::shared_ptr<EffectContext> createContext(const Parameter::Common& common) override;
Shraddha Basantwanif627d802022-11-08 14:45:07 +0530109 std::shared_ptr<EffectContext> getContext() override;
Shunkai Yao6afc8552022-10-26 22:47:20 +0000110 RetCode releaseContext() override;
111
Shraddha Basantwanif627d802022-11-08 14:45:07 +0530112 IEffect::Status effectProcessImpl(float* in, float* out, int samples) override;
113 std::string getEffectName() override { return kEffectName; }
114
Shunkai Yao6afc8552022-10-26 22:47:20 +0000115 private:
Shunkai Yao87811022023-02-13 17:40:37 +0000116 static const std::vector<Range::EnvironmentalReverbRange> kRanges;
Shunkai Yao812d5b42022-11-16 18:08:50 +0000117 std::shared_ptr<EnvReverbSwContext> mContext;
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +0530118 ndk::ScopedAStatus getParameterEnvironmentalReverb(const EnvironmentalReverb::Tag& tag,
119 Parameter::Specific* specific);
Shunkai Yao6afc8552022-10-26 22:47:20 +0000120};
121} // namespace aidl::android::hardware::audio::effect