Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 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 | #include "effect-impl/EffectUUID.h" |
| 26 | |
| 27 | namespace aidl::android::hardware::audio::effect { |
| 28 | |
Shunkai Yao | 812d5b4 | 2022-11-16 18:08:50 +0000 | [diff] [blame] | 29 | class EnvReverbSwContext final : public EffectContext { |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 30 | public: |
Shunkai Yao | 812d5b4 | 2022-11-16 18:08:50 +0000 | [diff] [blame] | 31 | EnvReverbSwContext(int statusDepth, const Parameter::Common& common) |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 32 | : EffectContext(statusDepth, common) { |
| 33 | LOG(DEBUG) << __func__; |
| 34 | } |
Shraddha Basantwani | dbb0ed6 | 2022-11-17 20:32:18 +0530 | [diff] [blame] | 35 | |
Sham Rathod | e362a46 | 2023-01-05 18:46:21 +0530 | [diff] [blame] | 36 | RetCode setErRoomLevel(int roomLevel); |
Shraddha Basantwani | dbb0ed6 | 2022-11-17 20:32:18 +0530 | [diff] [blame] | 37 | int getErRoomLevel() const { return mRoomLevel; } |
| 38 | |
Sham Rathod | e362a46 | 2023-01-05 18:46:21 +0530 | [diff] [blame] | 39 | RetCode setErRoomHfLevel(int roomHfLevel); |
Shraddha Basantwani | dbb0ed6 | 2022-11-17 20:32:18 +0530 | [diff] [blame] | 40 | int getErRoomHfLevel() const { return mRoomHfLevel; } |
| 41 | |
Sham Rathod | e362a46 | 2023-01-05 18:46:21 +0530 | [diff] [blame] | 42 | RetCode setErDecayTime(int decayTime); |
Shraddha Basantwani | dbb0ed6 | 2022-11-17 20:32:18 +0530 | [diff] [blame] | 43 | int getErDecayTime() const { return mDecayTime; } |
| 44 | |
Sham Rathod | e362a46 | 2023-01-05 18:46:21 +0530 | [diff] [blame] | 45 | RetCode setErDecayHfRatio(int decayHfRatio); |
Shraddha Basantwani | dbb0ed6 | 2022-11-17 20:32:18 +0530 | [diff] [blame] | 46 | int getErDecayHfRatio() const { return mDecayHfRatio; } |
| 47 | |
Sham Rathod | e362a46 | 2023-01-05 18:46:21 +0530 | [diff] [blame] | 48 | RetCode setErLevel(int level); |
Shraddha Basantwani | dbb0ed6 | 2022-11-17 20:32:18 +0530 | [diff] [blame] | 49 | int getErLevel() const { return mLevel; } |
| 50 | |
Sham Rathod | e362a46 | 2023-01-05 18:46:21 +0530 | [diff] [blame] | 51 | RetCode setErDelay(int delay); |
Shraddha Basantwani | dbb0ed6 | 2022-11-17 20:32:18 +0530 | [diff] [blame] | 52 | int getErDelay() const { return mDelay; } |
| 53 | |
Sham Rathod | e362a46 | 2023-01-05 18:46:21 +0530 | [diff] [blame] | 54 | RetCode setErDiffusion(int diffusion); |
Shraddha Basantwani | dbb0ed6 | 2022-11-17 20:32:18 +0530 | [diff] [blame] | 55 | int getErDiffusion() const { return mDiffusion; } |
| 56 | |
Sham Rathod | e362a46 | 2023-01-05 18:46:21 +0530 | [diff] [blame] | 57 | RetCode setErDensity(int density); |
Shraddha Basantwani | dbb0ed6 | 2022-11-17 20:32:18 +0530 | [diff] [blame] | 58 | 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 Rathod | e362a46 | 2023-01-05 18:46:21 +0530 | [diff] [blame] | 68 | int mRoomLevel = -6000; // Default room level |
| 69 | int mRoomHfLevel = 0; // Default room hf level |
Shraddha Basantwani | dbb0ed6 | 2022-11-17 20:32:18 +0530 | [diff] [blame] | 70 | int mDecayTime = 1000; // Default decay time |
| 71 | int mDecayHfRatio = 500; // Default decay hf ratio |
Sham Rathod | e362a46 | 2023-01-05 18:46:21 +0530 | [diff] [blame] | 72 | int mLevel = -6000; // Default level |
Shraddha Basantwani | dbb0ed6 | 2022-11-17 20:32:18 +0530 | [diff] [blame] | 73 | int mDelay = 40; // Default delay |
Sham Rathod | e362a46 | 2023-01-05 18:46:21 +0530 | [diff] [blame] | 74 | int mDiffusion = 1000; // Default diffusion |
| 75 | int mDensity = 1000; // Default density |
Shraddha Basantwani | dbb0ed6 | 2022-11-17 20:32:18 +0530 | [diff] [blame] | 76 | bool mBypass = false; // Default bypass |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
Shunkai Yao | 812d5b4 | 2022-11-16 18:08:50 +0000 | [diff] [blame] | 79 | class EnvReverbSw final : public EffectImpl { |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 80 | public: |
Shunkai Yao | c12e082 | 2022-12-12 07:13:58 +0000 | [diff] [blame] | 81 | static const std::string kEffectName; |
Shunkai Yao | 8781102 | 2023-02-13 17:40:37 +0000 | [diff] [blame] | 82 | static const Capability kCapability; |
Shunkai Yao | c12e082 | 2022-12-12 07:13:58 +0000 | [diff] [blame] | 83 | static const Descriptor kDescriptor; |
Shunkai Yao | 812d5b4 | 2022-11-16 18:08:50 +0000 | [diff] [blame] | 84 | EnvReverbSw() { LOG(DEBUG) << __func__; } |
| 85 | ~EnvReverbSw() { |
| 86 | cleanUp(); |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 87 | LOG(DEBUG) << __func__; |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 88 | } |
| 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 Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 94 | |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 95 | std::shared_ptr<EffectContext> createContext(const Parameter::Common& common) override; |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 96 | std::shared_ptr<EffectContext> getContext() override; |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 97 | RetCode releaseContext() override; |
| 98 | |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 99 | IEffect::Status effectProcessImpl(float* in, float* out, int samples) override; |
| 100 | std::string getEffectName() override { return kEffectName; } |
| 101 | |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 102 | private: |
Shunkai Yao | 8781102 | 2023-02-13 17:40:37 +0000 | [diff] [blame] | 103 | static const std::vector<Range::EnvironmentalReverbRange> kRanges; |
Shunkai Yao | 812d5b4 | 2022-11-16 18:08:50 +0000 | [diff] [blame] | 104 | std::shared_ptr<EnvReverbSwContext> mContext; |
Shraddha Basantwani | dbb0ed6 | 2022-11-17 20:32:18 +0530 | [diff] [blame] | 105 | ndk::ScopedAStatus getParameterEnvironmentalReverb(const EnvironmentalReverb::Tag& tag, |
| 106 | Parameter::Specific* specific); |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 107 | }; |
| 108 | } // namespace aidl::android::hardware::audio::effect |