# PcmAudioUtil

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/PcmAudioUtil.java+class:androidx.media3.exoplayer.audio.PcmAudioUtil)

*** ** * ** ***


```
@UnstableApi
public final class PcmAudioUtil
```

<br />

*** ** * ** ***

Utility methods for PCM audio data.

## Summary

| ### Public methods |
|---|---|
| `static https://developer.android.com/reference/java/nio/ByteBuffer.html` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/PcmAudioUtil#rampUpVolume(java.nio.ByteBuffer,int,int,int,int)( https://developer.android.com/reference/java/nio/ByteBuffer.html buffer, @https://developer.android.com/reference/androidx/media3/common/C.Encoding int pcmEncoding, int pcmFrameSize, int startFrameIndex, int rampFrameCount )` Returns a new `https://developer.android.com/reference/java/nio/ByteBuffer.html` with linear volume ramping applied. |
| `static int` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/PcmAudioUtil#readAs32BitIntPcm(java.nio.ByteBuffer,int)(https://developer.android.com/reference/java/nio/ByteBuffer.html buffer, @https://developer.android.com/reference/androidx/media3/common/C.Encoding int pcmEncoding)` Reads a single-channel PCM value from the buffer and returns it as a 32-bit integer PCM value. |
| `static void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/PcmAudioUtil#write32BitIntPcm(java.nio.ByteBuffer,int,int)( https://developer.android.com/reference/java/nio/ByteBuffer.html buffer, int pcm32bit, @https://developer.android.com/reference/androidx/media3/common/C.Encoding int pcmEncoding )` Writes a 32-bit integer PCM value to a buffer in the given target PCM encoding. |

## Public methods

### rampUpVolume

```
public static ByteBuffer rampUpVolume(
    ByteBuffer buffer,
    @C.Encoding int pcmEncoding,
    int pcmFrameSize,
    int startFrameIndex,
    int rampFrameCount
)
```

Returns a new `https://developer.android.com/reference/java/nio/ByteBuffer.html` with linear volume ramping applied.

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

| Returns |
|---|---|
| `https://developer.android.com/reference/java/nio/ByteBuffer.html` | The `https://developer.android.com/reference/java/nio/ByteBuffer.html` containing the modified PCM data. |

### readAs32BitIntPcm

```
public static int readAs32BitIntPcm(ByteBuffer buffer, @C.Encoding int pcmEncoding)
```

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

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/nio/ByteBuffer.html buffer` | The `https://developer.android.com/reference/java/nio/ByteBuffer.html` to read from. |
| `@https://developer.android.com/reference/androidx/media3/common/C.Encoding int pcmEncoding` | The `https://developer.android.com/reference/androidx/media3/common/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

```
public static void write32BitIntPcm(
    ByteBuffer buffer,
    int pcm32bit,
    @C.Encoding int pcmEncoding
)
```

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

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/nio/ByteBuffer.html buffer` | The `https://developer.android.com/reference/java/nio/ByteBuffer.html` to write to. |
| `int pcm32bit` | The 32-bit PCM value. |
| `@https://developer.android.com/reference/androidx/media3/common/C.Encoding int pcmEncoding` | The target `https://developer.android.com/reference/androidx/media3/common/C.Encoding` of the PCM data in the buffer. Value is one of the following: - `Format.NO_VALUE` <br /> |