1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef AUDIO_FRAMEWORK_AUDIO_EFFECT_H 17 #define AUDIO_FRAMEWORK_AUDIO_EFFECT_H 18 19 #include <cassert> 20 #include <cstdint> 21 #include <stddef.h> 22 #include <map> 23 #include <memory> 24 #include <string> 25 #include <vector> 26 #include "audio_info.h" 27 28 #define AUDIO_EFFECT_LIBRARY_INFO_SYM_AS_STR "AELI" 29 #define EFFECT_STRING_LEN_MAX 64 30 31 namespace OHOS { 32 namespace AudioStandard { 33 // audio effect manager info 34 constexpr int32_t AUDIO_EFFECT_COUNT_UPPER_LIMIT = 20; 35 constexpr int32_t AUDIO_EFFECT_COUNT_FIRST_NODE_UPPER_LIMIT = 1; 36 constexpr int32_t AUDIO_EFFECT_CHAIN_CONFIG_UPPER_LIMIT = 64; // max conf for sceneType + effectMode + deviceType 37 constexpr int32_t AUDIO_EFFECT_CHAIN_COUNT_UPPER_LIMIT = 32; // max num of effectChain 38 constexpr int32_t AUDIO_EFFECT_COUNT_PER_CHAIN_UPPER_LIMIT = 16; // max num of effect per effectChain 39 40 struct Library { 41 std::string name; 42 std::string path; 43 }; 44 45 struct Effect { 46 std::string name; 47 std::string libraryName; 48 }; 49 50 struct EffectChain { 51 std::string name; 52 std::vector<std::string> apply; 53 }; 54 55 struct Device { 56 std::string type; 57 std::string chain; 58 }; 59 60 struct Preprocess { 61 std::string stream; 62 std::vector<std::string> mode; 63 std::vector<std::vector<Device>> device; 64 }; 65 66 struct Postprocess { 67 std::string stream; 68 std::vector<std::string> mode; 69 std::vector<std::vector<Device>> device; 70 }; 71 72 struct OriginalEffectConfig { 73 float version; 74 std::vector<Library> libraries; 75 std::vector<Effect> effects; 76 std::vector<EffectChain> effectChains; 77 std::vector<Preprocess> preProcess; 78 std::vector<Postprocess> postProcess; 79 }; 80 81 struct StreamEffectMode { 82 std::string mode; 83 std::vector<Device> devicePort; 84 }; 85 86 struct Stream { 87 std::string scene; 88 std::vector<StreamEffectMode> streamEffectMode; 89 }; 90 91 struct ProcessNew { 92 std::vector<Stream> stream; 93 }; 94 95 struct SupportedEffectConfig { 96 std::vector<EffectChain> effectChains; 97 ProcessNew preProcessNew; 98 ProcessNew postProcessNew; 99 }; 100 101 102 /** 103 * Enumerates the audio scene effect type. 104 */ 105 enum AudioEffectScene { 106 SCENE_OTHERS = 0, 107 SCENE_MUSIC = 1, 108 SCENE_MOVIE = 2, 109 SCENE_GAME = 3, 110 SCENE_SPEECH = 4, 111 SCENE_RING = 5 112 }; 113 114 /** 115 * Enumerates the audio scene effct mode. 116 */ 117 enum AudioEffectMode { 118 EFFECT_NONE = 0, 119 EFFECT_DEFAULT = 1 120 }; 121 122 struct AudioSceneEffectInfo { 123 std::vector<AudioEffectMode> mode; 124 }; 125 126 const std::unordered_map<AudioEffectScene, std::string> AUDIO_SUPPORTED_SCENE_TYPES { 127 {SCENE_OTHERS, "SCENE_OTHERS"}, 128 {SCENE_MUSIC, "SCENE_MUSIC"}, 129 {SCENE_MOVIE, "SCENE_MOVIE"}, 130 {SCENE_GAME, "SCENE_GAME"}, 131 {SCENE_SPEECH, "SCENE_SPEECH"}, 132 {SCENE_RING, "SCENE_RING"} 133 }; 134 135 const std::unordered_map<AudioEffectMode, std::string> AUDIO_SUPPORTED_SCENE_MODES { 136 {EFFECT_NONE, "EFFECT_NONE"}, 137 {EFFECT_DEFAULT, "EFFECT_DEFAULT"}, 138 }; 139 140 const std::unordered_map<DeviceType, std::string> SUPPORTED_DEVICE_TYPE { 141 {DEVICE_TYPE_NONE, "DEVICE_TYPE_NONE"}, 142 {DEVICE_TYPE_INVALID, "DEVICE_TYPE_INVALID"}, 143 {DEVICE_TYPE_EARPIECE, "DEVICE_TYPE_EARPIECE"}, 144 {DEVICE_TYPE_SPEAKER, "DEVICE_TYPE_SPEAKER"}, 145 {DEVICE_TYPE_WIRED_HEADSET, "DEVICE_TYPE_WIRED_HEADSET"}, 146 {DEVICE_TYPE_WIRED_HEADPHONES, "DEVICE_TYPE_WIRED_HEADPHONES"}, 147 {DEVICE_TYPE_BLUETOOTH_SCO, "DEVICE_TYPE_BLUETOOTH_SCO"}, 148 {DEVICE_TYPE_BLUETOOTH_A2DP, "DEVICE_TYPE_BLUETOOTH_A2DP"}, 149 {DEVICE_TYPE_MIC, "DEVICE_TYPE_MIC"}, 150 {DEVICE_TYPE_WAKEUP, "DEVICE_TYPE_WAKEUP"}, 151 {DEVICE_TYPE_USB_HEADSET, "DEVICE_TYPE_USB_HEADSET"}, 152 {DEVICE_TYPE_FILE_SINK, "DEVICE_TYPE_FILE_SINK"}, 153 {DEVICE_TYPE_FILE_SOURCE, "DEVICE_TYPE_FILE_SOURCE"}, 154 {DEVICE_TYPE_EXTERN_CABLE, "DEVICE_TYPE_EXTERN_CABLE"}, 155 {DEVICE_TYPE_DEFAULT, "DEVICE_TYPE_DEFAULT"}, 156 }; 157 158 enum AudioEffectCommandCode { 159 EFFECT_CMD_INIT = 0, 160 EFFECT_CMD_SET_CONFIG = 1, 161 EFFECT_CMD_ENABLE = 2, 162 EFFECT_CMD_DISABLE = 3, 163 EFFECT_CMD_SET_PARAM = 4, 164 EFFECT_CMD_GET_PARAM = 5, 165 EFFECT_CMD_GET_CONFIG = 6, 166 }; 167 168 enum AudioEffectParamSetCode { 169 EFFECT_SET_BYPASS = 1, 170 EFFECT_SET_PARAM = 2, 171 }; 172 173 enum AudioDataFormat { 174 DATA_FORMAT_S16 = SAMPLE_S16LE, 175 DATA_FORMAT_S24 = SAMPLE_S24LE, 176 DATA_FORMAT_S32 = SAMPLE_S32LE, 177 DATA_FORMAT_F32 = SAMPLE_F32LE, 178 }; 179 180 struct AudioEffectParam { 181 int32_t status; 182 uint32_t paramSize; 183 uint32_t valueSize; 184 int32_t data[]; 185 }; 186 187 struct AudioBuffer { 188 size_t frameLength; 189 union { 190 void* raw; 191 float* f32; 192 int32_t* s32; 193 int16_t* s16; 194 uint8_t* u8; 195 }; 196 }; 197 198 struct AudioBufferConfig { 199 uint32_t samplingRate; 200 uint32_t channels; 201 uint8_t format; 202 }; 203 204 struct AudioEffectConfig { 205 AudioBufferConfig inputCfg; 206 AudioBufferConfig outputCfg; 207 }; 208 209 struct AudioEffectTransInfo { 210 uint32_t size; 211 void *data; 212 }; 213 214 struct AudioEffectDescriptor { 215 std::string libraryName; 216 std::string effectName; 217 }; 218 219 typedef struct AudioEffectInterface **AudioEffectHandle; 220 221 struct AudioEffectInterface { 222 int32_t (*process) (AudioEffectHandle self, AudioBuffer *inBuffer, AudioBuffer *outBuffer); 223 int32_t (*command) (AudioEffectHandle self, uint32_t cmdCode, 224 AudioEffectTransInfo *cmdInfo, AudioEffectTransInfo *replyInfo); 225 }; 226 227 struct AudioEffectLibrary { 228 uint32_t version; 229 const char *name; 230 const char *implementor; 231 bool (*checkEffect) (const AudioEffectDescriptor descriptor); 232 int32_t (*createEffect) (const AudioEffectDescriptor descriptor, AudioEffectHandle *handle); 233 int32_t (*releaseEffect) (AudioEffectHandle handle); 234 }; 235 236 struct AudioEffectLibEntry { 237 AudioEffectLibrary *audioEffectLibHandle; 238 std::string libraryName; 239 std::vector<std::string> effectName; 240 }; 241 242 } // namespace AudioStandard 243 } // namespace OHOS 244 245 #endif //AUDIO_FRAMEWORK_AUDIO_EFFECT_H