2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #ifndef ANDROID_AUDIO_EFFECT_H
19 #define ANDROID_AUDIO_EFFECT_H
24 #include <sys/cdefs.h>
25 #include <sys/types.h>
27 #include <system/audio.h>
33 /////////////////////////////////////////////////
35 /////////////////////////////////////////////////
38 //--- Effect descriptor structure effect_descriptor_t
41 // Unique effect ID (can be generated from the following site:
42 // http://www.itu.int/ITU-T/asn1/uuid.html)
43 // This format is used for both "type" and "uuid" fields of the effect descriptor structure.
44 // - When used for effect type and the engine is implementing and effect corresponding to a standard
45 // OpenSL ES interface, this ID must be the one defined in OpenSLES_IID.h for that interface.
46 // - When used as uuid, it should be a unique UUID for this particular implementation.
47 typedef struct effect_uuid_s {
50 uint16_t timeHiAndVersion;
55 // Maximum length of character strings in structures defines by this API.
56 #define EFFECT_STRING_LEN_MAX 64
58 // NULL UUID definition (matches SL_IID_NULL_)
59 #define EFFECT_UUID_INITIALIZER { 0xec7178ec, 0xe5e1, 0x4432, 0xa3f4, \
60 { 0x46, 0x57, 0xe6, 0x79, 0x52, 0x10 } }
61 static const effect_uuid_t EFFECT_UUID_NULL_ = EFFECT_UUID_INITIALIZER;
62 static const effect_uuid_t * const EFFECT_UUID_NULL = &EFFECT_UUID_NULL_;
63 static const char * const EFFECT_UUID_NULL_STR = "ec7178ec-e5e1-4432-a3f4-4657e6795210";
66 // The effect descriptor contains necessary information to facilitate the enumeration of the effect
67 // engines present in a library.
68 typedef struct effect_descriptor_s {
69 effect_uuid_t type; // UUID of to the OpenSL ES interface implemented by this effect
70 effect_uuid_t uuid; // UUID for this particular implementation
71 uint32_t apiVersion; // Version of the effect control API implemented
72 uint32_t flags; // effect engine capabilities/requirements flags (see below)
73 uint16_t cpuLoad; // CPU load indication (see below)
74 uint16_t memoryUsage; // Data Memory usage (see below)
75 char name[EFFECT_STRING_LEN_MAX]; // human readable effect name
76 char implementor[EFFECT_STRING_LEN_MAX]; // human readable effect implementor name
77 } effect_descriptor_t;
79 // CPU load and memory usage indication: each effect implementation must provide an indication of
80 // its CPU and memory usage for the audio effect framework to limit the number of effects
81 // instantiated at a given time on a given platform.
82 // The CPU load is expressed in 0.1 MIPS units as estimated on an ARM9E core (ARMv5TE) with 0 WS.
83 // The memory usage is expressed in KB and includes only dynamically allocated memory
85 // Definitions for flags field of effect descriptor.
86 // +---------------------------+-----------+-----------------------------------
87 // | description | bits | values
88 // +---------------------------+-----------+-----------------------------------
89 // | connection mode | 0..2 | 0 insert: after track process
90 // | | | 1 auxiliary: connect to track auxiliary
91 // | | | output and use send level
92 // | | | 2 replace: replaces track process function;
93 // | | | must implement SRC, volume and mono to stereo.
94 // | | | 3 pre processing: applied below audio HAL on input
95 // | | | 4 post processing: applied below audio HAL on output
96 // | | | 5 - 7 reserved
97 // +---------------------------+-----------+-----------------------------------
98 // | insertion preference | 3..5 | 0 none
99 // | | | 1 first of the chain
100 // | | | 2 last of the chain
101 // | | | 3 exclusive (only effect in the insert chain)
102 // | | | 4..7 reserved
103 // +---------------------------+-----------+-----------------------------------
104 // | Volume management | 6..8 | 0 none
105 // | | | 1 implements volume control
106 // | | | 2 requires volume indication
108 // +---------------------------+-----------+-----------------------------------
109 // | Device indication | 9..11 | 0 none
110 // | | | 1 requires device updates
111 // | | | 2, 4 reserved
112 // +---------------------------+-----------+-----------------------------------
113 // | Sample input mode | 12..13 | 1 direct: process() function or EFFECT_CMD_SET_CONFIG
114 // | | | command must specify a buffer descriptor
115 // | | | 2 provider: process() function uses the
116 // | | | bufferProvider indicated by the
117 // | | | EFFECT_CMD_SET_CONFIG command to request input.
119 // | | | 3 both: both input modes are supported
120 // +---------------------------+-----------+-----------------------------------
121 // | Sample output mode | 14..15 | 1 direct: process() function or EFFECT_CMD_SET_CONFIG
122 // | | | command must specify a buffer descriptor
123 // | | | 2 provider: process() function uses the
124 // | | | bufferProvider indicated by the
125 // | | | EFFECT_CMD_SET_CONFIG command to request output
127 // | | | 3 both: both output modes are supported
128 // +---------------------------+-----------+-----------------------------------
129 // | Hardware acceleration | 16..17 | 0 No hardware acceleration
130 // | | | 1 non tunneled hw acceleration: the process() function
131 // | | | reads the samples, send them to HW accelerated
132 // | | | effect processor, reads back the processed samples
133 // | | | and returns them to the output buffer.
134 // | | | 2 tunneled hw acceleration: the process() function is
135 // | | | transparent. The effect interface is only used to
136 // | | | control the effect engine. This mode is relevant for
137 // | | | global effects actually applied by the audio
138 // | | | hardware on the output stream.
139 // +---------------------------+-----------+-----------------------------------
140 // | Audio Mode indication | 18..19 | 0 none
141 // | | | 1 requires audio mode updates
142 // | | | 2..3 reserved
143 // +---------------------------+-----------+-----------------------------------
144 // | Audio source indication | 20..21 | 0 none
145 // | | | 1 requires audio source updates
146 // | | | 2..3 reserved
147 // +---------------------------+-----------+-----------------------------------
148 // | Effect offload supported | 22 | 0 The effect cannot be offloaded to an audio DSP
149 // | | | 1 The effect can be offloaded to an audio DSP
150 // +---------------------------+-----------+-----------------------------------
153 #define EFFECT_FLAG_TYPE_SHIFT 0
154 #define EFFECT_FLAG_TYPE_SIZE 3
155 #define EFFECT_FLAG_TYPE_MASK (((1 << EFFECT_FLAG_TYPE_SIZE) -1) \
156 << EFFECT_FLAG_TYPE_SHIFT)
157 #define EFFECT_FLAG_TYPE_INSERT (0 << EFFECT_FLAG_TYPE_SHIFT)
158 #define EFFECT_FLAG_TYPE_AUXILIARY (1 << EFFECT_FLAG_TYPE_SHIFT)
159 #define EFFECT_FLAG_TYPE_REPLACE (2 << EFFECT_FLAG_TYPE_SHIFT)
160 #define EFFECT_FLAG_TYPE_PRE_PROC (3 << EFFECT_FLAG_TYPE_SHIFT)
161 #define EFFECT_FLAG_TYPE_POST_PROC (4 << EFFECT_FLAG_TYPE_SHIFT)
164 #define EFFECT_FLAG_INSERT_SHIFT (EFFECT_FLAG_TYPE_SHIFT + EFFECT_FLAG_TYPE_SIZE)
165 #define EFFECT_FLAG_INSERT_SIZE 3
166 #define EFFECT_FLAG_INSERT_MASK (((1 << EFFECT_FLAG_INSERT_SIZE) -1) \
167 << EFFECT_FLAG_INSERT_SHIFT)
168 #define EFFECT_FLAG_INSERT_ANY (0 << EFFECT_FLAG_INSERT_SHIFT)
169 #define EFFECT_FLAG_INSERT_FIRST (1 << EFFECT_FLAG_INSERT_SHIFT)
170 #define EFFECT_FLAG_INSERT_LAST (2 << EFFECT_FLAG_INSERT_SHIFT)
171 #define EFFECT_FLAG_INSERT_EXCLUSIVE (3 << EFFECT_FLAG_INSERT_SHIFT)
175 #define EFFECT_FLAG_VOLUME_SHIFT (EFFECT_FLAG_INSERT_SHIFT + EFFECT_FLAG_INSERT_SIZE)
176 #define EFFECT_FLAG_VOLUME_SIZE 3
177 #define EFFECT_FLAG_VOLUME_MASK (((1 << EFFECT_FLAG_VOLUME_SIZE) -1) \
178 << EFFECT_FLAG_VOLUME_SHIFT)
179 #define EFFECT_FLAG_VOLUME_CTRL (1 << EFFECT_FLAG_VOLUME_SHIFT)
180 #define EFFECT_FLAG_VOLUME_IND (2 << EFFECT_FLAG_VOLUME_SHIFT)
181 #define EFFECT_FLAG_VOLUME_NONE (0 << EFFECT_FLAG_VOLUME_SHIFT)
184 #define EFFECT_FLAG_DEVICE_SHIFT (EFFECT_FLAG_VOLUME_SHIFT + EFFECT_FLAG_VOLUME_SIZE)
185 #define EFFECT_FLAG_DEVICE_SIZE 3
186 #define EFFECT_FLAG_DEVICE_MASK (((1 << EFFECT_FLAG_DEVICE_SIZE) -1) \
187 << EFFECT_FLAG_DEVICE_SHIFT)
188 #define EFFECT_FLAG_DEVICE_IND (1 << EFFECT_FLAG_DEVICE_SHIFT)
189 #define EFFECT_FLAG_DEVICE_NONE (0 << EFFECT_FLAG_DEVICE_SHIFT)
191 // Sample input modes
192 #define EFFECT_FLAG_INPUT_SHIFT (EFFECT_FLAG_DEVICE_SHIFT + EFFECT_FLAG_DEVICE_SIZE)
193 #define EFFECT_FLAG_INPUT_SIZE 2
194 #define EFFECT_FLAG_INPUT_MASK (((1 << EFFECT_FLAG_INPUT_SIZE) -1) \
195 << EFFECT_FLAG_INPUT_SHIFT)
196 #define EFFECT_FLAG_INPUT_DIRECT (1 << EFFECT_FLAG_INPUT_SHIFT)
197 #define EFFECT_FLAG_INPUT_PROVIDER (2 << EFFECT_FLAG_INPUT_SHIFT)
198 #define EFFECT_FLAG_INPUT_BOTH (3 << EFFECT_FLAG_INPUT_SHIFT)
200 // Sample output modes
201 #define EFFECT_FLAG_OUTPUT_SHIFT (EFFECT_FLAG_INPUT_SHIFT + EFFECT_FLAG_INPUT_SIZE)
202 #define EFFECT_FLAG_OUTPUT_SIZE 2
203 #define EFFECT_FLAG_OUTPUT_MASK (((1 << EFFECT_FLAG_OUTPUT_SIZE) -1) \
204 << EFFECT_FLAG_OUTPUT_SHIFT)
205 #define EFFECT_FLAG_OUTPUT_DIRECT (1 << EFFECT_FLAG_OUTPUT_SHIFT)
206 #define EFFECT_FLAG_OUTPUT_PROVIDER (2 << EFFECT_FLAG_OUTPUT_SHIFT)
207 #define EFFECT_FLAG_OUTPUT_BOTH (3 << EFFECT_FLAG_OUTPUT_SHIFT)
209 // Hardware acceleration mode
210 #define EFFECT_FLAG_HW_ACC_SHIFT (EFFECT_FLAG_OUTPUT_SHIFT + EFFECT_FLAG_OUTPUT_SIZE)
211 #define EFFECT_FLAG_HW_ACC_SIZE 2
212 #define EFFECT_FLAG_HW_ACC_MASK (((1 << EFFECT_FLAG_HW_ACC_SIZE) -1) \
213 << EFFECT_FLAG_HW_ACC_SHIFT)
214 #define EFFECT_FLAG_HW_ACC_SIMPLE (1 << EFFECT_FLAG_HW_ACC_SHIFT)
215 #define EFFECT_FLAG_HW_ACC_TUNNEL (2 << EFFECT_FLAG_HW_ACC_SHIFT)
217 // Audio mode indication
218 #define EFFECT_FLAG_AUDIO_MODE_SHIFT (EFFECT_FLAG_HW_ACC_SHIFT + EFFECT_FLAG_HW_ACC_SIZE)
219 #define EFFECT_FLAG_AUDIO_MODE_SIZE 2
220 #define EFFECT_FLAG_AUDIO_MODE_MASK (((1 << EFFECT_FLAG_AUDIO_MODE_SIZE) -1) \
221 << EFFECT_FLAG_AUDIO_MODE_SHIFT)
222 #define EFFECT_FLAG_AUDIO_MODE_IND (1 << EFFECT_FLAG_AUDIO_MODE_SHIFT)
223 #define EFFECT_FLAG_AUDIO_MODE_NONE (0 << EFFECT_FLAG_AUDIO_MODE_SHIFT)
225 // Audio source indication
226 #define EFFECT_FLAG_AUDIO_SOURCE_SHIFT (EFFECT_FLAG_AUDIO_MODE_SHIFT + EFFECT_FLAG_AUDIO_MODE_SIZE)
227 #define EFFECT_FLAG_AUDIO_SOURCE_SIZE 2
228 #define EFFECT_FLAG_AUDIO_SOURCE_MASK (((1 << EFFECT_FLAG_AUDIO_SOURCE_SIZE) -1) \
229 << EFFECT_FLAG_AUDIO_SOURCE_SHIFT)
230 #define EFFECT_FLAG_AUDIO_SOURCE_IND (1 << EFFECT_FLAG_AUDIO_SOURCE_SHIFT)
231 #define EFFECT_FLAG_AUDIO_SOURCE_NONE (0 << EFFECT_FLAG_AUDIO_SOURCE_SHIFT)
233 // Effect offload indication
234 #define EFFECT_FLAG_OFFLOAD_SHIFT (EFFECT_FLAG_AUDIO_SOURCE_SHIFT + \
235 EFFECT_FLAG_AUDIO_SOURCE_SIZE)
236 #define EFFECT_FLAG_OFFLOAD_SIZE 1
237 #define EFFECT_FLAG_OFFLOAD_MASK (((1 << EFFECT_FLAG_OFFLOAD_SIZE) -1) \
238 << EFFECT_FLAG_OFFLOAD_SHIFT)
239 #define EFFECT_FLAG_OFFLOAD_SUPPORTED (1 << EFFECT_FLAG_OFFLOAD_SHIFT)
241 #define EFFECT_MAKE_API_VERSION(M, m) (((M)<<16) | ((m) & 0xFFFF))
242 #define EFFECT_API_VERSION_MAJOR(v) ((v)>>16)
243 #define EFFECT_API_VERSION_MINOR(v) ((m) & 0xFFFF)
247 /////////////////////////////////////////////////
248 // Effect control interface
249 /////////////////////////////////////////////////
251 // Effect control interface version 2.0
252 #define EFFECT_CONTROL_API_VERSION EFFECT_MAKE_API_VERSION(2,0)
254 // Effect control interface structure: effect_interface_s
255 // The effect control interface is exposed by each effect engine implementation. It consists of
256 // a set of functions controlling the configuration, activation and process of the engine.
257 // The functions are grouped in a structure of type effect_interface_s.
259 // Effect control interface handle: effect_handle_t
260 // The effect_handle_t serves two purposes regarding the implementation of the effect engine:
261 // - 1 it is the address of a pointer to an effect_interface_s structure where the functions
262 // of the effect control API for a particular effect are located.
263 // - 2 it is the address of the context of a particular effect instance.
264 // A typical implementation in the effect library would define a structure as follows:
265 // struct effect_module_s {
266 // const struct effect_interface_s *itfe;
267 // effect_config_t config;
268 // effect_context_t context;
270 // The implementation of EffectCreate() function would then allocate a structure of this
271 // type and return its address as effect_handle_t
272 typedef struct effect_interface_s **effect_handle_t;
275 // Forward definition of type audio_buffer_t
276 typedef struct audio_buffer_s audio_buffer_t;
283 // Effect control interface definition
284 struct effect_interface_s {
285 ////////////////////////////////////////////////////////////////////////////////
289 // Description: Effect process function. Takes input samples as specified
290 // (count and location) in input buffer descriptor and output processed
291 // samples as specified in output buffer descriptor. If the buffer descriptor
292 // is not specified the function must use either the buffer or the
293 // buffer provider function installed by the EFFECT_CMD_SET_CONFIG command.
294 // The effect framework will call the process() function after the EFFECT_CMD_ENABLE
295 // command is received and until the EFFECT_CMD_DISABLE is received. When the engine
296 // receives the EFFECT_CMD_DISABLE command it should turn off the effect gracefully
297 // and when done indicate that it is OK to stop calling the process() function by
298 // returning the -ENODATA status.
300 // NOTE: the process() function implementation should be "real-time safe" that is
301 // it should not perform blocking calls: malloc/free, sleep, read/write/open/close,
302 // pthread_cond_wait/pthread_mutex_lock...
305 // self: handle to the effect interface this function
307 // inBuffer: buffer descriptor indicating where to read samples to process.
308 // If NULL, use the configuration passed by EFFECT_CMD_SET_CONFIG command.
310 // outBuffer: buffer descriptor indicating where to write processed samples.
311 // If NULL, use the configuration passed by EFFECT_CMD_SET_CONFIG command.
314 // returned value: 0 successful operation
315 // -ENODATA the engine has finished the disable phase and the framework
316 // can stop calling process()
317 // -EINVAL invalid interface handle or
318 // invalid input/output buffer description
319 ////////////////////////////////////////////////////////////////////////////////
320 int32_t (*process)(effect_handle_t self,
321 audio_buffer_t *inBuffer,
322 audio_buffer_t *outBuffer);
323 ////////////////////////////////////////////////////////////////////////////////
327 // Description: Send a command and receive a response to/from effect engine.
330 // self: handle to the effect interface this function
332 // cmdCode: command code: the command can be a standardized command defined in
333 // effect_command_e (see below) or a proprietary command.
334 // cmdSize: size of command in bytes
335 // pCmdData: pointer to command data
336 // pReplyData: pointer to reply data
339 // replySize: maximum size of reply data as input
340 // actual size of reply data as output
343 // returned value: 0 successful operation
344 // -EINVAL invalid interface handle or
345 // invalid command/reply size or format according to command code
346 // The return code should be restricted to indicate problems related to the this
347 // API specification. Status related to the execution of a particular command should be
348 // indicated as part of the reply field.
350 // *pReplyData updated with command response
352 ////////////////////////////////////////////////////////////////////////////////
353 int32_t (*command)(effect_handle_t self,
359 ////////////////////////////////////////////////////////////////////////////////
361 // Function: get_descriptor
363 // Description: Returns the effect descriptor
366 // self: handle to the effect interface this function
370 // pDescriptor: address where to return the effect descriptor.
373 // returned value: 0 successful operation.
374 // -EINVAL invalid interface handle or invalid pDescriptor
375 // *pDescriptor: updated with the effect descriptor.
377 ////////////////////////////////////////////////////////////////////////////////
378 int32_t (*get_descriptor)(effect_handle_t self,
379 effect_descriptor_t *pDescriptor);
380 ////////////////////////////////////////////////////////////////////////////////
382 // Function: process_reverse
384 // Description: Process reverse stream function. This function is used to pass
385 // a reference stream to the effect engine. If the engine does not need a reference
386 // stream, this function pointer can be set to NULL.
387 // This function would typically implemented by an Echo Canceler.
390 // self: handle to the effect interface this function
392 // inBuffer: buffer descriptor indicating where to read samples to process.
393 // If NULL, use the configuration passed by EFFECT_CMD_SET_CONFIG_REVERSE command.
395 // outBuffer: buffer descriptor indicating where to write processed samples.
396 // If NULL, use the configuration passed by EFFECT_CMD_SET_CONFIG_REVERSE command.
397 // If the buffer and buffer provider in the configuration received by
398 // EFFECT_CMD_SET_CONFIG_REVERSE are also NULL, do not return modified reverse
402 // returned value: 0 successful operation
403 // -ENODATA the engine has finished the disable phase and the framework
404 // can stop calling process_reverse()
405 // -EINVAL invalid interface handle or
406 // invalid input/output buffer description
407 ////////////////////////////////////////////////////////////////////////////////
408 int32_t (*process_reverse)(effect_handle_t self,
409 audio_buffer_t *inBuffer,
410 audio_buffer_t *outBuffer);
415 //--- Standardized command codes for command() function
417 enum effect_command_e {
418 EFFECT_CMD_INIT, // initialize effect engine
419 EFFECT_CMD_SET_CONFIG, // configure effect engine (see effect_config_t)
420 EFFECT_CMD_RESET, // reset effect engine
421 EFFECT_CMD_ENABLE, // enable effect process
422 EFFECT_CMD_DISABLE, // disable effect process
423 EFFECT_CMD_SET_PARAM, // set parameter immediately (see effect_param_t)
424 EFFECT_CMD_SET_PARAM_DEFERRED, // set parameter deferred
425 EFFECT_CMD_SET_PARAM_COMMIT, // commit previous set parameter deferred
426 EFFECT_CMD_GET_PARAM, // get parameter
427 EFFECT_CMD_SET_DEVICE, // set audio device (see audio.h, audio_devices_t)
428 EFFECT_CMD_SET_VOLUME, // set volume
429 EFFECT_CMD_SET_AUDIO_MODE, // set the audio mode (normal, ring, ...)
430 EFFECT_CMD_SET_CONFIG_REVERSE, // configure effect engine reverse stream(see effect_config_t)
431 EFFECT_CMD_SET_INPUT_DEVICE, // set capture device (see audio.h, audio_devices_t)
432 EFFECT_CMD_GET_CONFIG, // read effect engine configuration
433 EFFECT_CMD_GET_CONFIG_REVERSE, // read configure effect engine reverse stream configuration
434 EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS,// get all supported configurations for a feature.
435 EFFECT_CMD_GET_FEATURE_CONFIG, // get current feature configuration
436 EFFECT_CMD_SET_FEATURE_CONFIG, // set current feature configuration
437 EFFECT_CMD_SET_AUDIO_SOURCE, // set the audio source (see audio.h, audio_source_t)
438 EFFECT_CMD_OFFLOAD, // set if effect thread is an offload one,
439 // send the ioHandle of the effect thread
440 EFFECT_CMD_FIRST_PROPRIETARY = 0x10000 // first proprietary command code
443 //==================================================================================================
444 // command: EFFECT_CMD_INIT
445 //--------------------------------------------------------------------------------------------------
447 // Initialize effect engine: All configurations return to default
448 //--------------------------------------------------------------------------------------------------
452 //--------------------------------------------------------------------------------------------------
456 //==================================================================================================
457 // command: EFFECT_CMD_SET_CONFIG
458 //--------------------------------------------------------------------------------------------------
460 // Apply new audio parameters configurations for input and output buffers
461 //--------------------------------------------------------------------------------------------------
463 // size: sizeof(effect_config_t)
464 // data: effect_config_t
465 //--------------------------------------------------------------------------------------------------
469 //==================================================================================================
470 // command: EFFECT_CMD_RESET
471 //--------------------------------------------------------------------------------------------------
473 // Reset the effect engine. Keep configuration but resets state and buffer content
474 //--------------------------------------------------------------------------------------------------
478 //--------------------------------------------------------------------------------------------------
482 //==================================================================================================
483 // command: EFFECT_CMD_ENABLE
484 //--------------------------------------------------------------------------------------------------
486 // Enable the process. Called by the framework before the first call to process()
487 //--------------------------------------------------------------------------------------------------
491 //--------------------------------------------------------------------------------------------------
495 //==================================================================================================
496 // command: EFFECT_CMD_DISABLE
497 //--------------------------------------------------------------------------------------------------
499 // Disable the process. Called by the framework after the last call to process()
500 //--------------------------------------------------------------------------------------------------
504 //--------------------------------------------------------------------------------------------------
508 //==================================================================================================
509 // command: EFFECT_CMD_SET_PARAM
510 //--------------------------------------------------------------------------------------------------
512 // Set a parameter and apply it immediately
513 //--------------------------------------------------------------------------------------------------
515 // size: sizeof(effect_param_t) + size of param and value
516 // data: effect_param_t + param + value. See effect_param_t definition below for value offset
517 //--------------------------------------------------------------------------------------------------
521 //==================================================================================================
522 // command: EFFECT_CMD_SET_PARAM_DEFERRED
523 //--------------------------------------------------------------------------------------------------
525 // Set a parameter but apply it only when receiving EFFECT_CMD_SET_PARAM_COMMIT command
526 //--------------------------------------------------------------------------------------------------
528 // size: sizeof(effect_param_t) + size of param and value
529 // data: effect_param_t + param + value. See effect_param_t definition below for value offset
530 //--------------------------------------------------------------------------------------------------
534 //==================================================================================================
535 // command: EFFECT_CMD_SET_PARAM_COMMIT
536 //--------------------------------------------------------------------------------------------------
538 // Apply all previously received EFFECT_CMD_SET_PARAM_DEFERRED commands
539 //--------------------------------------------------------------------------------------------------
543 //--------------------------------------------------------------------------------------------------
547 //==================================================================================================
548 // command: EFFECT_CMD_GET_PARAM
549 //--------------------------------------------------------------------------------------------------
551 // Get a parameter value
552 //--------------------------------------------------------------------------------------------------
554 // size: sizeof(effect_param_t) + size of param
555 // data: effect_param_t + param
556 //--------------------------------------------------------------------------------------------------
558 // size: sizeof(effect_param_t) + size of param and value
559 // data: effect_param_t + param + value. See effect_param_t definition below for value offset
560 //==================================================================================================
561 // command: EFFECT_CMD_SET_DEVICE
562 //--------------------------------------------------------------------------------------------------
564 // Set the rendering device the audio output path is connected to. See audio.h, audio_devices_t
565 // for device values.
566 // The effect implementation must set EFFECT_FLAG_DEVICE_IND flag in its descriptor to receive this
567 // command when the device changes
568 //--------------------------------------------------------------------------------------------------
570 // size: sizeof(uint32_t)
572 //--------------------------------------------------------------------------------------------------
576 //==================================================================================================
577 // command: EFFECT_CMD_SET_VOLUME
578 //--------------------------------------------------------------------------------------------------
580 // Set and get volume. Used by audio framework to delegate volume control to effect engine.
581 // The effect implementation must set EFFECT_FLAG_VOLUME_IND or EFFECT_FLAG_VOLUME_CTRL flag in
582 // its descriptor to receive this command before every call to process() function
583 // If EFFECT_FLAG_VOLUME_CTRL flag is set in the effect descriptor, the effect engine must return
584 // the volume that should be applied before the effect is processed. The overall volume (the volume
585 // actually applied by the effect engine multiplied by the returned value) should match the value
586 // indicated in the command.
587 //--------------------------------------------------------------------------------------------------
589 // size: n * sizeof(uint32_t)
590 // data: volume for each channel defined in effect_config_t for output buffer expressed in
591 // 8.24 fixed point format
592 //--------------------------------------------------------------------------------------------------
594 // size: n * sizeof(uint32_t) / 0
595 // data: - if EFFECT_FLAG_VOLUME_CTRL is set in effect descriptor:
596 // volume for each channel defined in effect_config_t for output buffer expressed in
597 // 8.24 fixed point format
598 // - if EFFECT_FLAG_VOLUME_CTRL is not set in effect descriptor:
600 // It is legal to receive a null pointer as pReplyData in which case the effect framework has
601 // delegated volume control to another effect
602 //==================================================================================================
603 // command: EFFECT_CMD_SET_AUDIO_MODE
604 //--------------------------------------------------------------------------------------------------
606 // Set the audio mode. The effect implementation must set EFFECT_FLAG_AUDIO_MODE_IND flag in its
607 // descriptor to receive this command when the audio mode changes.
608 //--------------------------------------------------------------------------------------------------
610 // size: sizeof(uint32_t)
611 // data: audio_mode_t
612 //--------------------------------------------------------------------------------------------------
616 //==================================================================================================
617 // command: EFFECT_CMD_SET_CONFIG_REVERSE
618 //--------------------------------------------------------------------------------------------------
620 // Apply new audio parameters configurations for input and output buffers of reverse stream.
621 // An example of reverse stream is the echo reference supplied to an Acoustic Echo Canceler.
622 //--------------------------------------------------------------------------------------------------
624 // size: sizeof(effect_config_t)
625 // data: effect_config_t
626 //--------------------------------------------------------------------------------------------------
630 //==================================================================================================
631 // command: EFFECT_CMD_SET_INPUT_DEVICE
632 //--------------------------------------------------------------------------------------------------
634 // Set the capture device the audio input path is connected to. See audio.h, audio_devices_t
635 // for device values.
636 // The effect implementation must set EFFECT_FLAG_DEVICE_IND flag in its descriptor to receive this
637 // command when the device changes
638 //--------------------------------------------------------------------------------------------------
640 // size: sizeof(uint32_t)
642 //--------------------------------------------------------------------------------------------------
646 //==================================================================================================
647 // command: EFFECT_CMD_GET_CONFIG
648 //--------------------------------------------------------------------------------------------------
650 // Read audio parameters configurations for input and output buffers
651 //--------------------------------------------------------------------------------------------------
655 //--------------------------------------------------------------------------------------------------
657 // size: sizeof(effect_config_t)
658 // data: effect_config_t
659 //==================================================================================================
660 // command: EFFECT_CMD_GET_CONFIG_REVERSE
661 //--------------------------------------------------------------------------------------------------
663 // Read audio parameters configurations for input and output buffers of reverse stream
664 //--------------------------------------------------------------------------------------------------
668 //--------------------------------------------------------------------------------------------------
670 // size: sizeof(effect_config_t)
671 // data: effect_config_t
672 //==================================================================================================
673 // command: EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS
674 //--------------------------------------------------------------------------------------------------
676 // Queries for supported configurations for a particular feature (e.g. get the supported
677 // combinations of main and auxiliary channels for a noise suppressor).
678 // The command parameter is the feature identifier (See effect_feature_e for a list of defined
679 // features) followed by the maximum number of configuration descriptor to return.
680 // The reply is composed of:
681 // - status (uint32_t):
682 // - 0 if feature is supported
683 // - -ENOSYS if the feature is not supported,
684 // - -ENOMEM if the feature is supported but the total number of supported configurations
685 // exceeds the maximum number indicated by the caller.
686 // - total number of supported configurations (uint32_t)
687 // - an array of configuration descriptors.
688 // The actual number of descriptors returned must not exceed the maximum number indicated by
690 //--------------------------------------------------------------------------------------------------
692 // size: 2 x sizeof(uint32_t)
693 // data: effect_feature_e + maximum number of configurations to return
694 //--------------------------------------------------------------------------------------------------
696 // size: 2 x sizeof(uint32_t) + n x sizeof (<config descriptor>)
697 // data: status + total number of configurations supported + array of n config descriptors
698 //==================================================================================================
699 // command: EFFECT_CMD_GET_FEATURE_CONFIG
700 //--------------------------------------------------------------------------------------------------
702 // Retrieves current configuration for a given feature.
703 // The reply status is:
704 // - 0 if feature is supported
705 // - -ENOSYS if the feature is not supported,
706 //--------------------------------------------------------------------------------------------------
708 // size: sizeof(uint32_t)
709 // data: effect_feature_e
710 //--------------------------------------------------------------------------------------------------
712 // size: sizeof(uint32_t) + sizeof (<config descriptor>)
713 // data: status + config descriptor
714 //==================================================================================================
715 // command: EFFECT_CMD_SET_FEATURE_CONFIG
716 //--------------------------------------------------------------------------------------------------
718 // Sets current configuration for a given feature.
719 // The reply status is:
720 // - 0 if feature is supported
721 // - -ENOSYS if the feature is not supported,
722 // - -EINVAL if the configuration is invalid
723 //--------------------------------------------------------------------------------------------------
725 // size: sizeof(uint32_t) + sizeof (<config descriptor>)
726 // data: effect_feature_e + config descriptor
727 //--------------------------------------------------------------------------------------------------
729 // size: sizeof(uint32_t)
731 //==================================================================================================
732 // command: EFFECT_CMD_SET_AUDIO_SOURCE
733 //--------------------------------------------------------------------------------------------------
735 // Set the audio source the capture path is configured for (Camcorder, voice recognition...).
736 // See audio.h, audio_source_t for values.
737 //--------------------------------------------------------------------------------------------------
739 // size: sizeof(uint32_t)
741 //--------------------------------------------------------------------------------------------------
745 //==================================================================================================
746 // command: EFFECT_CMD_OFFLOAD
747 //--------------------------------------------------------------------------------------------------
749 // 1.indicate if the playback thread the effect is attached to is offloaded or not
750 // 2.update the io handle of the playback thread the effect is attached to
751 //--------------------------------------------------------------------------------------------------
753 // size: sizeof(effect_offload_param_t)
754 // data: effect_offload_param_t
755 //--------------------------------------------------------------------------------------------------
757 // size: sizeof(uint32_t)
759 //--------------------------------------------------------------------------------------------------
760 // command: EFFECT_CMD_FIRST_PROPRIETARY
761 //--------------------------------------------------------------------------------------------------
763 // All proprietary effect commands must use command codes above this value. The size and format of
764 // command and response fields is free in this case
765 //==================================================================================================
768 // Audio buffer descriptor used by process(), bufferProvider() functions and buffer_config_t
769 // structure. Multi-channel audio is always interleaved. The channel order is from LSB to MSB with
770 // regard to the channel mask definition in audio.h, audio_channel_mask_t e.g :
771 // Stereo: left, right
772 // 5 point 1: front left, front right, front center, low frequency, back left, back right
773 // The buffer size is expressed in frame count, a frame being composed of samples for all
774 // channels at a given time. Frame size for unspecified format (AUDIO_FORMAT_OTHER) is 8 bit by
776 struct audio_buffer_s {
777 size_t frameCount; // number of frames in buffer
779 void* raw; // raw pointer to start of buffer
780 int32_t* s32; // pointer to signed 32 bit data at start of buffer
781 int16_t* s16; // pointer to signed 16 bit data at start of buffer
782 uint8_t* u8; // pointer to unsigned 8 bit data at start of buffer
786 // The buffer_provider_s structure contains functions that can be used
787 // by the effect engine process() function to query and release input
788 // or output audio buffer.
789 // The getBuffer() function is called to retrieve a buffer where data
790 // should read from or written to by process() function.
791 // The releaseBuffer() function MUST be called when the buffer retrieved
792 // with getBuffer() is not needed anymore.
793 // The process function should use the buffer provider mechanism to retrieve
794 // input or output buffer if the inBuffer or outBuffer passed as argument is NULL
795 // and the buffer configuration (buffer_config_t) given by the EFFECT_CMD_SET_CONFIG
796 // command did not specify an audio buffer.
798 typedef int32_t (* buffer_function_t)(void *cookie, audio_buffer_t *buffer);
800 typedef struct buffer_provider_s {
801 buffer_function_t getBuffer; // retrieve next buffer
802 buffer_function_t releaseBuffer; // release used buffer
803 void *cookie; // for use by client of buffer provider functions
807 // The buffer_config_s structure specifies the input or output audio format
808 // to be used by the effect engine. It is part of the effect_config_t
809 // structure that defines both input and output buffer configurations and is
810 // passed by the EFFECT_CMD_SET_CONFIG or EFFECT_CMD_SET_CONFIG_REVERSE command.
811 typedef struct buffer_config_s {
812 audio_buffer_t buffer; // buffer for use by process() function if not passed explicitly
813 uint32_t samplingRate; // sampling rate
814 uint32_t channels; // channel mask (see audio_channel_mask_t in audio.h)
815 buffer_provider_t bufferProvider; // buffer provider
816 uint8_t format; // Audio format (see audio_format_t in audio.h)
817 uint8_t accessMode; // read/write or accumulate in buffer (effect_buffer_access_e)
818 uint16_t mask; // indicates which of the above fields is valid
821 // Values for "accessMode" field of buffer_config_t:
822 // overwrite, read only, accumulate (read/modify/write)
823 enum effect_buffer_access_e {
824 EFFECT_BUFFER_ACCESS_WRITE,
825 EFFECT_BUFFER_ACCESS_READ,
826 EFFECT_BUFFER_ACCESS_ACCUMULATE
830 // feature identifiers for EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS command
831 enum effect_feature_e {
832 EFFECT_FEATURE_AUX_CHANNELS, // supports auxiliary channels (e.g. dual mic noise suppressor)
836 // EFFECT_FEATURE_AUX_CHANNELS feature configuration descriptor. Describe a combination
837 // of main and auxiliary channels supported
838 typedef struct channel_config_s {
839 audio_channel_mask_t main_channels; // channel mask for main channels
840 audio_channel_mask_t aux_channels; // channel mask for auxiliary channels
844 // Values for bit field "mask" in buffer_config_t. If a bit is set, the corresponding field
845 // in buffer_config_t must be taken into account when executing the EFFECT_CMD_SET_CONFIG command
846 #define EFFECT_CONFIG_BUFFER 0x0001 // buffer field must be taken into account
847 #define EFFECT_CONFIG_SMP_RATE 0x0002 // samplingRate field must be taken into account
848 #define EFFECT_CONFIG_CHANNELS 0x0004 // channels field must be taken into account
849 #define EFFECT_CONFIG_FORMAT 0x0008 // format field must be taken into account
850 #define EFFECT_CONFIG_ACC_MODE 0x0010 // accessMode field must be taken into account
851 #define EFFECT_CONFIG_PROVIDER 0x0020 // bufferProvider field must be taken into account
852 #define EFFECT_CONFIG_ALL (EFFECT_CONFIG_BUFFER | EFFECT_CONFIG_SMP_RATE | \
853 EFFECT_CONFIG_CHANNELS | EFFECT_CONFIG_FORMAT | \
854 EFFECT_CONFIG_ACC_MODE | EFFECT_CONFIG_PROVIDER)
857 // effect_config_s structure describes the format of the pCmdData argument of EFFECT_CMD_SET_CONFIG
858 // command to configure audio parameters and buffers for effect engine input and output.
859 typedef struct effect_config_s {
860 buffer_config_t inputCfg;
861 buffer_config_t outputCfg;
865 // effect_param_s structure describes the format of the pCmdData argument of EFFECT_CMD_SET_PARAM
866 // command and pCmdData and pReplyData of EFFECT_CMD_GET_PARAM command.
867 // psize and vsize represent the actual size of parameter and value.
869 // NOTE: the start of value field inside the data field is always on a 32 bit boundary:
872 // | status | sizeof(int)
874 // | psize | sizeof(int)
876 // | vsize | sizeof(int)
879 // ~ parameter ~ > psize |
880 // | | | > ((psize - 1)/sizeof(int) + 1) * sizeof(int)
889 typedef struct effect_param_s {
890 int32_t status; // Transaction status (unused for command, used for reply)
891 uint32_t psize; // Parameter size
892 uint32_t vsize; // Value size
893 char data[]; // Start of Parameter + Value data
896 // structure used by EFFECT_CMD_OFFLOAD command
897 typedef struct effect_offload_param_s {
898 bool isOffload; // true if the playback thread the effect is attached to is offloaded
899 int ioHandle; // io handle of the playback thread the effect is attached to
900 } effect_offload_param_t;
903 /////////////////////////////////////////////////
904 // Effect library interface
905 /////////////////////////////////////////////////
907 // Effect library interface version 3.0
908 // Note that EffectsFactory.c only checks the major version component, so changes to the minor
909 // number can only be used for fully backwards compatible changes
910 #define EFFECT_LIBRARY_API_VERSION EFFECT_MAKE_API_VERSION(3,0)
912 #define AUDIO_EFFECT_LIBRARY_TAG ((('A') << 24) | (('E') << 16) | (('L') << 8) | ('T'))
914 // Every effect library must have a data structure named AUDIO_EFFECT_LIBRARY_INFO_SYM
915 // and the fields of this data structure must begin with audio_effect_library_t
917 typedef struct audio_effect_library_s {
918 // tag must be initialized to AUDIO_EFFECT_LIBRARY_TAG
920 // Version of the effect library API : 0xMMMMmmmm MMMM: Major, mmmm: minor
922 // Name of this library
924 // Author/owner/implementor of the library
925 const char *implementor;
927 ////////////////////////////////////////////////////////////////////////////////
929 // Function: create_effect
931 // Description: Creates an effect engine of the specified implementation uuid and
932 // returns an effect control interface on this engine. The function will allocate the
933 // resources for an instance of the requested effect engine and return
934 // a handle on the effect control interface.
937 // uuid: pointer to the effect uuid.
938 // sessionId: audio session to which this effect instance will be attached. All effects
939 // created with the same session ID are connected in series and process the same signal
940 // stream. Knowing that two effects are part of the same effect chain can help the
941 // library implement some kind of optimizations.
942 // ioId: identifies the output or input stream this effect is directed to at audio HAL.
943 // For future use especially with tunneled HW accelerated effects
946 // pHandle: address where to return the effect interface handle.
949 // returned value: 0 successful operation.
950 // -ENODEV library failed to initialize
951 // -EINVAL invalid pEffectUuid or pHandle
952 // -ENOENT no effect with this uuid found
953 // *pHandle: updated with the effect interface handle.
955 ////////////////////////////////////////////////////////////////////////////////
956 int32_t (*create_effect)(const effect_uuid_t *uuid,
959 effect_handle_t *pHandle);
961 ////////////////////////////////////////////////////////////////////////////////
963 // Function: release_effect
965 // Description: Releases the effect engine whose handle is given as argument.
966 // All resources allocated to this particular instance of the effect are
970 // handle: handle on the effect interface to be released.
973 // returned value: 0 successful operation.
974 // -ENODEV library failed to initialize
975 // -EINVAL invalid interface handle
977 ////////////////////////////////////////////////////////////////////////////////
978 int32_t (*release_effect)(effect_handle_t handle);
980 ////////////////////////////////////////////////////////////////////////////////
982 // Function: get_descriptor
984 // Description: Returns the descriptor of the effect engine which implementation UUID is
985 // given as argument.
988 // uuid: pointer to the effect uuid.
989 // pDescriptor: address where to return the effect descriptor.
992 // returned value: 0 successful operation.
993 // -ENODEV library failed to initialize
994 // -EINVAL invalid pDescriptor or uuid
995 // *pDescriptor: updated with the effect descriptor.
997 ////////////////////////////////////////////////////////////////////////////////
998 int32_t (*get_descriptor)(const effect_uuid_t *uuid,
999 effect_descriptor_t *pDescriptor);
1000 } audio_effect_library_t;
1002 // Name of the hal_module_info
1003 #define AUDIO_EFFECT_LIBRARY_INFO_SYM AELI
1005 // Name of the hal_module_info as a string
1006 #define AUDIO_EFFECT_LIBRARY_INFO_SYM_AS_STR "AELI"
1010 #endif // ANDROID_AUDIO_EFFECT_H