blob: 4f11a5c5d80d642c9c71e95b2ba93b47b19b7410 [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) {
61 // TODO : Add implementation to apply new bypass
62 mBypass = bypass;
63 return RetCode::SUCCESS;
64 }
65 bool getErBypass() const { return mBypass; }
66
67 private:
Sham Rathode362a462023-01-05 18:46:21 +053068 int mRoomLevel = -6000; // Default room level
69 int mRoomHfLevel = 0; // Default room hf level
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053070 int mDecayTime = 1000; // Default decay time
71 int mDecayHfRatio = 500; // Default decay hf ratio
Sham Rathode362a462023-01-05 18:46:21 +053072 int mLevel = -6000; // Default level
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053073 int mDelay = 40; // Default delay
Sham Rathode362a462023-01-05 18:46:21 +053074 int mDiffusion = 1000; // Default diffusion
75 int mDensity = 1000; // Default density
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +053076 bool mBypass = false; // Default bypass
Shunkai Yao6afc8552022-10-26 22:47:20 +000077};
78
Shunkai Yao812d5b42022-11-16 18:08:50 +000079class EnvReverbSw final : public EffectImpl {
Shunkai Yao6afc8552022-10-26 22:47:20 +000080 public:
Shunkai Yaoc12e0822022-12-12 07:13:58 +000081 static const std::string kEffectName;
Shunkai Yao87811022023-02-13 17:40:37 +000082 static const Capability kCapability;
Shunkai Yaoc12e0822022-12-12 07:13:58 +000083 static const Descriptor kDescriptor;
Shunkai Yao812d5b42022-11-16 18:08:50 +000084 EnvReverbSw() { LOG(DEBUG) << __func__; }
85 ~EnvReverbSw() {
86 cleanUp();
Shunkai Yao6afc8552022-10-26 22:47:20 +000087 LOG(DEBUG) << __func__;
Shunkai Yao6afc8552022-10-26 22:47:20 +000088 }
89
90 ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override;
91 ndk::ScopedAStatus setParameterSpecific(const Parameter::Specific& specific) override;
92 ndk::ScopedAStatus getParameterSpecific(const Parameter::Id& id,
93 Parameter::Specific* specific) override;
Shraddha Basantwanif627d802022-11-08 14:45:07 +053094
Shunkai Yao6afc8552022-10-26 22:47:20 +000095 std::shared_ptr<EffectContext> createContext(const Parameter::Common& common) override;
Shraddha Basantwanif627d802022-11-08 14:45:07 +053096 std::shared_ptr<EffectContext> getContext() override;
Shunkai Yao6afc8552022-10-26 22:47:20 +000097 RetCode releaseContext() override;
98
Shraddha Basantwanif627d802022-11-08 14:45:07 +053099 IEffect::Status effectProcessImpl(float* in, float* out, int samples) override;
100 std::string getEffectName() override { return kEffectName; }
101
Shunkai Yao6afc8552022-10-26 22:47:20 +0000102 private:
Shunkai Yao87811022023-02-13 17:40:37 +0000103 static const std::vector<Range::EnvironmentalReverbRange> kRanges;
Shunkai Yao812d5b42022-11-16 18:08:50 +0000104 std::shared_ptr<EnvReverbSwContext> mContext;
Shraddha Basantwanidbb0ed62022-11-17 20:32:18 +0530105 ndk::ScopedAStatus getParameterEnvironmentalReverb(const EnvironmentalReverb::Tag& tag,
106 Parameter::Specific* specific);
Shunkai Yao6afc8552022-10-26 22:47:20 +0000107};
108} // namespace aidl::android::hardware::audio::effect