1 /* 2 * Copyright (C) 2016 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 18 #ifndef ANDROID_AUDIO_EFFECT_CORE_H 19 #define ANDROID_AUDIO_EFFECT_CORE_H 20 21 #include "audio.h" 22 #include "audio_effect-base.h" 23 24 __BEGIN_DECLS 25 26 ///////////////////////////////////////////////// 27 // Common Definitions 28 ///////////////////////////////////////////////// 29 30 // 31 //--- Effect descriptor structure effect_descriptor_t 32 // 33 34 // This format is used for both "type" and "uuid" fields of the effect descriptor structure. 35 // - When used for effect type and the engine is implementing and effect corresponding to a standard 36 // OpenSL ES interface, this ID must be the one defined in OpenSLES_IID.h for that interface. 37 // - When used as uuid, it should be a unique UUID for this particular implementation. 38 typedef audio_uuid_t effect_uuid_t; 39 40 // Maximum length of character strings in structures defines by this API. 41 #define EFFECT_STRING_LEN_MAX 64 42 43 // NULL UUID definition (matches SL_IID_NULL_) 44 #define EFFECT_UUID_INITIALIZER { 0xec7178ec, 0xe5e1, 0x4432, 0xa3f4, \ 45 { 0x46, 0x57, 0xe6, 0x79, 0x52, 0x10 } } 46 static const effect_uuid_t EFFECT_UUID_NULL_ = EFFECT_UUID_INITIALIZER; 47 static const effect_uuid_t * const EFFECT_UUID_NULL = &EFFECT_UUID_NULL_; 48 static const char * const EFFECT_UUID_NULL_STR = "ec7178ec-e5e1-4432-a3f4-4657e6795210"; 49 50 // The effect descriptor contains necessary information to facilitate the enumeration of the effect 51 // engines present in a library. 52 typedef struct effect_descriptor_s { 53 effect_uuid_t type; // UUID of to the OpenSL ES interface implemented by this effect 54 effect_uuid_t uuid; // UUID for this particular implementation 55 uint32_t apiVersion; // Version of the effect control API implemented 56 uint32_t flags; // effect engine capabilities/requirements flags (see below) 57 uint16_t cpuLoad; // CPU load indication (see below) 58 uint16_t memoryUsage; // Data Memory usage (see below) 59 char name[EFFECT_STRING_LEN_MAX]; // human readable effect name 60 char implementor[EFFECT_STRING_LEN_MAX]; // human readable effect implementor name 61 } effect_descriptor_t; 62 63 ///////////////////////////////////////////////// 64 // Effect control interface 65 ///////////////////////////////////////////////// 66 67 // 68 //--- Standardized command codes for command() function 69 // 70 enum effect_command_e { 71 EFFECT_CMD_INIT, // initialize effect engine 72 EFFECT_CMD_SET_CONFIG, // configure effect engine (see effect_config_t) 73 EFFECT_CMD_RESET, // reset effect engine 74 EFFECT_CMD_ENABLE, // enable effect process 75 EFFECT_CMD_DISABLE, // disable effect process 76 EFFECT_CMD_SET_PARAM, // set parameter immediately (see effect_param_t) 77 EFFECT_CMD_SET_PARAM_DEFERRED, // set parameter deferred 78 EFFECT_CMD_SET_PARAM_COMMIT, // commit previous set parameter deferred 79 EFFECT_CMD_GET_PARAM, // get parameter 80 EFFECT_CMD_SET_DEVICE, // set audio device (see audio.h, audio_devices_t) 81 EFFECT_CMD_SET_VOLUME, // set volume 82 EFFECT_CMD_SET_AUDIO_MODE, // set the audio mode (normal, ring, ...) 83 EFFECT_CMD_SET_CONFIG_REVERSE, // configure effect engine reverse stream(see effect_config_t) 84 EFFECT_CMD_SET_INPUT_DEVICE, // set capture device (see audio.h, audio_devices_t) 85 EFFECT_CMD_GET_CONFIG, // read effect engine configuration 86 EFFECT_CMD_GET_CONFIG_REVERSE, // read configure effect engine reverse stream configuration 87 EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS,// get all supported configurations for a feature. 88 EFFECT_CMD_GET_FEATURE_CONFIG, // get current feature configuration 89 EFFECT_CMD_SET_FEATURE_CONFIG, // set current feature configuration 90 EFFECT_CMD_SET_AUDIO_SOURCE, // set the audio source (see audio.h, audio_source_t) 91 EFFECT_CMD_OFFLOAD, // set if effect thread is an offload one, 92 // send the ioHandle of the effect thread 93 EFFECT_CMD_DUMP, // dump effect current state, for debugging 94 EFFECT_CMD_FIRST_PROPRIETARY = 0x10000 // first proprietary command code 95 }; 96 97 //================================================================================================== 98 // command: EFFECT_CMD_INIT 99 //-------------------------------------------------------------------------------------------------- 100 // description: 101 // Initialize effect engine: All configurations return to default 102 //-------------------------------------------------------------------------------------------------- 103 // command format: 104 // size: 0 105 // data: N/A 106 //-------------------------------------------------------------------------------------------------- 107 // reply format: 108 // size: sizeof(int) 109 // data: status 110 //================================================================================================== 111 // command: EFFECT_CMD_SET_CONFIG 112 //-------------------------------------------------------------------------------------------------- 113 // description: 114 // Apply new audio parameters configurations for input and output buffers 115 //-------------------------------------------------------------------------------------------------- 116 // command format: 117 // size: sizeof(effect_config_t) 118 // data: effect_config_t 119 //-------------------------------------------------------------------------------------------------- 120 // reply format: 121 // size: sizeof(int) 122 // data: status 123 //================================================================================================== 124 // command: EFFECT_CMD_RESET 125 //-------------------------------------------------------------------------------------------------- 126 // description: 127 // Reset the effect engine. Keep configuration but resets state and buffer content 128 //-------------------------------------------------------------------------------------------------- 129 // command format: 130 // size: 0 131 // data: N/A 132 //-------------------------------------------------------------------------------------------------- 133 // reply format: 134 // size: 0 135 // data: N/A 136 //================================================================================================== 137 // command: EFFECT_CMD_ENABLE 138 //-------------------------------------------------------------------------------------------------- 139 // description: 140 // Enable the process. Called by the framework before the first call to process() 141 //-------------------------------------------------------------------------------------------------- 142 // command format: 143 // size: 0 144 // data: N/A 145 //-------------------------------------------------------------------------------------------------- 146 // reply format: 147 // size: sizeof(int) 148 // data: status 149 //================================================================================================== 150 // command: EFFECT_CMD_DISABLE 151 //-------------------------------------------------------------------------------------------------- 152 // description: 153 // Disable the process. Called by the framework after the last call to process() 154 //-------------------------------------------------------------------------------------------------- 155 // command format: 156 // size: 0 157 // data: N/A 158 //-------------------------------------------------------------------------------------------------- 159 // reply format: 160 // size: sizeof(int) 161 // data: status 162 //================================================================================================== 163 // command: EFFECT_CMD_SET_PARAM 164 //-------------------------------------------------------------------------------------------------- 165 // description: 166 // Set a parameter and apply it immediately 167 //-------------------------------------------------------------------------------------------------- 168 // command format: 169 // size: sizeof(effect_param_t) + size of param and value 170 // data: effect_param_t + param + value. See effect_param_t definition below for value offset 171 //-------------------------------------------------------------------------------------------------- 172 // reply format: 173 // size: sizeof(int) 174 // data: status 175 //================================================================================================== 176 // command: EFFECT_CMD_SET_PARAM_DEFERRED 177 //-------------------------------------------------------------------------------------------------- 178 // description: 179 // Set a parameter but apply it only when receiving EFFECT_CMD_SET_PARAM_COMMIT command 180 //-------------------------------------------------------------------------------------------------- 181 // command format: 182 // size: sizeof(effect_param_t) + size of param and value 183 // data: effect_param_t + param + value. See effect_param_t definition below for value offset 184 //-------------------------------------------------------------------------------------------------- 185 // reply format: 186 // size: 0 187 // data: N/A 188 //================================================================================================== 189 // command: EFFECT_CMD_SET_PARAM_COMMIT 190 //-------------------------------------------------------------------------------------------------- 191 // description: 192 // Apply all previously received EFFECT_CMD_SET_PARAM_DEFERRED commands 193 //-------------------------------------------------------------------------------------------------- 194 // command format: 195 // size: 0 196 // data: N/A 197 //-------------------------------------------------------------------------------------------------- 198 // reply format: 199 // size: sizeof(int) 200 // data: status 201 //================================================================================================== 202 // command: EFFECT_CMD_GET_PARAM 203 //-------------------------------------------------------------------------------------------------- 204 // description: 205 // Get a parameter value 206 //-------------------------------------------------------------------------------------------------- 207 // command format: 208 // size: sizeof(effect_param_t) + size of param 209 // data: effect_param_t + param 210 //-------------------------------------------------------------------------------------------------- 211 // reply format: 212 // size: sizeof(effect_param_t) + size of param and value 213 // data: effect_param_t + param + value. See effect_param_t definition below for value offset 214 //================================================================================================== 215 // command: EFFECT_CMD_SET_DEVICE 216 //-------------------------------------------------------------------------------------------------- 217 // description: 218 // Set the rendering device the audio output path is connected to. See audio.h, audio_devices_t 219 // for device values. 220 // The effect implementation must set EFFECT_FLAG_DEVICE_IND flag in its descriptor to receive this 221 // command when the device changes 222 //-------------------------------------------------------------------------------------------------- 223 // command format: 224 // size: sizeof(uint32_t) 225 // data: uint32_t 226 //-------------------------------------------------------------------------------------------------- 227 // reply format: 228 // size: 0 229 // data: N/A 230 //================================================================================================== 231 // command: EFFECT_CMD_SET_VOLUME 232 //-------------------------------------------------------------------------------------------------- 233 // description: 234 // Set and get volume. Used by audio framework to delegate volume control to effect engine. 235 // The effect implementation must set EFFECT_FLAG_VOLUME_IND or EFFECT_FLAG_VOLUME_CTRL flag in 236 // its descriptor to receive this command before every call to process() function 237 // If EFFECT_FLAG_VOLUME_CTRL flag is set in the effect descriptor, the effect engine must return 238 // the volume that should be applied before the effect is processed. The overall volume (the volume 239 // actually applied by the effect engine multiplied by the returned value) should match the value 240 // indicated in the command. 241 //-------------------------------------------------------------------------------------------------- 242 // command format: 243 // size: n * sizeof(uint32_t) 244 // data: volume for each channel defined in effect_config_t for output buffer expressed in 245 // 8.24 fixed point format 246 //-------------------------------------------------------------------------------------------------- 247 // reply format: 248 // size: n * sizeof(uint32_t) / 0 249 // data: - if EFFECT_FLAG_VOLUME_CTRL is set in effect descriptor: 250 // volume for each channel defined in effect_config_t for output buffer expressed in 251 // 8.24 fixed point format 252 // - if EFFECT_FLAG_VOLUME_CTRL is not set in effect descriptor: 253 // N/A 254 // It is legal to receive a null pointer as pReplyData in which case the effect framework has 255 // delegated volume control to another effect 256 //================================================================================================== 257 // command: EFFECT_CMD_SET_AUDIO_MODE 258 //-------------------------------------------------------------------------------------------------- 259 // description: 260 // Set the audio mode. The effect implementation must set EFFECT_FLAG_AUDIO_MODE_IND flag in its 261 // descriptor to receive this command when the audio mode changes. 262 //-------------------------------------------------------------------------------------------------- 263 // command format: 264 // size: sizeof(uint32_t) 265 // data: audio_mode_t 266 //-------------------------------------------------------------------------------------------------- 267 // reply format: 268 // size: 0 269 // data: N/A 270 //================================================================================================== 271 // command: EFFECT_CMD_SET_CONFIG_REVERSE 272 //-------------------------------------------------------------------------------------------------- 273 // description: 274 // Apply new audio parameters configurations for input and output buffers of reverse stream. 275 // An example of reverse stream is the echo reference supplied to an Acoustic Echo Canceler. 276 //-------------------------------------------------------------------------------------------------- 277 // command format: 278 // size: sizeof(effect_config_t) 279 // data: effect_config_t 280 //-------------------------------------------------------------------------------------------------- 281 // reply format: 282 // size: sizeof(int) 283 // data: status 284 //================================================================================================== 285 // command: EFFECT_CMD_SET_INPUT_DEVICE 286 //-------------------------------------------------------------------------------------------------- 287 // description: 288 // Set the capture device the audio input path is connected to. See audio.h, audio_devices_t 289 // for device values. 290 // The effect implementation must set EFFECT_FLAG_DEVICE_IND flag in its descriptor to receive this 291 // command when the device changes 292 //-------------------------------------------------------------------------------------------------- 293 // command format: 294 // size: sizeof(uint32_t) 295 // data: uint32_t 296 //-------------------------------------------------------------------------------------------------- 297 // reply format: 298 // size: 0 299 // data: N/A 300 //================================================================================================== 301 // command: EFFECT_CMD_GET_CONFIG 302 //-------------------------------------------------------------------------------------------------- 303 // description: 304 // Read audio parameters configurations for input and output buffers 305 //-------------------------------------------------------------------------------------------------- 306 // command format: 307 // size: 0 308 // data: N/A 309 //-------------------------------------------------------------------------------------------------- 310 // reply format: 311 // size: sizeof(effect_config_t) 312 // data: effect_config_t 313 //================================================================================================== 314 // command: EFFECT_CMD_GET_CONFIG_REVERSE 315 //-------------------------------------------------------------------------------------------------- 316 // description: 317 // Read audio parameters configurations for input and output buffers of reverse stream 318 //-------------------------------------------------------------------------------------------------- 319 // command format: 320 // size: 0 321 // data: N/A 322 //-------------------------------------------------------------------------------------------------- 323 // reply format: 324 // size: sizeof(effect_config_t) 325 // data: effect_config_t 326 //================================================================================================== 327 // command: EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS 328 //-------------------------------------------------------------------------------------------------- 329 // description: 330 // Queries for supported configurations for a particular feature (e.g. get the supported 331 // combinations of main and auxiliary channels for a noise suppressor). 332 // The command parameter is the feature identifier (See effect_feature_e for a list of defined 333 // features) followed by the maximum number of configuration descriptor to return. 334 // The reply is composed of: 335 // - status (uint32_t): 336 // - 0 if feature is supported 337 // - -ENOSYS if the feature is not supported, 338 // - -ENOMEM if the feature is supported but the total number of supported configurations 339 // exceeds the maximum number indicated by the caller. 340 // - total number of supported configurations (uint32_t) 341 // - an array of configuration descriptors. 342 // The actual number of descriptors returned must not exceed the maximum number indicated by 343 // the caller. 344 //-------------------------------------------------------------------------------------------------- 345 // command format: 346 // size: 2 x sizeof(uint32_t) 347 // data: effect_feature_e + maximum number of configurations to return 348 //-------------------------------------------------------------------------------------------------- 349 // reply format: 350 // size: 2 x sizeof(uint32_t) + n x sizeof (<config descriptor>) 351 // data: status + total number of configurations supported + array of n config descriptors 352 //================================================================================================== 353 // command: EFFECT_CMD_GET_FEATURE_CONFIG 354 //-------------------------------------------------------------------------------------------------- 355 // description: 356 // Retrieves current configuration for a given feature. 357 // The reply status is: 358 // - 0 if feature is supported 359 // - -ENOSYS if the feature is not supported, 360 //-------------------------------------------------------------------------------------------------- 361 // command format: 362 // size: sizeof(uint32_t) 363 // data: effect_feature_e 364 //-------------------------------------------------------------------------------------------------- 365 // reply format: 366 // size: sizeof(uint32_t) + sizeof (<config descriptor>) 367 // data: status + config descriptor 368 //================================================================================================== 369 // command: EFFECT_CMD_SET_FEATURE_CONFIG 370 //-------------------------------------------------------------------------------------------------- 371 // description: 372 // Sets current configuration for a given feature. 373 // The reply status is: 374 // - 0 if feature is supported 375 // - -ENOSYS if the feature is not supported, 376 // - -EINVAL if the configuration is invalid 377 //-------------------------------------------------------------------------------------------------- 378 // command format: 379 // size: sizeof(uint32_t) + sizeof (<config descriptor>) 380 // data: effect_feature_e + config descriptor 381 //-------------------------------------------------------------------------------------------------- 382 // reply format: 383 // size: sizeof(uint32_t) 384 // data: status 385 //================================================================================================== 386 // command: EFFECT_CMD_SET_AUDIO_SOURCE 387 //-------------------------------------------------------------------------------------------------- 388 // description: 389 // Set the audio source the capture path is configured for (Camcorder, voice recognition...). 390 // See audio.h, audio_source_t for values. 391 //-------------------------------------------------------------------------------------------------- 392 // command format: 393 // size: sizeof(uint32_t) 394 // data: uint32_t 395 //-------------------------------------------------------------------------------------------------- 396 // reply format: 397 // size: 0 398 // data: N/A 399 //================================================================================================== 400 // command: EFFECT_CMD_OFFLOAD 401 //-------------------------------------------------------------------------------------------------- 402 // description: 403 // 1.indicate if the playback thread the effect is attached to is offloaded or not 404 // 2.update the io handle of the playback thread the effect is attached to 405 //-------------------------------------------------------------------------------------------------- 406 // command format: 407 // size: sizeof(effect_offload_param_t) 408 // data: effect_offload_param_t 409 //-------------------------------------------------------------------------------------------------- 410 // reply format: 411 // size: sizeof(uint32_t) 412 // data: uint32_t 413 //================================================================================================== 414 // command: EFFECT_CMD_DUMP 415 //-------------------------------------------------------------------------------------------------- 416 // description: 417 // Output the current state description into the provided file descriptor for inclusion 418 // into the audio service dump 419 //-------------------------------------------------------------------------------------------------- 420 // command format: 421 // size: sizeof(uint32_t) 422 // data: uint32_t (which is in fact a file descriptor, int) 423 //-------------------------------------------------------------------------------------------------- 424 // reply format: 425 // size: 0 426 // data: N/A 427 //-------------------------------------------------------------------------------------------------- 428 // command: EFFECT_CMD_FIRST_PROPRIETARY 429 //-------------------------------------------------------------------------------------------------- 430 // description: 431 // All proprietary effect commands must use command codes above this value. The size and format of 432 // command and response fields is free in this case 433 //================================================================================================== 434 435 // Audio buffer descriptor used by process(), bufferProvider() functions and buffer_config_t 436 // structure. Multi-channel audio is always interleaved. The channel order is from LSB to MSB with 437 // regard to the channel mask definition in audio.h, audio_channel_mask_t e.g : 438 // Stereo: left, right 439 // 5 point 1: front left, front right, front center, low frequency, back left, back right 440 // The buffer size is expressed in frame count, a frame being composed of samples for all 441 // channels at a given time. Frame size for unspecified format (AUDIO_FORMAT_OTHER) is 8 bit by 442 // definition 443 typedef struct audio_buffer_s { 444 size_t frameCount; // number of frames in buffer 445 union { 446 void* raw; // raw pointer to start of buffer 447 float* f32; // pointer to float 32 bit data at start of buffer 448 int32_t* s32; // pointer to signed 32 bit data at start of buffer 449 int16_t* s16; // pointer to signed 16 bit data at start of buffer 450 uint8_t* u8; // pointer to unsigned 8 bit data at start of buffer 451 }; 452 } audio_buffer_t; 453 454 // The buffer_provider_s structure contains functions that can be used 455 // by the effect engine process() function to query and release input 456 // or output audio buffer. 457 // The getBuffer() function is called to retrieve a buffer where data 458 // should read from or written to by process() function. 459 // The releaseBuffer() function MUST be called when the buffer retrieved 460 // with getBuffer() is not needed anymore. 461 // The process function should use the buffer provider mechanism to retrieve 462 // input or output buffer if the inBuffer or outBuffer passed as argument is NULL 463 // and the buffer configuration (buffer_config_t) given by the EFFECT_CMD_SET_CONFIG 464 // command did not specify an audio buffer. 465 466 typedef int32_t (* buffer_function_t)(void *cookie, audio_buffer_t *buffer); 467 468 typedef struct buffer_provider_s { 469 buffer_function_t getBuffer; // retrieve next buffer 470 buffer_function_t releaseBuffer; // release used buffer 471 void *cookie; // for use by client of buffer provider functions 472 } buffer_provider_t; 473 474 // Determines which fields of buffer_config_t need to be considered. 475 enum { 476 EFFECT_CONFIG_BUFFER = 1 << 0, 477 EFFECT_CONFIG_SMP_RATE = 1 << 1, 478 EFFECT_CONFIG_CHANNELS = 1 << 2, 479 EFFECT_CONFIG_FORMAT = 1 << 3, 480 EFFECT_CONFIG_ACC_MODE = 1 << 4, 481 EFFECT_CONFIG_ALL = EFFECT_CONFIG_BUFFER | EFFECT_CONFIG_SMP_RATE | 482 EFFECT_CONFIG_CHANNELS | EFFECT_CONFIG_FORMAT | EFFECT_CONFIG_ACC_MODE 483 }; 484 485 // The buffer_config_s structure specifies the input or output audio format 486 // to be used by the effect engine. 487 typedef struct buffer_config_s { 488 audio_buffer_t buffer; // buffer for use by process() function if not passed explicitly 489 uint32_t samplingRate; // sampling rate 490 uint32_t channels; // channel mask (see audio_channel_mask_t in audio.h) 491 buffer_provider_t bufferProvider; // buffer provider 492 uint8_t format; // Audio format (see audio_format_t in audio.h) 493 uint8_t accessMode; // read/write or accumulate in buffer (effect_buffer_access_e) 494 uint16_t mask; // indicates which of the above fields is valid 495 } buffer_config_t; 496 497 // EFFECT_FEATURE_AUX_CHANNELS feature configuration descriptor. Describe a combination 498 // of main and auxiliary channels supported 499 typedef struct channel_config_s { 500 audio_channel_mask_t main_channels; // channel mask for main channels 501 audio_channel_mask_t aux_channels; // channel mask for auxiliary channels 502 } channel_config_t; 503 504 505 // effect_config_s structure is used to configure audio parameters and buffers for effect engine 506 // input and output. 507 typedef struct effect_config_s { 508 buffer_config_t inputCfg; 509 buffer_config_t outputCfg; 510 } effect_config_t; 511 512 513 // effect_param_s structure describes the format of the pCmdData argument of EFFECT_CMD_SET_PARAM 514 // command and pCmdData and pReplyData of EFFECT_CMD_GET_PARAM command. 515 // psize and vsize represent the actual size of parameter and value. 516 // 517 // NOTE: the start of value field inside the data field is always on a 32 bit boundary: 518 // 519 // +-----------+ 520 // | status | sizeof(int) 521 // +-----------+ 522 // | psize | sizeof(int) 523 // +-----------+ 524 // | vsize | sizeof(int) 525 // +-----------+ 526 // | | | | 527 // ~ parameter ~ > psize | 528 // | | | > ((psize - 1)/sizeof(int) + 1) * sizeof(int) 529 // +-----------+ | 530 // | padding | | 531 // +-----------+ 532 // | | | 533 // ~ value ~ > vsize 534 // | | | 535 // +-----------+ 536 537 typedef struct effect_param_s { 538 int32_t status; // Transaction status (unused for command, used for reply) 539 uint32_t psize; // Parameter size 540 uint32_t vsize; // Value size 541 char data[]; // Start of Parameter + Value data 542 } effect_param_t; 543 544 // Maximum effect_param_t size 545 #define EFFECT_PARAM_SIZE_MAX 65536 546 547 // structure used by EFFECT_CMD_OFFLOAD command 548 typedef struct effect_offload_param_s { 549 bool isOffload; // true if the playback thread the effect is attached to is offloaded 550 int ioHandle; // io handle of the playback thread the effect is attached to 551 } effect_offload_param_t; 552 553 554 __END_DECLS 555 556 #endif // ANDROID_AUDIO_EFFECT_CORE_H 557