# VorbisUtil

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

*** ** * ** ***


```
@UnstableApi
class VorbisUtil
```

<br />

*** ** * ** ***

Utility methods for parsing Vorbis streams.

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil.CommentHeader` Vorbis comment header. |
| `class https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil.Mode` Vorbis setup header modes. |
| `class https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil.VorbisIdHeader` Vorbis identification header. |

| ### Public functions |
|---|---|
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil#getPacketBlockSize(byte,androidx.media3.container.VorbisUtil.VorbisIdHeader,androidx.media3.container.VorbisUtil.Mode[])( firstByteOfAudioPacket: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html, idHeader: https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil.VorbisIdHeader!, modes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil.Mode!>! )` Returns the block size of the given packet. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil#getSampleCountInPacket(int,int,boolean)( packetBlockSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, previousPacketBlockSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, seenFirstAudioPacket: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` Returns the number of samples in the given packet. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil#iLog(int)(x: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns ilog(x), which is the index of the highest set bit in `x`. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil.CommentHeader!` | `https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil#readVorbisCommentHeader(androidx.media3.common.util.ParsableByteArray)(headerData: https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray!)` Reads a Vorbis comment header. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil.CommentHeader!` | `https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil#readVorbisCommentHeader(androidx.media3.common.util.ParsableByteArray,boolean,boolean)( headerData: https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray!, hasMetadataHeader: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, hasFramingBit: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` Reads a Vorbis comment header. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil.VorbisIdHeader!` | `https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil#readVorbisIdentificationHeader(androidx.media3.common.util.ParsableByteArray)(headerData: https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray!)` Reads a Vorbis identification header from `headerData`. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil.Mode!>!` | `https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil#readVorbisModes(androidx.media3.common.util.ParsableByteArray,int)(headerData: https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray!, channels: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` This method reads the modes which are located at the very end of the Vorbis setup header. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil#verifyVorbisHeaderCapturePattern(int,androidx.media3.common.util.ParsableByteArray,boolean)( headerType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, header: https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray!, quiet: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` Verifies whether the next bytes in `header` are a Vorbis header of the given ` headerType`. |

## Public functions

### getPacketBlockSize

```
java-static fun getPacketBlockSize(
    firstByteOfAudioPacket: Byte,
    idHeader: VorbisUtil.VorbisIdHeader!,
    modes: Array<VorbisUtil.Mode!>!
): Int
```

Returns the block size of the given packet.

| Parameters |
|---|---|
| `firstByteOfAudioPacket: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html` | The first byte of the audio packet. |
| `idHeader: https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil.VorbisIdHeader!` | The Vorbis identification header. |
| `modes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil.Mode!>!` | The Vorbis modes. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The block size of the packet. |

### getSampleCountInPacket

```
java-static fun getSampleCountInPacket(
    packetBlockSize: Int,
    previousPacketBlockSize: Int,
    seenFirstAudioPacket: Boolean
): Int
```

Returns the number of samples in the given packet.

| Parameters |
|---|---|
| `packetBlockSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The block size of the packet. |
| `previousPacketBlockSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The block size of the previous packet. |
| `seenFirstAudioPacket: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether the first audio packet has been seen. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of samples in the packet. |

### iLog

```
java-static fun iLog(x: Int): Int
```

Returns ilog(x), which is the index of the highest set bit in `x`.

See the [Vorbis spec](https://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-1190009.2.1)

| Parameters |
|---|---|
| `x: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the value of which the ilog should be calculated. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | ilog(x) |

### readVorbisCommentHeader

```
java-static fun readVorbisCommentHeader(headerData: ParsableByteArray!): VorbisUtil.CommentHeader!
```

Reads a Vorbis comment header.

See the [Vorbis spec/Comment header](https://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-640004.2.3)

| Parameters |
|---|---|
| `headerData: https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray!` | A `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray` wrapping the header data. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil.CommentHeader!` | A `https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil.CommentHeader` with all the comments. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/ParserException` | If an error occurs parsing the comment header. |

### readVorbisCommentHeader

```
java-static fun readVorbisCommentHeader(
    headerData: ParsableByteArray!,
    hasMetadataHeader: Boolean,
    hasFramingBit: Boolean
): VorbisUtil.CommentHeader!
```

Reads a Vorbis comment header.

The data provided may not contain the Vorbis metadata common header and the framing bit.

See the [Vorbis spec/Comment header](https://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-640004.2.3)

| Parameters |
|---|---|
| `headerData: https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray!` | A `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray` wrapping the header data. |
| `hasMetadataHeader: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether the `headerData` contains a Vorbis metadata common header preceding the comment header. |
| `hasFramingBit: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether the `headerData` contains a framing bit. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil.CommentHeader!` | A `https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil.CommentHeader` with all the comments. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/ParserException` | If an error occurs parsing the comment header. |

### readVorbisIdentificationHeader

```
java-static fun readVorbisIdentificationHeader(headerData: ParsableByteArray!): VorbisUtil.VorbisIdHeader!
```

Reads a Vorbis identification header from `headerData`.

See the [Vorbis spec/Identification header](https://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-630004.2.2)

| Parameters |
|---|---|
| `headerData: https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray!` | a `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray` wrapping the header data. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil.VorbisIdHeader!` | a `https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil.VorbisIdHeader` with meta data. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/ParserException` | thrown if invalid capture pattern is detected. |

### readVorbisModes

```
java-static fun readVorbisModes(headerData: ParsableByteArray!, channels: Int): Array<VorbisUtil.Mode!>!
```

This method reads the modes which are located at the very end of the Vorbis setup header. That's why we need to partially decode or at least read the entire setup header to know where to start reading the modes.

See the [Vorbis spec/Setup header](https://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-650004.2.4)

| Parameters |
|---|---|
| `headerData: https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray!` | a `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray` containing setup header data. |
| `channels: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the number of channels. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil.Mode!>!` | an array of `https://developer.android.com/reference/kotlin/androidx/media3/container/VorbisUtil.Mode`s. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/ParserException` | thrown if bit stream is invalid. |

### verifyVorbisHeaderCapturePattern

```
@CanIgnoreReturnValue
java-static fun verifyVorbisHeaderCapturePattern(
    headerType: Int,
    header: ParsableByteArray!,
    quiet: Boolean
): Boolean
```

Verifies whether the next bytes in `header` are a Vorbis header of the given `
headerType`.

| Parameters |
|---|---|
| `headerType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the type of the header expected. |
| `header: https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray!` | the alleged header bytes. |
| `quiet: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | if `true` no exceptions are thrown. Instead `false` is returned. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether the header is a Vorbis header. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/ParserException` | thrown if header type or capture pattern is not as expected. |