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 | f6a5027 | 2022-11-17 20:32:18 +0530 | [diff] [blame^] | 35 | |
| 36 | RetCode setErRoomLevel(int roomLevel) { |
| 37 | if (roomLevel < EnvironmentalReverb::MIN_ROOM_LEVEL_MB || |
| 38 | roomLevel > EnvironmentalReverb::MAX_ROOM_LEVEL_MB) { |
| 39 | LOG(ERROR) << __func__ << " invalid roomLevel: " << roomLevel; |
| 40 | return RetCode::ERROR_ILLEGAL_PARAMETER; |
| 41 | } |
| 42 | // TODO : Add implementation to apply new room level |
| 43 | mRoomLevel = roomLevel; |
| 44 | return RetCode::SUCCESS; |
| 45 | } |
| 46 | int getErRoomLevel() const { return mRoomLevel; } |
| 47 | |
| 48 | RetCode setErRoomHfLevel(int roomHfLevel) { |
| 49 | if (roomHfLevel < EnvironmentalReverb::MIN_ROOM_HF_LEVEL_MB || |
| 50 | roomHfLevel > EnvironmentalReverb::MAX_ROOM_HF_LEVEL_MB) { |
| 51 | LOG(ERROR) << __func__ << " invalid roomHfLevel: " << roomHfLevel; |
| 52 | return RetCode::ERROR_ILLEGAL_PARAMETER; |
| 53 | } |
| 54 | // TODO : Add implementation to apply new room HF level |
| 55 | mRoomHfLevel = roomHfLevel; |
| 56 | return RetCode::SUCCESS; |
| 57 | } |
| 58 | int getErRoomHfLevel() const { return mRoomHfLevel; } |
| 59 | |
| 60 | RetCode setErDecayTime(int decayTime) { |
| 61 | if (decayTime < EnvironmentalReverb::MIN_DECAY_TIME_MS || |
| 62 | decayTime > EnvironmentalReverb::MAX_DECAY_TIME_MS) { |
| 63 | LOG(ERROR) << __func__ << " invalid decayTime: " << decayTime; |
| 64 | return RetCode::ERROR_ILLEGAL_PARAMETER; |
| 65 | } |
| 66 | // TODO : Add implementation to apply new decay time |
| 67 | mDecayTime = decayTime; |
| 68 | return RetCode::SUCCESS; |
| 69 | } |
| 70 | int getErDecayTime() const { return mDecayTime; } |
| 71 | |
| 72 | RetCode setErDecayHfRatio(int decayHfRatio) { |
| 73 | if (decayHfRatio < EnvironmentalReverb::MIN_DECAY_HF_RATIO_PM || |
| 74 | decayHfRatio > EnvironmentalReverb::MAX_DECAY_HF_RATIO_PM) { |
| 75 | LOG(ERROR) << __func__ << " invalid decayHfRatio: " << decayHfRatio; |
| 76 | return RetCode::ERROR_ILLEGAL_PARAMETER; |
| 77 | } |
| 78 | // TODO : Add implementation to apply new decay HF ratio |
| 79 | mDecayHfRatio = decayHfRatio; |
| 80 | return RetCode::SUCCESS; |
| 81 | } |
| 82 | int getErDecayHfRatio() const { return mDecayHfRatio; } |
| 83 | |
| 84 | RetCode setErLevel(int level) { |
| 85 | if (level < EnvironmentalReverb::MIN_LEVEL_MB || |
| 86 | level > EnvironmentalReverb::MAX_LEVEL_MB) { |
| 87 | LOG(ERROR) << __func__ << " invalid level: " << level; |
| 88 | return RetCode::ERROR_ILLEGAL_PARAMETER; |
| 89 | } |
| 90 | // TODO : Add implementation to apply new level |
| 91 | mLevel = level; |
| 92 | return RetCode::SUCCESS; |
| 93 | } |
| 94 | int getErLevel() const { return mLevel; } |
| 95 | |
| 96 | RetCode setErDelay(int delay) { |
| 97 | if (delay < EnvironmentalReverb::MIN_DELAY_MS || |
| 98 | delay > EnvironmentalReverb::MAX_DELAY_MS) { |
| 99 | LOG(ERROR) << __func__ << " invalid delay: " << delay; |
| 100 | return RetCode::ERROR_ILLEGAL_PARAMETER; |
| 101 | } |
| 102 | // TODO : Add implementation to apply new delay |
| 103 | mDelay = delay; |
| 104 | return RetCode::SUCCESS; |
| 105 | } |
| 106 | int getErDelay() const { return mDelay; } |
| 107 | |
| 108 | RetCode setErDiffusion(int diffusion) { |
| 109 | if (diffusion < EnvironmentalReverb::MIN_DIFFUSION_PM || |
| 110 | diffusion > EnvironmentalReverb::MAX_DIFFUSION_PM) { |
| 111 | LOG(ERROR) << __func__ << " invalid diffusion: " << diffusion; |
| 112 | return RetCode::ERROR_ILLEGAL_PARAMETER; |
| 113 | } |
| 114 | // TODO : Add implementation to apply new diffusion |
| 115 | mDiffusion = diffusion; |
| 116 | return RetCode::SUCCESS; |
| 117 | } |
| 118 | int getErDiffusion() const { return mDiffusion; } |
| 119 | |
| 120 | RetCode setErDensity(int density) { |
| 121 | if (density < EnvironmentalReverb::MIN_DENSITY_PM || |
| 122 | density > EnvironmentalReverb::MAX_DENSITY_PM) { |
| 123 | LOG(ERROR) << __func__ << " invalid density: " << density; |
| 124 | return RetCode::ERROR_ILLEGAL_PARAMETER; |
| 125 | } |
| 126 | // TODO : Add implementation to apply new density |
| 127 | mDensity = density; |
| 128 | return RetCode::SUCCESS; |
| 129 | } |
| 130 | int getErDensity() const { return mDensity; } |
| 131 | |
| 132 | RetCode setErBypass(bool bypass) { |
| 133 | // TODO : Add implementation to apply new bypass |
| 134 | mBypass = bypass; |
| 135 | return RetCode::SUCCESS; |
| 136 | } |
| 137 | bool getErBypass() const { return mBypass; } |
| 138 | |
| 139 | private: |
| 140 | int mRoomLevel = EnvironmentalReverb::MIN_ROOM_LEVEL_MB; // Default room level |
| 141 | int mRoomHfLevel = EnvironmentalReverb::MAX_ROOM_HF_LEVEL_MB; // Default room hf level |
| 142 | int mDecayTime = 1000; // Default decay time |
| 143 | int mDecayHfRatio = 500; // Default decay hf ratio |
| 144 | int mLevel = EnvironmentalReverb::MIN_LEVEL_MB; // Default level |
| 145 | int mDelay = 40; // Default delay |
| 146 | int mDiffusion = EnvironmentalReverb::MAX_DIFFUSION_PM; // Default diffusion |
| 147 | int mDensity = EnvironmentalReverb::MAX_DENSITY_PM; // Default density |
| 148 | bool mBypass = false; // Default bypass |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 149 | }; |
| 150 | |
Shunkai Yao | 812d5b4 | 2022-11-16 18:08:50 +0000 | [diff] [blame] | 151 | class EnvReverbSw final : public EffectImpl { |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 152 | public: |
Shunkai Yao | c12e082 | 2022-12-12 07:13:58 +0000 | [diff] [blame] | 153 | static const std::string kEffectName; |
| 154 | static const EnvironmentalReverb::Capability kCapability; |
| 155 | static const Descriptor kDescriptor; |
Shunkai Yao | 812d5b4 | 2022-11-16 18:08:50 +0000 | [diff] [blame] | 156 | EnvReverbSw() { LOG(DEBUG) << __func__; } |
| 157 | ~EnvReverbSw() { |
| 158 | cleanUp(); |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 159 | LOG(DEBUG) << __func__; |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override; |
| 163 | ndk::ScopedAStatus setParameterSpecific(const Parameter::Specific& specific) override; |
| 164 | ndk::ScopedAStatus getParameterSpecific(const Parameter::Id& id, |
| 165 | Parameter::Specific* specific) override; |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 166 | |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 167 | std::shared_ptr<EffectContext> createContext(const Parameter::Common& common) override; |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 168 | std::shared_ptr<EffectContext> getContext() override; |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 169 | RetCode releaseContext() override; |
| 170 | |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 171 | IEffect::Status effectProcessImpl(float* in, float* out, int samples) override; |
| 172 | std::string getEffectName() override { return kEffectName; } |
| 173 | |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 174 | private: |
Shunkai Yao | 812d5b4 | 2022-11-16 18:08:50 +0000 | [diff] [blame] | 175 | std::shared_ptr<EnvReverbSwContext> mContext; |
Shraddha Basantwani | f6a5027 | 2022-11-17 20:32:18 +0530 | [diff] [blame^] | 176 | ndk::ScopedAStatus getParameterEnvironmentalReverb(const EnvironmentalReverb::Tag& tag, |
| 177 | Parameter::Specific* specific); |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 178 | }; |
| 179 | } // namespace aidl::android::hardware::audio::effect |