1 /* 2 * Copyright (C) 2023 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 <optional> 20 21 #include <aidl/android/hardware/audio/effect/BnEffect.h> 22 23 #include <audio_effects/effect_aec.h> 24 #include <audio_effects/effect_agc.h> 25 #include <audio_effects/effect_agc2.h> 26 #include <audio_effects/effect_ns.h> 27 #include <system/audio_effects/effect_uuid.h> 28 29 #include "effect-impl/EffectTypes.h" 30 31 namespace aidl::android::hardware::audio::effect { 32 33 // Acoustic Echo Cancellation 34 static const std::string kAcousticEchoCancelerEffectName = "Acoustic Echo Canceler"; 35 static const std::vector<Range::AcousticEchoCancelerRange> kAcousticEchoCancelerRanges = { 36 MAKE_RANGE(AcousticEchoCanceler, AcousticEchoCanceler::echoDelayUs, 0, 500)}; 37 static const Capability kAcousticEchoCancelerCap = {.range = kAcousticEchoCancelerRanges}; 38 static const Descriptor kAcousticEchoCancelerDesc = { 39 .common = {.id = {.type = getEffectTypeUuidAcousticEchoCanceler(), 40 .uuid = getEffectImplUuidAcousticEchoCancelerSw(), 41 .proxy = std::nullopt}, 42 .flags = {.type = Flags::Type::PRE_PROC, .deviceIndication = true}, 43 .name = kAcousticEchoCancelerEffectName, 44 .implementor = "The Android Open Source Project"}, 45 .capability = kAcousticEchoCancelerCap}; 46 47 // Automatic Gain Control 1 48 static const std::string kAutomaticGainControlV1EffectName = "Automatic Gain Control V1"; 49 static const std::vector<Range::AutomaticGainControlV1Range> kAutomaticGainControlV1Ranges = { 50 MAKE_RANGE(AutomaticGainControlV1, AutomaticGainControlV1::targetPeakLevelDbFs, -3100, 0), 51 MAKE_RANGE(AutomaticGainControlV1, AutomaticGainControlV1::maxCompressionGainDb, 0, 9000)}; 52 static const Capability kAutomaticGainControlV1Cap = {.range = kAutomaticGainControlV1Ranges}; 53 static const Descriptor kAutomaticGainControlV1Desc = { 54 .common = {.id = {.type = getEffectTypeUuidAutomaticGainControlV1(), 55 .uuid = getEffectImplUuidAutomaticGainControlV1Sw(), 56 .proxy = std::nullopt}, 57 .flags = {.type = Flags::Type::PRE_PROC, .deviceIndication = true}, 58 .name = kAutomaticGainControlV1EffectName, 59 .implementor = "The Android Open Source Project"}, 60 .capability = kAutomaticGainControlV1Cap}; 61 62 // Automatic Gain Control 2 63 static const std::string kAutomaticGainControlV2EffectName = "Automatic Gain Control V2"; 64 const std::vector<Range::AutomaticGainControlV2Range> kAutomaticGainControlV2Ranges = { 65 MAKE_RANGE(AutomaticGainControlV2, AutomaticGainControlV2::fixedDigitalGainMb, 0, 90), 66 // extra_staturation_margin_db is no longer configurable in webrtc 67 MAKE_RANGE(AutomaticGainControlV2, AutomaticGainControlV2::saturationMarginMb, 2, 2), 68 // WebRTC only supports RMS level estimator now 69 MAKE_RANGE(AutomaticGainControlV2, AutomaticGainControlV2::levelEstimator, 70 AutomaticGainControlV2::LevelEstimator::RMS, 71 AutomaticGainControlV2::LevelEstimator::RMS)}; 72 static const Capability kAutomaticGainControlV2Cap = {.range = kAutomaticGainControlV2Ranges}; 73 static const Descriptor kAutomaticGainControlV2Desc = { 74 .common = {.id = {.type = getEffectTypeUuidAutomaticGainControlV2(), 75 .uuid = getEffectImplUuidAutomaticGainControlV2Sw(), 76 .proxy = std::nullopt}, 77 .flags = {.type = Flags::Type::PRE_PROC, .deviceIndication = true}, 78 .name = kAutomaticGainControlV2EffectName, 79 .implementor = "The Android Open Source Project"}, 80 .capability = kAutomaticGainControlV2Cap}; 81 82 // Noise suppression 83 static const std::string kNoiseSuppressionEffectName = "Noise Suppression"; 84 static const Descriptor kNoiseSuppressionDesc = { 85 .common = {.id = {.type = getEffectTypeUuidNoiseSuppression(), 86 .uuid = getEffectImplUuidNoiseSuppressionSw(), 87 .proxy = std::nullopt}, 88 .flags = {.type = Flags::Type::PRE_PROC, .deviceIndication = true}, 89 .name = kNoiseSuppressionEffectName, 90 .implementor = "The Android Open Source Project"}}; 91 92 enum class PreProcessingEffectType { 93 ACOUSTIC_ECHO_CANCELLATION, 94 AUTOMATIC_GAIN_CONTROL_V1, 95 AUTOMATIC_GAIN_CONTROL_V2, 96 NOISE_SUPPRESSION, 97 }; 98 99 inline std::ostream& operator<<(std::ostream& out, const PreProcessingEffectType& type) { 100 switch (type) { 101 case PreProcessingEffectType::ACOUSTIC_ECHO_CANCELLATION: 102 return out << kAcousticEchoCancelerEffectName; 103 case PreProcessingEffectType::AUTOMATIC_GAIN_CONTROL_V1: 104 return out << kAutomaticGainControlV1EffectName; 105 case PreProcessingEffectType::AUTOMATIC_GAIN_CONTROL_V2: 106 return out << kAutomaticGainControlV2EffectName; 107 case PreProcessingEffectType::NOISE_SUPPRESSION: 108 return out << kNoiseSuppressionEffectName; 109 } 110 return out << "EnumPreProcessingEffectTypeError"; 111 } 112 113 } // namespace aidl::android::hardware::audio::effect 114