Eric Laurent | 5fe37c6 | 2010-05-21 06:05:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | #ifndef ANDROID_EFFECTAPI_H_ |
| 18 | #define ANDROID_EFFECTAPI_H_ |
| 19 | |
| 20 | #include <errno.h> |
| 21 | #include <stdint.h> |
| 22 | #include <sys/types.h> |
| 23 | #include <media/AudioCommon.h> |
| 24 | |
| 25 | #if __cplusplus |
| 26 | extern "C" { |
| 27 | #endif |
| 28 | |
| 29 | ///////////////////////////////////////////////// |
| 30 | // Effect control interface |
| 31 | ///////////////////////////////////////////////// |
| 32 | |
| 33 | // The effect control interface is exposed by each effect engine implementation. It consists of |
| 34 | // a set of functions controlling the configuration, activation and process of the engine. |
| 35 | // The functions are grouped in a structure of type effect_interface_s: |
| 36 | // struct effect_interface_s { |
| 37 | // effect_process_t process; |
| 38 | // effect_command_t command; |
| 39 | // }; |
| 40 | |
| 41 | |
| 42 | // effect_interface_t: Effect control interface handle. |
| 43 | // The effect_interface_t serves two purposes regarding the implementation of the effect engine: |
| 44 | // - 1 it is the address of a pointer to an effect_interface_s structure where the functions |
| 45 | // of the effect control API for a particular effect are located. |
| 46 | // - 2 it is the address of the context of a particular effect instance. |
| 47 | // A typical implementation in the effect library would define a structure as follows: |
| 48 | // struct effect_module_s { |
| 49 | // const struct effect_interface_s *itfe; |
| 50 | // effect_config_t config; |
| 51 | // effect_context_t context; |
| 52 | // } |
| 53 | // The implementation of EffectCreate() function would then allocate a structure of this |
| 54 | // type and return its address as effect_interface_t |
| 55 | typedef struct effect_interface_s **effect_interface_t; |
| 56 | |
| 57 | |
| 58 | // Effect API version 1.0 |
| 59 | #define EFFECT_API_VERSION 0x0100 // Format 0xMMmm MM: Major version, mm: minor version |
| 60 | |
| 61 | // Maximum length of character strings in structures defines by this API. |
| 62 | #define EFFECT_STRING_LEN_MAX 64 |
| 63 | |
| 64 | // |
| 65 | //--- Effect descriptor structure effect_descriptor_t |
| 66 | // |
| 67 | |
| 68 | // Unique effect ID (can be generated from the following site: http://www.itu.int/ITU-T/asn1/uuid.html) |
| 69 | // This format is used for both "type" and "uuid" fields of the effect descriptor structure. |
| 70 | // - When used for effect type and the engine is implementing and effect corresponding to a standard OpenSL ES |
| 71 | // interface, this ID must be the one defined in OpenSLES_IID.h for that interface. |
| 72 | // - When used as uuid, it should be a unique UUID for this particular implementation. |
| 73 | typedef struct effect_uuid_s { |
| 74 | uint32_t timeLow; |
| 75 | uint16_t timeMid; |
| 76 | uint16_t timeHiAndVersion; |
| 77 | uint16_t clockSeq; |
| 78 | uint8_t node[6]; |
| 79 | } effect_uuid_t; |
| 80 | |
| 81 | // NULL UUID definition (matches SL_IID_NULL_) |
| 82 | #define EFFECT_UUID_INITIALIZER { 0xec7178ec, 0xe5e1, 0x4432, 0xa3f4, { 0x46, 0x57, 0xe6, 0x79, 0x52, 0x10 } } |
| 83 | static const effect_uuid_t EFFECT_UUID_NULL_ = EFFECT_UUID_INITIALIZER; |
| 84 | const effect_uuid_t * const EFFECT_UUID_NULL = &EFFECT_UUID_NULL_; |
| 85 | const char * const EFFECT_UUID_NULL_STR = "ec7178ec-e5e1-4432-a3f4-4657e6795210"; |
| 86 | |
| 87 | // the effect descriptor contains necessary information to facilitate the enumeration of the effect |
| 88 | // engines present in a library. |
| 89 | typedef struct effect_descriptor_s { |
| 90 | effect_uuid_t type; // UUID corresponding to the OpenSL ES interface implemented by this effect |
| 91 | effect_uuid_t uuid; // UUID for this particular implementation |
| 92 | uint16_t apiVersion; // Version of the effect API implemented: must match current EFFECT_API_VERSION |
| 93 | uint32_t flags; // effect engine capabilities/requirements flags (see below) |
| 94 | char name[EFFECT_STRING_LEN_MAX] ; // human readable effect name |
| 95 | char implementor[EFFECT_STRING_LEN_MAX] ; // human readable effect implementor name |
| 96 | } effect_descriptor_t; |
| 97 | |
| 98 | // definitions for flags field of effect descriptor. |
| 99 | // +---------------------------+-----------+----------------------------------- |
| 100 | // | description | bits | values |
| 101 | // +---------------------------+-----------+----------------------------------- |
| 102 | // | connection mode | 0..1 | 0 insert: after track process |
| 103 | // | | | 1 auxiliary: connect to track auxiliary |
| 104 | // | | | output and use send level |
| 105 | // | | | 2 replace: replaces track process function; |
| 106 | // | | | must implement SRC, volume and mono to stereo. |
| 107 | // | | | 3 reserved |
| 108 | // +---------------------------+-----------+----------------------------------- |
| 109 | // | insertion preference | 2..4 | 0 none |
| 110 | // | | | 1 first of the chain |
| 111 | // | | | 2 last of the chain |
| 112 | // | | | 3 exclusive (only effect in the insert chain) |
| 113 | // | | | 4..7 reserved |
| 114 | // +---------------------------+-----------+----------------------------------- |
| 115 | // | Volume management | 5..6 | 0 none |
| 116 | // | | | 1 implements volume control |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 117 | // | | | 2 requires volume indication |
| 118 | // | | | 3 reserved |
Eric Laurent | 5fe37c6 | 2010-05-21 06:05:13 -0700 | [diff] [blame] | 119 | // +---------------------------+-----------+----------------------------------- |
| 120 | // | Device management | 7..8 | 0 none |
| 121 | // | | | 1 requires device updates |
| 122 | // | | | 2..3 reserved |
| 123 | // +---------------------------+-----------+----------------------------------- |
| 124 | // | Sample input mode | 9..10 | 0 direct: process() function or EFFECT_CMD_CONFIGURE |
| 125 | // | | | command must specify a buffer descriptor |
| 126 | // | | | 1 provider: process() function uses the |
| 127 | // | | | bufferProvider indicated by the |
| 128 | // | | | EFFECT_CMD_CONFIGURE command to request input buffers. |
| 129 | // | | | 2 both: both input modes are supported |
| 130 | // | | | 3 reserved |
| 131 | // +---------------------------+-----------+----------------------------------- |
| 132 | // | Sample output mode | 11..12 | 0 direct: process() function or EFFECT_CMD_CONFIGURE |
| 133 | // | | | command must specify a buffer descriptor |
| 134 | // | | | 1 provider: process() function uses the |
| 135 | // | | | bufferProvider indicated by the |
| 136 | // | | | EFFECT_CMD_CONFIGURE command to request output buffers. |
| 137 | // | | | 2 both: both output modes are supported |
| 138 | // | | | 3 reserved |
| 139 | // +---------------------------+-----------+----------------------------------- |
| 140 | |
| 141 | // insert mode |
| 142 | #define EFFECT_FLAG_TYPE_MASK 0x00000003 |
| 143 | #define EFFECT_FLAG_TYPE_INSERT 0x00000000 |
| 144 | #define EFFECT_FLAG_TYPE_AUXILIARY 0x00000001 |
| 145 | #define EFFECT_FLAG_TYPE_REPLACE 0x00000002 |
| 146 | |
| 147 | // insert preference |
| 148 | #define EFFECT_FLAG_INSERT_MASK 0x0000001C |
| 149 | #define EFFECT_FLAG_INSERT_ANY 0x00000000 |
| 150 | #define EFFECT_FLAG_INSERT_FIRST 0x00000004 |
| 151 | #define EFFECT_FLAG_INSERT_LAST 0x00000008 |
| 152 | #define EFFECT_FLAG_INSERT_EXCLUSIVE 0x0000000C |
| 153 | |
| 154 | |
| 155 | // volume control |
| 156 | #define EFFECT_FLAG_VOLUME_MASK 0x00000060 |
| 157 | #define EFFECT_FLAG_VOLUME_CTRL 0x00000020 |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 158 | #define EFFECT_FLAG_VOLUME_IND 0x00000040 |
Eric Laurent | 5fe37c6 | 2010-05-21 06:05:13 -0700 | [diff] [blame] | 159 | #define EFFECT_FLAG_VOLUME_NONE 0x00000000 |
| 160 | |
| 161 | // device control |
| 162 | #define EFFECT_FLAG_DEVICE_MASK 0x00000180 |
| 163 | #define EFFECT_FLAG_DEVICE_IND 0x00000080 |
| 164 | #define EFFECT_FLAG_DEVICE_NONE 0x00000000 |
| 165 | |
| 166 | // sample input modes |
| 167 | #define EFFECT_FLAG_INPUT_MASK 0x00000600 |
| 168 | #define EFFECT_FLAG_INPUT_DIRECT 0x00000000 |
| 169 | #define EFFECT_FLAG_INPUT_PROVIDER 0x00000200 |
| 170 | #define EFFECT_FLAG_INPUT_BOTH 0x00000400 |
| 171 | |
| 172 | // sample output modes |
| 173 | #define EFFECT_FLAG_OUTPUT_MASK 0x00001800 |
| 174 | #define EFFECT_FLAG_OUTPUT_DIRECT 0x00000000 |
| 175 | #define EFFECT_FLAG_OUTPUT_PROVIDER 0x00000800 |
| 176 | #define EFFECT_FLAG_OUTPUT_BOTH 0x00001000 |
| 177 | |
| 178 | // forward definition of type audio_buffer_t |
| 179 | typedef struct audio_buffer_s audio_buffer_t; |
| 180 | |
| 181 | //////////////////////////////////////////////////////////////////////////////// |
| 182 | // |
| 183 | // Function: process |
| 184 | // |
| 185 | // Description: Effect process function. Takes input samples as specified |
| 186 | // (count and location) in input buffer descriptor and output processed |
| 187 | // samples as specified in output buffer descriptor. If the buffer descriptor |
| 188 | // is not specified the function must use either the buffer or the |
| 189 | // buffer provider function installed by the EFFECT_CMD_CONFIGURE command. |
| 190 | // |
| 191 | // NOTE: the process() function implementation should be "real-time safe" that is |
| 192 | // it should not perform blocking calls: malloc/free, sleep, read/write/open/close, |
| 193 | // pthread_cond_wait/pthread_mutex_lock... |
| 194 | // |
| 195 | // Input: |
| 196 | // effect_interface_t: handle to the effect interface this function |
| 197 | // is called on. |
| 198 | // inBuffer: buffer descriptor indicating where to read samples to process. |
| 199 | // If NULL, use the configuration passed by EFFECT_CMD_CONFIGURE command. |
| 200 | // |
| 201 | // inBuffer: buffer descriptor indicating where to write processed samples. |
| 202 | // If NULL, use the configuration passed by EFFECT_CMD_CONFIGURE command. |
| 203 | // |
| 204 | // Output: |
| 205 | // returned value: 0 successful operation |
| 206 | // -EINVAL invalid interface handle or |
| 207 | // invalid input/output buffer description |
| 208 | //////////////////////////////////////////////////////////////////////////////// |
| 209 | typedef int32_t (*effect_process_t)(effect_interface_t self, audio_buffer_t *inBuffer, audio_buffer_t *outBuffer); |
| 210 | |
| 211 | //////////////////////////////////////////////////////////////////////////////// |
| 212 | // |
| 213 | // Function: command |
| 214 | // |
| 215 | // Description: Send a command and receive a response to/from effect engine. |
| 216 | // |
| 217 | // Input: |
| 218 | // effect_interface_t: handle to the effect interface this function |
| 219 | // is called on. |
| 220 | // cmdCode: command code: the command can be a standardized command defined in |
| 221 | // effect_command_e (see below) or a proprietary command. |
| 222 | // cmdSize: size of command in bytes |
| 223 | // pCmdData: pointer to command data |
| 224 | // pReplyData: pointer to reply data |
| 225 | // |
| 226 | // Input/Output: |
| 227 | // replySize: maximum size of reply data as input |
| 228 | // actual size of reply data as output |
| 229 | // |
| 230 | // Output: |
| 231 | // returned value: 0 successful operation |
| 232 | // -EINVAL invalid interface handle or |
| 233 | // invalid command/reply size or format according to command code |
| 234 | // The return code should be restricted to indicate problems related to the this |
| 235 | // API specification. Status related to the execution of a particular command should be |
| 236 | // indicated as part of the reply field. |
| 237 | // |
| 238 | // *pReplyData updated with command response |
| 239 | // |
| 240 | //////////////////////////////////////////////////////////////////////////////// |
| 241 | typedef int32_t (*effect_command_t)(effect_interface_t self, int32_t cmdCode, int32_t cmdSize, void *pCmdData, int32_t *replySize, void *pReplyData); |
| 242 | |
| 243 | |
| 244 | // Effect control interface definition |
| 245 | struct effect_interface_s { |
| 246 | effect_process_t process; |
| 247 | effect_command_t command; |
| 248 | }; |
| 249 | |
| 250 | |
| 251 | //--- Standardized command codes for command function |
| 252 | // +--------------------------------+-------------------------------+-------------------------------+-------------------------- |
| 253 | // | description | command code | command format | reply format |
| 254 | // +--------------------------------+-------------------------------+-------------------------------+-------------------------- |
| 255 | // | Initialize effect engine: | EFFECT_CMD_INIT | size: 0 | size: sizeof(int) |
| 256 | // | All configurations return to | | data: N/A | data: status |
| 257 | // | default | | | |
| 258 | // +--------------------------------+-------------------------------+-------------------------------+-------------------------- |
| 259 | // | Apply new audio parameters | EFFECT_CMD_CONFIGURE | size: sizeof(effect_config_t) | size: sizeof(int) |
| 260 | // | configurations for input and | | data: effect_config_t | data: status |
| 261 | // | output buffers | | | |
| 262 | // +--------------------------------+-------------------------------+-------------------------------+-------------------------- |
| 263 | // | Reset effect engine: keep | EFFECT_CMD_RESET | size: 0 | size: 0 |
| 264 | // | configuration but reset state | | data: N/A | data: N/A |
| 265 | // | and buffer content. | | | |
| 266 | // | Called by the framework before | | | |
| 267 | // | enabling the effect | | | |
| 268 | // +--------------------------------+-------------------------------+-------------------------------+-------------------------- |
| 269 | // | Enable the process | EFFECT_CMD_ENABLE | size: 0 | size: sizeof(int) |
| 270 | // | Called by the framework before | | data: N/A | data: status |
| 271 | // | the first call to process() | | | |
| 272 | // +--------------------------------+-------------------------------+-------------------------------+-------------------------- |
| 273 | // | Disable the process | EFFECT_CMD_DISABLE | size: 0 | size: sizeof(int) |
| 274 | // | Called by the framework after | | data: N/A | data: status |
| 275 | // | the last call to process() | | | |
| 276 | // +--------------------------------+-------------------------------+-------------------------------+-------------------------- |
| 277 | // | Set a parameter and apply it | EFFECT_CMD_SET_PARAM | size: sizeof(effect_param_t) | size: sizeof(int) |
| 278 | // | immediately | | + size of param + value | data: status |
| 279 | // | | | data: effect_param_t | |
| 280 | // +--------------------------------+-------------------------------+-------------------------------+-------------------------- |
| 281 | // | Set a parameter but apply it | EFFECT_CMD_SET_PARAM_DEFERRED | size: sizeof(effect_param_t) | size: 0 |
| 282 | // | only when receiving command | | + size of param + value | data: N/A |
| 283 | // | EFFECT_CMD_SET_PARAM_COMMIT | | data: effect_param_t | |
| 284 | // +--------------------------------+-------------------------------+-------------------------------+-------------------------- |
| 285 | // | Apply all previously received | EFFECT_CMD_SET_PARAM_COMMIT | size: 0 | size: sizeof(int) |
| 286 | // | EFFECT_CMD_SET_PARAM_DEFERRED | | data: N/A | data: status |
| 287 | // | commands | | | |
| 288 | // +--------------------------------+-------------------------------+-------------------------------+-------------------------- |
| 289 | // | Get a parameter value | EFFECT_CMD_GET_PARAM | size: sizeof(effect_param_t) | size: sizeof(effect_param_t) |
| 290 | // | | | + size of param | + size of param + value |
| 291 | // | | | data: effect_param_t | data: effect_param_t |
| 292 | // +--------------------------------+-------------------------------+-------------------------------+-------------------------- |
| 293 | // | Set the rendering device the | EFFECT_CMD_SET_DEVICE | size: sizeof(uint32_t) | size: 0 |
| 294 | // | audio output path is connected | | data: audio_device_e | data: N/A |
| 295 | // | to. See audio_device_e in | | | |
| 296 | // | AudioCommon.h for device values| | | |
| 297 | // +--------------------------------+-------------------------------+-------------------------------+-------------------------- |
| 298 | // | Set and get volume. Used by | EFFECT_CMD_SET_VOLUME | size: n * sizeof(uint32_t) | size: n * sizeof(uint32_t) |
| 299 | // | audio framework to delegate | | data: volume for each channel | data: volume for each channel |
| 300 | // | volume control to effect engine| | defined in effect_config_t in | defined in effect_config_t in |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 301 | // | If volume control flag is set | | 8.24 fixed point format | 8.24 fixed point format |
| 302 | // | in the effect descriptor, the | | | It is legal to receive a null |
| 303 | // | effect engine must return the | | | pointer as pReplyData in which |
| 304 | // | volume that should be applied | | | case the effect framework has |
| 305 | // | before the effect is processed | | | delegated volume control to |
| 306 | // | The overall volume (the volume | | | another effect. |
Eric Laurent | 5fe37c6 | 2010-05-21 06:05:13 -0700 | [diff] [blame] | 307 | // | actually applied by the effect | | | |
| 308 | // | multiplied by the returned | | | |
| 309 | // | value) should match the | | | |
| 310 | // | requested value | | | |
| 311 | // +--------------------------------+-------------------------------+-------------------------------+-------------------------- |
| 312 | // | All proprietary effect commands| EFFECT_CMD_FIRST_PROPRIETARY | | |
| 313 | // | must use command codes above | | | |
| 314 | // | this value. The size and format| | | |
| 315 | // | of command and response fields | | | |
| 316 | // | is free in this case. | | | |
| 317 | // +--------------------------------+-------------------------------+-------------------------------+-------------------------- |
| 318 | |
| 319 | |
| 320 | enum effect_command_e { |
| 321 | EFFECT_CMD_INIT, // initialize effect engine |
| 322 | EFFECT_CMD_CONFIGURE, // configure effect engine (see effect_config_t) |
| 323 | EFFECT_CMD_RESET, // reset effect engine |
| 324 | EFFECT_CMD_ENABLE, // enable effect process |
| 325 | EFFECT_CMD_DISABLE, // disable effect process |
| 326 | EFFECT_CMD_SET_PARAM, // set parameter immediately (see effect_param_t) |
| 327 | EFFECT_CMD_SET_PARAM_DEFERRED, // set parameter deferred |
| 328 | EFFECT_CMD_SET_PARAM_COMMIT, // commit previous set parameter deferred |
| 329 | EFFECT_CMD_GET_PARAM, // get parameter |
| 330 | EFFECT_CMD_SET_DEVICE, // set audio device (see audio_device_e in AudioCommon.h) |
| 331 | EFFECT_CMD_SET_VOLUME, // set volume |
| 332 | EFFECT_CMD_FIRST_PROPRIETARY = 0x10000 // first proprietary command code |
| 333 | }; |
| 334 | |
| 335 | // Audio buffer descriptor used by process(), bufferProvider() functions and buffer_config_t structure |
| 336 | // Multi-channel audio is always interleaved. The channel order is from LSB to MSB with regard to the |
| 337 | // channel mask definition in audio_channels_e (AudioCommon.h) e.g : |
| 338 | // Stereo: left, right |
| 339 | // 5 point 1: front left, front right, front center, low frequency, back left, back right |
| 340 | // The buffer size is expressed in frame count, a frame being composed of samples for all |
| 341 | // channels at a given time |
| 342 | struct audio_buffer_s { |
| 343 | size_t frameCount; // number of frames in buffer |
| 344 | union { |
| 345 | void* raw; // raw pointer to start of buffer |
| 346 | int32_t* s32; // pointer to signed 32 bit data at start of buffer |
| 347 | int16_t* s16; // pointer to signed 16 bit data at start of buffer |
| 348 | uint8_t* u8; // pointer to unsigned 8 bit data at start of buffer |
| 349 | }; |
| 350 | }; |
| 351 | |
| 352 | // the buffer_provider_s structure contains functions that can be used |
| 353 | // by the effect engine process() function to query and release input |
| 354 | // or output audio buffer. |
| 355 | // The getBuffer() function is called to retrieve a buffer where data |
| 356 | // should read from or written to by process() function. |
| 357 | // The releaseBuffer() function MUST be called when the buffer retrieved |
| 358 | // with getBuffer() is not needed anymore. |
| 359 | // The process function should use the buffer provider mechanism to retrieve |
| 360 | // input or output buffer if the inBuffer or outBuffer passed as argument is NULL |
| 361 | // and the buffer configuration (buffer_config_t) given by the EFFECT_CMD_CONFIGURE |
| 362 | // command did not specify an audio buffer. |
| 363 | |
| 364 | typedef int32_t (* buffer_function_t)(void *cookie, audio_buffer_t *buffer); |
| 365 | |
| 366 | typedef struct buffer_provider_s { |
| 367 | buffer_function_t getBuffer; // retrieve next buffer |
| 368 | buffer_function_t releaseBuffer; // release used buffer |
| 369 | void *cookie; // for use by client of buffer provider functions |
| 370 | } buffer_provider_t; |
| 371 | |
| 372 | // The buffer_config_s structure specifies the input or output audio format |
| 373 | // to be used by the effect engine. It is part of the effect_config_t |
| 374 | // structure that defines both input and output buffer configurations and is |
| 375 | // passed by the EFFECT_CMD_CONFIGURE command. |
| 376 | typedef struct buffer_config_s { |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 377 | audio_buffer_t buffer; // buffer for use by process() function if not passed explicitly |
Eric Laurent | 5fe37c6 | 2010-05-21 06:05:13 -0700 | [diff] [blame] | 378 | uint32_t samplingRate; // sampling rate |
| 379 | uint32_t channels; // channel mask (see audio_channels_e in AudioCommon.h) |
| 380 | buffer_provider_t bufferProvider; // buffer provider |
| 381 | uint8_t format; // PCM format (see audio_format_e in AudioCommon.h) |
| 382 | uint8_t accessMode; // read/write or accumulate in buffer (effect_buffer_access_e) |
| 383 | uint16_t mask; // indicates which of the above fields is valid |
| 384 | } buffer_config_t; |
| 385 | |
| 386 | // values for "accessMode" field of buffer_config_t: |
| 387 | // overwrite, read only, accumulate (read/modify/write) |
| 388 | enum effect_buffer_access_e { |
| 389 | EFFECT_BUFFER_ACCESS_WRITE, |
| 390 | EFFECT_BUFFER_ACCESS_READ, |
| 391 | EFFECT_BUFFER_ACCESS_ACCUMULATE |
| 392 | |
| 393 | }; |
| 394 | |
| 395 | // values for bit field "mask" in buffer_config_t. If a bit is set, the corresponding field |
| 396 | // in buffer_config_t must be taken into account when executing the EFFECT_CMD_CONFIGURE command |
| 397 | #define EFFECT_CONFIG_BUFFER 0x0001 // buffer field must be taken into account |
| 398 | #define EFFECT_CONFIG_SMP_RATE 0x0002 // samplingRate field must be taken into account |
| 399 | #define EFFECT_CONFIG_CHANNELS 0x0004 // channels field must be taken into account |
| 400 | #define EFFECT_CONFIG_FORMAT 0x0008 // format field must be taken into account |
| 401 | #define EFFECT_CONFIG_ACC_MODE 0x0010 // accessMode field must be taken into account |
| 402 | #define EFFECT_CONFIG_PROVIDER 0x0020 // bufferProvider field must be taken into account |
| 403 | #define EFFECT_CONFIG_ALL (EFFECT_CONFIG_BUFFER | EFFECT_CONFIG_SMP_RATE | \ |
| 404 | EFFECT_CONFIG_CHANNELS | EFFECT_CONFIG_FORMAT | \ |
| 405 | EFFECT_CONFIG_ACC_MODE | EFFECT_CONFIG_PROVIDER) |
| 406 | |
| 407 | // effect_config_s structure describes the format of the pCmdData argument of EFFECT_CMD_CONFIGURE command |
| 408 | // to configure audio parameters and buffers for effect engine input and output. |
| 409 | typedef struct effect_config_s { |
| 410 | buffer_config_t inputCfg; |
| 411 | buffer_config_t outputCfg;; |
| 412 | } effect_config_t; |
| 413 | |
| 414 | // effect_param_s structure describes the format of the pCmdData argument of EFFECT_CMD_SET_PARAM |
| 415 | // command and pCmdData and pReplyData of EFFECT_CMD_GET_PARAM command. |
| 416 | // psize and vsize represent the actual size of parameter and value. |
| 417 | // |
| 418 | // NOTE: the start of value field inside the data field is always on a 32 bit boundary: |
| 419 | // |
| 420 | // +-----------+ |
| 421 | // | status | sizeof(int) |
| 422 | // +-----------+ |
| 423 | // | psize | sizeof(int) |
| 424 | // +-----------+ |
| 425 | // | vsize | sizeof(int) |
| 426 | // +-----------+ |
| 427 | // | | | | |
| 428 | // ~ parameter ~ > psize | |
| 429 | // | | | > ((psize - 1)/sizeof(int) + 1) * sizeof(int) |
| 430 | // +-----------+ | |
| 431 | // | padding | | |
| 432 | // +-----------+ |
| 433 | // | | | |
| 434 | // ~ value ~ > vsize |
| 435 | // | | | |
| 436 | // +-----------+ |
| 437 | |
| 438 | typedef struct effect_param_s { |
| 439 | int32_t status; // Transaction status (unused for command, used for reply) |
| 440 | uint32_t psize; // Parameter size |
| 441 | uint32_t vsize; // Value size |
| 442 | char data[]; // Start of Parameter + Value data |
| 443 | } effect_param_t; |
| 444 | |
| 445 | |
| 446 | ///////////////////////////////////////////////// |
| 447 | // Effect library interface |
| 448 | ///////////////////////////////////////////////// |
| 449 | |
| 450 | // An effect library is required to implement and expose the following functions |
| 451 | // to enable effect enumeration and instantiation. The name of these functions must be as |
| 452 | // specified here as the effect framework will get the function address with dlsym(): |
| 453 | // |
| 454 | // - effect_QueryNumberEffects_t EffectQueryNumberEffects; |
| 455 | // - effect_QueryNextEffect_t EffectQueryNext; |
| 456 | // - effect_CreateEffect_t EffectCreate; |
| 457 | // - effect_ReleaseEffect_t EffectRelease; |
| 458 | |
| 459 | |
| 460 | //////////////////////////////////////////////////////////////////////////////// |
| 461 | // |
| 462 | // Function: EffectQueryNumberEffects |
| 463 | // |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 464 | // Description: Returns the number of different effects exposed by the |
Eric Laurent | 5fe37c6 | 2010-05-21 06:05:13 -0700 | [diff] [blame] | 465 | // library. Each effect must have a unique effect uuid (see |
| 466 | // effect_descriptor_t). This function together with EffectQueryNext() |
| 467 | // is used to enumerate all effects present in the library. |
| 468 | // Each time EffectQueryNumberEffects() is called, the library must |
| 469 | // reset the index of the effect descriptor returned by next call to |
| 470 | // EffectQueryNext() to restart enumeration from the beginning. |
| 471 | // |
| 472 | // Input/Output: |
| 473 | // pNumEffects: address where the number of effects should be returned. |
| 474 | // |
| 475 | // Output: |
| 476 | // returned value: 0 successful operation. |
| 477 | // -ENODEV library failed to initialize |
| 478 | // -EINVAL invalid pNumEffects |
| 479 | // *pNumEffects: updated with number of effects in library |
| 480 | // |
| 481 | //////////////////////////////////////////////////////////////////////////////// |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 482 | typedef int32_t (*effect_QueryNumberEffects_t)(uint32_t *pNumEffects); |
Eric Laurent | 5fe37c6 | 2010-05-21 06:05:13 -0700 | [diff] [blame] | 483 | |
| 484 | //////////////////////////////////////////////////////////////////////////////// |
| 485 | // |
| 486 | // Function: EffectQueryNext |
| 487 | // |
| 488 | // Description: Returns a descriptor of the next available effect. |
| 489 | // See effect_descriptor_t for details on effect descriptors. |
| 490 | // This function together with EffectQueryNext() is used to enumerate all |
| 491 | // effects present in the library. The enumeration sequence is: |
| 492 | // EffectQueryNumberEffects(&num_effects); |
| 493 | // while (num_effects--) |
| 494 | // EffectQueryNext(); |
| 495 | // |
| 496 | // Input/Output: |
| 497 | // pDescriptor: address where to return the effect descriptor. |
| 498 | // |
| 499 | // Output: |
| 500 | // returned value: 0 successful operation. |
| 501 | // -ENODEV library failed to initialize |
| 502 | // -EINVAL invalid pDescriptor |
| 503 | // -ENOENT no more effect available |
| 504 | // *pDescriptor: updated with the effect descriptor. |
| 505 | // |
| 506 | //////////////////////////////////////////////////////////////////////////////// |
| 507 | typedef int32_t (*effect_QueryNextEffect_t)(effect_descriptor_t *pDescriptor); |
| 508 | |
| 509 | //////////////////////////////////////////////////////////////////////////////// |
| 510 | // |
| 511 | // Function: EffectCreate |
| 512 | // |
| 513 | // Description: Creates an effect engine of the specified type and returns an |
| 514 | // effect control interface on this engine. The function will allocate the |
| 515 | // resources for an instance of the requested effect engine and return |
| 516 | // a handle on the effect control interface. |
| 517 | // |
| 518 | // Input: |
| 519 | // pEffectUuid: pointer to the effect uuid. |
| 520 | // |
| 521 | // Input/Output: |
| 522 | // pInterface: address where to return the effect interface. |
| 523 | // |
| 524 | // Output: |
| 525 | // returned value: 0 successful operation. |
| 526 | // -ENODEV library failed to initialize |
| 527 | // -EINVAL invalid pEffectUuid or pInterface |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 528 | // -ENOENT no effect with this uuid found |
Eric Laurent | 5fe37c6 | 2010-05-21 06:05:13 -0700 | [diff] [blame] | 529 | // *pInterface: updated with the effect interface handle. |
| 530 | // |
| 531 | //////////////////////////////////////////////////////////////////////////////// |
| 532 | typedef int32_t (*effect_CreateEffect_t)(effect_uuid_t *uuid, effect_interface_t *pInterface); |
| 533 | |
| 534 | //////////////////////////////////////////////////////////////////////////////// |
| 535 | // |
| 536 | // Function: EffectRelease |
| 537 | // |
| 538 | // Description: Releases the effect engine whose handle is given as argument. |
| 539 | // All resources allocated to this particular instance of the effect are |
| 540 | // released. |
| 541 | // |
| 542 | // Input: |
| 543 | // interface: handle on the effect interface to be released. |
| 544 | // |
| 545 | // Output: |
| 546 | // returned value: 0 successful operation. |
| 547 | // -ENODEV library failed to initialize |
| 548 | // -EINVAL invalid interface handle |
| 549 | // |
| 550 | //////////////////////////////////////////////////////////////////////////////// |
| 551 | typedef int32_t (*effect_ReleaseEffect_t)(effect_interface_t interface); |
| 552 | |
| 553 | |
| 554 | #if __cplusplus |
| 555 | } // extern "C" |
| 556 | #endif |
| 557 | |
| 558 | |
| 559 | #endif /*ANDROID_EFFECTAPI_H_*/ |