@UnstableApi
public final class PcmAudioUtil


Utility methods for PCM audio data.

Summary

Public methods

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

Returns a new ByteBuffer with linear volume ramping applied.

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.

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.

Public methods

rampUpVolume

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

Returns a new ByteBuffer with linear volume ramping applied.

Parameters
ByteBuffer buffer

The input buffer containing PCM frames. The buffer will be fully consumed by this method.

@C.Encoding int pcmEncoding

The C.Encoding of the PCM frames.

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
ByteBuffer

The ByteBuffer 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
ByteBuffer buffer

The ByteBuffer to read from.

@C.Encoding int pcmEncoding

The C.Encoding of the PCM data in the buffer.

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
ByteBuffer buffer

The ByteBuffer to write to.

int pcm32bit

The 32-bit PCM value.

@C.Encoding int pcmEncoding

The target C.Encoding of the PCM data in the buffer.