dom/system/gonk/android_audio/EffectApi.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Copyright (C) 2010 The Android Open Source Project
michael@0 3 *
michael@0 4 * Licensed under the Apache License, Version 2.0 (the "License");
michael@0 5 * you may not use this file except in compliance with the License.
michael@0 6 * You may obtain a copy of the License at
michael@0 7 *
michael@0 8 * http://www.apache.org/licenses/LICENSE-2.0
michael@0 9 *
michael@0 10 * Unless required by applicable law or agreed to in writing, software
michael@0 11 * distributed under the License is distributed on an "AS IS" BASIS,
michael@0 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
michael@0 13 * See the License for the specific language governing permissions and
michael@0 14 * limitations under the License.
michael@0 15 */
michael@0 16
michael@0 17 #ifndef ANDROID_EFFECTAPI_H_
michael@0 18 #define ANDROID_EFFECTAPI_H_
michael@0 19
michael@0 20 #include <errno.h>
michael@0 21 #include <stdint.h>
michael@0 22 #include <sys/types.h>
michael@0 23
michael@0 24 #if __cplusplus
michael@0 25 extern "C" {
michael@0 26 #endif
michael@0 27
michael@0 28 /////////////////////////////////////////////////
michael@0 29 // Effect control interface
michael@0 30 /////////////////////////////////////////////////
michael@0 31
michael@0 32 // The effect control interface is exposed by each effect engine implementation. It consists of
michael@0 33 // a set of functions controlling the configuration, activation and process of the engine.
michael@0 34 // The functions are grouped in a structure of type effect_interface_s:
michael@0 35 // struct effect_interface_s {
michael@0 36 // effect_process_t process;
michael@0 37 // effect_command_t command;
michael@0 38 // };
michael@0 39
michael@0 40
michael@0 41 // effect_interface_t: Effect control interface handle.
michael@0 42 // The effect_interface_t serves two purposes regarding the implementation of the effect engine:
michael@0 43 // - 1 it is the address of a pointer to an effect_interface_s structure where the functions
michael@0 44 // of the effect control API for a particular effect are located.
michael@0 45 // - 2 it is the address of the context of a particular effect instance.
michael@0 46 // A typical implementation in the effect library would define a structure as follows:
michael@0 47 // struct effect_module_s {
michael@0 48 // const struct effect_interface_s *itfe;
michael@0 49 // effect_config_t config;
michael@0 50 // effect_context_t context;
michael@0 51 // }
michael@0 52 // The implementation of EffectCreate() function would then allocate a structure of this
michael@0 53 // type and return its address as effect_interface_t
michael@0 54 typedef struct effect_interface_s **effect_interface_t;
michael@0 55
michael@0 56
michael@0 57 // Effect API version 1.0
michael@0 58 #define EFFECT_API_VERSION 0x0100 // Format 0xMMmm MM: Major version, mm: minor version
michael@0 59
michael@0 60 // Maximum length of character strings in structures defines by this API.
michael@0 61 #define EFFECT_STRING_LEN_MAX 64
michael@0 62
michael@0 63 //
michael@0 64 //--- Effect descriptor structure effect_descriptor_t
michael@0 65 //
michael@0 66
michael@0 67 // Unique effect ID (can be generated from the following site:
michael@0 68 // http://www.itu.int/ITU-T/asn1/uuid.html)
michael@0 69 // This format is used for both "type" and "uuid" fields of the effect descriptor structure.
michael@0 70 // - When used for effect type and the engine is implementing and effect corresponding to a standard
michael@0 71 // OpenSL ES interface, this ID must be the one defined in OpenSLES_IID.h for that interface.
michael@0 72 // - When used as uuid, it should be a unique UUID for this particular implementation.
michael@0 73 typedef struct effect_uuid_s {
michael@0 74 uint32_t timeLow;
michael@0 75 uint16_t timeMid;
michael@0 76 uint16_t timeHiAndVersion;
michael@0 77 uint16_t clockSeq;
michael@0 78 uint8_t node[6];
michael@0 79 } effect_uuid_t;
michael@0 80
michael@0 81 // NULL UUID definition (matches SL_IID_NULL_)
michael@0 82 #define EFFECT_UUID_INITIALIZER { 0xec7178ec, 0xe5e1, 0x4432, 0xa3f4, \
michael@0 83 { 0x46, 0x57, 0xe6, 0x79, 0x52, 0x10 } }
michael@0 84 static const effect_uuid_t EFFECT_UUID_NULL_ = EFFECT_UUID_INITIALIZER;
michael@0 85 const effect_uuid_t * const EFFECT_UUID_NULL = &EFFECT_UUID_NULL_;
michael@0 86 const char * const EFFECT_UUID_NULL_STR = "ec7178ec-e5e1-4432-a3f4-4657e6795210";
michael@0 87
michael@0 88 // The effect descriptor contains necessary information to facilitate the enumeration of the effect
michael@0 89 // engines present in a library.
michael@0 90 typedef struct effect_descriptor_s {
michael@0 91 effect_uuid_t type; // UUID of to the OpenSL ES interface implemented by this effect
michael@0 92 effect_uuid_t uuid; // UUID for this particular implementation
michael@0 93 uint16_t apiVersion; // Version of the effect API implemented: matches EFFECT_API_VERSION
michael@0 94 uint32_t flags; // effect engine capabilities/requirements flags (see below)
michael@0 95 uint16_t cpuLoad; // CPU load indication (see below)
michael@0 96 uint16_t memoryUsage; // Data Memory usage (see below)
michael@0 97 char name[EFFECT_STRING_LEN_MAX]; // human readable effect name
michael@0 98 char implementor[EFFECT_STRING_LEN_MAX]; // human readable effect implementor name
michael@0 99 } effect_descriptor_t;
michael@0 100
michael@0 101 // CPU load and memory usage indication: each effect implementation must provide an indication of
michael@0 102 // its CPU and memory usage for the audio effect framework to limit the number of effects
michael@0 103 // instantiated at a given time on a given platform.
michael@0 104 // The CPU load is expressed in 0.1 MIPS units as estimated on an ARM9E core (ARMv5TE) with 0 WS.
michael@0 105 // The memory usage is expressed in KB and includes only dynamically allocated memory
michael@0 106
michael@0 107 // Definitions for flags field of effect descriptor.
michael@0 108 // +---------------------------+-----------+-----------------------------------
michael@0 109 // | description | bits | values
michael@0 110 // +---------------------------+-----------+-----------------------------------
michael@0 111 // | connection mode | 0..1 | 0 insert: after track process
michael@0 112 // | | | 1 auxiliary: connect to track auxiliary
michael@0 113 // | | | output and use send level
michael@0 114 // | | | 2 replace: replaces track process function;
michael@0 115 // | | | must implement SRC, volume and mono to stereo.
michael@0 116 // | | | 3 reserved
michael@0 117 // +---------------------------+-----------+-----------------------------------
michael@0 118 // | insertion preference | 2..4 | 0 none
michael@0 119 // | | | 1 first of the chain
michael@0 120 // | | | 2 last of the chain
michael@0 121 // | | | 3 exclusive (only effect in the insert chain)
michael@0 122 // | | | 4..7 reserved
michael@0 123 // +---------------------------+-----------+-----------------------------------
michael@0 124 // | Volume management | 5..6 | 0 none
michael@0 125 // | | | 1 implements volume control
michael@0 126 // | | | 2 requires volume indication
michael@0 127 // | | | 3 reserved
michael@0 128 // +---------------------------+-----------+-----------------------------------
michael@0 129 // | Device indication | 7..8 | 0 none
michael@0 130 // | | | 1 requires device updates
michael@0 131 // | | | 2..3 reserved
michael@0 132 // +---------------------------+-----------+-----------------------------------
michael@0 133 // | Sample input mode | 9..10 | 0 direct: process() function or EFFECT_CMD_CONFIGURE
michael@0 134 // | | | command must specify a buffer descriptor
michael@0 135 // | | | 1 provider: process() function uses the
michael@0 136 // | | | bufferProvider indicated by the
michael@0 137 // | | | EFFECT_CMD_CONFIGURE command to request input.
michael@0 138 // | | | buffers.
michael@0 139 // | | | 2 both: both input modes are supported
michael@0 140 // | | | 3 reserved
michael@0 141 // +---------------------------+-----------+-----------------------------------
michael@0 142 // | Sample output mode | 11..12 | 0 direct: process() function or EFFECT_CMD_CONFIGURE
michael@0 143 // | | | command must specify a buffer descriptor
michael@0 144 // | | | 1 provider: process() function uses the
michael@0 145 // | | | bufferProvider indicated by the
michael@0 146 // | | | EFFECT_CMD_CONFIGURE command to request output
michael@0 147 // | | | buffers.
michael@0 148 // | | | 2 both: both output modes are supported
michael@0 149 // | | | 3 reserved
michael@0 150 // +---------------------------+-----------+-----------------------------------
michael@0 151 // | Hardware acceleration | 13..15 | 0 No hardware acceleration
michael@0 152 // | | | 1 non tunneled hw acceleration: the process() function
michael@0 153 // | | | reads the samples, send them to HW accelerated
michael@0 154 // | | | effect processor, reads back the processed samples
michael@0 155 // | | | and returns them to the output buffer.
michael@0 156 // | | | 2 tunneled hw acceleration: the process() function is
michael@0 157 // | | | transparent. The effect interface is only used to
michael@0 158 // | | | control the effect engine. This mode is relevant for
michael@0 159 // | | | global effects actually applied by the audio
michael@0 160 // | | | hardware on the output stream.
michael@0 161 // +---------------------------+-----------+-----------------------------------
michael@0 162 // | Audio Mode indication | 16..17 | 0 none
michael@0 163 // | | | 1 requires audio mode updates
michael@0 164 // | | | 2..3 reserved
michael@0 165 // +---------------------------+-----------+-----------------------------------
michael@0 166
michael@0 167 // Insert mode
michael@0 168 #define EFFECT_FLAG_TYPE_MASK 0x00000003
michael@0 169 #define EFFECT_FLAG_TYPE_INSERT 0x00000000
michael@0 170 #define EFFECT_FLAG_TYPE_AUXILIARY 0x00000001
michael@0 171 #define EFFECT_FLAG_TYPE_REPLACE 0x00000002
michael@0 172
michael@0 173 // Insert preference
michael@0 174 #define EFFECT_FLAG_INSERT_MASK 0x0000001C
michael@0 175 #define EFFECT_FLAG_INSERT_ANY 0x00000000
michael@0 176 #define EFFECT_FLAG_INSERT_FIRST 0x00000004
michael@0 177 #define EFFECT_FLAG_INSERT_LAST 0x00000008
michael@0 178 #define EFFECT_FLAG_INSERT_EXCLUSIVE 0x0000000C
michael@0 179
michael@0 180
michael@0 181 // Volume control
michael@0 182 #define EFFECT_FLAG_VOLUME_MASK 0x00000060
michael@0 183 #define EFFECT_FLAG_VOLUME_CTRL 0x00000020
michael@0 184 #define EFFECT_FLAG_VOLUME_IND 0x00000040
michael@0 185 #define EFFECT_FLAG_VOLUME_NONE 0x00000000
michael@0 186
michael@0 187 // Device indication
michael@0 188 #define EFFECT_FLAG_DEVICE_MASK 0x00000180
michael@0 189 #define EFFECT_FLAG_DEVICE_IND 0x00000080
michael@0 190 #define EFFECT_FLAG_DEVICE_NONE 0x00000000
michael@0 191
michael@0 192 // Sample input modes
michael@0 193 #define EFFECT_FLAG_INPUT_MASK 0x00000600
michael@0 194 #define EFFECT_FLAG_INPUT_DIRECT 0x00000000
michael@0 195 #define EFFECT_FLAG_INPUT_PROVIDER 0x00000200
michael@0 196 #define EFFECT_FLAG_INPUT_BOTH 0x00000400
michael@0 197
michael@0 198 // Sample output modes
michael@0 199 #define EFFECT_FLAG_OUTPUT_MASK 0x00001800
michael@0 200 #define EFFECT_FLAG_OUTPUT_DIRECT 0x00000000
michael@0 201 #define EFFECT_FLAG_OUTPUT_PROVIDER 0x00000800
michael@0 202 #define EFFECT_FLAG_OUTPUT_BOTH 0x00001000
michael@0 203
michael@0 204 // Hardware acceleration mode
michael@0 205 #define EFFECT_FLAG_HW_ACC_MASK 0x00006000
michael@0 206 #define EFFECT_FLAG_HW_ACC_SIMPLE 0x00002000
michael@0 207 #define EFFECT_FLAG_HW_ACC_TUNNEL 0x00004000
michael@0 208
michael@0 209 // Audio mode indication
michael@0 210 #define EFFECT_FLAG_AUDIO_MODE_MASK 0x00018000
michael@0 211 #define EFFECT_FLAG_AUDIO_MODE_IND 0x00008000
michael@0 212 #define EFFECT_FLAG_AUDIO_MODE_NONE 0x00000000
michael@0 213
michael@0 214 // Forward definition of type audio_buffer_t
michael@0 215 typedef struct audio_buffer_s audio_buffer_t;
michael@0 216
michael@0 217 ////////////////////////////////////////////////////////////////////////////////
michael@0 218 //
michael@0 219 // Function: process
michael@0 220 //
michael@0 221 // Description: Effect process function. Takes input samples as specified
michael@0 222 // (count and location) in input buffer descriptor and output processed
michael@0 223 // samples as specified in output buffer descriptor. If the buffer descriptor
michael@0 224 // is not specified the function must use either the buffer or the
michael@0 225 // buffer provider function installed by the EFFECT_CMD_CONFIGURE command.
michael@0 226 // The effect framework will call the process() function after the EFFECT_CMD_ENABLE
michael@0 227 // command is received and until the EFFECT_CMD_DISABLE is received. When the engine
michael@0 228 // receives the EFFECT_CMD_DISABLE command it should turn off the effect gracefully
michael@0 229 // and when done indicate that it is OK to stop calling the process() function by
michael@0 230 // returning the -ENODATA status.
michael@0 231 //
michael@0 232 // NOTE: the process() function implementation should be "real-time safe" that is
michael@0 233 // it should not perform blocking calls: malloc/free, sleep, read/write/open/close,
michael@0 234 // pthread_cond_wait/pthread_mutex_lock...
michael@0 235 //
michael@0 236 // Input:
michael@0 237 // effect_interface_t: handle to the effect interface this function
michael@0 238 // is called on.
michael@0 239 // inBuffer: buffer descriptor indicating where to read samples to process.
michael@0 240 // If NULL, use the configuration passed by EFFECT_CMD_CONFIGURE command.
michael@0 241 //
michael@0 242 // inBuffer: buffer descriptor indicating where to write processed samples.
michael@0 243 // If NULL, use the configuration passed by EFFECT_CMD_CONFIGURE command.
michael@0 244 //
michael@0 245 // Output:
michael@0 246 // returned value: 0 successful operation
michael@0 247 // -ENODATA the engine has finished the disable phase and the framework
michael@0 248 // can stop calling process()
michael@0 249 // -EINVAL invalid interface handle or
michael@0 250 // invalid input/output buffer description
michael@0 251 ////////////////////////////////////////////////////////////////////////////////
michael@0 252 typedef int32_t (*effect_process_t)(effect_interface_t self,
michael@0 253 audio_buffer_t *inBuffer,
michael@0 254 audio_buffer_t *outBuffer);
michael@0 255
michael@0 256 ////////////////////////////////////////////////////////////////////////////////
michael@0 257 //
michael@0 258 // Function: command
michael@0 259 //
michael@0 260 // Description: Send a command and receive a response to/from effect engine.
michael@0 261 //
michael@0 262 // Input:
michael@0 263 // effect_interface_t: handle to the effect interface this function
michael@0 264 // is called on.
michael@0 265 // cmdCode: command code: the command can be a standardized command defined in
michael@0 266 // effect_command_e (see below) or a proprietary command.
michael@0 267 // cmdSize: size of command in bytes
michael@0 268 // pCmdData: pointer to command data
michael@0 269 // pReplyData: pointer to reply data
michael@0 270 //
michael@0 271 // Input/Output:
michael@0 272 // replySize: maximum size of reply data as input
michael@0 273 // actual size of reply data as output
michael@0 274 //
michael@0 275 // Output:
michael@0 276 // returned value: 0 successful operation
michael@0 277 // -EINVAL invalid interface handle or
michael@0 278 // invalid command/reply size or format according to command code
michael@0 279 // The return code should be restricted to indicate problems related to the this
michael@0 280 // API specification. Status related to the execution of a particular command should be
michael@0 281 // indicated as part of the reply field.
michael@0 282 //
michael@0 283 // *pReplyData updated with command response
michael@0 284 //
michael@0 285 ////////////////////////////////////////////////////////////////////////////////
michael@0 286 typedef int32_t (*effect_command_t)(effect_interface_t self,
michael@0 287 uint32_t cmdCode,
michael@0 288 uint32_t cmdSize,
michael@0 289 void *pCmdData,
michael@0 290 uint32_t *replySize,
michael@0 291 void *pReplyData);
michael@0 292
michael@0 293
michael@0 294 // Effect control interface definition
michael@0 295 struct effect_interface_s {
michael@0 296 effect_process_t process;
michael@0 297 effect_command_t command;
michael@0 298 };
michael@0 299
michael@0 300
michael@0 301 //
michael@0 302 //--- Standardized command codes for command() function
michael@0 303 //
michael@0 304 enum effect_command_e {
michael@0 305 EFFECT_CMD_INIT, // initialize effect engine
michael@0 306 EFFECT_CMD_CONFIGURE, // configure effect engine (see effect_config_t)
michael@0 307 EFFECT_CMD_RESET, // reset effect engine
michael@0 308 EFFECT_CMD_ENABLE, // enable effect process
michael@0 309 EFFECT_CMD_DISABLE, // disable effect process
michael@0 310 EFFECT_CMD_SET_PARAM, // set parameter immediately (see effect_param_t)
michael@0 311 EFFECT_CMD_SET_PARAM_DEFERRED, // set parameter deferred
michael@0 312 EFFECT_CMD_SET_PARAM_COMMIT, // commit previous set parameter deferred
michael@0 313 EFFECT_CMD_GET_PARAM, // get parameter
michael@0 314 EFFECT_CMD_SET_DEVICE, // set audio device (see audio_device_e)
michael@0 315 EFFECT_CMD_SET_VOLUME, // set volume
michael@0 316 EFFECT_CMD_SET_AUDIO_MODE, // set the audio mode (normal, ring, ...)
michael@0 317 EFFECT_CMD_FIRST_PROPRIETARY = 0x10000 // first proprietary command code
michael@0 318 };
michael@0 319
michael@0 320 //==================================================================================================
michael@0 321 // command: EFFECT_CMD_INIT
michael@0 322 //--------------------------------------------------------------------------------------------------
michael@0 323 // description:
michael@0 324 // Initialize effect engine: All configurations return to default
michael@0 325 //--------------------------------------------------------------------------------------------------
michael@0 326 // command format:
michael@0 327 // size: 0
michael@0 328 // data: N/A
michael@0 329 //--------------------------------------------------------------------------------------------------
michael@0 330 // reply format:
michael@0 331 // size: sizeof(int)
michael@0 332 // data: status
michael@0 333 //==================================================================================================
michael@0 334 // command: EFFECT_CMD_CONFIGURE
michael@0 335 //--------------------------------------------------------------------------------------------------
michael@0 336 // description:
michael@0 337 // Apply new audio parameters configurations for input and output buffers
michael@0 338 //--------------------------------------------------------------------------------------------------
michael@0 339 // command format:
michael@0 340 // size: sizeof(effect_config_t)
michael@0 341 // data: effect_config_t
michael@0 342 //--------------------------------------------------------------------------------------------------
michael@0 343 // reply format:
michael@0 344 // size: sizeof(int)
michael@0 345 // data: status
michael@0 346 //==================================================================================================
michael@0 347 // command: EFFECT_CMD_RESET
michael@0 348 //--------------------------------------------------------------------------------------------------
michael@0 349 // description:
michael@0 350 // Reset the effect engine. Keep configuration but resets state and buffer content
michael@0 351 //--------------------------------------------------------------------------------------------------
michael@0 352 // command format:
michael@0 353 // size: 0
michael@0 354 // data: N/A
michael@0 355 //--------------------------------------------------------------------------------------------------
michael@0 356 // reply format:
michael@0 357 // size: 0
michael@0 358 // data: N/A
michael@0 359 //==================================================================================================
michael@0 360 // command: EFFECT_CMD_ENABLE
michael@0 361 //--------------------------------------------------------------------------------------------------
michael@0 362 // description:
michael@0 363 // Enable the process. Called by the framework before the first call to process()
michael@0 364 //--------------------------------------------------------------------------------------------------
michael@0 365 // command format:
michael@0 366 // size: 0
michael@0 367 // data: N/A
michael@0 368 //--------------------------------------------------------------------------------------------------
michael@0 369 // reply format:
michael@0 370 // size: sizeof(int)
michael@0 371 // data: status
michael@0 372 //==================================================================================================
michael@0 373 // command: EFFECT_CMD_DISABLE
michael@0 374 //--------------------------------------------------------------------------------------------------
michael@0 375 // description:
michael@0 376 // Disable the process. Called by the framework after the last call to process()
michael@0 377 //--------------------------------------------------------------------------------------------------
michael@0 378 // command format:
michael@0 379 // size: 0
michael@0 380 // data: N/A
michael@0 381 //--------------------------------------------------------------------------------------------------
michael@0 382 // reply format:
michael@0 383 // size: sizeof(int)
michael@0 384 // data: status
michael@0 385 //==================================================================================================
michael@0 386 // command: EFFECT_CMD_SET_PARAM
michael@0 387 //--------------------------------------------------------------------------------------------------
michael@0 388 // description:
michael@0 389 // Set a parameter and apply it immediately
michael@0 390 //--------------------------------------------------------------------------------------------------
michael@0 391 // command format:
michael@0 392 // size: sizeof(effect_param_t) + size of param and value
michael@0 393 // data: effect_param_t + param + value. See effect_param_t definition below for value offset
michael@0 394 //--------------------------------------------------------------------------------------------------
michael@0 395 // reply format:
michael@0 396 // size: sizeof(int)
michael@0 397 // data: status
michael@0 398 //==================================================================================================
michael@0 399 // command: EFFECT_CMD_SET_PARAM_DEFERRED
michael@0 400 //--------------------------------------------------------------------------------------------------
michael@0 401 // description:
michael@0 402 // Set a parameter but apply it only when receiving EFFECT_CMD_SET_PARAM_COMMIT command
michael@0 403 //--------------------------------------------------------------------------------------------------
michael@0 404 // command format:
michael@0 405 // size: sizeof(effect_param_t) + size of param and value
michael@0 406 // data: effect_param_t + param + value. See effect_param_t definition below for value offset
michael@0 407 //--------------------------------------------------------------------------------------------------
michael@0 408 // reply format:
michael@0 409 // size: 0
michael@0 410 // data: N/A
michael@0 411 //==================================================================================================
michael@0 412 // command: EFFECT_CMD_SET_PARAM_COMMIT
michael@0 413 //--------------------------------------------------------------------------------------------------
michael@0 414 // description:
michael@0 415 // Apply all previously received EFFECT_CMD_SET_PARAM_DEFERRED commands
michael@0 416 //--------------------------------------------------------------------------------------------------
michael@0 417 // command format:
michael@0 418 // size: 0
michael@0 419 // data: N/A
michael@0 420 //--------------------------------------------------------------------------------------------------
michael@0 421 // reply format:
michael@0 422 // size: sizeof(int)
michael@0 423 // data: status
michael@0 424 //==================================================================================================
michael@0 425 // command: EFFECT_CMD_GET_PARAM
michael@0 426 //--------------------------------------------------------------------------------------------------
michael@0 427 // description:
michael@0 428 // Get a parameter value
michael@0 429 //--------------------------------------------------------------------------------------------------
michael@0 430 // command format:
michael@0 431 // size: sizeof(effect_param_t) + size of param
michael@0 432 // data: effect_param_t + param
michael@0 433 //--------------------------------------------------------------------------------------------------
michael@0 434 // reply format:
michael@0 435 // size: sizeof(effect_param_t) + size of param and value
michael@0 436 // data: effect_param_t + param + value. See effect_param_t definition below for value offset
michael@0 437 //==================================================================================================
michael@0 438 // command: EFFECT_CMD_SET_DEVICE
michael@0 439 //--------------------------------------------------------------------------------------------------
michael@0 440 // description:
michael@0 441 // Set the rendering device the audio output path is connected to. See audio_device_e for device
michael@0 442 // values.
michael@0 443 // The effect implementation must set EFFECT_FLAG_DEVICE_IND flag in its descriptor to receive this
michael@0 444 // command when the device changes
michael@0 445 //--------------------------------------------------------------------------------------------------
michael@0 446 // command format:
michael@0 447 // size: sizeof(uint32_t)
michael@0 448 // data: audio_device_e
michael@0 449 //--------------------------------------------------------------------------------------------------
michael@0 450 // reply format:
michael@0 451 // size: 0
michael@0 452 // data: N/A
michael@0 453 //==================================================================================================
michael@0 454 // command: EFFECT_CMD_SET_VOLUME
michael@0 455 //--------------------------------------------------------------------------------------------------
michael@0 456 // description:
michael@0 457 // Set and get volume. Used by audio framework to delegate volume control to effect engine.
michael@0 458 // The effect implementation must set EFFECT_FLAG_VOLUME_IND or EFFECT_FLAG_VOLUME_CTRL flag in
michael@0 459 // its descriptor to receive this command before every call to process() function
michael@0 460 // If EFFECT_FLAG_VOLUME_CTRL flag is set in the effect descriptor, the effect engine must return
michael@0 461 // the volume that should be applied before the effect is processed. The overall volume (the volume
michael@0 462 // actually applied by the effect engine multiplied by the returned value) should match the value
michael@0 463 // indicated in the command.
michael@0 464 //--------------------------------------------------------------------------------------------------
michael@0 465 // command format:
michael@0 466 // size: n * sizeof(uint32_t)
michael@0 467 // data: volume for each channel defined in effect_config_t for output buffer expressed in
michael@0 468 // 8.24 fixed point format
michael@0 469 //--------------------------------------------------------------------------------------------------
michael@0 470 // reply format:
michael@0 471 // size: n * sizeof(uint32_t) / 0
michael@0 472 // data: - if EFFECT_FLAG_VOLUME_CTRL is set in effect descriptor:
michael@0 473 // volume for each channel defined in effect_config_t for output buffer expressed in
michael@0 474 // 8.24 fixed point format
michael@0 475 // - if EFFECT_FLAG_VOLUME_CTRL is not set in effect descriptor:
michael@0 476 // N/A
michael@0 477 // It is legal to receive a null pointer as pReplyData in which case the effect framework has
michael@0 478 // delegated volume control to another effect
michael@0 479 //==================================================================================================
michael@0 480 // command: EFFECT_CMD_SET_AUDIO_MODE
michael@0 481 //--------------------------------------------------------------------------------------------------
michael@0 482 // description:
michael@0 483 // Set the audio mode. The effect implementation must set EFFECT_FLAG_AUDIO_MODE_IND flag in its
michael@0 484 // descriptor to receive this command when the audio mode changes.
michael@0 485 //--------------------------------------------------------------------------------------------------
michael@0 486 // command format:
michael@0 487 // size: sizeof(uint32_t)
michael@0 488 // data: audio_mode_e
michael@0 489 //--------------------------------------------------------------------------------------------------
michael@0 490 // reply format:
michael@0 491 // size: 0
michael@0 492 // data: N/A
michael@0 493 //==================================================================================================
michael@0 494 // command: EFFECT_CMD_FIRST_PROPRIETARY
michael@0 495 //--------------------------------------------------------------------------------------------------
michael@0 496 // description:
michael@0 497 // All proprietary effect commands must use command codes above this value. The size and format of
michael@0 498 // command and response fields is free in this case
michael@0 499 //==================================================================================================
michael@0 500
michael@0 501
michael@0 502 // Audio buffer descriptor used by process(), bufferProvider() functions and buffer_config_t
michael@0 503 // structure. Multi-channel audio is always interleaved. The channel order is from LSB to MSB with
michael@0 504 // regard to the channel mask definition in audio_channels_e e.g :
michael@0 505 // Stereo: left, right
michael@0 506 // 5 point 1: front left, front right, front center, low frequency, back left, back right
michael@0 507 // The buffer size is expressed in frame count, a frame being composed of samples for all
michael@0 508 // channels at a given time. Frame size for unspecified format (AUDIO_FORMAT_OTHER) is 8 bit by
michael@0 509 // definition
michael@0 510 struct audio_buffer_s {
michael@0 511 size_t frameCount; // number of frames in buffer
michael@0 512 union {
michael@0 513 void* raw; // raw pointer to start of buffer
michael@0 514 int32_t* s32; // pointer to signed 32 bit data at start of buffer
michael@0 515 int16_t* s16; // pointer to signed 16 bit data at start of buffer
michael@0 516 uint8_t* u8; // pointer to unsigned 8 bit data at start of buffer
michael@0 517 };
michael@0 518 };
michael@0 519
michael@0 520 // The buffer_provider_s structure contains functions that can be used
michael@0 521 // by the effect engine process() function to query and release input
michael@0 522 // or output audio buffer.
michael@0 523 // The getBuffer() function is called to retrieve a buffer where data
michael@0 524 // should read from or written to by process() function.
michael@0 525 // The releaseBuffer() function MUST be called when the buffer retrieved
michael@0 526 // with getBuffer() is not needed anymore.
michael@0 527 // The process function should use the buffer provider mechanism to retrieve
michael@0 528 // input or output buffer if the inBuffer or outBuffer passed as argument is NULL
michael@0 529 // and the buffer configuration (buffer_config_t) given by the EFFECT_CMD_CONFIGURE
michael@0 530 // command did not specify an audio buffer.
michael@0 531
michael@0 532 typedef int32_t (* buffer_function_t)(void *cookie, audio_buffer_t *buffer);
michael@0 533
michael@0 534 typedef struct buffer_provider_s {
michael@0 535 buffer_function_t getBuffer; // retrieve next buffer
michael@0 536 buffer_function_t releaseBuffer; // release used buffer
michael@0 537 void *cookie; // for use by client of buffer provider functions
michael@0 538 } buffer_provider_t;
michael@0 539
michael@0 540
michael@0 541 // The buffer_config_s structure specifies the input or output audio format
michael@0 542 // to be used by the effect engine. It is part of the effect_config_t
michael@0 543 // structure that defines both input and output buffer configurations and is
michael@0 544 // passed by the EFFECT_CMD_CONFIGURE command.
michael@0 545 typedef struct buffer_config_s {
michael@0 546 audio_buffer_t buffer; // buffer for use by process() function if not passed explicitly
michael@0 547 uint32_t samplingRate; // sampling rate
michael@0 548 uint32_t channels; // channel mask (see audio_channels_e)
michael@0 549 buffer_provider_t bufferProvider; // buffer provider
michael@0 550 uint8_t format; // Audio format (see audio_format_e)
michael@0 551 uint8_t accessMode; // read/write or accumulate in buffer (effect_buffer_access_e)
michael@0 552 uint16_t mask; // indicates which of the above fields is valid
michael@0 553 } buffer_config_t;
michael@0 554
michael@0 555 // Sample format
michael@0 556 enum audio_format_e {
michael@0 557 SAMPLE_FORMAT_PCM_S15, // PCM signed 16 bits
michael@0 558 SAMPLE_FORMAT_PCM_U8, // PCM unsigned 8 bits
michael@0 559 SAMPLE_FORMAT_PCM_S7_24, // PCM signed 7.24 fixed point representation
michael@0 560 SAMPLE_FORMAT_OTHER // other format (e.g. compressed)
michael@0 561 };
michael@0 562
michael@0 563 // Channel mask
michael@0 564 enum audio_channels_e {
michael@0 565 CHANNEL_FRONT_LEFT = 0x1, // front left channel
michael@0 566 CHANNEL_FRONT_RIGHT = 0x2, // front right channel
michael@0 567 CHANNEL_FRONT_CENTER = 0x4, // front center channel
michael@0 568 CHANNEL_LOW_FREQUENCY = 0x8, // low frequency channel
michael@0 569 CHANNEL_BACK_LEFT = 0x10, // back left channel
michael@0 570 CHANNEL_BACK_RIGHT = 0x20, // back right channel
michael@0 571 CHANNEL_FRONT_LEFT_OF_CENTER = 0x40, // front left of center channel
michael@0 572 CHANNEL_FRONT_RIGHT_OF_CENTER = 0x80, // front right of center channel
michael@0 573 CHANNEL_BACK_CENTER = 0x100, // back center channel
michael@0 574 CHANNEL_MONO = CHANNEL_FRONT_LEFT,
michael@0 575 CHANNEL_STEREO = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT),
michael@0 576 CHANNEL_QUAD = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT |
michael@0 577 CHANNEL_BACK_LEFT | CHANNEL_BACK_RIGHT),
michael@0 578 CHANNEL_SURROUND = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT |
michael@0 579 CHANNEL_FRONT_CENTER | CHANNEL_BACK_CENTER),
michael@0 580 CHANNEL_5POINT1 = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT |
michael@0 581 CHANNEL_FRONT_CENTER | CHANNEL_LOW_FREQUENCY | CHANNEL_BACK_LEFT | CHANNEL_BACK_RIGHT),
michael@0 582 CHANNEL_7POINT1 = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT |
michael@0 583 CHANNEL_FRONT_CENTER | CHANNEL_LOW_FREQUENCY | CHANNEL_BACK_LEFT | CHANNEL_BACK_RIGHT |
michael@0 584 CHANNEL_FRONT_LEFT_OF_CENTER | CHANNEL_FRONT_RIGHT_OF_CENTER),
michael@0 585 };
michael@0 586
michael@0 587 // Render device
michael@0 588 enum audio_device_e {
michael@0 589 DEVICE_EARPIECE = 0x1, // earpiece
michael@0 590 DEVICE_SPEAKER = 0x2, // speaker
michael@0 591 DEVICE_WIRED_HEADSET = 0x4, // wired headset, with microphone
michael@0 592 DEVICE_WIRED_HEADPHONE = 0x8, // wired headphone, without microphone
michael@0 593 DEVICE_BLUETOOTH_SCO = 0x10, // generic bluetooth SCO
michael@0 594 DEVICE_BLUETOOTH_SCO_HEADSET = 0x20, // bluetooth SCO headset
michael@0 595 DEVICE_BLUETOOTH_SCO_CARKIT = 0x40, // bluetooth SCO car kit
michael@0 596 DEVICE_BLUETOOTH_A2DP = 0x80, // generic bluetooth A2DP
michael@0 597 DEVICE_BLUETOOTH_A2DP_HEADPHONES = 0x100, // bluetooth A2DP headphones
michael@0 598 DEVICE_BLUETOOTH_A2DP_SPEAKER = 0x200, // bluetooth A2DP speakers
michael@0 599 DEVICE_AUX_DIGITAL = 0x400, // digital output
michael@0 600 DEVICE_EXTERNAL_SPEAKER = 0x800 // external speaker (stereo and High quality)
michael@0 601 };
michael@0 602
michael@0 603 #if ANDROID_VERSION < 17
michael@0 604 // Audio mode
michael@0 605 enum audio_mode_e {
michael@0 606 AUDIO_MODE_NORMAL, // device idle
michael@0 607 AUDIO_MODE_RINGTONE, // device ringing
michael@0 608 AUDIO_MODE_IN_CALL // audio call connected (VoIP or telephony)
michael@0 609 };
michael@0 610 #endif
michael@0 611
michael@0 612 // Values for "accessMode" field of buffer_config_t:
michael@0 613 // overwrite, read only, accumulate (read/modify/write)
michael@0 614 enum effect_buffer_access_e {
michael@0 615 EFFECT_BUFFER_ACCESS_WRITE,
michael@0 616 EFFECT_BUFFER_ACCESS_READ,
michael@0 617 EFFECT_BUFFER_ACCESS_ACCUMULATE
michael@0 618
michael@0 619 };
michael@0 620
michael@0 621 // Values for bit field "mask" in buffer_config_t. If a bit is set, the corresponding field
michael@0 622 // in buffer_config_t must be taken into account when executing the EFFECT_CMD_CONFIGURE command
michael@0 623 #define EFFECT_CONFIG_BUFFER 0x0001 // buffer field must be taken into account
michael@0 624 #define EFFECT_CONFIG_SMP_RATE 0x0002 // samplingRate field must be taken into account
michael@0 625 #define EFFECT_CONFIG_CHANNELS 0x0004 // channels field must be taken into account
michael@0 626 #define EFFECT_CONFIG_FORMAT 0x0008 // format field must be taken into account
michael@0 627 #define EFFECT_CONFIG_ACC_MODE 0x0010 // accessMode field must be taken into account
michael@0 628 #define EFFECT_CONFIG_PROVIDER 0x0020 // bufferProvider field must be taken into account
michael@0 629 #define EFFECT_CONFIG_ALL (EFFECT_CONFIG_BUFFER | EFFECT_CONFIG_SMP_RATE | \
michael@0 630 EFFECT_CONFIG_CHANNELS | EFFECT_CONFIG_FORMAT | \
michael@0 631 EFFECT_CONFIG_ACC_MODE | EFFECT_CONFIG_PROVIDER)
michael@0 632
michael@0 633
michael@0 634 // effect_config_s structure describes the format of the pCmdData argument of EFFECT_CMD_CONFIGURE
michael@0 635 // command to configure audio parameters and buffers for effect engine input and output.
michael@0 636 typedef struct effect_config_s {
michael@0 637 buffer_config_t inputCfg;
michael@0 638 buffer_config_t outputCfg;;
michael@0 639 } effect_config_t;
michael@0 640
michael@0 641
michael@0 642 // effect_param_s structure describes the format of the pCmdData argument of EFFECT_CMD_SET_PARAM
michael@0 643 // command and pCmdData and pReplyData of EFFECT_CMD_GET_PARAM command.
michael@0 644 // psize and vsize represent the actual size of parameter and value.
michael@0 645 //
michael@0 646 // NOTE: the start of value field inside the data field is always on a 32 bit boundary:
michael@0 647 //
michael@0 648 // +-----------+
michael@0 649 // | status | sizeof(int)
michael@0 650 // +-----------+
michael@0 651 // | psize | sizeof(int)
michael@0 652 // +-----------+
michael@0 653 // | vsize | sizeof(int)
michael@0 654 // +-----------+
michael@0 655 // | | | |
michael@0 656 // ~ parameter ~ > psize |
michael@0 657 // | | | > ((psize - 1)/sizeof(int) + 1) * sizeof(int)
michael@0 658 // +-----------+ |
michael@0 659 // | padding | |
michael@0 660 // +-----------+
michael@0 661 // | | |
michael@0 662 // ~ value ~ > vsize
michael@0 663 // | | |
michael@0 664 // +-----------+
michael@0 665
michael@0 666 typedef struct effect_param_s {
michael@0 667 int32_t status; // Transaction status (unused for command, used for reply)
michael@0 668 uint32_t psize; // Parameter size
michael@0 669 uint32_t vsize; // Value size
michael@0 670 char data[]; // Start of Parameter + Value data
michael@0 671 } effect_param_t;
michael@0 672
michael@0 673
michael@0 674 /////////////////////////////////////////////////
michael@0 675 // Effect library interface
michael@0 676 /////////////////////////////////////////////////
michael@0 677
michael@0 678 // An effect library is required to implement and expose the following functions
michael@0 679 // to enable effect enumeration and instantiation. The name of these functions must be as
michael@0 680 // specified here as the effect framework will get the function address with dlsym():
michael@0 681 //
michael@0 682 // - effect_QueryNumberEffects_t EffectQueryNumberEffects;
michael@0 683 // - effect_QueryEffect_t EffectQueryEffect;
michael@0 684 // - effect_CreateEffect_t EffectCreate;
michael@0 685 // - effect_ReleaseEffect_t EffectRelease;
michael@0 686
michael@0 687
michael@0 688 ////////////////////////////////////////////////////////////////////////////////
michael@0 689 //
michael@0 690 // Function: EffectQueryNumberEffects
michael@0 691 //
michael@0 692 // Description: Returns the number of different effects exposed by the
michael@0 693 // library. Each effect must have a unique effect uuid (see
michael@0 694 // effect_descriptor_t). This function together with EffectQueryEffect()
michael@0 695 // is used to enumerate all effects present in the library.
michael@0 696 //
michael@0 697 // Input/Output:
michael@0 698 // pNumEffects: address where the number of effects should be returned.
michael@0 699 //
michael@0 700 // Output:
michael@0 701 // returned value: 0 successful operation.
michael@0 702 // -ENODEV library failed to initialize
michael@0 703 // -EINVAL invalid pNumEffects
michael@0 704 // *pNumEffects: updated with number of effects in library
michael@0 705 //
michael@0 706 ////////////////////////////////////////////////////////////////////////////////
michael@0 707 typedef int32_t (*effect_QueryNumberEffects_t)(uint32_t *pNumEffects);
michael@0 708
michael@0 709 ////////////////////////////////////////////////////////////////////////////////
michael@0 710 //
michael@0 711 // Function: EffectQueryEffect
michael@0 712 //
michael@0 713 // Description: Returns the descriptor of the effect engine which index is
michael@0 714 // given as first argument.
michael@0 715 // See effect_descriptor_t for details on effect descriptors.
michael@0 716 // This function together with EffectQueryNumberEffects() is used to enumerate all
michael@0 717 // effects present in the library. The enumeration sequence is:
michael@0 718 // EffectQueryNumberEffects(&num_effects);
michael@0 719 // for (i = 0; i < num_effects; i++)
michael@0 720 // EffectQueryEffect(i,...);
michael@0 721 //
michael@0 722 // Input/Output:
michael@0 723 // index: index of the effect
michael@0 724 // pDescriptor: address where to return the effect descriptor.
michael@0 725 //
michael@0 726 // Output:
michael@0 727 // returned value: 0 successful operation.
michael@0 728 // -ENODEV library failed to initialize
michael@0 729 // -EINVAL invalid pDescriptor or index
michael@0 730 // -ENOSYS effect list has changed since last execution of
michael@0 731 // EffectQueryNumberEffects()
michael@0 732 // -ENOENT no more effect available
michael@0 733 // *pDescriptor: updated with the effect descriptor.
michael@0 734 //
michael@0 735 ////////////////////////////////////////////////////////////////////////////////
michael@0 736 typedef int32_t (*effect_QueryEffect_t)(uint32_t index,
michael@0 737 effect_descriptor_t *pDescriptor);
michael@0 738
michael@0 739 ////////////////////////////////////////////////////////////////////////////////
michael@0 740 //
michael@0 741 // Function: EffectCreate
michael@0 742 //
michael@0 743 // Description: Creates an effect engine of the specified type and returns an
michael@0 744 // effect control interface on this engine. The function will allocate the
michael@0 745 // resources for an instance of the requested effect engine and return
michael@0 746 // a handle on the effect control interface.
michael@0 747 //
michael@0 748 // Input:
michael@0 749 // uuid: pointer to the effect uuid.
michael@0 750 // sessionId: audio session to which this effect instance will be attached. All effects
michael@0 751 // created with the same session ID are connected in series and process the same signal
michael@0 752 // stream. Knowing that two effects are part of the same effect chain can help the
michael@0 753 // library implement some kind of optimizations.
michael@0 754 // ioId: identifies the output or input stream this effect is directed to at audio HAL.
michael@0 755 // For future use especially with tunneled HW accelerated effects
michael@0 756 //
michael@0 757 // Input/Output:
michael@0 758 // pInterface: address where to return the effect interface.
michael@0 759 //
michael@0 760 // Output:
michael@0 761 // returned value: 0 successful operation.
michael@0 762 // -ENODEV library failed to initialize
michael@0 763 // -EINVAL invalid pEffectUuid or pInterface
michael@0 764 // -ENOENT no effect with this uuid found
michael@0 765 // *pInterface: updated with the effect interface handle.
michael@0 766 //
michael@0 767 ////////////////////////////////////////////////////////////////////////////////
michael@0 768 typedef int32_t (*effect_CreateEffect_t)(effect_uuid_t *uuid,
michael@0 769 int32_t sessionId,
michael@0 770 int32_t ioId,
michael@0 771 effect_interface_t *pInterface);
michael@0 772
michael@0 773 ////////////////////////////////////////////////////////////////////////////////
michael@0 774 //
michael@0 775 // Function: EffectRelease
michael@0 776 //
michael@0 777 // Description: Releases the effect engine whose handle is given as argument.
michael@0 778 // All resources allocated to this particular instance of the effect are
michael@0 779 // released.
michael@0 780 //
michael@0 781 // Input:
michael@0 782 // interface: handle on the effect interface to be released.
michael@0 783 //
michael@0 784 // Output:
michael@0 785 // returned value: 0 successful operation.
michael@0 786 // -ENODEV library failed to initialize
michael@0 787 // -EINVAL invalid interface handle
michael@0 788 //
michael@0 789 ////////////////////////////////////////////////////////////////////////////////
michael@0 790 typedef int32_t (*effect_ReleaseEffect_t)(effect_interface_t interface);
michael@0 791
michael@0 792
michael@0 793 #if __cplusplus
michael@0 794 } // extern "C"
michael@0 795 #endif
michael@0 796
michael@0 797
michael@0 798 #endif /*ANDROID_EFFECTAPI_H_*/

mercurial