1 /* 2 * Copyright (C) 2011 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_H 19 #define ANDROID_AUDIO_EFFECT_H 20 21 #include <errno.h> 22 #include <stdint.h> 23 #include <strings.h> 24 #include <sys/cdefs.h> 25 #include <sys/types.h> 26 27 #include <cutils/bitops.h> 28 29 #include <system/audio.h> 30 31 32 __BEGIN_DECLS 33 34 35 ///////////////////////////////////////////////// 36 // Common Definitions 37 ///////////////////////////////////////////////// 38 39 // 40 //--- Effect descriptor structure effect_descriptor_t 41 // 42 43 // Unique effect ID (can be generated from the following site: 44 // http://www.itu.int/ITU-T/asn1/uuid.html) 45 // This format is used for both "type" and "uuid" fields of the effect descriptor structure. 46 // - When used for effect type and the engine is implementing and effect corresponding to a standard 47 // OpenSL ES interface, this ID must be the one defined in OpenSLES_IID.h for that interface. 48 // - When used as uuid, it should be a unique UUID for this particular implementation. 49 typedef struct effect_uuid_s { 50 uint32_t timeLow; 51 uint16_t timeMid; 52 uint16_t timeHiAndVersion; 53 uint16_t clockSeq; 54 uint8_t node[6]; 55 } effect_uuid_t; 56 57 // Maximum length of character strings in structures defines by this API. 58 #define EFFECT_STRING_LEN_MAX 64 59 60 // NULL UUID definition (matches SL_IID_NULL_) 61 #define EFFECT_UUID_INITIALIZER { 0xec7178ec, 0xe5e1, 0x4432, 0xa3f4, \ 62 { 0x46, 0x57, 0xe6, 0x79, 0x52, 0x10 } } 63 static const effect_uuid_t EFFECT_UUID_NULL_ = EFFECT_UUID_INITIALIZER; 64 const effect_uuid_t * const EFFECT_UUID_NULL = &EFFECT_UUID_NULL_; 65 const char * const EFFECT_UUID_NULL_STR = "ec7178ec-e5e1-4432-a3f4-4657e6795210"; 66 67 // The effect descriptor contains necessary information to facilitate the enumeration of the effect 68 // engines present in a library. 69 typedef struct effect_descriptor_s { 70 effect_uuid_t type; // UUID of to the OpenSL ES interface implemented by this effect 71 effect_uuid_t uuid; // UUID for this particular implementation 72 uint32_t apiVersion; // Version of the effect control API implemented 73 uint32_t flags; // effect engine capabilities/requirements flags (see below) 74 uint16_t cpuLoad; // CPU load indication (see below) 75 uint16_t memoryUsage; // Data Memory usage (see below) 76 char name[EFFECT_STRING_LEN_MAX]; // human readable effect name 77 char implementor[EFFECT_STRING_LEN_MAX]; // human readable effect implementor name 78 } effect_descriptor_t; 79 80 // CPU load and memory usage indication: each effect implementation must provide an indication of 81 // its CPU and memory usage for the audio effect framework to limit the number of effects 82 // instantiated at a given time on a given platform. 83 // The CPU load is expressed in 0.1 MIPS units as estimated on an ARM9E core (ARMv5TE) with 0 WS. 84 // The memory usage is expressed in KB and includes only dynamically allocated memory 85 86 // Definitions for flags field of effect descriptor. 87 // +---------------------------+-----------+----------------------------------- 88 // | description | bits | values 89 // +---------------------------+-----------+----------------------------------- 90 // | connection mode | 0..2 | 0 insert: after track process 91 // | | | 1 auxiliary: connect to track auxiliary 92 // | | | output and use send level 93 // | | | 2 replace: replaces track process function; 94 // | | | must implement SRC, volume and mono to stereo. 95 // | | | 3 pre processing: applied below audio HAL on input 96 // | | | 4 post processing: applied below audio HAL on output 97 // | | | 5 - 7 reserved 98 // +---------------------------+-----------+----------------------------------- 99 // | insertion preference | 3..5 | 0 none 100 // | | | 1 first of the chain 101 // | | | 2 last of the chain 102 // | | | 3 exclusive (only effect in the insert chain) 103 // | | | 4..7 reserved 104 // +---------------------------+-----------+----------------------------------- 105 // | Volume management | 6..8 | 0 none 106 // | | | 1 implements volume control 107 // | | | 2 requires volume indication 108 // | | | 4 reserved 109 // +---------------------------+-----------+----------------------------------- 110 // | Device indication | 9..11 | 0 none 111 // | | | 1 requires device updates 112 // | | | 2, 4 reserved 113 // +---------------------------+-----------+----------------------------------- 114 // | Sample input mode | 12..13 | 1 direct: process() function or EFFECT_CMD_SET_CONFIG 115 // | | | command must specify a buffer descriptor 116 // | | | 2 provider: process() function uses the 117 // | | | bufferProvider indicated by the 118 // | | | EFFECT_CMD_SET_CONFIG command to request input. 119 // | | | buffers. 120 // | | | 3 both: both input modes are supported 121 // +---------------------------+-----------+----------------------------------- 122 // | Sample output mode | 14..15 | 1 direct: process() function or EFFECT_CMD_SET_CONFIG 123 // | | | command must specify a buffer descriptor 124 // | | | 2 provider: process() function uses the 125 // | | | bufferProvider indicated by the 126 // | | | EFFECT_CMD_SET_CONFIG command to request output 127 // | | | buffers. 128 // | | | 3 both: both output modes are supported 129 // +---------------------------+-----------+----------------------------------- 130 // | Hardware acceleration | 16..17 | 0 No hardware acceleration 131 // | | | 1 non tunneled hw acceleration: the process() function 132 // | | | reads the samples, send them to HW accelerated 133 // | | | effect processor, reads back the processed samples 134 // | | | and returns them to the output buffer. 135 // | | | 2 tunneled hw acceleration: the process() function is 136 // | | | transparent. The effect interface is only used to 137 // | | | control the effect engine. This mode is relevant for 138 // | | | global effects actually applied by the audio 139 // | | | hardware on the output stream. 140 // +---------------------------+-----------+----------------------------------- 141 // | Audio Mode indication | 18..19 | 0 none 142 // | | | 1 requires audio mode updates 143 // | | | 2..3 reserved 144 // +---------------------------+-----------+----------------------------------- 145 146 // Insert mode 147 #define EFFECT_FLAG_TYPE_SHIFT 0 148 #define EFFECT_FLAG_TYPE_SIZE 3 149 #define EFFECT_FLAG_TYPE_MASK (((1 << EFFECT_FLAG_TYPE_SIZE) -1) \ 150 << EFFECT_FLAG_TYPE_SHIFT) 151 #define EFFECT_FLAG_TYPE_INSERT (0 << EFFECT_FLAG_TYPE_SHIFT) 152 #define EFFECT_FLAG_TYPE_AUXILIARY (1 << EFFECT_FLAG_TYPE_SHIFT) 153 #define EFFECT_FLAG_TYPE_REPLACE (2 << EFFECT_FLAG_TYPE_SHIFT) 154 #define EFFECT_FLAG_TYPE_PRE_PROC (3 << EFFECT_FLAG_TYPE_SHIFT) 155 #define EFFECT_FLAG_TYPE_POST_PROC (4 << EFFECT_FLAG_TYPE_SHIFT) 156 157 // Insert preference 158 #define EFFECT_FLAG_INSERT_SHIFT (EFFECT_FLAG_TYPE_SHIFT + EFFECT_FLAG_TYPE_SIZE) 159 #define EFFECT_FLAG_INSERT_SIZE 3 160 #define EFFECT_FLAG_INSERT_MASK (((1 << EFFECT_FLAG_INSERT_SIZE) -1) \ 161 << EFFECT_FLAG_INSERT_SHIFT) 162 #define EFFECT_FLAG_INSERT_ANY (0 << EFFECT_FLAG_INSERT_SHIFT) 163 #define EFFECT_FLAG_INSERT_FIRST (1 << EFFECT_FLAG_INSERT_SHIFT) 164 #define EFFECT_FLAG_INSERT_LAST (2 << EFFECT_FLAG_INSERT_SHIFT) 165 #define EFFECT_FLAG_INSERT_EXCLUSIVE (3 << EFFECT_FLAG_INSERT_SHIFT) 166 167 168 // Volume control 169 #define EFFECT_FLAG_VOLUME_SHIFT (EFFECT_FLAG_INSERT_SHIFT + EFFECT_FLAG_INSERT_SIZE) 170 #define EFFECT_FLAG_VOLUME_SIZE 3 171 #define EFFECT_FLAG_VOLUME_MASK (((1 << EFFECT_FLAG_VOLUME_SIZE) -1) \ 172 << EFFECT_FLAG_VOLUME_SHIFT) 173 #define EFFECT_FLAG_VOLUME_CTRL (1 << EFFECT_FLAG_VOLUME_SHIFT) 174 #define EFFECT_FLAG_VOLUME_IND (2 << EFFECT_FLAG_VOLUME_SHIFT) 175 #define EFFECT_FLAG_VOLUME_NONE (0 << EFFECT_FLAG_VOLUME_SHIFT) 176 177 // Device indication 178 #define EFFECT_FLAG_DEVICE_SHIFT (EFFECT_FLAG_VOLUME_SHIFT + EFFECT_FLAG_VOLUME_SIZE) 179 #define EFFECT_FLAG_DEVICE_SIZE 3 180 #define EFFECT_FLAG_DEVICE_MASK (((1 << EFFECT_FLAG_DEVICE_SIZE) -1) \ 181 << EFFECT_FLAG_DEVICE_SHIFT) 182 #define EFFECT_FLAG_DEVICE_IND (1 << EFFECT_FLAG_DEVICE_SHIFT) 183 #define EFFECT_FLAG_DEVICE_NONE (0 << EFFECT_FLAG_DEVICE_SHIFT) 184 185 // Sample input modes 186 #define EFFECT_FLAG_INPUT_SHIFT (EFFECT_FLAG_DEVICE_SHIFT + EFFECT_FLAG_DEVICE_SIZE) 187 #define EFFECT_FLAG_INPUT_SIZE 2 188 #define EFFECT_FLAG_INPUT_MASK (((1 << EFFECT_FLAG_INPUT_SIZE) -1) \ 189 << EFFECT_FLAG_INPUT_SHIFT) 190 #define EFFECT_FLAG_INPUT_DIRECT (1 << EFFECT_FLAG_INPUT_SHIFT) 191 #define EFFECT_FLAG_INPUT_PROVIDER (2 << EFFECT_FLAG_INPUT_SHIFT) 192 #define EFFECT_FLAG_INPUT_BOTH (3 << EFFECT_FLAG_INPUT_SHIFT) 193 194 // Sample output modes 195 #define EFFECT_FLAG_OUTPUT_SHIFT (EFFECT_FLAG_INPUT_SHIFT + EFFECT_FLAG_INPUT_SIZE) 196 #define EFFECT_FLAG_OUTPUT_SIZE 2 197 #define EFFECT_FLAG_OUTPUT_MASK (((1 << EFFECT_FLAG_OUTPUT_SIZE) -1) \ 198 << EFFECT_FLAG_OUTPUT_SHIFT) 199 #define EFFECT_FLAG_OUTPUT_DIRECT (1 << EFFECT_FLAG_OUTPUT_SHIFT) 200 #define EFFECT_FLAG_OUTPUT_PROVIDER (2 << EFFECT_FLAG_OUTPUT_SHIFT) 201 #define EFFECT_FLAG_OUTPUT_BOTH (3 << EFFECT_FLAG_OUTPUT_SHIFT) 202 203 // Hardware acceleration mode 204 #define EFFECT_FLAG_HW_ACC_SHIFT (EFFECT_FLAG_OUTPUT_SHIFT + EFFECT_FLAG_OUTPUT_SIZE) 205 #define EFFECT_FLAG_HW_ACC_SIZE 2 206 #define EFFECT_FLAG_HW_ACC_MASK (((1 << EFFECT_FLAG_HW_ACC_SIZE) -1) \ 207 << EFFECT_FLAG_HW_ACC_SHIFT) 208 #define EFFECT_FLAG_HW_ACC_SIMPLE (1 << EFFECT_FLAG_HW_ACC_SHIFT) 209 #define EFFECT_FLAG_HW_ACC_TUNNEL (2 << EFFECT_FLAG_HW_ACC_SHIFT) 210 211 // Audio mode indication 212 #define EFFECT_FLAG_AUDIO_MODE_SHIFT (EFFECT_FLAG_HW_ACC_SHIFT + EFFECT_FLAG_HW_ACC_SIZE) 213 #define EFFECT_FLAG_AUDIO_MODE_SIZE 2 214 #define EFFECT_FLAG_AUDIO_MODE_MASK (((1 << EFFECT_FLAG_AUDIO_MODE_SIZE) -1) \ 215 << EFFECT_FLAG_AUDIO_MODE_SHIFT) 216 #define EFFECT_FLAG_AUDIO_MODE_IND (1 << EFFECT_FLAG_AUDIO_MODE_SHIFT) 217 #define EFFECT_FLAG_AUDIO_MODE_NONE (0 << EFFECT_FLAG_AUDIO_MODE_SHIFT) 218 219 220 #define EFFECT_MAKE_API_VERSION(M, m) (((M)<<16) | ((m) & 0xFFFF)) 221 #define EFFECT_API_VERSION_MAJOR(v) ((v)>>16) 222 #define EFFECT_API_VERSION_MINOR(v) ((m) & 0xFFFF) 223 224 225 226 ///////////////////////////////////////////////// 227 // Effect control interface 228 ///////////////////////////////////////////////// 229 230 // Effect control interface version 2.0 231 #define EFFECT_CONTROL_API_VERSION EFFECT_MAKE_API_VERSION(2,0) 232 233 // Effect control interface structure: effect_interface_s 234 // The effect control interface is exposed by each effect engine implementation. It consists of 235 // a set of functions controlling the configuration, activation and process of the engine. 236 // The functions are grouped in a structure of type effect_interface_s. 237 // 238 // Effect control interface handle: effect_handle_t 239 // The effect_handle_t serves two purposes regarding the implementation of the effect engine: 240 // - 1 it is the address of a pointer to an effect_interface_s structure where the functions 241 // of the effect control API for a particular effect are located. 242 // - 2 it is the address of the context of a particular effect instance. 243 // A typical implementation in the effect library would define a structure as follows: 244 // struct effect_module_s { 245 // const struct effect_interface_s *itfe; 246 // effect_config_t config; 247 // effect_context_t context; 248 // } 249 // The implementation of EffectCreate() function would then allocate a structure of this 250 // type and return its address as effect_handle_t 251 typedef struct effect_interface_s **effect_handle_t; 252 253 254 // Forward definition of type audio_buffer_t 255 typedef struct audio_buffer_s audio_buffer_t; 256 257 258 259 260 261 262 // Effect control interface definition 263 struct effect_interface_s { 264 //////////////////////////////////////////////////////////////////////////////// 265 // 266 // Function: process 267 // 268 // Description: Effect process function. Takes input samples as specified 269 // (count and location) in input buffer descriptor and output processed 270 // samples as specified in output buffer descriptor. If the buffer descriptor 271 // is not specified the function must use either the buffer or the 272 // buffer provider function installed by the EFFECT_CMD_SET_CONFIG command. 273 // The effect framework will call the process() function after the EFFECT_CMD_ENABLE 274 // command is received and until the EFFECT_CMD_DISABLE is received. When the engine 275 // receives the EFFECT_CMD_DISABLE command it should turn off the effect gracefully 276 // and when done indicate that it is OK to stop calling the process() function by 277 // returning the -ENODATA status. 278 // 279 // NOTE: the process() function implementation should be "real-time safe" that is 280 // it should not perform blocking calls: malloc/free, sleep, read/write/open/close, 281 // pthread_cond_wait/pthread_mutex_lock... 282 // 283 // Input: 284 // self: handle to the effect interface this function 285 // is called on. 286 // inBuffer: buffer descriptor indicating where to read samples to process. 287 // If NULL, use the configuration passed by EFFECT_CMD_SET_CONFIG command. 288 // 289 // outBuffer: buffer descriptor indicating where to write processed samples. 290 // If NULL, use the configuration passed by EFFECT_CMD_SET_CONFIG command. 291 // 292 // Output: 293 // returned value: 0 successful operation 294 // -ENODATA the engine has finished the disable phase and the framework 295 // can stop calling process() 296 // -EINVAL invalid interface handle or 297 // invalid input/output buffer description 298 //////////////////////////////////////////////////////////////////////////////// 299 int32_t (*process)(effect_handle_t self, 300 audio_buffer_t *inBuffer, 301 audio_buffer_t *outBuffer); 302 //////////////////////////////////////////////////////////////////////////////// 303 // 304 // Function: command 305 // 306 // Description: Send a command and receive a response to/from effect engine. 307 // 308 // Input: 309 // self: handle to the effect interface this function 310 // is called on. 311 // cmdCode: command code: the command can be a standardized command defined in 312 // effect_command_e (see below) or a proprietary command. 313 // cmdSize: size of command in bytes 314 // pCmdData: pointer to command data 315 // pReplyData: pointer to reply data 316 // 317 // Input/Output: 318 // replySize: maximum size of reply data as input 319 // actual size of reply data as output 320 // 321 // Output: 322 // returned value: 0 successful operation 323 // -EINVAL invalid interface handle or 324 // invalid command/reply size or format according to command code 325 // The return code should be restricted to indicate problems related to the this 326 // API specification. Status related to the execution of a particular command should be 327 // indicated as part of the reply field. 328 // 329 // *pReplyData updated with command response 330 // 331 //////////////////////////////////////////////////////////////////////////////// 332 int32_t (*command)(effect_handle_t self, 333 uint32_t cmdCode, 334 uint32_t cmdSize, 335 void *pCmdData, 336 uint32_t *replySize, 337 void *pReplyData); 338 //////////////////////////////////////////////////////////////////////////////// 339 // 340 // Function: get_descriptor 341 // 342 // Description: Returns the effect descriptor 343 // 344 // Input: 345 // self: handle to the effect interface this function 346 // is called on. 347 // 348 // Input/Output: 349 // pDescriptor: address where to return the effect descriptor. 350 // 351 // Output: 352 // returned value: 0 successful operation. 353 // -EINVAL invalid interface handle or invalid pDescriptor 354 // *pDescriptor: updated with the effect descriptor. 355 // 356 //////////////////////////////////////////////////////////////////////////////// 357 int32_t (*get_descriptor)(effect_handle_t self, 358 effect_descriptor_t *pDescriptor); 359 //////////////////////////////////////////////////////////////////////////////// 360 // 361 // Function: process_reverse 362 // 363 // Description: Process reverse stream function. This function is used to pass 364 // a reference stream to the effect engine. If the engine does not need a reference 365 // stream, this function pointer can be set to NULL. 366 // This function would typically implemented by an Echo Canceler. 367 // 368 // Input: 369 // self: handle to the effect interface this function 370 // is called on. 371 // inBuffer: buffer descriptor indicating where to read samples to process. 372 // If NULL, use the configuration passed by EFFECT_CMD_SET_CONFIG_REVERSE command. 373 // 374 // outBuffer: buffer descriptor indicating where to write processed samples. 375 // If NULL, use the configuration passed by EFFECT_CMD_SET_CONFIG_REVERSE command. 376 // If the buffer and buffer provider in the configuration received by 377 // EFFECT_CMD_SET_CONFIG_REVERSE are also NULL, do not return modified reverse 378 // stream data 379 // 380 // Output: 381 // returned value: 0 successful operation 382 // -ENODATA the engine has finished the disable phase and the framework 383 // can stop calling process_reverse() 384 // -EINVAL invalid interface handle or 385 // invalid input/output buffer description 386 //////////////////////////////////////////////////////////////////////////////// 387 int32_t (*process_reverse)(effect_handle_t self, 388 audio_buffer_t *inBuffer, 389 audio_buffer_t *outBuffer); 390 }; 391 392 393 // 394 //--- Standardized command codes for command() function 395 // 396 enum effect_command_e { 397 EFFECT_CMD_INIT, // initialize effect engine 398 EFFECT_CMD_SET_CONFIG, // configure effect engine (see effect_config_t) 399 EFFECT_CMD_RESET, // reset effect engine 400 EFFECT_CMD_ENABLE, // enable effect process 401 EFFECT_CMD_DISABLE, // disable effect process 402 EFFECT_CMD_SET_PARAM, // set parameter immediately (see effect_param_t) 403 EFFECT_CMD_SET_PARAM_DEFERRED, // set parameter deferred 404 EFFECT_CMD_SET_PARAM_COMMIT, // commit previous set parameter deferred 405 EFFECT_CMD_GET_PARAM, // get parameter 406 EFFECT_CMD_SET_DEVICE, // set audio device (see audio.h, audio_devices_t) 407 EFFECT_CMD_SET_VOLUME, // set volume 408 EFFECT_CMD_SET_AUDIO_MODE, // set the audio mode (normal, ring, ...) 409 EFFECT_CMD_SET_CONFIG_REVERSE, // configure effect engine reverse stream(see effect_config_t) 410 EFFECT_CMD_SET_INPUT_DEVICE, // set capture device (see audio.h, audio_devices_t) 411 EFFECT_CMD_GET_CONFIG, // read effect engine configuration 412 EFFECT_CMD_GET_CONFIG_REVERSE, // read configure effect engine reverse stream configuration 413 EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS,// get all supported configurations for a feature. 414 EFFECT_CMD_GET_FEATURE_CONFIG, // get current feature configuration 415 EFFECT_CMD_SET_FEATURE_CONFIG, // set current feature configuration 416 EFFECT_CMD_FIRST_PROPRIETARY = 0x10000 // first proprietary command code 417 }; 418 419 //================================================================================================== 420 // command: EFFECT_CMD_INIT 421 //-------------------------------------------------------------------------------------------------- 422 // description: 423 // Initialize effect engine: All configurations return to default 424 //-------------------------------------------------------------------------------------------------- 425 // command format: 426 // size: 0 427 // data: N/A 428 //-------------------------------------------------------------------------------------------------- 429 // reply format: 430 // size: sizeof(int) 431 // data: status 432 //================================================================================================== 433 // command: EFFECT_CMD_SET_CONFIG 434 //-------------------------------------------------------------------------------------------------- 435 // description: 436 // Apply new audio parameters configurations for input and output buffers 437 //-------------------------------------------------------------------------------------------------- 438 // command format: 439 // size: sizeof(effect_config_t) 440 // data: effect_config_t 441 //-------------------------------------------------------------------------------------------------- 442 // reply format: 443 // size: sizeof(int) 444 // data: status 445 //================================================================================================== 446 // command: EFFECT_CMD_RESET 447 //-------------------------------------------------------------------------------------------------- 448 // description: 449 // Reset the effect engine. Keep configuration but resets state and buffer content 450 //-------------------------------------------------------------------------------------------------- 451 // command format: 452 // size: 0 453 // data: N/A 454 //-------------------------------------------------------------------------------------------------- 455 // reply format: 456 // size: 0 457 // data: N/A 458 //================================================================================================== 459 // command: EFFECT_CMD_ENABLE 460 //-------------------------------------------------------------------------------------------------- 461 // description: 462 // Enable the process. Called by the framework before the first call to process() 463 //-------------------------------------------------------------------------------------------------- 464 // command format: 465 // size: 0 466 // data: N/A 467 //-------------------------------------------------------------------------------------------------- 468 // reply format: 469 // size: sizeof(int) 470 // data: status 471 //================================================================================================== 472 // command: EFFECT_CMD_DISABLE 473 //-------------------------------------------------------------------------------------------------- 474 // description: 475 // Disable the process. Called by the framework after the last call to process() 476 //-------------------------------------------------------------------------------------------------- 477 // command format: 478 // size: 0 479 // data: N/A 480 //-------------------------------------------------------------------------------------------------- 481 // reply format: 482 // size: sizeof(int) 483 // data: status 484 //================================================================================================== 485 // command: EFFECT_CMD_SET_PARAM 486 //-------------------------------------------------------------------------------------------------- 487 // description: 488 // Set a parameter and apply it immediately 489 //-------------------------------------------------------------------------------------------------- 490 // command format: 491 // size: sizeof(effect_param_t) + size of param and value 492 // data: effect_param_t + param + value. See effect_param_t definition below for value offset 493 //-------------------------------------------------------------------------------------------------- 494 // reply format: 495 // size: sizeof(int) 496 // data: status 497 //================================================================================================== 498 // command: EFFECT_CMD_SET_PARAM_DEFERRED 499 //-------------------------------------------------------------------------------------------------- 500 // description: 501 // Set a parameter but apply it only when receiving EFFECT_CMD_SET_PARAM_COMMIT command 502 //-------------------------------------------------------------------------------------------------- 503 // command format: 504 // size: sizeof(effect_param_t) + size of param and value 505 // data: effect_param_t + param + value. See effect_param_t definition below for value offset 506 //-------------------------------------------------------------------------------------------------- 507 // reply format: 508 // size: 0 509 // data: N/A 510 //================================================================================================== 511 // command: EFFECT_CMD_SET_PARAM_COMMIT 512 //-------------------------------------------------------------------------------------------------- 513 // description: 514 // Apply all previously received EFFECT_CMD_SET_PARAM_DEFERRED commands 515 //-------------------------------------------------------------------------------------------------- 516 // command format: 517 // size: 0 518 // data: N/A 519 //-------------------------------------------------------------------------------------------------- 520 // reply format: 521 // size: sizeof(int) 522 // data: status 523 //================================================================================================== 524 // command: EFFECT_CMD_GET_PARAM 525 //-------------------------------------------------------------------------------------------------- 526 // description: 527 // Get a parameter value 528 //-------------------------------------------------------------------------------------------------- 529 // command format: 530 // size: sizeof(effect_param_t) + size of param 531 // data: effect_param_t + param 532 //-------------------------------------------------------------------------------------------------- 533 // reply format: 534 // size: sizeof(effect_param_t) + size of param and value 535 // data: effect_param_t + param + value. See effect_param_t definition below for value offset 536 //================================================================================================== 537 // command: EFFECT_CMD_SET_DEVICE 538 //-------------------------------------------------------------------------------------------------- 539 // description: 540 // Set the rendering device the audio output path is connected to. See audio.h, audio_devices_t 541 // for device values. 542 // The effect implementation must set EFFECT_FLAG_DEVICE_IND flag in its descriptor to receive this 543 // command when the device changes 544 //-------------------------------------------------------------------------------------------------- 545 // command format: 546 // size: sizeof(uint32_t) 547 // data: uint32_t 548 //-------------------------------------------------------------------------------------------------- 549 // reply format: 550 // size: 0 551 // data: N/A 552 //================================================================================================== 553 // command: EFFECT_CMD_SET_VOLUME 554 //-------------------------------------------------------------------------------------------------- 555 // description: 556 // Set and get volume. Used by audio framework to delegate volume control to effect engine. 557 // The effect implementation must set EFFECT_FLAG_VOLUME_IND or EFFECT_FLAG_VOLUME_CTRL flag in 558 // its descriptor to receive this command before every call to process() function 559 // If EFFECT_FLAG_VOLUME_CTRL flag is set in the effect descriptor, the effect engine must return 560 // the volume that should be applied before the effect is processed. The overall volume (the volume 561 // actually applied by the effect engine multiplied by the returned value) should match the value 562 // indicated in the command. 563 //-------------------------------------------------------------------------------------------------- 564 // command format: 565 // size: n * sizeof(uint32_t) 566 // data: volume for each channel defined in effect_config_t for output buffer expressed in 567 // 8.24 fixed point format 568 //-------------------------------------------------------------------------------------------------- 569 // reply format: 570 // size: n * sizeof(uint32_t) / 0 571 // data: - if EFFECT_FLAG_VOLUME_CTRL is set in effect descriptor: 572 // volume for each channel defined in effect_config_t for output buffer expressed in 573 // 8.24 fixed point format 574 // - if EFFECT_FLAG_VOLUME_CTRL is not set in effect descriptor: 575 // N/A 576 // It is legal to receive a null pointer as pReplyData in which case the effect framework has 577 // delegated volume control to another effect 578 //================================================================================================== 579 // command: EFFECT_CMD_SET_AUDIO_MODE 580 //-------------------------------------------------------------------------------------------------- 581 // description: 582 // Set the audio mode. The effect implementation must set EFFECT_FLAG_AUDIO_MODE_IND flag in its 583 // descriptor to receive this command when the audio mode changes. 584 //-------------------------------------------------------------------------------------------------- 585 // command format: 586 // size: sizeof(uint32_t) 587 // data: audio_mode_t 588 //-------------------------------------------------------------------------------------------------- 589 // reply format: 590 // size: 0 591 // data: N/A 592 //================================================================================================== 593 // command: EFFECT_CMD_SET_CONFIG_REVERSE 594 //-------------------------------------------------------------------------------------------------- 595 // description: 596 // Apply new audio parameters configurations for input and output buffers of reverse stream. 597 // An example of reverse stream is the echo reference supplied to an Acoustic Echo Canceler. 598 //-------------------------------------------------------------------------------------------------- 599 // command format: 600 // size: sizeof(effect_config_t) 601 // data: effect_config_t 602 //-------------------------------------------------------------------------------------------------- 603 // reply format: 604 // size: sizeof(int) 605 // data: status 606 //================================================================================================== 607 // command: EFFECT_CMD_SET_INPUT_DEVICE 608 //-------------------------------------------------------------------------------------------------- 609 // description: 610 // Set the capture device the audio input path is connected to. See audio.h, audio_devices_t 611 // for device values. 612 // The effect implementation must set EFFECT_FLAG_DEVICE_IND flag in its descriptor to receive this 613 // command when the device changes 614 //-------------------------------------------------------------------------------------------------- 615 // command format: 616 // size: sizeof(uint32_t) 617 // data: uint32_t 618 //-------------------------------------------------------------------------------------------------- 619 // reply format: 620 // size: 0 621 // data: N/A 622 //================================================================================================== 623 // command: EFFECT_CMD_GET_CONFIG 624 //-------------------------------------------------------------------------------------------------- 625 // description: 626 // Read audio parameters configurations for input and output buffers 627 //-------------------------------------------------------------------------------------------------- 628 // command format: 629 // size: 0 630 // data: N/A 631 //-------------------------------------------------------------------------------------------------- 632 // reply format: 633 // size: sizeof(effect_config_t) 634 // data: effect_config_t 635 //================================================================================================== 636 // command: EFFECT_CMD_GET_CONFIG_REVERSE 637 //-------------------------------------------------------------------------------------------------- 638 // description: 639 // Read audio parameters configurations for input and output buffers of reverse stream 640 //-------------------------------------------------------------------------------------------------- 641 // command format: 642 // size: 0 643 // data: N/A 644 //-------------------------------------------------------------------------------------------------- 645 // reply format: 646 // size: sizeof(effect_config_t) 647 // data: effect_config_t 648 //================================================================================================== 649 // command: EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS 650 //-------------------------------------------------------------------------------------------------- 651 // description: 652 // Queries for supported configurations for a particular feature (e.g. get the supported 653 // combinations of main and auxiliary channels for a noise suppressor). 654 // The command parameter is the feature identifier (See effect_feature_e for a list of defined 655 // features) followed by the maximum number of configuration descriptor to return. 656 // The reply is composed of: 657 // - status (uint32_t): 658 // - 0 if feature is supported 659 // - -ENOSYS if the feature is not supported, 660 // - -ENOMEM if the feature is supported but the total number of supported configurations 661 // exceeds the maximum number indicated by the caller. 662 // - total number of supported configurations (uint32_t) 663 // - an array of configuration descriptors. 664 // The actual number of descriptors returned must not exceed the maximum number indicated by 665 // the caller. 666 //-------------------------------------------------------------------------------------------------- 667 // command format: 668 // size: 2 x sizeof(uint32_t) 669 // data: effect_feature_e + maximum number of configurations to return 670 //-------------------------------------------------------------------------------------------------- 671 // reply format: 672 // size: 2 x sizeof(uint32_t) + n x sizeof (<config descriptor>) 673 // data: status + total number of configurations supported + array of n config descriptors 674 //================================================================================================== 675 // command: EFFECT_CMD_GET_FEATURE_CONFIG 676 //-------------------------------------------------------------------------------------------------- 677 // description: 678 // Retrieves current configuration for a given feature. 679 // The reply status is: 680 // - 0 if feature is supported 681 // - -ENOSYS if the feature is not supported, 682 //-------------------------------------------------------------------------------------------------- 683 // command format: 684 // size: sizeof(uint32_t) 685 // data: effect_feature_e 686 //-------------------------------------------------------------------------------------------------- 687 // reply format: 688 // size: sizeof(uint32_t) + sizeof (<config descriptor>) 689 // data: status + config descriptor 690 //================================================================================================== 691 // command: EFFECT_CMD_SET_FEATURE_CONFIG 692 //-------------------------------------------------------------------------------------------------- 693 // description: 694 // Sets current configuration for a given feature. 695 // The reply status is: 696 // - 0 if feature is supported 697 // - -ENOSYS if the feature is not supported, 698 // - -EINVAL if the configuration is invalid 699 //-------------------------------------------------------------------------------------------------- 700 // command format: 701 // size: sizeof(uint32_t) + sizeof (<config descriptor>) 702 // data: effect_feature_e + config descriptor 703 //-------------------------------------------------------------------------------------------------- 704 // reply format: 705 // size: sizeof(uint32_t) 706 // data: status 707 //================================================================================================== 708 // command: EFFECT_CMD_FIRST_PROPRIETARY 709 //-------------------------------------------------------------------------------------------------- 710 // description: 711 // All proprietary effect commands must use command codes above this value. The size and format of 712 // command and response fields is free in this case 713 //================================================================================================== 714 715 716 // Audio buffer descriptor used by process(), bufferProvider() functions and buffer_config_t 717 // structure. Multi-channel audio is always interleaved. The channel order is from LSB to MSB with 718 // regard to the channel mask definition in audio.h, audio_channel_mask_t e.g : 719 // Stereo: left, right 720 // 5 point 1: front left, front right, front center, low frequency, back left, back right 721 // The buffer size is expressed in frame count, a frame being composed of samples for all 722 // channels at a given time. Frame size for unspecified format (AUDIO_FORMAT_OTHER) is 8 bit by 723 // definition 724 struct audio_buffer_s { 725 size_t frameCount; // number of frames in buffer 726 union { 727 void* raw; // raw pointer to start of buffer 728 int32_t* s32; // pointer to signed 32 bit data at start of buffer 729 int16_t* s16; // pointer to signed 16 bit data at start of buffer 730 uint8_t* u8; // pointer to unsigned 8 bit data at start of buffer 731 }; 732 }; 733 734 // The buffer_provider_s structure contains functions that can be used 735 // by the effect engine process() function to query and release input 736 // or output audio buffer. 737 // The getBuffer() function is called to retrieve a buffer where data 738 // should read from or written to by process() function. 739 // The releaseBuffer() function MUST be called when the buffer retrieved 740 // with getBuffer() is not needed anymore. 741 // The process function should use the buffer provider mechanism to retrieve 742 // input or output buffer if the inBuffer or outBuffer passed as argument is NULL 743 // and the buffer configuration (buffer_config_t) given by the EFFECT_CMD_SET_CONFIG 744 // command did not specify an audio buffer. 745 746 typedef int32_t (* buffer_function_t)(void *cookie, audio_buffer_t *buffer); 747 748 typedef struct buffer_provider_s { 749 buffer_function_t getBuffer; // retrieve next buffer 750 buffer_function_t releaseBuffer; // release used buffer 751 void *cookie; // for use by client of buffer provider functions 752 } buffer_provider_t; 753 754 755 // The buffer_config_s structure specifies the input or output audio format 756 // to be used by the effect engine. It is part of the effect_config_t 757 // structure that defines both input and output buffer configurations and is 758 // passed by the EFFECT_CMD_SET_CONFIG or EFFECT_CMD_SET_CONFIG_REVERSE command. 759 typedef struct buffer_config_s { 760 audio_buffer_t buffer; // buffer for use by process() function if not passed explicitly 761 uint32_t samplingRate; // sampling rate 762 uint32_t channels; // channel mask (see audio_channel_mask_t in audio.h) 763 buffer_provider_t bufferProvider; // buffer provider 764 uint8_t format; // Audio format (see see audio_format_t in audio.h) 765 uint8_t accessMode; // read/write or accumulate in buffer (effect_buffer_access_e) 766 uint16_t mask; // indicates which of the above fields is valid 767 } buffer_config_t; 768 769 // Values for "accessMode" field of buffer_config_t: 770 // overwrite, read only, accumulate (read/modify/write) 771 enum effect_buffer_access_e { 772 EFFECT_BUFFER_ACCESS_WRITE, 773 EFFECT_BUFFER_ACCESS_READ, 774 EFFECT_BUFFER_ACCESS_ACCUMULATE 775 776 }; 777 778 // feature identifiers for EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS command 779 enum effect_feature_e { 780 EFFECT_FEATURE_AUX_CHANNELS, // supports auxiliary channels (e.g. dual mic noise suppressor) 781 EFFECT_FEATURE_CNT 782 }; 783 784 // EFFECT_FEATURE_AUX_CHANNELS feature configuration descriptor. Describe a combination 785 // of main and auxiliary channels supported 786 typedef struct channel_config_s { 787 uint32_t main_channels; // channel mask for main channels 788 uint32_t aux_channels; // channel mask for auxiliary channels 789 } channel_config_t; 790 791 792 // Values for bit field "mask" in buffer_config_t. If a bit is set, the corresponding field 793 // in buffer_config_t must be taken into account when executing the EFFECT_CMD_SET_CONFIG command 794 #define EFFECT_CONFIG_BUFFER 0x0001 // buffer field must be taken into account 795 #define EFFECT_CONFIG_SMP_RATE 0x0002 // samplingRate field must be taken into account 796 #define EFFECT_CONFIG_CHANNELS 0x0004 // channels field must be taken into account 797 #define EFFECT_CONFIG_FORMAT 0x0008 // format field must be taken into account 798 #define EFFECT_CONFIG_ACC_MODE 0x0010 // accessMode field must be taken into account 799 #define EFFECT_CONFIG_PROVIDER 0x0020 // bufferProvider field must be taken into account 800 #define EFFECT_CONFIG_ALL (EFFECT_CONFIG_BUFFER | EFFECT_CONFIG_SMP_RATE | \ 801 EFFECT_CONFIG_CHANNELS | EFFECT_CONFIG_FORMAT | \ 802 EFFECT_CONFIG_ACC_MODE | EFFECT_CONFIG_PROVIDER) 803 804 805 // effect_config_s structure describes the format of the pCmdData argument of EFFECT_CMD_SET_CONFIG 806 // command to configure audio parameters and buffers for effect engine input and output. 807 typedef struct effect_config_s { 808 buffer_config_t inputCfg; 809 buffer_config_t outputCfg; 810 } effect_config_t; 811 812 813 // effect_param_s structure describes the format of the pCmdData argument of EFFECT_CMD_SET_PARAM 814 // command and pCmdData and pReplyData of EFFECT_CMD_GET_PARAM command. 815 // psize and vsize represent the actual size of parameter and value. 816 // 817 // NOTE: the start of value field inside the data field is always on a 32 bit boundary: 818 // 819 // +-----------+ 820 // | status | sizeof(int) 821 // +-----------+ 822 // | psize | sizeof(int) 823 // +-----------+ 824 // | vsize | sizeof(int) 825 // +-----------+ 826 // | | | | 827 // ~ parameter ~ > psize | 828 // | | | > ((psize - 1)/sizeof(int) + 1) * sizeof(int) 829 // +-----------+ | 830 // | padding | | 831 // +-----------+ 832 // | | | 833 // ~ value ~ > vsize 834 // | | | 835 // +-----------+ 836 837 typedef struct effect_param_s { 838 int32_t status; // Transaction status (unused for command, used for reply) 839 uint32_t psize; // Parameter size 840 uint32_t vsize; // Value size 841 char data[]; // Start of Parameter + Value data 842 } effect_param_t; 843 844 845 846 ///////////////////////////////////////////////// 847 // Effect library interface 848 ///////////////////////////////////////////////// 849 850 // Effect library interface version 2.0 851 #define EFFECT_LIBRARY_API_VERSION EFFECT_MAKE_API_VERSION(2,0) 852 853 #define AUDIO_EFFECT_LIBRARY_TAG ((('A') << 24) | (('E') << 16) | (('L') << 8) | ('T')) 854 855 // Every effect library must have a data structure named AUDIO_EFFECT_LIBRARY_INFO_SYM 856 // and the fields of this data structure must begin with audio_effect_library_t 857 858 typedef struct audio_effect_library_s { 859 // tag must be initialized to AUDIO_EFFECT_LIBRARY_TAG 860 uint32_t tag; 861 // Version of the effect library API : 0xMMMMmmmm MMMM: Major, mmmm: minor 862 uint32_t version; 863 // Name of this library 864 const char *name; 865 // Author/owner/implementor of the library 866 const char *implementor; 867 868 //////////////////////////////////////////////////////////////////////////////// 869 // 870 // Function: query_num_effects 871 // 872 // Description: Returns the number of different effects exposed by the 873 // library. Each effect must have a unique effect uuid (see 874 // effect_descriptor_t). This function together with EffectQueryEffect() 875 // is used to enumerate all effects present in the library. 876 // 877 // Input/Output: 878 // pNumEffects: address where the number of effects should be returned. 879 // 880 // Output: 881 // returned value: 0 successful operation. 882 // -ENODEV library failed to initialize 883 // -EINVAL invalid pNumEffects 884 // *pNumEffects: updated with number of effects in library 885 // 886 //////////////////////////////////////////////////////////////////////////////// 887 int32_t (*query_num_effects)(uint32_t *pNumEffects); 888 889 //////////////////////////////////////////////////////////////////////////////// 890 // 891 // Function: query_effect 892 // 893 // Description: Returns the descriptor of the effect engine which index is 894 // given as argument. 895 // See effect_descriptor_t for details on effect descriptors. 896 // This function together with EffectQueryNumberEffects() is used to enumerate all 897 // effects present in the library. The enumeration sequence is: 898 // EffectQueryNumberEffects(&num_effects); 899 // for (i = 0; i < num_effects; i++) 900 // EffectQueryEffect(i,...); 901 // 902 // Input/Output: 903 // index: index of the effect 904 // pDescriptor: address where to return the effect descriptor. 905 // 906 // Output: 907 // returned value: 0 successful operation. 908 // -ENODEV library failed to initialize 909 // -EINVAL invalid pDescriptor or index 910 // -ENOSYS effect list has changed since last execution of 911 // EffectQueryNumberEffects() 912 // -ENOENT no more effect available 913 // *pDescriptor: updated with the effect descriptor. 914 // 915 //////////////////////////////////////////////////////////////////////////////// 916 int32_t (*query_effect)(uint32_t index, 917 effect_descriptor_t *pDescriptor); 918 919 //////////////////////////////////////////////////////////////////////////////// 920 // 921 // Function: create_effect 922 // 923 // Description: Creates an effect engine of the specified implementation uuid and 924 // returns an effect control interface on this engine. The function will allocate the 925 // resources for an instance of the requested effect engine and return 926 // a handle on the effect control interface. 927 // 928 // Input: 929 // uuid: pointer to the effect uuid. 930 // sessionId: audio session to which this effect instance will be attached. All effects 931 // created with the same session ID are connected in series and process the same signal 932 // stream. Knowing that two effects are part of the same effect chain can help the 933 // library implement some kind of optimizations. 934 // ioId: identifies the output or input stream this effect is directed to at audio HAL. 935 // For future use especially with tunneled HW accelerated effects 936 // 937 // Input/Output: 938 // pHandle: address where to return the effect interface handle. 939 // 940 // Output: 941 // returned value: 0 successful operation. 942 // -ENODEV library failed to initialize 943 // -EINVAL invalid pEffectUuid or pHandle 944 // -ENOENT no effect with this uuid found 945 // *pHandle: updated with the effect interface handle. 946 // 947 //////////////////////////////////////////////////////////////////////////////// 948 int32_t (*create_effect)(const effect_uuid_t *uuid, 949 int32_t sessionId, 950 int32_t ioId, 951 effect_handle_t *pHandle); 952 953 //////////////////////////////////////////////////////////////////////////////// 954 // 955 // Function: release_effect 956 // 957 // Description: Releases the effect engine whose handle is given as argument. 958 // All resources allocated to this particular instance of the effect are 959 // released. 960 // 961 // Input: 962 // handle: handle on the effect interface to be released. 963 // 964 // Output: 965 // returned value: 0 successful operation. 966 // -ENODEV library failed to initialize 967 // -EINVAL invalid interface handle 968 // 969 //////////////////////////////////////////////////////////////////////////////// 970 int32_t (*release_effect)(effect_handle_t handle); 971 972 //////////////////////////////////////////////////////////////////////////////// 973 // 974 // Function: get_descriptor 975 // 976 // Description: Returns the descriptor of the effect engine which implementation UUID is 977 // given as argument. 978 // 979 // Input/Output: 980 // uuid: pointer to the effect uuid. 981 // pDescriptor: address where to return the effect descriptor. 982 // 983 // Output: 984 // returned value: 0 successful operation. 985 // -ENODEV library failed to initialize 986 // -EINVAL invalid pDescriptor or uuid 987 // *pDescriptor: updated with the effect descriptor. 988 // 989 //////////////////////////////////////////////////////////////////////////////// 990 int32_t (*get_descriptor)(const effect_uuid_t *uuid, 991 effect_descriptor_t *pDescriptor); 992 } audio_effect_library_t; 993 994 // Name of the hal_module_info 995 #define AUDIO_EFFECT_LIBRARY_INFO_SYM AELI 996 997 // Name of the hal_module_info as a string 998 #define AUDIO_EFFECT_LIBRARY_INFO_SYM_AS_STR "AELI" 999 1000 __END_DECLS 1001 1002 #endif // ANDROID_AUDIO_EFFECT_H 1003