# AacUtil

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

*** ** * ** ***


```
@UnstableApi
public final class AacUtil
```

<br />

*** ** * ** ***

Utility methods for handling AAC audio streams.

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = https://developer.android.com/reference/java/lang/annotation/ElementType.html#TYPE_USE) @https://developer.android.com/reference/androidx/annotation/IntDef(value = ) public annotation https://developer.android.com/reference/androidx/media3/extractor/AacUtil.AacAudioObjectType` Valid AAC Audio object types. |
| `public final class https://developer.android.com/reference/androidx/media3/extractor/AacUtil.Config` Holds sample format information for AAC audio. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/AacUtil#AAC_ELD_MAX_RATE_BYTES_PER_SECOND() = 8000` Maximum rate for an AAC ELD audio stream, in bytes per second. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/AacUtil#AAC_HE_AUDIO_SAMPLE_COUNT() = 2048` Number of raw audio samples that are produced per channel when decoding an AAC HE access unit. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/AacUtil#AAC_HE_V1_MAX_RATE_BYTES_PER_SECOND() = 16000` Maximum rate for an AAC HE V1 audio stream, in bytes per second. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/AacUtil#AAC_HE_V2_MAX_RATE_BYTES_PER_SECOND() = 7000` Maximum rate for an AAC HE V2 audio stream, in bytes per second. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/AacUtil#AAC_LC_AUDIO_SAMPLE_COUNT() = 1024` Number of raw audio samples that are produced per channel when decoding an AAC LC access unit. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/AacUtil#AAC_LC_MAX_RATE_BYTES_PER_SECOND() = 100000` Maximum rate for an AAC LC audio stream, in bytes per second. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/AacUtil#AAC_LD_AUDIO_SAMPLE_COUNT() = 512` Number of raw audio samples that are produced per channel when decoding an AAC LD access unit. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/AacUtil#AAC_XHE_AUDIO_SAMPLE_COUNT() = 1024` Number of raw audio samples that are produced per channel when decoding an AAC XHE access unit. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/AacUtil#AAC_XHE_MAX_RATE_BYTES_PER_SECOND() = 256000` Maximum rate for an AAC XHE audio stream, in bytes per second. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/AacUtil#AUDIO_OBJECT_TYPE_AAC_ELD() = 23` |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/AacUtil#AUDIO_OBJECT_TYPE_AAC_ER_BSAC() = 22` |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/AacUtil#AUDIO_OBJECT_TYPE_AAC_LC() = 2` |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/AacUtil#AUDIO_OBJECT_TYPE_AAC_PS() = 29` |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/AacUtil#AUDIO_OBJECT_TYPE_AAC_SBR() = 5` |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/AacUtil#AUDIO_OBJECT_TYPE_AAC_XHE() = 42` |

| ### Public methods |
|---|---|
| `static byte[]` | `https://developer.android.com/reference/androidx/media3/extractor/AacUtil#buildAacLcAudioSpecificConfig(int,int)(int sampleRate, int channelCount)` Builds a simple AAC LC AudioSpecificConfig, as defined in ISO 14496-3 1.6.2.1 |
| `static byte[]` | `https://developer.android.com/reference/androidx/media3/extractor/AacUtil#buildAudioSpecificConfig(int,int,int)( int audioObjectType, int sampleRateIndex, int channelConfig )` Builds a simple AudioSpecificConfig, as defined in ISO 14496-3 1.6.2.1 |
| `static https://developer.android.com/reference/androidx/media3/extractor/AacUtil.Config` | `https://developer.android.com/reference/androidx/media3/extractor/AacUtil#parseAudioSpecificConfig(byte[])(byte[] audioSpecificConfig)` Parses an AAC AudioSpecificConfig, as defined in ISO 14496-3 1.6.2.1 |
| `static https://developer.android.com/reference/androidx/media3/extractor/AacUtil.Config` | `https://developer.android.com/reference/androidx/media3/extractor/AacUtil#parseAudioSpecificConfig(androidx.media3.common.util.ParsableBitArray,boolean)( https://developer.android.com/reference/androidx/media3/common/util/ParsableBitArray bitArray, boolean forceReadToEnd )` Parses an AAC AudioSpecificConfig, as defined in ISO 14496-3 1.6.2.1 |

## Constants

### AAC_ELD_MAX_RATE_BYTES_PER_SECOND

```
public static final int AAC_ELD_MAX_RATE_BYTES_PER_SECOND = 8000
```

Maximum rate for an AAC ELD audio stream, in bytes per second.

Fraunhofer documentation shows AAC-ELD as useful for up to \~ 64 kbit/s so we use this value.

### AAC_HE_AUDIO_SAMPLE_COUNT

```
public static final int AAC_HE_AUDIO_SAMPLE_COUNT = 2048
```

Number of raw audio samples that are produced per channel when decoding an AAC HE access unit.

### AAC_HE_V1_MAX_RATE_BYTES_PER_SECOND

```
public static final int AAC_HE_V1_MAX_RATE_BYTES_PER_SECOND = 16000
```

Maximum rate for an AAC HE V1 audio stream, in bytes per second.

### AAC_HE_V2_MAX_RATE_BYTES_PER_SECOND

```
public static final int AAC_HE_V2_MAX_RATE_BYTES_PER_SECOND = 7000
```

Maximum rate for an AAC HE V2 audio stream, in bytes per second.

### AAC_LC_AUDIO_SAMPLE_COUNT

```
public static final int AAC_LC_AUDIO_SAMPLE_COUNT = 1024
```

Number of raw audio samples that are produced per channel when decoding an AAC LC access unit.

### AAC_LC_MAX_RATE_BYTES_PER_SECOND

```
public static final int AAC_LC_MAX_RATE_BYTES_PER_SECOND = 100000
```

Maximum rate for an AAC LC audio stream, in bytes per second.

### AAC_LD_AUDIO_SAMPLE_COUNT

```
public static final int AAC_LD_AUDIO_SAMPLE_COUNT = 512
```

Number of raw audio samples that are produced per channel when decoding an AAC LD access unit.

### AAC_XHE_AUDIO_SAMPLE_COUNT

```
public static final int AAC_XHE_AUDIO_SAMPLE_COUNT = 1024
```

Number of raw audio samples that are produced per channel when decoding an AAC XHE access unit.

### AAC_XHE_MAX_RATE_BYTES_PER_SECOND

```
public static final int AAC_XHE_MAX_RATE_BYTES_PER_SECOND = 256000
```

Maximum rate for an AAC XHE audio stream, in bytes per second.

Fraunhofer documentation says "500 kbit/s and above" for stereo, so we use a rate generously above the 500 kbit/s level.

### AUDIO_OBJECT_TYPE_AAC_ELD

```
public static final int AUDIO_OBJECT_TYPE_AAC_ELD = 23
```

### AUDIO_OBJECT_TYPE_AAC_ER_BSAC

```
public static final int AUDIO_OBJECT_TYPE_AAC_ER_BSAC = 22
```

### AUDIO_OBJECT_TYPE_AAC_LC

```
public static final int AUDIO_OBJECT_TYPE_AAC_LC = 2
```

### AUDIO_OBJECT_TYPE_AAC_PS

```
public static final int AUDIO_OBJECT_TYPE_AAC_PS = 29
```

### AUDIO_OBJECT_TYPE_AAC_SBR

```
public static final int AUDIO_OBJECT_TYPE_AAC_SBR = 5
```

### AUDIO_OBJECT_TYPE_AAC_XHE

```
public static final int AUDIO_OBJECT_TYPE_AAC_XHE = 42
```

## Public methods

### buildAacLcAudioSpecificConfig

```
public static byte[] buildAacLcAudioSpecificConfig(int sampleRate, int channelCount)
```

Builds a simple AAC LC AudioSpecificConfig, as defined in ISO 14496-3 1.6.2.1

| Parameters |
|---|---|
| `int sampleRate` | The sample rate in Hz. |
| `int channelCount` | The channel count. |

| Returns |
|---|---|
| `byte[]` | The AudioSpecificConfig. |

### buildAudioSpecificConfig

```
public static byte[] buildAudioSpecificConfig(
    int audioObjectType,
    int sampleRateIndex,
    int channelConfig
)
```

Builds a simple AudioSpecificConfig, as defined in ISO 14496-3 1.6.2.1

| Parameters |
|---|---|
| `int audioObjectType` | The audio object type. |
| `int sampleRateIndex` | The sample rate index. |
| `int channelConfig` | The channel configuration. |

| Returns |
|---|---|
| `byte[]` | The AudioSpecificConfig. |

### parseAudioSpecificConfig

```
public static AacUtil.Config parseAudioSpecificConfig(byte[] audioSpecificConfig)
```

Parses an AAC AudioSpecificConfig, as defined in ISO 14496-3 1.6.2.1

| Parameters |
|---|---|
| `byte[] audioSpecificConfig` | A byte array containing the AudioSpecificConfig to parse. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/AacUtil.Config` | The parsed configuration. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/ParserException` | If the AudioSpecificConfig cannot be parsed because it is invalid or unsupported. |

### parseAudioSpecificConfig

```
public static AacUtil.Config parseAudioSpecificConfig(
    ParsableBitArray bitArray,
    boolean forceReadToEnd
)
```

Parses an AAC AudioSpecificConfig, as defined in ISO 14496-3 1.6.2.1

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/ParsableBitArray bitArray` | A `https://developer.android.com/reference/androidx/media3/common/util/ParsableBitArray` containing the AudioSpecificConfig to parse. The position is advanced to the end of the AudioSpecificConfig. |
| `boolean forceReadToEnd` | Whether the entire AudioSpecificConfig should be read. Required for knowing the length of the configuration payload. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/AacUtil.Config` | The parsed configuration. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/ParserException` | If the AudioSpecificConfig cannot be parsed because it is invalid or unsupported. |