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