# DefaultAudioTrackBufferSizeProvider

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

*** ** * ** ***


```
@UnstableApi
class DefaultAudioTrackBufferSizeProvider : DefaultAudioSink.AudioTrackBufferSizeProvider
```

<br />

*** ** * ** ***

Provide the buffer size to use when creating an `https://developer.android.com/reference/android/media/AudioTrack.html`.

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider.Builder` A builder to create `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider` instances. |

| ### Protected constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#DefaultAudioTrackBufferSizeProvider(androidx.media3.exoplayer.audio.DefaultAudioTrackBufferSizeProvider.Builder)( builder: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider.Builder! )` |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#getBufferSizeInBytes(int,int,int,int,int,int,double)( minBufferSizeInBytes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, @https://developer.android.com/reference/kotlin/androidx/media3/common/C.Encoding encoding: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, @https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioSink.OutputMode outputMode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, pcmFrameSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, sampleRate: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, bitrate: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, maxAudioTrackPlaybackSpeed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html )` Returns the buffer size to use when creating an `https://developer.android.com/reference/android/media/AudioTrack.html` for a specific format and output mode. |

| ### Protected functions |
|---|---|
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#durationUsToBytes(int,int,int)(durationUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, samplingRate: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, frameSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#get1xBufferSizeInBytes(int,int,int,int,int,int)( minBufferSizeInBytes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, encoding: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, outputMode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, pcmFrameSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, sampleRate: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, bitrate: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Returns the buffer size for playback at 1x speed. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#getOffloadBufferSizeInBytes(int)(@https://developer.android.com/reference/kotlin/androidx/media3/common/C.Encoding encoding: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns the buffer size for offload playback. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#getPassthroughBufferSizeInBytes(int,int)(@https://developer.android.com/reference/kotlin/androidx/media3/common/C.Encoding encoding: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, bitrate: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns the buffer size for passthrough playback. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#getPcmBufferSizeInBytes(int,int,int)( minBufferSizeInBytes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, samplingRate: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, frameSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Returns the buffer size for PCM playback. |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#ac3BufferMultiplicationFactor()` The multiplication factor to apply to AC3 passthrough buffer to avoid underruns on some devices (e.g., Broadcom 7271). |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#dtshdBufferMultiplicationFactor()` The multiplication factor to apply to DTS-HD (DTS Express) passthrough buffer to avoid underruns. |

| ### Protected properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#maxPcmBufferDurationUs()` **This property is deprecated.** This constraint does not apply to the new default fixed buffer size logic. <br /> |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#minPcmBufferDurationUs()` **This property is deprecated.** This constraint does not apply to the new default fixed buffer size logic. <br /> |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#offloadBufferDurationUs()` The length for offload `https://developer.android.com/reference/android/media/AudioTrack.html` buffers, in microseconds. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#passthroughBufferDurationUs()` The length for passthrough `https://developer.android.com/reference/android/media/AudioTrack.html` buffers, in microseconds. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#pcmBufferMultiplicationFactor()` **This property is deprecated.** Use the default fixed buffer size logic instead, or `https://developer.android.com/reference/kotlin/androidx/media3/common/C#LENGTH_UNSET()` to not use this factor. <br /> |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#targetPcmBufferDurationUs()` The target length for PCM `https://developer.android.com/reference/android/media/AudioTrack.html` buffers, in microseconds. |

### Inherited Constants

From [androidx.media3.exoplayer.audio.DefaultAudioSink.AudioTrackBufferSizeProvider](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioSink.AudioTrackBufferSizeProvider) `const https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioSink.AudioTrackBufferSizeProvider!` `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioSink.AudioTrackBufferSizeProvider#DEFAULT()`

Default instance.

## Protected constructors

### DefaultAudioTrackBufferSizeProvider

```
protected DefaultAudioTrackBufferSizeProvider(
    builder: DefaultAudioTrackBufferSizeProvider.Builder!
)
```

## Public functions

### getBufferSizeInBytes

```
fun getBufferSizeInBytes(
    minBufferSizeInBytes: Int,
    @C.Encoding encoding: Int,
    @DefaultAudioSink.OutputMode outputMode: Int,
    pcmFrameSize: Int,
    sampleRate: Int,
    bitrate: Int,
    maxAudioTrackPlaybackSpeed: Double
): Int
```

Returns the buffer size to use when creating an `https://developer.android.com/reference/android/media/AudioTrack.html` for a specific format and output mode.

| Parameters |
|---|---|
| `minBufferSizeInBytes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The minimum buffer size in bytes required to play this format. See `https://developer.android.com/reference/android/media/AudioTrack.html#getMinBufferSize(int, int, int)`. |
| `@https://developer.android.com/reference/kotlin/androidx/media3/common/C.Encoding encoding: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/C.Encoding` of the format. Value is one of the following: - `Format.NO_VALUE` <br /> |
| `@https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioSink.OutputMode outputMode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | How the audio will be played. One of the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioSink.OutputMode`. |
| `pcmFrameSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The size of the PCM frames if the `encoding` is PCM, 1 otherwise, in bytes. |
| `sampleRate: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The sample rate of the format, in Hz. |
| `bitrate: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The bitrate of the audio stream if the stream is compressed, or `https://developer.android.com/reference/kotlin/androidx/media3/common/Format#NO_VALUE()` if `encoding` is PCM or the bitrate is not known. |
| `maxAudioTrackPlaybackSpeed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html` | The maximum speed the content will be played using `https://developer.android.com/reference/android/media/AudioTrack.html#setPlaybackParams(android.media.PlaybackParams)`. 0.5 is 2x slow motion, 1 is real time, 2 is 2x fast forward, etc. This will be `1` unless `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioSink.Builder#setEnableAudioOutputPlaybackParameters(boolean)` is enabled. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The computed buffer size in bytes. It should always be `>= minBufferSizeInBytes`. The computed buffer size must contain an integer number of frames: `bufferSizeInBytes % pcmFrameSize == 0`. |

## Protected functions

### durationUsToBytes

```
protected java-static fun durationUsToBytes(durationUs: Int, samplingRate: Int, frameSize: Int): Int
```

### get1xBufferSizeInBytes

```
protected fun get1xBufferSizeInBytes(
    minBufferSizeInBytes: Int,
    encoding: Int,
    outputMode: Int,
    pcmFrameSize: Int,
    sampleRate: Int,
    bitrate: Int
): Int
```

Returns the buffer size for playback at 1x speed.

### getOffloadBufferSizeInBytes

```
protected fun getOffloadBufferSizeInBytes(@C.Encoding encoding: Int): Int
```

Returns the buffer size for offload playback.

### getPassthroughBufferSizeInBytes

```
protected fun getPassthroughBufferSizeInBytes(@C.Encoding encoding: Int, bitrate: Int): Int
```

Returns the buffer size for passthrough playback.

### getPcmBufferSizeInBytes

```
protected fun getPcmBufferSizeInBytes(
    minBufferSizeInBytes: Int,
    samplingRate: Int,
    frameSize: Int
): Int
```

Returns the buffer size for PCM playback.

## Public properties

### ac3BufferMultiplicationFactor

```
val ac3BufferMultiplicationFactor: Int
```

The multiplication factor to apply to AC3 passthrough buffer to avoid underruns on some devices (e.g., Broadcom 7271).

### dtshdBufferMultiplicationFactor

```
val dtshdBufferMultiplicationFactor: Int
```

The multiplication factor to apply to DTS-HD (DTS Express) passthrough buffer to avoid underruns.

## Protected properties

### maxPcmBufferDurationUs

```
protected val maxPcmBufferDurationUs: Int
```

> [!CAUTION]
> **This property is deprecated.**   
>
> This constraint does not apply to the new default fixed buffer size logic. Use `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#targetPcmBufferDurationUs()` to configure a fixed buffer size instead. This is only used if `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#pcmBufferMultiplicationFactor()` is set to enable deprecated dynamic logic.

The maximum length for PCM `https://developer.android.com/reference/android/media/AudioTrack.html` buffers, in microseconds.

### minPcmBufferDurationUs

```
protected val minPcmBufferDurationUs: Int
```

> [!CAUTION]
> **This property is deprecated.**   
>
> This constraint does not apply to the new default fixed buffer size logic. Use `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#targetPcmBufferDurationUs()` to configure a fixed buffer size instead. This is only used if `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProvider#pcmBufferMultiplicationFactor()` is set to enable deprecated dynamic logic.

The minimum length for PCM `https://developer.android.com/reference/android/media/AudioTrack.html` buffers, in microseconds.

### offloadBufferDurationUs

```
protected val offloadBufferDurationUs: Int
```

The length for offload `https://developer.android.com/reference/android/media/AudioTrack.html` buffers, in microseconds.

### passthroughBufferDurationUs

```
protected val passthroughBufferDurationUs: Int
```

The length for passthrough `https://developer.android.com/reference/android/media/AudioTrack.html` buffers, in microseconds.

### pcmBufferMultiplicationFactor

```
protected val pcmBufferMultiplicationFactor: Int
```

> [!CAUTION]
> **This property is deprecated.**   
>
> Use the default fixed buffer size logic instead, or `https://developer.android.com/reference/kotlin/androidx/media3/common/C#LENGTH_UNSET()` to not use this factor.

The multiplication factor to apply to the minimum buffer size requested.

### targetPcmBufferDurationUs

```
protected val targetPcmBufferDurationUs: Int
```

The target length for PCM `https://developer.android.com/reference/android/media/AudioTrack.html` buffers, in microseconds.