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