• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 constexpr int32_t HDI_SET_PATAM = 6;
41 constexpr int32_t HDI_INIT = 0;
42 constexpr int32_t HDI_BYPASS = 1;
43 constexpr int32_t HDI_HEAD_MODE = 2;
44 constexpr int32_t HDI_ROOM_MODE = 3;
45 constexpr int32_t HDI_BLUETOOTH_MODE = 4;
46 constexpr int32_t HDI_DESTROY = 5;
47 
48 enum AudioSpatialDeviceType {
49     EARPHONE_TYPE_NONE = 0,
50     EARPHONE_TYPE_INEAR,
51     EARPHONE_TYPE_HALF_INEAR,
52     EARPHONE_TYPE_HEADPHONE,
53     EARPHONE_TYPE_GLASSES,
54     EARPHONE_TYPE_OTHERS,
55 };
56 
57 struct AudioSpatialDeviceState {
58     std::string address;
59     bool isSpatializationSupported;
60     bool isHeadTrackingSupported;
61     AudioSpatialDeviceType spatialDeviceType;
62 };
63 
64 struct Library {
65     std::string name;
66     std::string path;
67 };
68 
69 struct Effect {
70     std::string name;
71     std::string libraryName;
72 };
73 
74 struct EffectChain {
75     std::string name;
76     std::vector<std::string> apply;
77     std::string label = "";
78 };
79 
80 struct Device {
81     std::string type;
82     std::string chain;
83 };
84 
85 struct Preprocess {
86     std::string stream;
87     std::vector<std::string> mode;
88     std::vector<std::vector<Device>> device;
89 };
90 
91 struct Postprocess {
92     std::string stream;
93     std::vector<std::string> mode;
94     std::vector<std::vector<Device>> device;
95 };
96 
97 struct OriginalEffectConfig {
98     float version;
99     std::vector<Library> libraries;
100     std::vector<Effect> effects;
101     std::vector<EffectChain> effectChains;
102     std::vector<Preprocess> preProcess;
103     std::vector<Postprocess> postProcess;
104 };
105 
106 struct StreamEffectMode {
107     std::string mode;
108     std::vector<Device> devicePort;
109 };
110 
111 struct Stream {
112     std::string scene;
113     std::vector<StreamEffectMode> streamEffectMode;
114 };
115 
116 struct ProcessNew {
117     std::vector<Stream> stream;
118 };
119 
120 struct SupportedEffectConfig {
121     std::vector<EffectChain> effectChains;
122     ProcessNew preProcessNew;
123     ProcessNew postProcessNew;
124 };
125 
126 
127 /**
128 * Enumerates the audio scene effect type.
129 */
130 enum AudioEffectScene {
131     SCENE_OTHERS = 0,
132     SCENE_MUSIC = 1,
133     SCENE_MOVIE = 2,
134     SCENE_GAME = 3,
135     SCENE_SPEECH = 4,
136     SCENE_RING = 5
137 };
138 
139 /**
140 * Enumerates the audio scene effct mode.
141 */
142 enum AudioEffectMode {
143     EFFECT_NONE = 0,
144     EFFECT_DEFAULT = 1
145 };
146 
147 struct AudioSceneEffectInfo {
148     std::vector<AudioEffectMode> mode;
149 };
150 
151 const std::unordered_map<AudioEffectScene, std::string> AUDIO_SUPPORTED_SCENE_TYPES {
152     {SCENE_OTHERS, "SCENE_OTHERS"},
153     {SCENE_MUSIC, "SCENE_MUSIC"},
154     {SCENE_MOVIE, "SCENE_MOVIE"},
155     {SCENE_GAME, "SCENE_GAME"},
156     {SCENE_SPEECH, "SCENE_SPEECH"},
157     {SCENE_RING, "SCENE_RING"}
158 };
159 
160 const std::unordered_map<AudioEffectMode, std::string> AUDIO_SUPPORTED_SCENE_MODES {
161     {EFFECT_NONE, "EFFECT_NONE"},
162     {EFFECT_DEFAULT, "EFFECT_DEFAULT"},
163 };
164 
165 const std::unordered_map<DeviceType, std::string> SUPPORTED_DEVICE_TYPE {
166     {DEVICE_TYPE_NONE, "DEVICE_TYPE_NONE"},
167     {DEVICE_TYPE_INVALID, "DEVICE_TYPE_INVALID"},
168     {DEVICE_TYPE_EARPIECE, "DEVICE_TYPE_EARPIECE"},
169     {DEVICE_TYPE_SPEAKER, "DEVICE_TYPE_SPEAKER"},
170     {DEVICE_TYPE_WIRED_HEADSET, "DEVICE_TYPE_WIRED_HEADSET"},
171     {DEVICE_TYPE_WIRED_HEADPHONES, "DEVICE_TYPE_WIRED_HEADPHONES"},
172     {DEVICE_TYPE_BLUETOOTH_SCO, "DEVICE_TYPE_BLUETOOTH_SCO"},
173     {DEVICE_TYPE_BLUETOOTH_A2DP, "DEVICE_TYPE_BLUETOOTH_A2DP"},
174     {DEVICE_TYPE_MIC, "DEVICE_TYPE_MIC"},
175     {DEVICE_TYPE_WAKEUP, "DEVICE_TYPE_WAKEUP"},
176     {DEVICE_TYPE_USB_HEADSET, "DEVICE_TYPE_USB_HEADSET"},
177     {DEVICE_TYPE_FILE_SINK, "DEVICE_TYPE_FILE_SINK"},
178     {DEVICE_TYPE_FILE_SOURCE, "DEVICE_TYPE_FILE_SOURCE"},
179     {DEVICE_TYPE_EXTERN_CABLE, "DEVICE_TYPE_EXTERN_CABLE"},
180     {DEVICE_TYPE_DEFAULT, "DEVICE_TYPE_DEFAULT"},
181 };
182 
183 enum AudioEffectCommandCode {
184     EFFECT_CMD_INIT = 0,
185     EFFECT_CMD_SET_CONFIG = 1,
186     EFFECT_CMD_ENABLE = 2,
187     EFFECT_CMD_DISABLE = 3,
188     EFFECT_CMD_SET_PARAM = 4,
189     EFFECT_CMD_GET_PARAM = 5,
190     EFFECT_CMD_GET_CONFIG = 6,
191     EFFECT_CMD_SET_IMU = 7
192 };
193 
194 enum AudioEffectParamSetCode {
195     EFFECT_SET_BYPASS = 1,
196     EFFECT_SET_PARAM = 2,
197 };
198 
199 enum AudioDataFormat {
200     DATA_FORMAT_S16 = SAMPLE_S16LE,
201     DATA_FORMAT_S24 = SAMPLE_S24LE,
202     DATA_FORMAT_S32 = SAMPLE_S32LE,
203     DATA_FORMAT_F32 = SAMPLE_F32LE,
204 };
205 
206 struct AudioEffectParam {
207     int32_t status;
208     uint32_t paramSize;
209     uint32_t valueSize;
210     int32_t data[];
211 };
212 
213 struct AudioBuffer {
214     size_t frameLength;
215     union {
216         void*     raw;
217         float*    f32;
218         int32_t*  s32;
219         int16_t*  s16;
220         uint8_t*  u8;
221     };
222     void *metaData;
223 };
224 
225 struct AudioBufferConfig {
226     uint32_t samplingRate;
227     uint32_t channels;
228     uint8_t format;
229     uint64_t channelLayout;
230     AudioEncodingType encoding;
231 };
232 
233 struct AudioEffectConfig {
234     AudioBufferConfig inputCfg;
235     AudioBufferConfig outputCfg;
236 };
237 
238 struct AudioEffectTransInfo {
239     uint32_t size;
240     void *data;
241 };
242 
243 struct AudioEffectDescriptor {
244     std::string libraryName;
245     std::string effectName;
246 };
247 
248 typedef struct AudioEffectInterface **AudioEffectHandle;
249 
250 struct AudioEffectInterface {
251     int32_t (*process) (AudioEffectHandle self, AudioBuffer *inBuffer, AudioBuffer *outBuffer);
252     int32_t (*command) (AudioEffectHandle self, uint32_t cmdCode,
253         AudioEffectTransInfo *cmdInfo, AudioEffectTransInfo *replyInfo);
254 };
255 
256 struct AudioEffectLibrary {
257     uint32_t version;
258     const char *name;
259     const char *implementor;
260     bool (*checkEffect) (const AudioEffectDescriptor descriptor);
261     int32_t (*createEffect) (const AudioEffectDescriptor descriptor, AudioEffectHandle *handle);
262     int32_t (*releaseEffect) (AudioEffectHandle handle);
263 };
264 
265 struct AudioEffectLibEntry {
266     AudioEffectLibrary *audioEffectLibHandle;
267     std::string libraryName;
268     std::vector<std::string> effectName;
269 };
270 
271 struct AudioSpatializationState {
272     bool spatializationEnabled;
273     bool headTrackingEnabled;
274 };
275 
276 } // namespace AudioStandard
277 } // namespace OHOS
278 
279 #endif //AUDIO_FRAMEWORK_AUDIO_EFFECT_H