Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 53334cdb authored by Eric Laurent's avatar Eric Laurent
Browse files

Various fixes and improvements in audio effects implementation

Effect API:
- Use different definitions for audio device, channels, formats... in AudioSystem and EffectApi:
  Removed media/AudioCommon.h file created for initial version of EffectApi
- Indicate audio session and output ID to effect library when calling EffectCreate(). Session ID can be useful to optimize
the implementation of effect chains in the same audio session. Output ID can be used for effects implemented in audio hardware.
- Renamed EffectQueryNext() function to EffectQueryEffect() and changed operating mode:
  now an index is passed for the queried effect instead of implicitly querying the next one.
- Added CPU load and memory usage indication in effects descriptor
- Added flags and commands to indicate changes in audio mode (ring tone, in call...) to effect engine
- Added flag to indicate hardware accelerated effect implementation.
- Renamed EffectFactoryApi.h to EffectsFactoryApi.h for consistency with EffectsFactory.c/h

Effect libraries:
- Reflected changes in Effect API
- Several fixes in reverb implementation
- Added build option TEST_EFFECT_LIBRARIES in makefile to prepare integration of actual effect library.
- Replaced pointer by integer identifier for library handle returned by effects factory

Audio effect framework:
- Added support for audio session -1 in preparation of output stage effects configuration.
- Reflected changes in Effect API
- Removed volume ramp up/down when effect is inserted/removed: this has to be taken care of by effect engines.
- Added some overflow verification on indexes used for deferred parameter updates via shared memory
- Added hardcoded CPU and memory limit check when creating a new effect instance

Change-Id: I43fee5182ee201384ea3479af6d0acb95092901d
parent 03791188
Loading
Loading
Loading
Loading

include/media/AudioCommon.h

deleted100644 → 0
+0 −80
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_AUDIOCOMMON_H_
#define ANDROID_AUDIOCOMMON_H_

#if __cplusplus
extern "C" {
#endif

/////////////////////////////////////////////////
//      Common definitions for PCM audio
/////////////////////////////////////////////////


// PCM Sample format
enum audio_format_e {
    PCM_FORMAT_S15 = 1,     // PCM signed 16 bits, must be 1 for backward compatibility
    PCM_FORMAT_U8 = 2,      // PCM unsigned 8 bits, must be 2 for backward compatibility
    PCM_FORMAT_S7_24        // signed 7.24 fixed point representation
};

// Channel mask definitions
enum audio_channels_e {
    CHANNEL_FRONT_LEFT = 0x4,                   // front left channel
    CHANNEL_FRONT_RIGHT = 0x8,                  // front right channel
    CHANNEL_FRONT_CENTER = 0x10,                // front center channel
    CHANNEL_LOW_FREQUENCY = 0x20,               // low frequency channel
    CHANNEL_BACK_LEFT = 0x40,                   // back left channel
    CHANNEL_BACK_RIGHT = 0x80,                  // back right channel
    CHANNEL_FRONT_LEFT_OF_CENTER = 0x100,       // front left of center channel
    CHANNEL_FRONT_RIGHT_OF_CENTER = 0x200,      // front right of center channel
    CHANNEL_BACK_CENTER = 0x400,                // back center channel
    CHANNEL_MONO = CHANNEL_FRONT_LEFT,
    CHANNEL_STEREO = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT),
    CHANNEL_QUAD = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT |
            CHANNEL_BACK_LEFT | CHANNEL_BACK_RIGHT),
    CHANNEL_SURROUND = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT |
            CHANNEL_FRONT_CENTER | CHANNEL_BACK_CENTER),
    CHANNEL_5POINT1 = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT |
            CHANNEL_FRONT_CENTER | CHANNEL_LOW_FREQUENCY | CHANNEL_BACK_LEFT | CHANNEL_BACK_RIGHT),
    CHANNEL_7POINT1 = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT |
            CHANNEL_FRONT_CENTER | CHANNEL_LOW_FREQUENCY | CHANNEL_BACK_LEFT | CHANNEL_BACK_RIGHT |
            CHANNEL_FRONT_LEFT_OF_CENTER | CHANNEL_FRONT_RIGHT_OF_CENTER),
};

// Render device definitions
enum audio_device_e {
    DEVICE_EARPIECE = 0x1,                      // earpiece
    DEVICE_SPEAKER = 0x2,                       // speaker
    DEVICE_WIRED_HEADSET = 0x4,                 // wired headset, with microphone
    DEVICE_WIRED_HEADPHONE = 0x8,               // wired headphone, without microphone
    DEVICE_BLUETOOTH_SCO = 0x10,                // generic bluetooth SCO
    DEVICE_BLUETOOTH_SCO_HEADSET = 0x20,        // bluetooth SCO headset
    DEVICE_BLUETOOTH_SCO_CARKIT = 0x40,         // bluetooth SCO car kit
    DEVICE_BLUETOOTH_A2DP = 0x80,               // generic bluetooth A2DP
    DEVICE_BLUETOOTH_A2DP_HEADPHONES = 0x100,   // bluetooth A2DP headphones
    DEVICE_BLUETOOTH_A2DP_SPEAKER = 0x200,      // bluetooth A2DP speakers
    DEVICE_AUX_DIGITAL = 0x400                  // digital output
};

#if __cplusplus
}  // extern "C"
#endif


#endif /*ANDROID_AUDIOCOMMON_H_*/
+10 −10
Original line number Diff line number Diff line
@@ -93,14 +93,14 @@ public:

    /*
     * Returns the number of effects available. This method together
     * with EffectQueryNext() is used to enumerate all effects:
     * with queryEffect() is used to enumerate all effects:
     * The enumeration sequence is:
     *      QueryNumberEffects(&num_effects);
     *      while (num_effects--)
     *          QueryNextEffect();
     *      queryNumberEffects(&num_effects);
     *      for (i = 0; i < num_effects; i++)
     *          queryEffect(i,...);
     *
     * Parameters:
     *      pNumEffects:    address where the number of effects should be returned.
     *      numEffects:    address where the number of effects should be returned.
     *
     * Returned status (from utils/Errors.h) can be:
     *      NO_ERROR   successful operation.
@@ -114,24 +114,24 @@ public:
    static status_t queryNumberEffects(uint32_t *numEffects);

    /*
     * Returns number effect descriptor during effect
     * Returns an effect descriptor during effect
     * enumeration.
     *
     * Parameters:
     *      pDescriptor:    address where the effect descriptor should be returned.
     *      index:      index of the queried effect.
     *      descriptor: address where the effect descriptor should be returned.
     *
     * Returned status (from utils/Errors.h) can be:
     *      NO_ERROR        successful operation.
     *      NAME_NOT_FOUND  no more effect available
     *      PERMISSION_DENIED could not get AudioFlinger interface
     *      NO_INIT         effect library failed to initialize
     *      BAD_VALUE       invalid descriptor pointer
     *      BAD_VALUE       invalid descriptor pointer or index
     *      INVALID_OPERATION  effect list has changed since last execution of queryNumberEffects()
     *
     * Returned value
     *   *descriptor:     updated with effect descriptor
     */
    static status_t queryNextEffect(effect_descriptor_t *descriptor);
    static status_t queryEffect(uint32_t index, effect_descriptor_t *descriptor);


    /*
+33 −29
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@
#include <utils/RefBase.h>
#include <utils/threads.h>
#include <media/IAudioFlinger.h>
#include <media/AudioCommon.h>

namespace android {

@@ -51,8 +50,8 @@ public:

    // Audio sub formats (see AudioSystem::audio_format).
    enum pcm_sub_format {
        PCM_SUB_16_BIT          = PCM_FORMAT_S15, // must be 1 for backward compatibility
        PCM_SUB_8_BIT           = PCM_FORMAT_U8, // must be 2 for backward compatibility
        PCM_SUB_16_BIT          = 0x1, // must be 1 for backward compatibility
        PCM_SUB_8_BIT           = 0x2, // must be 2 for backward compatibility
    };

    // MP3 sub format field definition : can use 11 LSBs in the same way as MP3 frame header to specify
@@ -104,21 +103,26 @@ public:
    // Channel mask definitions must be kept in sync with JAVA values in /media/java/android/media/AudioFormat.java
    enum audio_channels {
        // output channels
        CHANNEL_OUT_FRONT_LEFT = CHANNEL_FRONT_LEFT,
        CHANNEL_OUT_FRONT_RIGHT = CHANNEL_FRONT_RIGHT,
        CHANNEL_OUT_FRONT_CENTER = CHANNEL_FRONT_CENTER,
        CHANNEL_OUT_LOW_FREQUENCY = CHANNEL_LOW_FREQUENCY,
        CHANNEL_OUT_BACK_LEFT = CHANNEL_BACK_LEFT,
        CHANNEL_OUT_BACK_RIGHT = CHANNEL_BACK_RIGHT,
        CHANNEL_OUT_FRONT_LEFT_OF_CENTER = CHANNEL_FRONT_LEFT_OF_CENTER,
        CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = CHANNEL_FRONT_RIGHT_OF_CENTER,
        CHANNEL_OUT_BACK_CENTER = CHANNEL_BACK_CENTER,
        CHANNEL_OUT_MONO = CHANNEL_MONO,
        CHANNEL_OUT_STEREO = CHANNEL_STEREO,
        CHANNEL_OUT_QUAD = CHANNEL_QUAD,
        CHANNEL_OUT_SURROUND = CHANNEL_SURROUND,
        CHANNEL_OUT_5POINT1 = CHANNEL_5POINT1,
        CHANNEL_OUT_7POINT1 = CHANNEL_7POINT1,
        CHANNEL_OUT_FRONT_LEFT = 0x4,
        CHANNEL_OUT_FRONT_RIGHT = 0x8,
        CHANNEL_OUT_FRONT_CENTER = 0x10,
        CHANNEL_OUT_LOW_FREQUENCY = 0x20,
        CHANNEL_OUT_BACK_LEFT = 0x40,
        CHANNEL_OUT_BACK_RIGHT = 0x80,
        CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x100,
        CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x200,
        CHANNEL_OUT_BACK_CENTER = 0x400,
        CHANNEL_OUT_MONO = CHANNEL_OUT_FRONT_LEFT,
        CHANNEL_OUT_STEREO = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT),
        CHANNEL_OUT_QUAD = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
                CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT),
        CHANNEL_OUT_SURROUND = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
                CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_BACK_CENTER),
        CHANNEL_OUT_5POINT1 = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
                CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT),
        CHANNEL_OUT_7POINT1 = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
                CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT |
                CHANNEL_OUT_FRONT_LEFT_OF_CENTER | CHANNEL_OUT_FRONT_RIGHT_OF_CENTER),
        CHANNEL_OUT_ALL = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
                CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT |
                CHANNEL_OUT_FRONT_LEFT_OF_CENTER | CHANNEL_OUT_FRONT_RIGHT_OF_CENTER | CHANNEL_OUT_BACK_CENTER),
@@ -238,17 +242,17 @@ public:

    enum audio_devices {
        // output devices
        DEVICE_OUT_EARPIECE = DEVICE_EARPIECE,
        DEVICE_OUT_SPEAKER = DEVICE_SPEAKER,
        DEVICE_OUT_WIRED_HEADSET = DEVICE_WIRED_HEADSET,
        DEVICE_OUT_WIRED_HEADPHONE = DEVICE_WIRED_HEADPHONE,
        DEVICE_OUT_BLUETOOTH_SCO = DEVICE_BLUETOOTH_SCO,
        DEVICE_OUT_BLUETOOTH_SCO_HEADSET = DEVICE_BLUETOOTH_SCO_HEADSET,
        DEVICE_OUT_BLUETOOTH_SCO_CARKIT = DEVICE_BLUETOOTH_SCO_CARKIT,
        DEVICE_OUT_BLUETOOTH_A2DP = DEVICE_BLUETOOTH_A2DP,
        DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = DEVICE_BLUETOOTH_A2DP_HEADPHONES,
        DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = DEVICE_BLUETOOTH_A2DP_SPEAKER,
        DEVICE_OUT_AUX_DIGITAL = DEVICE_AUX_DIGITAL,
        DEVICE_OUT_EARPIECE = 0x1,
        DEVICE_OUT_SPEAKER = 0x2,
        DEVICE_OUT_WIRED_HEADSET = 0x4,
        DEVICE_OUT_WIRED_HEADPHONE = 0x8,
        DEVICE_OUT_BLUETOOTH_SCO = 0x10,
        DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20,
        DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40,
        DEVICE_OUT_BLUETOOTH_A2DP = 0x80,
        DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100,
        DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200,
        DEVICE_OUT_AUX_DIGITAL = 0x400,
        DEVICE_OUT_DEFAULT = 0x8000,
        DEVICE_OUT_ALL = (DEVICE_OUT_EARPIECE | DEVICE_OUT_SPEAKER | DEVICE_OUT_WIRED_HEADSET |
                DEVICE_OUT_WIRED_HEADPHONE | DEVICE_OUT_BLUETOOTH_SCO | DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
+348 −118

File changed.

Preview size limit exceeded, changes collapsed.

+19 −12
Original line number Diff line number Diff line
@@ -14,8 +14,8 @@
 * limitations under the License.
 */

#ifndef ANDROID_EFFECTFACTORYAPI_H_
#define ANDROID_EFFECTFACTORYAPI_H_
#ifndef ANDROID_EFFECTSFACTORYAPI_H_
#define ANDROID_EFFECTSFACTORYAPI_H_

#include <errno.h>
#include <stdint.h>
@@ -36,11 +36,11 @@ extern "C" {
//
//    Description:    Returns the number of different effects in all loaded libraries.
//          Each effect must have a different effect uuid (see
//          effect_descriptor_t). This function together with EffectQueryNext()
//          effect_descriptor_t). This function together with EffectQueryEffect()
//          is used to enumerate all effects present in all loaded libraries.
//          Each time EffectQueryNumberEffects() is called, the factory must
//          reset the index of the effect descriptor returned by next call to
//          EffectQueryNext() to restart enumeration from the beginning.
//          EffectQueryEffect() to restart enumeration from the beginning.
//
//    Input/Output:
//          pNumEffects:    address where the number of effects should be returned.
@@ -56,28 +56,29 @@ int EffectQueryNumberEffects(uint32_t *pNumEffects);

////////////////////////////////////////////////////////////////////////////////
//
//    Function:       EffectQueryNext
//    Function:       EffectQueryEffect
//
//    Description:    Returns a descriptor of the next available effect.
//          See effect_descriptor_t for a details on effect descriptor.
//          This function together with EffectQueryNext() is used to enumerate all
//          This function together with EffectQueryNumberEffects() is used to enumerate all
//          effects present in all loaded libraries. The enumeration sequence is:
//              EffectQueryNumberEffects(&num_effects);
//              while (num_effects--)
//                  EffectQueryNext();
//              for (i = 0; i < num_effects; i++)
//                  EffectQueryEffect(i,...);
//
//    Input/Output:
//          pDescriptor:    address where to return the effect descriptor.
//
//    Output:
//        returned value:    0          successful operation.
//                          -ENOENT     no more effect available
//                          -ENODEV     factory failed to initialize
//                          -EINVAL     invalid pDescriptor
//                          -ENOENT     no more effect available
//                          -ENOSYS     effect list has changed since last execution of EffectQueryNumberEffects()
//        *pDescriptor:     updated with the effect descriptor.
//
////////////////////////////////////////////////////////////////////////////////
int EffectQueryNext(effect_descriptor_t *pDescriptor);
int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor);

////////////////////////////////////////////////////////////////////////////////
//
@@ -90,6 +91,12 @@ int EffectQueryNext(effect_descriptor_t *pDescriptor);
//
//    Input:
//          pEffectUuid:    pointer to the effect uuid.
//          sessionId:  audio session to which this effect instance will be attached. All effects created
//              with the same session ID are connected in series and process the same signal stream.
//              Knowing that two effects are part of the same effect chain can help the library implement
//              some kind of optimizations.
//          ioId:   identifies the output or input stream this effect is directed to at audio HAL. For future
//              use especially with tunneled HW accelerated effects
//
//    Input/Output:
//          pInterface:    address where to return the effect interface.
@@ -102,7 +109,7 @@ int EffectQueryNext(effect_descriptor_t *pDescriptor);
//        *pInterface:     updated with the effect interface.
//
////////////////////////////////////////////////////////////////////////////////
int EffectCreate(effect_uuid_t *pEffectUuid, effect_interface_t *pInterface);
int EffectCreate(effect_uuid_t *pEffectUuid, int32_t sessionId, int32_t ioId, effect_interface_t *pInterface);

////////////////////////////////////////////////////////////////////////////////
//
@@ -211,4 +218,4 @@ int EffectIsNullUuid(effect_uuid_t *pEffectUuid);
#endif


#endif /*ANDROID_EFFECTFACTORYAPI_H_*/
#endif /*ANDROID_EFFECTSFACTORYAPI_H_*/
Loading