Added in API level 28

DynamicsProcessing


class DynamicsProcessing : AudioEffect

DynamicsProcessing is an audio effect for equalizing and changing dynamic range properties of the sound. It is composed of multiple stages including equalization, multi-band compression and limiter.

The number of bands and active stages is configurable, and most parameters can be controlled in realtime, such as gains, attack/release times, thresholds, etc.

The effect is instantiated and controlled by channels. Each channel has the same basic architecture, but all of their parameters are independent from other channels.

The basic channel configuration is:

Channel 0          Channel 1       ....       Channel N-1
       Input              Input                       Input
         |                  |                           |
    +----v----+        +----v----+                 +----v----+
    |inputGain|        |inputGain|                 |inputGain|
    +---------+        +---------+                 +---------+
         |                  |                           |
   +-----v-----+      +-----v-----+               +-----v-----+
   |   PreEQ   |      |   PreEQ   |               |   PreEQ   |
   +-----------+      +-----------+               +-----------+
         |                  |                           |
   +-----v-----+      +-----v-----+               +-----v-----+
   |    MBC    |      |    MBC    |               |    MBC    |
   +-----------+      +-----------+               +-----------+
         |                  |                           |
   +-----v-----+      +-----v-----+               +-----v-----+
   |  PostEQ   |      |  PostEQ   |               |  PostEQ   |
   +-----------+      +-----------+               +-----------+
         |                  |                           |
   +-----v-----+      +-----v-----+               +-----v-----+
   |  Limiter  |      |  Limiter  |               |  Limiter  |
   +-----------+      +-----------+               +-----------+
         |                  |                           |
      Output             Output                      Output
  

Where the stages are: inputGain: input gain factor in decibels (dB). 0 dB means no change in level. PreEQ: Multi-band Equalizer. MBC: Multi-band Compressor PostEQ: Multi-band Equalizer Limiter: Single band compressor/limiter.

An application creates a DynamicsProcessing object to instantiate and control this audio effect in the audio framework. A DynamicsProcessor.Config and DynamicsProcessor.Config.Builder are available to help configure the multiple stages and each band parameters if desired.

See each stage documentation for further details.

If no Config is specified during creation, a default configuration is chosen.

To attach the DynamicsProcessing to a particular AudioTrack or MediaPlayer, specify the audio session ID of this AudioTrack or MediaPlayer when constructing the effect (see AudioTrack.getAudioSessionId() and MediaPlayer.getAudioSessionId()).

To attach the DynamicsProcessing to a particular AudioTrack or MediaPlayer, specify the audio session ID of this AudioTrack or MediaPlayer when constructing the DynamicsProcessing.

See android.media.MediaPlayer#getAudioSessionId() for details on audio sessions.

See android.media.audiofx.AudioEffect class for more details on controlling audio effects.

Summary

Nested classes

Base class for bands

Base class for stages that hold bands

Class for Channel configuration parameters.

Class for Config object, used by DynamicsProcessing to configure and update the audio effect.

Class for Equalizer stage

Class for Equalizer Bands Equalizer bands have three controllable parameters: enabled/disabled, cutoffFrequency and gain

Class for Limiter Stage Limiter is a single band compressor at the end of the processing chain, commonly used to protect the signal from overloading and distortion.

Class for Multi-Band Compressor (MBC) stage

Class for Multi-Band compressor bands MBC bands have multiple controllable parameters: enabled/disabled, cutoffFrequency, attackTime, releaseTime, ratio, threshold, kneeWidth, noiseGateThreshold, expanderRatio, preGain and postGain.

base class for the different stages.

Constants
static Int

Index of variant that favors frequency resolution.

static Int

Index of variant that favors time resolution resolution.

Inherited constants
String ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION

Intent to signal to the effect control application or service that an audio session is closed and that effects should not be applied anymore.

The effect control application receiving this intent will delete all effects on this session and store current settings in package specific storage.

The calling package name is indicated by the EXTRA_PACKAGE_NAME extra and the audio session ID by the EXTRA_AUDIO_SESSION extra. Both extras are mandatory.

It is good practice for applications to broadcast this intent when music playback stops and/or when exiting to free system resources consumed by audio effect engines.

String ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL

Intent to launch an audio effect control panel UI.

The goal of this intent is to enable separate implementations of music/media player applications and audio effect control application or services. This will allow platform vendors to offer more advanced control options for standard effects or control for platform specific effects.

The intent carries a number of extras used by the player application to communicate necessary pieces of information to the control panel application.

The calling application must use the android.app.Activity#startActivityForResult(Intent, int) method to launch the control panel so that its package name is indicated and used by the control panel application to keep track of changes for this particular application.

The EXTRA_AUDIO_SESSION extra will indicate an audio session to which the audio effects should be applied. If no audio session is specified, either one of the follownig will happen:

- If an audio session was previously opened by the calling application with ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION intent, the effect changes will be applied to that session.

- If no audio session is opened, the changes will be stored in the package specific storage area and applied whenever a new audio session is opened by this application.

The EXTRA_CONTENT_TYPE extra will help the control panel application customize both the UI layout and the default audio effect settings if none are already stored for the calling application.

String ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION

Intent to signal to the effect control application or service that a new audio session is opened and requires audio effects to be applied.

This is different from ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL in that no UI should be displayed in this case. Music player applications can broadcast this intent before starting playback to make sure that any audio effect settings previously selected by the user are applied.

The effect control application receiving this intent will look for previously stored settings for the calling application, create all required audio effects and apply the effect settings to the specified audio session.

The calling package name is indicated by the EXTRA_PACKAGE_NAME extra and the audio session ID by the EXTRA_AUDIO_SESSION extra. Both extras are mandatory.

If no stored settings are found for the calling application, default settings for the content type indicated by EXTRA_CONTENT_TYPE will be applied. The default settings for a given content type are platform specific.

Int ALREADY_EXISTS

Internal operation status. Not returned by any method.

Int CONTENT_TYPE_GAME

Value for EXTRA_CONTENT_TYPE when the type of content played is game audio

Int CONTENT_TYPE_MOVIE

Value for EXTRA_CONTENT_TYPE when the type of content played is video or movie

Int CONTENT_TYPE_MUSIC

Value for EXTRA_CONTENT_TYPE when the type of content played is music

Int CONTENT_TYPE_VOICE

Value for EXTRA_CONTENT_TYPE when the type of content played is voice audio

String EFFECT_AUXILIARY

Effect connection mode is auxiliary.

Auxiliary effects must be created on session 0 (global output mix). In order for a MediaPlayer or AudioTrack to be fed into this effect, they must be explicitely attached to this effect and a send level must be specified.

Use the effect ID returned by getId() to designate this particular effect when attaching it to the MediaPlayer or AudioTrack.

String EFFECT_INSERT

Effect connection mode is insert. Specifying an audio session ID when creating the effect will insert this effect after all players in the same audio session.

String EFFECT_POST_PROCESSING

Effect connection mode is post processing. The audio post processing effects are attached to an audio output stream or device

String EFFECT_PRE_PROCESSING

Effect connection mode is pre processing. The audio pre processing effects are attached to an audio input stream or device

Int ERROR

Unspecified error.

Int ERROR_BAD_VALUE

Operation failed due to bad parameter value.

Int ERROR_DEAD_OBJECT

Operation failed due to dead remote object.

Int ERROR_INVALID_OPERATION

Operation failed because it was requested in wrong state.

Int ERROR_NO_INIT

Operation failed due to bad object initialization.

Int ERROR_NO_MEMORY

Operation failed due to lack of memory.

String EXTRA_AUDIO_SESSION

Contains the ID of the audio session the effects should be applied to.

This extra is for use with ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL, ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION and ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION intents.

The extra value is of type int and is the audio session ID.

String EXTRA_CONTENT_TYPE

Indicates which type of content is played by the application.

This extra is for use with ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL and ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION intents.

This information is used by the effect control application to customize UI and select appropriate default effect settings. The content type is one of the following:

If omitted, the content type defaults to CONTENT_TYPE_MUSIC.

String EXTRA_PACKAGE_NAME

Contains the package name of the calling application.

This extra is for use with ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION and ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION intents.

The extra value is a string containing the full package name.

Int SUCCESS

Successful operation.

Public constructors
DynamicsProcessing(audioSession: Int)

Class constructor.

DynamicsProcessing(priority: Int, audioSession: Int, cfg: DynamicsProcessing.Config?)

Class constructor for the DynamicsProcessing audio effect

Public methods
DynamicsProcessing.Channel!

Int

Gets the number of channels in the effect engine

DynamicsProcessing.Config!

Returns the Config object used to setup this effect.

Float

DynamicsProcessing.Limiter!

DynamicsProcessing.MbcBand!
getMbcBandByChannelIndex(channelIndex: Int, band: Int)

DynamicsProcessing.Mbc!
getMbcByChannelIndex(channelIndex: Int)

DynamicsProcessing.EqBand!
getPostEqBandByChannelIndex(channelIndex: Int, band: Int)

DynamicsProcessing.Eq!

DynamicsProcessing.EqBand!
getPreEqBandByChannelIndex(channelIndex: Int, band: Int)

DynamicsProcessing.Eq!
getPreEqByChannelIndex(channelIndex: Int)

Unit

Unit
setChannelTo(channelIndex: Int, channel: DynamicsProcessing.Channel!)

Unit

Unit
setInputGainbyChannel(channelIndex: Int, inputGain: Float)

Unit

Unit

Unit

Unit

Unit
setMbcBandByChannelIndex(channelIndex: Int, band: Int, mbcBand: DynamicsProcessing.MbcBand!)

Unit

Unit

Unit

Unit
setPostEqBandByChannelIndex(channelIndex: Int, band: Int, postEqBand: DynamicsProcessing.EqBand!)

Unit

Unit

Unit

Unit
setPreEqBandByChannelIndex(channelIndex: Int, band: Int, preEqBand: DynamicsProcessing.EqBand!)

Unit

Inherited functions
Unit finalize()

AudioEffect.Descriptor! getDescriptor()

Get the effect descriptor.

Boolean getEnabled()

Returns effect enabled state

Int getId()

Returns effect unique identifier. This system wide unique identifier can be used to attach this effect to a MediaPlayer or an AudioTrack when the effect is an auxiliary effect (Reverb)

Boolean hasControl()

Checks if this AudioEffect object is controlling the effect engine.

Array<AudioEffect.Descriptor!>! queryEffects()

Query all effects available on the platform. Returns an array of android.media.audiofx.AudioEffect.Descriptor objects

Unit release()

Releases the native AudioEffect resources. It is a good practice to release the effect engine when not in use as control can be returned to other applications or the native resources released.

Unit setControlStatusListener(listener: AudioEffect.OnControlStatusChangeListener!)

Sets the listener AudioEffect notifies when the effect engine control is taken or returned.

Unit setEnableStatusListener(listener: AudioEffect.OnEnableStatusChangeListener!)

Sets the listener AudioEffect notifies when the effect engine is enabled or disabled.

Int setEnabled(enabled: Boolean)

Enable or disable the effect. Creating an audio effect does not automatically apply this effect on the audio source. It creates the resources necessary to process this effect but the audio signal is still bypassed through the effect engine. Calling this method will make that the effect is actually applied or not to the audio content being played in the corresponding audio session.

Inherited properties
UUID! EFFECT_TYPE_AEC

UUID for Acoustic Echo Canceler (AEC)

UUID! EFFECT_TYPE_AGC

UUID for Automatic Gain Control (AGC)

UUID! EFFECT_TYPE_BASS_BOOST

UUID for bass boost effect

UUID! EFFECT_TYPE_DYNAMICS_PROCESSING

UUID for Dynamics Processing

UUID! EFFECT_TYPE_ENV_REVERB

UUID for environmental reverberation effect

UUID! EFFECT_TYPE_EQUALIZER

UUID for equalizer effect

UUID EFFECT_TYPE_HAPTIC_GENERATOR

UUID for Haptic Generator.

UUID! EFFECT_TYPE_LOUDNESS_ENHANCER

UUID for Loudness Enhancer

UUID! EFFECT_TYPE_NS

UUID for Noise Suppressor (NS)

UUID! EFFECT_TYPE_PRESET_REVERB

UUID for preset reverberation effect

UUID! EFFECT_TYPE_VIRTUALIZER

UUID for virtualizer effect

Constants

VARIANT_FAVOR_FREQUENCY_RESOLUTION

Added in API level 28
static val VARIANT_FAVOR_FREQUENCY_RESOLUTION: Int

Index of variant that favors frequency resolution. Frequency domain based implementation.

Value: 0

VARIANT_FAVOR_TIME_RESOLUTION

Added in API level 28
static val VARIANT_FAVOR_TIME_RESOLUTION: Int

Index of variant that favors time resolution resolution. Time domain based implementation.

Value: 1

Public constructors

DynamicsProcessing

Added in API level 28
DynamicsProcessing(audioSession: Int)

Class constructor.

Parameters
audioSession Int: system-wide unique audio session identifier. The DynamicsProcessing will be attached to the MediaPlayer or AudioTrack in the same audio session.

DynamicsProcessing

Added in API level 28
DynamicsProcessing(
    priority: Int,
    audioSession: Int,
    cfg: DynamicsProcessing.Config?)

Class constructor for the DynamicsProcessing audio effect

Parameters
priority Int: the priority level requested by the application for controlling the DynamicsProcessing engine. As the same engine can be shared by several applications, this parameter indicates how much the requesting application needs control of effect parameters. The normal priority is 0, above normal is a positive number, below normal a negative number.
audioSession Int: system-wide unique audio session identifier. The DynamicsProcessing will be attached to the MediaPlayer or AudioTrack in the same audio session.
cfg DynamicsProcessing.Config?: Config object used to setup the audio effect, including bands per stage, and specific parameters for each stage/band. Use android.media.audiofx.DynamicsProcessing.Config.Builder to create a Config object that suits your needs. A null cfg parameter will create and use a default configuration for the effect

Public methods

getChannelByChannelIndex

Added in API level 28
fun getChannelByChannelIndex(channelIndex: Int): DynamicsProcessing.Channel!

getChannelCount

Added in API level 28
fun getChannelCount(): Int

Gets the number of channels in the effect engine

Return
Int number of channels currently in use by the effect engine

getConfig

Added in API level 28
fun getConfig(): DynamicsProcessing.Config!

Returns the Config object used to setup this effect.

Return
DynamicsProcessing.Config! Config Current Config object used to setup this DynamicsProcessing effect.

getInputGainByChannelIndex

Added in API level 28
fun getInputGainByChannelIndex(channelIndex: Int): Float

getLimiterByChannelIndex

Added in API level 28
fun getLimiterByChannelIndex(channelIndex: Int): DynamicsProcessing.Limiter!

getMbcBandByChannelIndex

Added in API level 28
fun getMbcBandByChannelIndex(
    channelIndex: Int,
    band: Int
): DynamicsProcessing.MbcBand!

getMbcByChannelIndex

Added in API level 28
fun getMbcByChannelIndex(channelIndex: Int): DynamicsProcessing.Mbc!

getPostEqBandByChannelIndex

Added in API level 28
fun getPostEqBandByChannelIndex(
    channelIndex: Int,
    band: Int
): DynamicsProcessing.EqBand!

getPostEqByChannelIndex

Added in API level 28
fun getPostEqByChannelIndex(channelIndex: Int): DynamicsProcessing.Eq!

getPreEqBandByChannelIndex

Added in API level 28
fun getPreEqBandByChannelIndex(
    channelIndex: Int,
    band: Int
): DynamicsProcessing.EqBand!

getPreEqByChannelIndex

Added in API level 28
fun getPreEqByChannelIndex(channelIndex: Int): DynamicsProcessing.Eq!

setAllChannelsTo

Added in API level 28
fun setAllChannelsTo(channel: DynamicsProcessing.Channel!): Unit

setChannelTo

Added in API level 28
fun setChannelTo(
    channelIndex: Int,
    channel: DynamicsProcessing.Channel!
): Unit

setInputGainAllChannelsTo

Added in API level 28
fun setInputGainAllChannelsTo(inputGain: Float): Unit

setInputGainbyChannel

Added in API level 28
fun setInputGainbyChannel(
    channelIndex: Int,
    inputGain: Float
): Unit

setLimiterAllChannelsTo

Added in API level 28
fun setLimiterAllChannelsTo(limiter: DynamicsProcessing.Limiter!): Unit

setLimiterByChannelIndex

Added in API level 28
fun setLimiterByChannelIndex(
    channelIndex: Int,
    limiter: DynamicsProcessing.Limiter!
): Unit

setMbcAllChannelsTo

Added in API level 28
fun setMbcAllChannelsTo(mbc: DynamicsProcessing.Mbc!): Unit

setMbcBandAllChannelsTo

Added in API level 28
fun setMbcBandAllChannelsTo(
    band: Int,
    mbcBand: DynamicsProcessing.MbcBand!
): Unit

setMbcBandByChannelIndex

Added in API level 28
fun setMbcBandByChannelIndex(
    channelIndex: Int,
    band: Int,
    mbcBand: DynamicsProcessing.MbcBand!
): Unit

setMbcByChannelIndex

Added in API level 28
fun setMbcByChannelIndex(
    channelIndex: Int,
    mbc: DynamicsProcessing.Mbc!
): Unit

setPostEqAllChannelsTo

Added in API level 28
fun setPostEqAllChannelsTo(postEq: DynamicsProcessing.Eq!): Unit

setPostEqBandAllChannelsTo

Added in API level 28
fun setPostEqBandAllChannelsTo(
    band: Int,
    postEqBand: DynamicsProcessing.EqBand!
): Unit

setPostEqBandByChannelIndex

Added in API level 28
fun setPostEqBandByChannelIndex(
    channelIndex: Int,
    band: Int,
    postEqBand: DynamicsProcessing.EqBand!
): Unit

setPostEqByChannelIndex

Added in API level 28
fun setPostEqByChannelIndex(
    channelIndex: Int,
    postEq: DynamicsProcessing.Eq!
): Unit

setPreEqAllChannelsTo

Added in API level 28
fun setPreEqAllChannelsTo(preEq: DynamicsProcessing.Eq!): Unit

setPreEqBandAllChannelsTo

Added in API level 28
fun setPreEqBandAllChannelsTo(
    band: Int,
    preEqBand: DynamicsProcessing.EqBand!
): Unit

setPreEqBandByChannelIndex

Added in API level 28
fun setPreEqBandByChannelIndex(
    channelIndex: Int,
    band: Int,
    preEqBand: DynamicsProcessing.EqBand!
): Unit

setPreEqByChannelIndex

Added in API level 28
fun setPreEqByChannelIndex(
    channelIndex: Int,
    preEq: DynamicsProcessing.Eq!
): Unit