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