DefaultGainProvider


@UnstableApi
class DefaultGainProvider : 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

A builder for DefaultGainProvider instances.

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

Constants

const DefaultGainProvider.FadeProvider!

Equal power fade in.

const DefaultGainProvider.FadeProvider!

Equal gain fade in.

const DefaultGainProvider.FadeProvider!

Equal power fade out.

const DefaultGainProvider.FadeProvider!

Equal gain fade out.

Public functions

Float
getGainFactorAtSamplePosition(
    samplePosition: @IntRange(from = 0) Long,
    sampleRate: @IntRange(from = 1) Int
)

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

Long
isUnityUntil(
    samplePosition: @IntRange(from = 0) Long,
    sampleRate: @IntRange(from = 1) Int
)

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

const val FADE_IN_EQUAL_POWERDefaultGainProvider.FadeProvider!

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

const val FADE_IN_LINEARDefaultGainProvider.FadeProvider!

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

const val FADE_OUT_EQUAL_POWERDefaultGainProvider.FadeProvider!

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

const val FADE_OUT_LINEARDefaultGainProvider.FadeProvider!

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 functions

getGainFactorAtSamplePosition

fun getGainFactorAtSamplePosition(
    samplePosition: @IntRange(from = 0) Long,
    sampleRate: @IntRange(from = 1) Int
): Float

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

fun isUnityUntil(
    samplePosition: @IntRange(from = 0) Long,
    sampleRate: @IntRange(from = 1) Int
): Long

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
samplePosition: @IntRange(from = 0) Long

Inclusive starting position of the unity range.

sampleRate: @IntRange(from = 1) Int

Sample rate in Hertz related to samplePosition.