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