DefaultGainProvider


@UnstableApi
public final class DefaultGainProvider implements GainProcessor.GainProvider


Provides gain automation information to be applied on an audio stream.

The class allows combining multiple fade shapes into one single automation line, with common fade shapes already implemented (e.g. FADE_IN_LINEAR).

See also
GainProcessor

Summary

Nested types

public final class DefaultGainProvider.Builder

A builder for DefaultGainProvider instances.

Represents a time unit-agnostic fade shape to be applied over an automation.

Constants

static final DefaultGainProvider.FadeProvider

Equal power fade in.

static final DefaultGainProvider.FadeProvider

Equal gain fade in.

static final DefaultGainProvider.FadeProvider

Equal power fade out.

static final DefaultGainProvider.FadeProvider

Equal gain fade out.

Public methods

float
getGainFactorAtSamplePosition(
    @IntRange(from = 0) long samplePosition,
    @IntRange(from = 1) int sampleRate
)

Returns a gain factor between [0f; 1f] to apply at the given sample position relative to sampleRate.

long
isUnityUntil(
    @IntRange(from = 0) long samplePosition,
    @IntRange(from = 1) int sampleRate
)

Returns the exclusive upper limit of the range starting at samplePosition where the gain value is 1f (unity), or TIME_UNSET if samplePosition does not correspond to a gain of 1f.

Constants

FADE_IN_EQUAL_POWER

public static final DefaultGainProvider.FadeProvider FADE_IN_EQUAL_POWER

Equal power fade in.

Ramps from 0 to 1 using an equal power curve.

Summing this with FADE_OUT_EQUAL_POWER returns a constant power of 1 for all valid indexes.

FADE_IN_LINEAR

public static final DefaultGainProvider.FadeProvider FADE_IN_LINEAR

Equal gain fade in.

Ramps linearly from 0 to 1.

Summing this with FADE_OUT_LINEAR returns a constant gain of 1 for all valid indexes.

FADE_OUT_EQUAL_POWER

public static final DefaultGainProvider.FadeProvider FADE_OUT_EQUAL_POWER

Equal power fade out.

Ramps from 1 to 0 using an equal power curve.

Summing this with FADE_IN_EQUAL_POWER returns a constant power of 1 for all valid indexes.

FADE_OUT_LINEAR

public static final DefaultGainProvider.FadeProvider FADE_OUT_LINEAR

Equal gain fade out.

Ramps linearly from 1 to 0.

Summing this with FADE_IN_LINEAR returns a constant gain of 1 for all valid indexes.

Public methods

getGainFactorAtSamplePosition

public float getGainFactorAtSamplePosition(
    @IntRange(from = 0) long samplePosition,
    @IntRange(from = 1) int sampleRate
)

Returns a gain factor between [0f; 1f] to apply at the given sample position relative to sampleRate.

Returned values must not change for the same pair of parameter values within the lifetime of the instance.

isUnityUntil

public long isUnityUntil(
    @IntRange(from = 0) long samplePosition,
    @IntRange(from = 1) int sampleRate
)

Returns the exclusive upper limit of the range starting at samplePosition where the gain value is 1f (unity), or TIME_UNSET if samplePosition does not correspond to a gain of 1f.

If the range continues until the end of the stream, this method returns TIME_END_OF_SOURCE.

Returned values must not change for the same pair of parameter values within the lifetime of the instance.

Parameters
@IntRange(from = 0) long samplePosition

Inclusive starting position of the unity range.

@IntRange(from = 1) int sampleRate

Sample rate in Hertz related to samplePosition.