> Documentation index: https://developer.android.com/reference/llms.txt

# PcmAudioUtil

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

*** ** * ** ***


```
@UnstableApi
class PcmAudioUtil
```

<br />

*** ** * ** ***

Utility methods for PCM audio data.

## Summary

| ### Public functions |
|---|---|
| `java-static ByteBuffer!` | `rampUpVolume( buffer: ByteBuffer!, @C.Encoding pcmEncoding: Int, pcmFrameSize: Int, startFrameIndex: Int, rampFrameCount: Int )` Returns a new `ByteBuffer` with linear volume ramping applied. |
| `java-static ByteBuffer!` | `@CanIgnoreReturnValue rampUpVolume( buffer: ByteBuffer!, outputBuffer: ByteBuffer!, @C.Encoding pcmEncoding: Int, pcmFrameSize: Int, startFrameIndex: Int, rampFrameCount: Int )` Returns a `ByteBuffer` with linear volume ramping applied, using the provided ` outputBuffer`. |
| `java-static Int` | `readAs32BitIntPcm(buffer: ByteBuffer!, @C.Encoding pcmEncoding: Int)` Reads a single-channel PCM value from the buffer and returns it as a 32-bit integer PCM value. |
| `java-static Unit` | `write32BitIntPcm( buffer: ByteBuffer!, pcm32bit: Int, @C.Encoding pcmEncoding: Int )` Writes a 32-bit integer PCM value to a buffer in the given target PCM encoding. |

## Public functions

### rampUpVolume

```
java-static fun rampUpVolume(
    buffer: ByteBuffer!,
    @C.Encoding pcmEncoding: Int,
    pcmFrameSize: Int,
    startFrameIndex: Int,
    rampFrameCount: Int
): ByteBuffer!
```

Returns a new `ByteBuffer` with linear volume ramping applied.

| Parameters |
|---|---|
| `buffer: ByteBuffer!` | The input buffer containing PCM frames. The buffer will be fully consumed by this method. |
| `@C.Encoding pcmEncoding: Int` | The `C.Encoding` of the PCM frames. Value is one of the following: - `Format.NO_VALUE` <br /> |
| `pcmFrameSize: Int` | The overall frame size of one PCM frame (including all channels). |
| `startFrameIndex: Int` | The index of the first frame within the audio ramp duration (as specified by `rampFrameCount`). |
| `rampFrameCount: Int` | The overall ramp duration in number of frames. |

| Returns |
|---|---|
| `ByteBuffer!` | The `ByteBuffer` containing the modified PCM data. |

### rampUpVolume

```
@CanIgnoreReturnValue
java-static fun rampUpVolume(
    buffer: ByteBuffer!,
    outputBuffer: ByteBuffer!,
    @C.Encoding pcmEncoding: Int,
    pcmFrameSize: Int,
    startFrameIndex: Int,
    rampFrameCount: Int
): ByteBuffer!
```

Returns a `ByteBuffer` with linear volume ramping applied, using the provided `
outputBuffer`.

| Parameters |
|---|---|
| `buffer: ByteBuffer!` | The input buffer containing PCM frames. The buffer will be fully consumed by this method. |
| `outputBuffer: ByteBuffer!` | The buffer to write the ramped PCM data into. It must be a direct byte buffer with native byte order and sufficient capacity. Its position and limit will be set to contain the written data. |
| `@C.Encoding pcmEncoding: Int` | The `C.Encoding` of the PCM frames. Value is one of the following: - `Format.NO_VALUE` <br /> |
| `pcmFrameSize: Int` | The overall frame size of one PCM frame (including all channels). |
| `startFrameIndex: Int` | The index of the first frame within the audio ramp duration (as specified by `rampFrameCount`). |
| `rampFrameCount: Int` | The overall ramp duration in number of frames. |

| Returns |
|---|---|
| `ByteBuffer!` | The `ByteBuffer` containing the modified PCM data. |

### readAs32BitIntPcm

```
java-static fun readAs32BitIntPcm(buffer: ByteBuffer!, @C.Encoding pcmEncoding: Int): Int
```

Reads a single-channel PCM value from the buffer and returns it as a 32-bit integer PCM value.

| Parameters |
|---|---|
| `buffer: ByteBuffer!` | The `ByteBuffer` to read from. |
| `@C.Encoding pcmEncoding: Int` | The `C.Encoding` of the PCM data in the buffer. Value is one of the following: - `Format.NO_VALUE` <br /> |

| Returns |
|---|---|
| `Int` | The 32-bit PCM value of the read buffer. |

### write32BitIntPcm

```
java-static fun write32BitIntPcm(
    buffer: ByteBuffer!,
    pcm32bit: Int,
    @C.Encoding pcmEncoding: Int
): Unit
```

Writes a 32-bit integer PCM value to a buffer in the given target PCM encoding.

| Parameters |
|---|---|
| `buffer: ByteBuffer!` | The `ByteBuffer` to write to. |
| `pcm32bit: Int` | The 32-bit PCM value. |
| `@C.Encoding pcmEncoding: Int` | The target `C.Encoding` of the PCM data in the buffer. Value is one of the following: - `Format.NO_VALUE` <br /> |