# DefaultGainProvider

Artifact: [androidx.media3:media3-common](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/common/audio/DefaultGainProvider.java+class:androidx.media3.common.audio.DefaultGainProvider)

*** ** * ** ***


```
@UnstableApi
public final class DefaultGainProvider implements GainProcessor.GainProvider
```

<br />

*** ** * ** ***

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

The class allows combining multiple `https://developer.android.com/reference/androidx/media3/common/audio/DefaultGainProvider.FadeProvider` into one single automation line, with common fade shapes already implemented (e.g. `https://developer.android.com/reference/androidx/media3/common/audio/DefaultGainProvider#FADE_IN_LINEAR()`).

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/audio/GainProcessor` |   |

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/media3/common/audio/DefaultGainProvider.Builder` A builder for `https://developer.android.com/reference/androidx/media3/common/audio/DefaultGainProvider` instances. |
| `public interface https://developer.android.com/reference/androidx/media3/common/audio/DefaultGainProvider.FadeProvider` Represents a time unit-agnostic fade shape to be applied over an automation. |

| ### Constants |
|---|---|
| `static final https://developer.android.com/reference/androidx/media3/common/audio/DefaultGainProvider.FadeProvider` | `https://developer.android.com/reference/androidx/media3/common/audio/DefaultGainProvider#FADE_IN_EQUAL_POWER()` Equal power fade in. |
| `static final https://developer.android.com/reference/androidx/media3/common/audio/DefaultGainProvider.FadeProvider` | `https://developer.android.com/reference/androidx/media3/common/audio/DefaultGainProvider#FADE_IN_LINEAR()` Equal gain fade in. |
| `static final https://developer.android.com/reference/androidx/media3/common/audio/DefaultGainProvider.FadeProvider` | `https://developer.android.com/reference/androidx/media3/common/audio/DefaultGainProvider#FADE_OUT_EQUAL_POWER()` Equal power fade out. |
| `static final https://developer.android.com/reference/androidx/media3/common/audio/DefaultGainProvider.FadeProvider` | `https://developer.android.com/reference/androidx/media3/common/audio/DefaultGainProvider#FADE_OUT_LINEAR()` Equal gain fade out. |

| ### Public methods |
|---|---|
| `float` | `https://developer.android.com/reference/androidx/media3/common/audio/DefaultGainProvider#getGainFactorAtSamplePosition(long,int)( @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) long samplePosition, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 1) int sampleRate )` Returns a gain factor between \[0f; 1f\] to apply at the given sample position relative to `sampleRate`. |
| `long` | `https://developer.android.com/reference/androidx/media3/common/audio/DefaultGainProvider#isUnityUntil(long,int)( @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) long samplePosition, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 1) int sampleRate )` Returns the exclusive upper limit of the range starting at `samplePosition` where the gain value is 1f (unity), or `https://developer.android.com/reference/androidx/media3/common/C#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 `https://developer.android.com/reference/androidx/media3/common/audio/DefaultGainProvider#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 `https://developer.android.com/reference/androidx/media3/common/audio/DefaultGainProvider#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 `https://developer.android.com/reference/androidx/media3/common/audio/DefaultGainProvider#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 `https://developer.android.com/reference/androidx/media3/common/audio/DefaultGainProvider#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 `https://developer.android.com/reference/androidx/media3/common/C#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 `https://developer.android.com/reference/androidx/media3/common/C#TIME_END_OF_SOURCE()`.

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) long samplePosition` | Inclusive starting position of the unity range. |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 1) int sampleRate` | Sample rate in Hertz related to `samplePosition`. |