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