1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.media; 18 19 import static android.media.audio.Flags.FLAG_DOLBY_AC4_LEVEL4_ENCODING_API; 20 import static android.media.audio.Flags.FLAG_IAMF_DEFINITIONS_API; 21 import static android.media.audio.Flags.FLAG_SONY_360RA_MPEGH_3D_FORMAT; 22 23 import android.annotation.FlaggedApi; 24 import android.annotation.IntDef; 25 import android.annotation.IntRange; 26 import android.annotation.NonNull; 27 import android.annotation.TestApi; 28 import android.compat.annotation.UnsupportedAppUsage; 29 import android.os.Build; 30 import android.os.Parcel; 31 import android.os.Parcelable; 32 33 import java.lang.annotation.Retention; 34 import java.lang.annotation.RetentionPolicy; 35 import java.util.Arrays; 36 import java.util.Objects; 37 38 /** 39 * The {@link AudioFormat} class is used to access a number of audio format and 40 * channel configuration constants. They are for instance used 41 * in {@link AudioTrack} and {@link AudioRecord}, as valid values in individual parameters of 42 * constructors like {@link AudioTrack#AudioTrack(int, int, int, int, int, int)}, where the fourth 43 * parameter is one of the <code>AudioFormat.ENCODING_*</code> constants. 44 * The <code>AudioFormat</code> constants are also used in {@link MediaFormat} to specify 45 * audio related values commonly used in media, such as for {@link MediaFormat#KEY_CHANNEL_MASK}. 46 * <p>The {@link AudioFormat.Builder} class can be used to create instances of 47 * the <code>AudioFormat</code> format class. 48 * Refer to 49 * {@link AudioFormat.Builder} for documentation on the mechanics of the configuration and building 50 * of such instances. Here we describe the main concepts that the <code>AudioFormat</code> class 51 * allow you to convey in each instance, they are: 52 * <ol> 53 * <li><a href="#sampleRate">sample rate</a> 54 * <li><a href="#encoding">encoding</a> 55 * <li><a href="#channelMask">channel masks</a> 56 * </ol> 57 * <p>Closely associated with the <code>AudioFormat</code> is the notion of an 58 * <a href="#audioFrame">audio frame</a>, which is used throughout the documentation 59 * to represent the minimum size complete unit of audio data. 60 * 61 * <h4 id="sampleRate">Sample rate</h4> 62 * <p>Expressed in Hz, the sample rate in an <code>AudioFormat</code> instance expresses the number 63 * of audio samples for each channel per second in the content you are playing or recording. It is 64 * not the sample rate 65 * at which content is rendered or produced. For instance a sound at a media sample rate of 8000Hz 66 * can be played on a device operating at a sample rate of 48000Hz; the sample rate conversion is 67 * automatically handled by the platform, it will not play at 6x speed. 68 * 69 * <p>As of API {@link android.os.Build.VERSION_CODES#M}, 70 * sample rates up to 192kHz are supported 71 * for <code>AudioRecord</code> and <code>AudioTrack</code>, with sample rate conversion 72 * performed as needed. 73 * To improve efficiency and avoid lossy conversions, it is recommended to match the sample rate 74 * for <code>AudioRecord</code> and <code>AudioTrack</code> to the endpoint device 75 * sample rate, and limit the sample rate to no more than 48kHz unless there are special 76 * device capabilities that warrant a higher rate. 77 * 78 * <h4 id="encoding">Encoding</h4> 79 * <p>Audio encoding is used to describe the bit representation of audio data, which can be 80 * either linear PCM or compressed audio, such as AC3 or DTS. 81 * <p>For linear PCM, the audio encoding describes the sample size, 8 bits, 16 bits, or 32 bits, 82 * and the sample representation, integer or float. 83 * <ul> 84 * <li> {@link #ENCODING_PCM_8BIT}: The audio sample is a 8 bit unsigned integer in the 85 * range [0, 255], with a 128 offset for zero. This is typically stored as a Java byte in a 86 * byte array or ByteBuffer. Since the Java byte is <em>signed</em>, 87 * be careful with math operations and conversions as the most significant bit is inverted. 88 * </li> 89 * <li> {@link #ENCODING_PCM_16BIT}: The audio sample is a 16 bit signed integer 90 * typically stored as a Java short in a short array, but when the short 91 * is stored in a ByteBuffer, it is native endian (as compared to the default Java big endian). 92 * The short has full range from [-32768, 32767], 93 * and is sometimes interpreted as fixed point Q.15 data. 94 * </li> 95 * <li> {@link #ENCODING_PCM_FLOAT}: Introduced in 96 * API {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this encoding specifies that 97 * the audio sample is a 32 bit IEEE single precision float. The sample can be 98 * manipulated as a Java float in a float array, though within a ByteBuffer 99 * it is stored in native endian byte order. 100 * The nominal range of <code>ENCODING_PCM_FLOAT</code> audio data is [-1.0, 1.0]. 101 * It is implementation dependent whether the positive maximum of 1.0 is included 102 * in the interval. Values outside of the nominal range are clamped before 103 * sending to the endpoint device. Beware that 104 * the handling of NaN is undefined; subnormals may be treated as zero; and 105 * infinities are generally clamped just like other values for <code>AudioTrack</code> 106 * – try to avoid infinities because they can easily generate a NaN. 107 * <br> 108 * To achieve higher audio bit depth than a signed 16 bit integer short, 109 * it is recommended to use <code>ENCODING_PCM_FLOAT</code> for audio capture, processing, 110 * and playback. 111 * Floats are efficiently manipulated by modern CPUs, 112 * have greater precision than 24 bit signed integers, 113 * and have greater dynamic range than 32 bit signed integers. 114 * <code>AudioRecord</code> as of API {@link android.os.Build.VERSION_CODES#M} and 115 * <code>AudioTrack</code> as of API {@link android.os.Build.VERSION_CODES#LOLLIPOP} 116 * support <code>ENCODING_PCM_FLOAT</code>. 117 * </li> 118 * <li> {@link #ENCODING_PCM_24BIT_PACKED}: Introduced in 119 * API {@link android.os.Build.VERSION_CODES#S}, 120 * this encoding specifies the audio sample is an 121 * extended precision 24 bit signed integer 122 * stored as a 3 Java bytes in a {@code ByteBuffer} or byte array in native endian 123 * (see {@link java.nio.ByteOrder#nativeOrder()}). 124 * Each sample has full range from [-8388608, 8388607], 125 * and can be interpreted as fixed point Q.23 data. 126 * </li> 127 * <li> {@link #ENCODING_PCM_32BIT}: Introduced in 128 * API {@link android.os.Build.VERSION_CODES#S}, 129 * this encoding specifies the audio sample is an 130 * extended precision 32 bit signed integer 131 * stored as a 4 Java bytes in a {@code ByteBuffer} or byte array in native endian 132 * (see {@link java.nio.ByteOrder#nativeOrder()}). 133 * Each sample has full range from [-2147483648, 2147483647], 134 * and can be interpreted as fixed point Q.31 data. 135 * </li> 136 * </ul> 137 * <p>For compressed audio, the encoding specifies the method of compression, 138 * for example {@link #ENCODING_AC3} and {@link #ENCODING_DTS}. The compressed 139 * audio data is typically stored as bytes in 140 * a byte array or ByteBuffer. When a compressed audio encoding is specified 141 * for an <code>AudioTrack</code>, it creates a direct (non-mixed) track 142 * for output to an endpoint (such as HDMI) capable of decoding the compressed audio. 143 * For (most) other endpoints, which are not capable of decoding such compressed audio, 144 * you will need to decode the data first, typically by creating a {@link MediaCodec}. 145 * Alternatively, one may use {@link MediaPlayer} for playback of compressed 146 * audio files or streams. 147 * <p>When compressed audio is sent out through a direct <code>AudioTrack</code>, 148 * it need not be written in exact multiples of the audio access unit; 149 * this differs from <code>MediaCodec</code> input buffers. 150 * 151 * <h4 id="channelMask">Channel mask</h4> 152 * <p>Channel masks are used in <code>AudioTrack</code> and <code>AudioRecord</code> to describe 153 * the samples and their arrangement in the audio frame. They are also used in the endpoint (e.g. 154 * a USB audio interface, a DAC connected to headphones) to specify allowable configurations of a 155 * particular device. 156 * <br>As of API {@link android.os.Build.VERSION_CODES#M}, there are two types of channel masks: 157 * channel position masks and channel index masks. 158 * 159 * <h5 id="channelPositionMask">Channel position masks</h5> 160 * Channel position masks are the original Android channel masks, and are used since API 161 * {@link android.os.Build.VERSION_CODES#BASE}. 162 * For input and output, they imply a positional nature - the location of a speaker or a microphone 163 * for recording or playback. 164 * <br>For a channel position mask, each allowed channel position corresponds to a bit in the 165 * channel mask. If that channel position is present in the audio frame, that bit is set, 166 * otherwise it is zero. The order of the bits (from lsb to msb) corresponds to the order of that 167 * position's sample in the audio frame. 168 * <br>The canonical channel position masks by channel count are as follows: 169 * <br><table> 170 * <tr><td>channel count</td><td>channel position mask</td></tr> 171 * <tr><td>1</td><td>{@link #CHANNEL_OUT_MONO}</td></tr> 172 * <tr><td>2</td><td>{@link #CHANNEL_OUT_STEREO}</td></tr> 173 * <tr><td>3</td><td>{@link #CHANNEL_OUT_STEREO} | {@link #CHANNEL_OUT_FRONT_CENTER}</td></tr> 174 * <tr><td>4</td><td>{@link #CHANNEL_OUT_QUAD}</td></tr> 175 * <tr><td>5</td><td>{@link #CHANNEL_OUT_QUAD} | {@link #CHANNEL_OUT_FRONT_CENTER}</td></tr> 176 * <tr><td>6</td><td>{@link #CHANNEL_OUT_5POINT1}</td></tr> 177 * <tr><td>7</td><td>{@link #CHANNEL_OUT_5POINT1} | {@link #CHANNEL_OUT_BACK_CENTER}</td></tr> 178 * <tr><td>8</td><td>{@link #CHANNEL_OUT_7POINT1_SURROUND}</td></tr> 179 * </table> 180 * <br>These masks are an ORed composite of individual channel masks. For example 181 * {@link #CHANNEL_OUT_STEREO} is composed of {@link #CHANNEL_OUT_FRONT_LEFT} and 182 * {@link #CHANNEL_OUT_FRONT_RIGHT}. 183 * <p> 184 * The following diagram represents the layout of the output channels, as seen from above 185 * the listener (in the center at the "lis" position, facing the front-center channel). 186 * <pre> 187 * TFL ----- TFC ----- TFR T is Top 188 * | \ | / | 189 * | FL --- FC --- FR | F is Front 190 * | |\ | /| | 191 * | | BFL-BFC-BFR | | BF is Bottom Front 192 * | | | | 193 * | FWL lis FWR | W is Wide 194 * | | | | 195 * TSL SL TC SR TSR S is Side 196 * | | | | 197 * | BL --- BC -- BR | B is Back 198 * | / \ | 199 * TBL ----- TBC ----- TBR C is Center, L/R is Left/Right 200 * </pre> 201 * All "T" (top) channels are above the listener, all "BF" (bottom-front) channels are below the 202 * listener, all others are in the listener's horizontal plane. When used in conjunction, LFE1 and 203 * LFE2 are below the listener, when used alone, LFE plane is undefined. 204 * See the channel definitions for the abbreviations 205 * 206 * <h5 id="channelIndexMask">Channel index masks</h5> 207 * Channel index masks are introduced in API {@link android.os.Build.VERSION_CODES#M}. They allow 208 * the selection of a particular channel from the source or sink endpoint by number, i.e. the first 209 * channel, the second channel, and so forth. This avoids problems with artificially assigning 210 * positions to channels of an endpoint, or figuring what the i<sup>th</sup> position bit is within 211 * an endpoint's channel position mask etc. 212 * <br>Here's an example where channel index masks address this confusion: dealing with a 4 channel 213 * USB device. Using a position mask, and based on the channel count, this would be a 214 * {@link #CHANNEL_OUT_QUAD} device, but really one is only interested in channel 0 215 * through channel 3. The USB device would then have the following individual bit channel masks: 216 * {@link #CHANNEL_OUT_FRONT_LEFT}, 217 * {@link #CHANNEL_OUT_FRONT_RIGHT}, {@link #CHANNEL_OUT_BACK_LEFT} 218 * and {@link #CHANNEL_OUT_BACK_RIGHT}. But which is channel 0 and which is 219 * channel 3? 220 * <br>For a channel index mask, each channel number is represented as a bit in the mask, from the 221 * lsb (channel 0) upwards to the msb, numerically this bit value is 222 * <code>1 << channelNumber</code>. 223 * A set bit indicates that channel is present in the audio frame, otherwise it is cleared. 224 * The order of the bits also correspond to that channel number's sample order in the audio frame. 225 * <br>For the previous 4 channel USB device example, the device would have a channel index mask 226 * <code>0xF</code>. Suppose we wanted to select only the first and the third channels; this would 227 * correspond to a channel index mask <code>0x5</code> (the first and third bits set). If an 228 * <code>AudioTrack</code> uses this channel index mask, the audio frame would consist of two 229 * samples, the first sample of each frame routed to channel 0, and the second sample of each frame 230 * routed to channel 2. 231 * The canonical channel index masks by channel count are given by the formula 232 * <code>(1 << channelCount) - 1</code>. 233 * 234 * <h5>Use cases</h5> 235 * <ul> 236 * <li><i>Channel position mask for an endpoint:</i> <code>CHANNEL_OUT_FRONT_LEFT</code>, 237 * <code>CHANNEL_OUT_FRONT_CENTER</code>, etc. for HDMI home theater purposes. 238 * <li><i>Channel position mask for an audio stream:</i> Creating an <code>AudioTrack</code> 239 * to output movie content, where 5.1 multichannel output is to be written. 240 * <li><i>Channel index mask for an endpoint:</i> USB devices for which input and output do not 241 * correspond to left or right speaker or microphone. 242 * <li><i>Channel index mask for an audio stream:</i> An <code>AudioRecord</code> may only want the 243 * third and fourth audio channels of the endpoint (i.e. the second channel pair), and not care the 244 * about position it corresponds to, in which case the channel index mask is <code>0xC</code>. 245 * Multichannel <code>AudioRecord</code> sessions should use channel index masks. 246 * </ul> 247 * <h4 id="audioFrame">Audio Frame</h4> 248 * <p>For linear PCM, an audio frame consists of a set of samples captured at the same time, 249 * whose count and 250 * channel association are given by the <a href="#channelMask">channel mask</a>, 251 * and whose sample contents are specified by the <a href="#encoding">encoding</a>. 252 * For example, a stereo 16 bit PCM frame consists of 253 * two 16 bit linear PCM samples, with a frame size of 4 bytes. 254 * For compressed audio, an audio frame may alternately 255 * refer to an access unit of compressed data bytes that is logically grouped together for 256 * decoding and bitstream access (e.g. {@link MediaCodec}), 257 * or a single byte of compressed data (e.g. {@link AudioTrack#getBufferSizeInFrames() 258 * AudioTrack.getBufferSizeInFrames()}), 259 * or the linear PCM frame result from decoding the compressed data 260 * (e.g.{@link AudioTrack#getPlaybackHeadPosition() 261 * AudioTrack.getPlaybackHeadPosition()}), 262 * depending on the context where audio frame is used. 263 * For the purposes of {@link AudioFormat#getFrameSizeInBytes()}, a compressed data format 264 * returns a frame size of 1 byte. 265 */ 266 public final class AudioFormat implements Parcelable { 267 268 //--------------------------------------------------------- 269 // Constants 270 //-------------------- 271 /** Invalid audio data format */ 272 public static final int ENCODING_INVALID = 0; 273 /** Default audio data format */ 274 public static final int ENCODING_DEFAULT = 1; 275 276 // These values must be kept in sync with core/jni/android_media_AudioFormat.h 277 // Also sync av/services/audiopolicy/managerdefault/ConfigParsingUtils.h 278 /** Audio data format: PCM 16 bit per sample. Guaranteed to be supported by devices. */ 279 public static final int ENCODING_PCM_16BIT = 2; 280 /** Audio data format: PCM 8 bit per sample. Not guaranteed to be supported by devices. */ 281 public static final int ENCODING_PCM_8BIT = 3; 282 /** Audio data format: single-precision floating-point per sample */ 283 public static final int ENCODING_PCM_FLOAT = 4; 284 /** Audio data format: AC-3 compressed, also known as Dolby Digital */ 285 public static final int ENCODING_AC3 = 5; 286 /** Audio data format: E-AC-3 compressed, also known as Dolby Digital Plus or DD+ */ 287 public static final int ENCODING_E_AC3 = 6; 288 /** Audio data format: DTS compressed */ 289 public static final int ENCODING_DTS = 7; 290 /** Audio data format: DTS HD compressed */ 291 public static final int ENCODING_DTS_HD = 8; 292 /** Audio data format: MP3 compressed */ 293 public static final int ENCODING_MP3 = 9; 294 /** Audio data format: AAC LC compressed */ 295 public static final int ENCODING_AAC_LC = 10; 296 /** Audio data format: AAC HE V1 compressed */ 297 public static final int ENCODING_AAC_HE_V1 = 11; 298 /** Audio data format: AAC HE V2 compressed */ 299 public static final int ENCODING_AAC_HE_V2 = 12; 300 301 /** Audio data format: compressed audio wrapped in PCM for HDMI 302 * or S/PDIF passthrough. 303 * For devices whose SDK version is less than {@link android.os.Build.VERSION_CODES#S}, the 304 * channel mask of IEC61937 track must be {@link #CHANNEL_OUT_STEREO}. 305 * Data should be written to the stream in a short[] array. 306 * If the data is written in a byte[] array then there may be endian problems 307 * on some platforms when converting to short internally. 308 */ 309 public static final int ENCODING_IEC61937 = 13; 310 /** Audio data format: DOLBY TRUEHD compressed 311 **/ 312 public static final int ENCODING_DOLBY_TRUEHD = 14; 313 /** Audio data format: AAC ELD compressed */ 314 public static final int ENCODING_AAC_ELD = 15; 315 /** Audio data format: AAC xHE compressed */ 316 public static final int ENCODING_AAC_XHE = 16; 317 /** Audio data format: AC-4 (levels 0-3) sync frame transport format */ 318 public static final int ENCODING_AC4 = 17; 319 /** Audio data format: E-AC-3-JOC compressed 320 * E-AC-3-JOC streams can be decoded by downstream devices supporting {@link #ENCODING_E_AC3}. 321 * Use {@link #ENCODING_E_AC3} as the AudioTrack encoding when the downstream device 322 * supports {@link #ENCODING_E_AC3} but not {@link #ENCODING_E_AC3_JOC}. 323 **/ 324 public static final int ENCODING_E_AC3_JOC = 18; 325 /** Audio data format: Dolby MAT (Metadata-enhanced Audio Transmission) 326 * Dolby MAT bitstreams are used to transmit Dolby TrueHD, channel-based PCM, or PCM with 327 * metadata (object audio) over HDMI (e.g. Dolby Atmos content). 328 **/ 329 public static final int ENCODING_DOLBY_MAT = 19; 330 /** Audio data format: OPUS compressed. */ 331 public static final int ENCODING_OPUS = 20; 332 333 /** @hide 334 * We do not permit legacy short array reads or writes for encodings 335 * introduced after this threshold. 336 */ 337 public static final int ENCODING_LEGACY_SHORT_ARRAY_THRESHOLD = ENCODING_OPUS; 338 339 /** Audio data format: PCM 24 bit per sample packed as 3 bytes. 340 * 341 * The bytes are in little-endian order, so the least significant byte 342 * comes first in the byte array. 343 * 344 * Not guaranteed to be supported by devices, may be emulated if not supported. */ 345 public static final int ENCODING_PCM_24BIT_PACKED = 21; 346 /** Audio data format: PCM 32 bit per sample. 347 * Not guaranteed to be supported by devices, may be emulated if not supported. */ 348 public static final int ENCODING_PCM_32BIT = 22; 349 350 /** Audio data format: MPEG-H baseline profile, level 3 */ 351 public static final int ENCODING_MPEGH_BL_L3 = 23; 352 /** Audio data format: MPEG-H baseline profile, level 4 */ 353 public static final int ENCODING_MPEGH_BL_L4 = 24; 354 /** Audio data format: MPEG-H low complexity profile, level 3 */ 355 public static final int ENCODING_MPEGH_LC_L3 = 25; 356 /** Audio data format: MPEG-H low complexity profile, level 4 */ 357 public static final int ENCODING_MPEGH_LC_L4 = 26; 358 /** Audio data format: DTS UHD Profile-1 compressed (aka DTS:X Profile 1) 359 * Has the same meaning and value as ENCODING_DTS_UHD_P1. 360 * @deprecated Use {@link #ENCODING_DTS_UHD_P1} instead. */ 361 @Deprecated public static final int ENCODING_DTS_UHD = 27; 362 /** Audio data format: DRA compressed */ 363 public static final int ENCODING_DRA = 28; 364 /** Audio data format: DTS HD Master Audio compressed 365 * DTS HD Master Audio stream is variable bit rate and contains lossless audio. 366 * Use {@link #ENCODING_DTS_HD_MA} for lossless audio content (DTS-HD MA Lossless) 367 * and use {@link #ENCODING_DTS_HD} for other DTS bitstreams with extension substream 368 * (DTS 8Ch Discrete, DTS Hi Res, DTS Express). */ 369 public static final int ENCODING_DTS_HD_MA = 29; 370 /** Audio data format: DTS UHD Profile-1 compressed (aka DTS:X Profile 1) 371 * Has the same meaning and value as the deprecated {@link #ENCODING_DTS_UHD}.*/ 372 public static final int ENCODING_DTS_UHD_P1 = 27; 373 /** Audio data format: DTS UHD Profile-2 compressed 374 * DTS-UHD Profile-2 supports delivery of Channel-Based Audio, Object-Based Audio 375 * and High Order Ambisonic presentations up to the fourth order. 376 * Use {@link #ENCODING_DTS_UHD_P1} to transmit DTS UHD Profile 1 (aka DTS:X Profile 1) 377 * bitstream. 378 * Use {@link #ENCODING_DTS_UHD_P2} to transmit DTS UHD Profile 2 (aka DTS:X Profile 2) 379 * bitstream. */ 380 public static final int ENCODING_DTS_UHD_P2 = 30; 381 /** Audio data format: Direct Stream Digital */ 382 public static final int ENCODING_DSD = 31; 383 /** Audio data format: AC-4 level 4 sync frame transport format */ 384 @FlaggedApi(FLAG_DOLBY_AC4_LEVEL4_ENCODING_API) 385 public static final int ENCODING_AC4_L4 = 32; 386 387 /** 388 * Audio data format: IAMF using the 389 * <a href="https://aomediacodec.github.io/iamf/#profiles-simple">simple profile</a> 390 * with audio streams <a href="https://aomediacodec.github.io/iamf/#codec_id">encoded</a> 391 * in OPUS. 392 */ 393 @FlaggedApi(FLAG_IAMF_DEFINITIONS_API) 394 public static final int ENCODING_IAMF_SIMPLE_PROFILE_OPUS = 33; 395 /** 396 * Audio data format: IAMF using the 397 * <a href="https://aomediacodec.github.io/iamf/#profiles-simple">simple profile</a> 398 * with audio streams <a href="https://aomediacodec.github.io/iamf/#codec_id">encoded</a> 399 * in AAC. 400 */ 401 @FlaggedApi(FLAG_IAMF_DEFINITIONS_API) 402 public static final int ENCODING_IAMF_SIMPLE_PROFILE_AAC = 34; 403 /** 404 * Audio data format: IAMF using the 405 * <a href="https://aomediacodec.github.io/iamf/#profiles-simple">simple profile</a> 406 * with audio streams <a href="https://aomediacodec.github.io/iamf/#codec_id">encoded</a> 407 * in FLAC. 408 */ 409 @FlaggedApi(FLAG_IAMF_DEFINITIONS_API) 410 public static final int ENCODING_IAMF_SIMPLE_PROFILE_FLAC = 35; 411 /** 412 * Audio data format: IAMF using the 413 * <a href="https://aomediacodec.github.io/iamf/#profiles-simple">simple profile</a> 414 * with audio streams <a href="https://aomediacodec.github.io/iamf/#codec_id">encoded</a> 415 * in PCM. 416 */ 417 @FlaggedApi(FLAG_IAMF_DEFINITIONS_API) 418 public static final int ENCODING_IAMF_SIMPLE_PROFILE_PCM = 36; 419 /** 420 * Audio data format: IAMF using the 421 * <a href="https://aomediacodec.github.io/iamf/#profiles-base">base profile</a> 422 * with audio streams <a href="https://aomediacodec.github.io/iamf/#codec_id">encoded</a> 423 * in OPUS. 424 */ 425 @FlaggedApi(FLAG_IAMF_DEFINITIONS_API) 426 public static final int ENCODING_IAMF_BASE_PROFILE_OPUS = 37; 427 /** 428 * Audio data format: IAMF using the 429 * <a href="https://aomediacodec.github.io/iamf/#profiles-base">base profile</a> 430 * with audio streams <a href="https://aomediacodec.github.io/iamf/#codec_id">encoded</a> 431 * in AAC. 432 */ 433 @FlaggedApi(FLAG_IAMF_DEFINITIONS_API) 434 public static final int ENCODING_IAMF_BASE_PROFILE_AAC = 38; 435 /** 436 * Audio data format: IAMF using the 437 * <a href="https://aomediacodec.github.io/iamf/#profiles-base">base profile</a> 438 * with audio streams <a href="https://aomediacodec.github.io/iamf/#codec_id">encoded</a> 439 * in FLAC. 440 */ 441 @FlaggedApi(FLAG_IAMF_DEFINITIONS_API) 442 public static final int ENCODING_IAMF_BASE_PROFILE_FLAC = 39; 443 /** 444 * Audio data format: IAMF using the 445 * <a href="https://aomediacodec.github.io/iamf/#profiles-base">base profile</a> 446 * with audio streams <a href="https://aomediacodec.github.io/iamf/#codec_id">encoded</a> 447 * in PCM. 448 */ 449 @FlaggedApi(FLAG_IAMF_DEFINITIONS_API) 450 public static final int ENCODING_IAMF_BASE_PROFILE_PCM = 40; 451 /** 452 * Audio data format: IAMF using the 453 * <a href="https://aomediacodec.github.io/iamf/#profiles-base-enhanced">base-enhanced profile</a> 454 * with audio streams <a href="https://aomediacodec.github.io/iamf/#codec_id">encoded</a> 455 * in OPUS. 456 */ 457 @FlaggedApi(FLAG_IAMF_DEFINITIONS_API) 458 public static final int ENCODING_IAMF_BASE_ENHANCED_PROFILE_OPUS = 41; 459 /** 460 * Audio data format: IAMF using the 461 * <a href="https://aomediacodec.github.io/iamf/#profiles-base-enhanced">base-enhanced profile</a> 462 * with audio streams <a href="https://aomediacodec.github.io/iamf/#codec_id">encoded</a> 463 * in AAC. 464 */ 465 @FlaggedApi(FLAG_IAMF_DEFINITIONS_API) 466 public static final int ENCODING_IAMF_BASE_ENHANCED_PROFILE_AAC = 42; 467 /** 468 * Audio data format: IAMF using the 469 * <a href="https://aomediacodec.github.io/iamf/#profiles-base-enhanced">base-enhanced profile</a> 470 * with audio streams <a href="https://aomediacodec.github.io/iamf/#codec_id">encoded</a> 471 * in FLAC. 472 */ 473 @FlaggedApi(FLAG_IAMF_DEFINITIONS_API) 474 public static final int ENCODING_IAMF_BASE_ENHANCED_PROFILE_FLAC = 43; 475 /** 476 * Audio data format: IAMF using the 477 * <a href="https://aomediacodec.github.io/iamf/#profiles-base-enhanced">base-enhanced profile</a> 478 * with audio streams <a href="https://aomediacodec.github.io/iamf/#codec_id">encoded</a> 479 * in PCM. 480 */ 481 @FlaggedApi(FLAG_IAMF_DEFINITIONS_API) 482 public static final int ENCODING_IAMF_BASE_ENHANCED_PROFILE_PCM = 44; 483 484 /** @hide */ toLogFriendlyEncoding(int enc)485 public static String toLogFriendlyEncoding(int enc) { 486 switch(enc) { 487 case ENCODING_INVALID: 488 return "ENCODING_INVALID"; 489 case ENCODING_PCM_16BIT: 490 return "ENCODING_PCM_16BIT"; 491 case ENCODING_PCM_8BIT: 492 return "ENCODING_PCM_8BIT"; 493 case ENCODING_PCM_FLOAT: 494 return "ENCODING_PCM_FLOAT"; 495 case ENCODING_AC3: 496 return "ENCODING_AC3"; 497 case ENCODING_E_AC3: 498 return "ENCODING_E_AC3"; 499 case ENCODING_DTS: 500 return "ENCODING_DTS"; 501 case ENCODING_DTS_HD: 502 return "ENCODING_DTS_HD"; 503 case ENCODING_MP3: 504 return "ENCODING_MP3"; 505 case ENCODING_AAC_LC: 506 return "ENCODING_AAC_LC"; 507 case ENCODING_AAC_HE_V1: 508 return "ENCODING_AAC_HE_V1"; 509 case ENCODING_AAC_HE_V2: 510 return "ENCODING_AAC_HE_V2"; 511 case ENCODING_IEC61937: 512 return "ENCODING_IEC61937"; 513 case ENCODING_DOLBY_TRUEHD: 514 return "ENCODING_DOLBY_TRUEHD"; 515 case ENCODING_AAC_ELD: 516 return "ENCODING_AAC_ELD"; 517 case ENCODING_AAC_XHE: 518 return "ENCODING_AAC_XHE"; 519 case ENCODING_AC4: 520 return "ENCODING_AC4"; 521 case ENCODING_AC4_L4: 522 return "ENCODING_AC4_L4"; 523 case ENCODING_E_AC3_JOC: 524 return "ENCODING_E_AC3_JOC"; 525 case ENCODING_DOLBY_MAT: 526 return "ENCODING_DOLBY_MAT"; 527 case ENCODING_OPUS: 528 return "ENCODING_OPUS"; 529 case ENCODING_PCM_24BIT_PACKED: 530 return "ENCODING_PCM_24BIT_PACKED"; 531 case ENCODING_PCM_32BIT: 532 return "ENCODING_PCM_32BIT"; 533 case ENCODING_MPEGH_BL_L3: 534 return "ENCODING_MPEGH_BL_L3"; 535 case ENCODING_MPEGH_BL_L4: 536 return "ENCODING_MPEGH_BL_L4"; 537 case ENCODING_MPEGH_LC_L3: 538 return "ENCODING_MPEGH_LC_L3"; 539 case ENCODING_MPEGH_LC_L4: 540 return "ENCODING_MPEGH_LC_L4"; 541 case ENCODING_DTS_UHD_P1: 542 return "ENCODING_DTS_UHD_P1"; 543 case ENCODING_DRA: 544 return "ENCODING_DRA"; 545 case ENCODING_DTS_HD_MA: 546 return "ENCODING_DTS_HD_MA"; 547 case ENCODING_DTS_UHD_P2: 548 return "ENCODING_DTS_UHD_P2"; 549 case ENCODING_DSD: 550 return "ENCODING_DSD"; 551 case ENCODING_IAMF_BASE_ENHANCED_PROFILE_AAC: 552 return "ENCODING_IAMF_BASE_ENHANCED_PROFILE_AAC"; 553 case ENCODING_IAMF_BASE_ENHANCED_PROFILE_FLAC: 554 return "ENCODING_IAMF_BASE_ENHANCED_PROFILE_FLAC"; 555 case ENCODING_IAMF_BASE_ENHANCED_PROFILE_OPUS: 556 return "ENCODING_IAMF_BASE_ENHANCED_PROFILE_OPUS"; 557 case ENCODING_IAMF_BASE_ENHANCED_PROFILE_PCM: 558 return "ENCODING_IAMF_BASE_ENHANCED_PROFILE_PCM"; 559 case ENCODING_IAMF_BASE_PROFILE_AAC: 560 return "ENCODING_IAMF_BASE_PROFILE_AAC"; 561 case ENCODING_IAMF_BASE_PROFILE_FLAC: 562 return "ENCODING_IAMF_BASE_PROFILE_FLAC"; 563 case ENCODING_IAMF_BASE_PROFILE_OPUS: 564 return "ENCODING_IAMF_BASE_PROFILE_OPUS"; 565 case ENCODING_IAMF_BASE_PROFILE_PCM: 566 return "ENCODING_IAMF_BASE_PROFILE_PCM"; 567 case ENCODING_IAMF_SIMPLE_PROFILE_AAC: 568 return "ENCODING_IAMF_SIMPLE_PROFILE_AAC"; 569 case ENCODING_IAMF_SIMPLE_PROFILE_FLAC: 570 return "ENCODING_IAMF_SIMPLE_PROFILE_FLAC"; 571 case ENCODING_IAMF_SIMPLE_PROFILE_OPUS: 572 return "ENCODING_IAMF_SIMPLE_PROFILE_OPUS"; 573 case ENCODING_IAMF_SIMPLE_PROFILE_PCM: 574 return "ENCODING_IAMF_SIMPLE_PROFILE_PCM"; 575 default : 576 return "invalid encoding " + enc; 577 } 578 } 579 580 /** Invalid audio channel configuration */ 581 /** @deprecated Use {@link #CHANNEL_INVALID} instead. */ 582 @Deprecated public static final int CHANNEL_CONFIGURATION_INVALID = 0; 583 /** Default audio channel configuration */ 584 /** @deprecated Use {@link #CHANNEL_OUT_DEFAULT} or {@link #CHANNEL_IN_DEFAULT} instead. */ 585 @Deprecated public static final int CHANNEL_CONFIGURATION_DEFAULT = 1; 586 /** Mono audio configuration */ 587 /** @deprecated Use {@link #CHANNEL_OUT_MONO} or {@link #CHANNEL_IN_MONO} instead. */ 588 @Deprecated public static final int CHANNEL_CONFIGURATION_MONO = 2; 589 /** Stereo (2 channel) audio configuration */ 590 /** @deprecated Use {@link #CHANNEL_OUT_STEREO} or {@link #CHANNEL_IN_STEREO} instead. */ 591 @Deprecated public static final int CHANNEL_CONFIGURATION_STEREO = 3; 592 593 /** Invalid audio channel mask */ 594 public static final int CHANNEL_INVALID = 0; 595 /** Default audio channel mask */ 596 public static final int CHANNEL_OUT_DEFAULT = 1; 597 598 // Output channel mask definitions below are translated to the native values defined in 599 // in /system/media/audio/include/system/audio.h in the JNI code of AudioTrack 600 /** Front left output channel (see FL in channel diagram) */ 601 public static final int CHANNEL_OUT_FRONT_LEFT = 0x4; 602 /** Front right output channel (see FR in channel diagram) */ 603 public static final int CHANNEL_OUT_FRONT_RIGHT = 0x8; 604 /** Front center output channel (see FC in channel diagram) */ 605 public static final int CHANNEL_OUT_FRONT_CENTER = 0x10; 606 /** LFE "low frequency effect" channel 607 * When used in conjunction with {@link #CHANNEL_OUT_LOW_FREQUENCY_2}, it is intended 608 * to contain the left low-frequency effect signal, also referred to as "LFE1" 609 * in ITU-R BS.2159-8 */ 610 public static final int CHANNEL_OUT_LOW_FREQUENCY = 0x20; 611 /** Back left output channel (see BL in channel diagram) */ 612 public static final int CHANNEL_OUT_BACK_LEFT = 0x40; 613 /** Back right output channel (see BR in channel diagram) */ 614 public static final int CHANNEL_OUT_BACK_RIGHT = 0x80; 615 public static final int CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x100; 616 public static final int CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x200; 617 /** Back center output channel (see BC in channel diagram) */ 618 public static final int CHANNEL_OUT_BACK_CENTER = 0x400; 619 /** Side left output channel (see SL in channel diagram) */ 620 public static final int CHANNEL_OUT_SIDE_LEFT = 0x800; 621 /** Side right output channel (see SR in channel diagram) */ 622 public static final int CHANNEL_OUT_SIDE_RIGHT = 0x1000; 623 /** Top center (above listener) output channel (see TC in channel diagram) */ 624 public static final int CHANNEL_OUT_TOP_CENTER = 0x2000; 625 /** Top front left output channel (see TFL in channel diagram above FL) */ 626 public static final int CHANNEL_OUT_TOP_FRONT_LEFT = 0x4000; 627 /** Top front center output channel (see TFC in channel diagram above FC) */ 628 public static final int CHANNEL_OUT_TOP_FRONT_CENTER = 0x8000; 629 /** Top front right output channel (see TFR in channel diagram above FR) */ 630 public static final int CHANNEL_OUT_TOP_FRONT_RIGHT = 0x10000; 631 /** Top back left output channel (see TBL in channel diagram above BL) */ 632 public static final int CHANNEL_OUT_TOP_BACK_LEFT = 0x20000; 633 /** Top back center output channel (see TBC in channel diagram above BC) */ 634 public static final int CHANNEL_OUT_TOP_BACK_CENTER = 0x40000; 635 /** Top back right output channel (see TBR in channel diagram above BR) */ 636 public static final int CHANNEL_OUT_TOP_BACK_RIGHT = 0x80000; 637 /** Top side left output channel (see TSL in channel diagram above SL) */ 638 public static final int CHANNEL_OUT_TOP_SIDE_LEFT = 0x100000; 639 /** Top side right output channel (see TSR in channel diagram above SR) */ 640 public static final int CHANNEL_OUT_TOP_SIDE_RIGHT = 0x200000; 641 /** Bottom front left output channel (see BFL in channel diagram below FL) */ 642 public static final int CHANNEL_OUT_BOTTOM_FRONT_LEFT = 0x400000; 643 /** Bottom front center output channel (see BFC in channel diagram below FC) */ 644 public static final int CHANNEL_OUT_BOTTOM_FRONT_CENTER = 0x800000; 645 /** Bottom front right output channel (see BFR in channel diagram below FR) */ 646 public static final int CHANNEL_OUT_BOTTOM_FRONT_RIGHT = 0x1000000; 647 /** The second LFE channel 648 * When used in conjunction with {@link #CHANNEL_OUT_LOW_FREQUENCY}, it is intended 649 * to contain the right low-frequency effect signal, also referred to as "LFE2" 650 * in ITU-R BS.2159-8 */ 651 public static final int CHANNEL_OUT_LOW_FREQUENCY_2 = 0x2000000; 652 /** Front wide left output channel (see FWL in channel diagram) */ 653 public static final int CHANNEL_OUT_FRONT_WIDE_LEFT = 0x4000000; 654 /** Front wide right output channel (see FWR in channel diagram) */ 655 public static final int CHANNEL_OUT_FRONT_WIDE_RIGHT = 0x8000000; 656 /** @hide 657 * Haptic channels can be used by internal framework code. Use the same values as in native. 658 */ 659 public static final int CHANNEL_OUT_HAPTIC_B = 0x10000000; 660 /** @hide */ 661 public static final int CHANNEL_OUT_HAPTIC_A = 0x20000000; 662 663 public static final int CHANNEL_OUT_MONO = CHANNEL_OUT_FRONT_LEFT; 664 public static final int CHANNEL_OUT_STEREO = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT); 665 // aka QUAD_BACK 666 public static final int CHANNEL_OUT_QUAD = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT | 667 CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT); 668 /** @hide */ 669 public static final int CHANNEL_OUT_QUAD_SIDE = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT | 670 CHANNEL_OUT_SIDE_LEFT | CHANNEL_OUT_SIDE_RIGHT); 671 public static final int CHANNEL_OUT_SURROUND = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT | 672 CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_BACK_CENTER); 673 // aka 5POINT1_BACK 674 /** Output channel mask for 5.1 */ 675 public static final int CHANNEL_OUT_5POINT1 = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT | 676 CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT); 677 /** Output channel mask for 6.1 678 * Same as 5.1 with the addition of the back center channel */ 679 public static final int CHANNEL_OUT_6POINT1 = (CHANNEL_OUT_5POINT1 | CHANNEL_OUT_BACK_CENTER); 680 /** @hide */ 681 public static final int CHANNEL_OUT_5POINT1_SIDE = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT | 682 CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | 683 CHANNEL_OUT_SIDE_LEFT | CHANNEL_OUT_SIDE_RIGHT); 684 // different from AUDIO_CHANNEL_OUT_7POINT1 used internally, and not accepted by AudioRecord. 685 /** @deprecated Not the typical 7.1 surround configuration. Use {@link #CHANNEL_OUT_7POINT1_SURROUND} instead. */ 686 @Deprecated public static final int CHANNEL_OUT_7POINT1 = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT | 687 CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT | 688 CHANNEL_OUT_FRONT_LEFT_OF_CENTER | CHANNEL_OUT_FRONT_RIGHT_OF_CENTER); 689 /** Output channel mask for 7.1 */ 690 // matches AUDIO_CHANNEL_OUT_7POINT1 691 public static final int CHANNEL_OUT_7POINT1_SURROUND = ( 692 CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_FRONT_RIGHT | 693 CHANNEL_OUT_SIDE_LEFT | CHANNEL_OUT_SIDE_RIGHT | 694 CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT | 695 CHANNEL_OUT_LOW_FREQUENCY); 696 /** Output channel mask for 5.1.2 697 * Same as 5.1 with the addition of left and right top channels */ 698 public static final int CHANNEL_OUT_5POINT1POINT2 = (CHANNEL_OUT_5POINT1 | 699 CHANNEL_OUT_TOP_SIDE_LEFT | CHANNEL_OUT_TOP_SIDE_RIGHT); 700 /** Output channel mask for 5.1.4 701 * Same as 5.1 with the addition of four top channels */ 702 public static final int CHANNEL_OUT_5POINT1POINT4 = (CHANNEL_OUT_5POINT1 | 703 CHANNEL_OUT_TOP_FRONT_LEFT | CHANNEL_OUT_TOP_FRONT_RIGHT | 704 CHANNEL_OUT_TOP_BACK_LEFT | CHANNEL_OUT_TOP_BACK_RIGHT); 705 /** Output channel mask for 7.1.2 706 * Same as 7.1 with the addition of left and right top channels*/ 707 public static final int CHANNEL_OUT_7POINT1POINT2 = (CHANNEL_OUT_7POINT1_SURROUND | 708 CHANNEL_OUT_TOP_SIDE_LEFT | CHANNEL_OUT_TOP_SIDE_RIGHT); 709 /** Output channel mask for 7.1.4 710 * Same as 7.1 with the addition of four top channels */ 711 public static final int CHANNEL_OUT_7POINT1POINT4 = (CHANNEL_OUT_7POINT1_SURROUND | 712 CHANNEL_OUT_TOP_FRONT_LEFT | CHANNEL_OUT_TOP_FRONT_RIGHT | 713 CHANNEL_OUT_TOP_BACK_LEFT | CHANNEL_OUT_TOP_BACK_RIGHT); 714 /** Output channel mask for 9.1.4 715 * Same as 7.1.4 with the addition of left and right front wide channels */ 716 public static final int CHANNEL_OUT_9POINT1POINT4 = (CHANNEL_OUT_7POINT1POINT4 717 | CHANNEL_OUT_FRONT_WIDE_LEFT | CHANNEL_OUT_FRONT_WIDE_RIGHT); 718 /** Output channel mask for 9.1.6 719 * Same as 9.1.4 with the addition of left and right top side channels */ 720 public static final int CHANNEL_OUT_9POINT1POINT6 = (CHANNEL_OUT_9POINT1POINT4 721 | CHANNEL_OUT_TOP_SIDE_LEFT | CHANNEL_OUT_TOP_SIDE_RIGHT); 722 /** Output channel mask for 13.0 */ 723 @FlaggedApi(FLAG_SONY_360RA_MPEGH_3D_FORMAT) 724 public static final int CHANNEL_OUT_13POINT0 = ( 725 CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_FRONT_RIGHT | 726 CHANNEL_OUT_SIDE_LEFT | CHANNEL_OUT_SIDE_RIGHT | 727 CHANNEL_OUT_TOP_FRONT_LEFT | CHANNEL_OUT_TOP_FRONT_CENTER | 728 CHANNEL_OUT_TOP_FRONT_RIGHT | 729 CHANNEL_OUT_TOP_BACK_LEFT | CHANNEL_OUT_TOP_BACK_RIGHT | 730 CHANNEL_OUT_BOTTOM_FRONT_LEFT | CHANNEL_OUT_BOTTOM_FRONT_CENTER | 731 CHANNEL_OUT_BOTTOM_FRONT_RIGHT); 732 /** @hide */ 733 public static final int CHANNEL_OUT_22POINT2 = (CHANNEL_OUT_7POINT1POINT4 | 734 CHANNEL_OUT_FRONT_LEFT_OF_CENTER | CHANNEL_OUT_FRONT_RIGHT_OF_CENTER | 735 CHANNEL_OUT_BACK_CENTER | CHANNEL_OUT_TOP_CENTER | 736 CHANNEL_OUT_TOP_FRONT_CENTER | CHANNEL_OUT_TOP_BACK_CENTER | 737 CHANNEL_OUT_TOP_SIDE_LEFT | CHANNEL_OUT_TOP_SIDE_RIGHT | 738 CHANNEL_OUT_BOTTOM_FRONT_LEFT | CHANNEL_OUT_BOTTOM_FRONT_RIGHT | 739 CHANNEL_OUT_BOTTOM_FRONT_CENTER | 740 CHANNEL_OUT_LOW_FREQUENCY_2); 741 // CHANNEL_OUT_ALL is not yet defined; if added then it should match AUDIO_CHANNEL_OUT_ALL 742 743 /** @hide */ 744 @IntDef(flag = true, prefix = "CHANNEL_OUT", value = { 745 CHANNEL_OUT_FRONT_LEFT, 746 CHANNEL_OUT_FRONT_RIGHT, 747 CHANNEL_OUT_FRONT_CENTER, 748 CHANNEL_OUT_LOW_FREQUENCY, 749 CHANNEL_OUT_BACK_LEFT, 750 CHANNEL_OUT_BACK_RIGHT, 751 CHANNEL_OUT_FRONT_LEFT_OF_CENTER, 752 CHANNEL_OUT_FRONT_RIGHT_OF_CENTER, 753 CHANNEL_OUT_BACK_CENTER, 754 CHANNEL_OUT_SIDE_LEFT, 755 CHANNEL_OUT_SIDE_RIGHT, 756 CHANNEL_OUT_TOP_CENTER, 757 CHANNEL_OUT_TOP_FRONT_LEFT, 758 CHANNEL_OUT_TOP_FRONT_CENTER, 759 CHANNEL_OUT_TOP_FRONT_RIGHT, 760 CHANNEL_OUT_TOP_BACK_LEFT, 761 CHANNEL_OUT_TOP_BACK_CENTER, 762 CHANNEL_OUT_TOP_BACK_RIGHT, 763 CHANNEL_OUT_TOP_SIDE_LEFT, 764 CHANNEL_OUT_TOP_SIDE_RIGHT, 765 CHANNEL_OUT_BOTTOM_FRONT_LEFT, 766 CHANNEL_OUT_BOTTOM_FRONT_CENTER, 767 CHANNEL_OUT_BOTTOM_FRONT_RIGHT, 768 CHANNEL_OUT_LOW_FREQUENCY_2, 769 CHANNEL_OUT_FRONT_WIDE_LEFT, 770 CHANNEL_OUT_FRONT_WIDE_RIGHT, 771 CHANNEL_OUT_HAPTIC_B, 772 CHANNEL_OUT_HAPTIC_A 773 }) 774 @Retention(RetentionPolicy.SOURCE) 775 public @interface ChannelOut {} 776 777 /** Minimum value for sample rate, 778 * assuming AudioTrack and AudioRecord share the same limitations. 779 * @hide 780 */ 781 // never unhide 782 public static final int SAMPLE_RATE_HZ_MIN = AudioSystem.SAMPLE_RATE_HZ_MIN; 783 /** Maximum value for sample rate, 784 * assuming AudioTrack and AudioRecord share the same limitations. 785 * @hide 786 */ 787 // never unhide 788 public static final int SAMPLE_RATE_HZ_MAX = AudioSystem.SAMPLE_RATE_HZ_MAX; 789 /** Sample rate will be a route-dependent value. 790 * For AudioTrack, it is usually the sink sample rate, 791 * and for AudioRecord it is usually the source sample rate. 792 */ 793 public static final int SAMPLE_RATE_UNSPECIFIED = 0; 794 795 /** 796 * @hide 797 * Return the input channel mask corresponding to an output channel mask. 798 * This can be used for submix rerouting for the mask of the recorder to map to that of the mix. 799 * @param outMask a combination of the CHANNEL_OUT_* definitions, but not CHANNEL_OUT_DEFAULT 800 * @return a combination of CHANNEL_IN_* definitions matching an output channel mask 801 * @throws IllegalArgumentException 802 */ inChannelMaskFromOutChannelMask(int outMask)803 public static int inChannelMaskFromOutChannelMask(int outMask) throws IllegalArgumentException { 804 if (outMask == CHANNEL_OUT_DEFAULT) { 805 throw new IllegalArgumentException( 806 "Illegal CHANNEL_OUT_DEFAULT channel mask for input."); 807 } 808 switch (channelCountFromOutChannelMask(outMask)) { 809 case 1: 810 return CHANNEL_IN_MONO; 811 case 2: 812 return CHANNEL_IN_STEREO; 813 default: 814 throw new IllegalArgumentException("Unsupported channel configuration for input."); 815 } 816 } 817 818 /** 819 * @hide 820 * Return the number of channels from an input channel mask 821 * @param mask a combination of the CHANNEL_IN_* definitions, even CHANNEL_IN_DEFAULT 822 * @return number of channels for the mask 823 */ 824 @TestApi channelCountFromInChannelMask(int mask)825 public static int channelCountFromInChannelMask(int mask) { 826 return Integer.bitCount(mask); 827 } 828 /** 829 * @hide 830 * Return the number of channels from an output channel mask 831 * @param mask a combination of the CHANNEL_OUT_* definitions, but not CHANNEL_OUT_DEFAULT 832 * @return number of channels for the mask 833 */ 834 @TestApi channelCountFromOutChannelMask(int mask)835 public static int channelCountFromOutChannelMask(int mask) { 836 return Integer.bitCount(mask); 837 } 838 /** 839 * @hide 840 * Return a channel mask ready to be used by native code 841 * @param javaMask a combination of the CHANNEL_OUT_* definitions, but not CHANNEL_OUT_DEFAULT 842 * @return a native channel mask 843 */ convertChannelOutMaskToNativeMask(int javaMask)844 public static int convertChannelOutMaskToNativeMask(int javaMask) { 845 return (javaMask >> 2); 846 } 847 848 /** 849 * @hide 850 * Return a java output channel mask 851 * @param nativeMask a native channel mask 852 * @return a combination of the CHANNEL_OUT_* definitions 853 */ convertNativeChannelMaskToOutMask(int nativeMask)854 public static int convertNativeChannelMaskToOutMask(int nativeMask) { 855 return (nativeMask << 2); 856 } 857 858 /** 859 * @hide 860 * Return a human-readable string from a java channel mask 861 * @param javaMask a bit field of CHANNEL_OUT_* values 862 * @return a string in the "mono", "stereo", "5.1" style, or the hex version when not a standard 863 * mask. 864 */ javaChannelOutMaskToString(int javaMask)865 public static String javaChannelOutMaskToString(int javaMask) { 866 // save haptics info for end of string 867 int haptics = javaMask & (CHANNEL_OUT_HAPTIC_A | CHANNEL_OUT_HAPTIC_B); 868 // continue without looking at haptic channels 869 javaMask &= ~(CHANNEL_OUT_HAPTIC_A | CHANNEL_OUT_HAPTIC_B); 870 StringBuilder result = new StringBuilder(""); 871 switch (javaMask) { 872 case CHANNEL_OUT_MONO: 873 result.append("mono"); 874 break; 875 case CHANNEL_OUT_STEREO: 876 result.append("stereo"); 877 break; 878 case CHANNEL_OUT_QUAD: 879 result.append("quad"); 880 break; 881 case CHANNEL_OUT_QUAD_SIDE: 882 result.append("quad side"); 883 break; 884 case CHANNEL_OUT_SURROUND: 885 result.append("4.0"); 886 break; 887 case CHANNEL_OUT_5POINT1: 888 result.append("5.1"); 889 break; 890 case CHANNEL_OUT_6POINT1: 891 result.append("6.1"); 892 break; 893 case CHANNEL_OUT_5POINT1_SIDE: 894 result.append("5.1 side"); 895 break; 896 case CHANNEL_OUT_7POINT1: 897 result.append("7.1 (5 fronts)"); 898 break; 899 case CHANNEL_OUT_7POINT1_SURROUND: 900 result.append("7.1"); 901 break; 902 case CHANNEL_OUT_5POINT1POINT2: 903 result.append("5.1.2"); 904 break; 905 case CHANNEL_OUT_5POINT1POINT4: 906 result.append("5.1.4"); 907 break; 908 case CHANNEL_OUT_7POINT1POINT2: 909 result.append("7.1.2"); 910 break; 911 case CHANNEL_OUT_7POINT1POINT4: 912 result.append("7.1.4"); 913 break; 914 case CHANNEL_OUT_9POINT1POINT4: 915 result.append("9.1.4"); 916 break; 917 case CHANNEL_OUT_9POINT1POINT6: 918 result.append("9.1.6"); 919 break; 920 case CHANNEL_OUT_13POINT0: 921 result.append("360RA 13ch"); 922 break; 923 case CHANNEL_OUT_22POINT2: 924 result.append("22.2"); 925 break; 926 default: 927 result.append("0x").append(Integer.toHexString(javaMask)); 928 break; 929 } 930 if ((haptics & (CHANNEL_OUT_HAPTIC_A | CHANNEL_OUT_HAPTIC_B)) != 0) { 931 result.append("(+haptic "); 932 if ((haptics & CHANNEL_OUT_HAPTIC_A) == CHANNEL_OUT_HAPTIC_A) { 933 result.append("A"); 934 } 935 if ((haptics & CHANNEL_OUT_HAPTIC_B) == CHANNEL_OUT_HAPTIC_B) { 936 result.append("B"); 937 } 938 result.append(")"); 939 } 940 return result.toString(); 941 } 942 943 public static final int CHANNEL_IN_DEFAULT = 1; 944 // These directly match native 945 public static final int CHANNEL_IN_LEFT = 0x4; 946 public static final int CHANNEL_IN_RIGHT = 0x8; 947 public static final int CHANNEL_IN_FRONT = 0x10; 948 public static final int CHANNEL_IN_BACK = 0x20; 949 public static final int CHANNEL_IN_LEFT_PROCESSED = 0x40; 950 public static final int CHANNEL_IN_RIGHT_PROCESSED = 0x80; 951 public static final int CHANNEL_IN_FRONT_PROCESSED = 0x100; 952 public static final int CHANNEL_IN_BACK_PROCESSED = 0x200; 953 public static final int CHANNEL_IN_PRESSURE = 0x400; 954 public static final int CHANNEL_IN_X_AXIS = 0x800; 955 public static final int CHANNEL_IN_Y_AXIS = 0x1000; 956 public static final int CHANNEL_IN_Z_AXIS = 0x2000; 957 public static final int CHANNEL_IN_VOICE_UPLINK = 0x4000; 958 public static final int CHANNEL_IN_VOICE_DNLINK = 0x8000; 959 // CHANNEL_IN_BACK_LEFT to TOP_RIGHT are not microphone positions 960 // but surround channels which are used when dealing with multi-channel inputs, 961 // e.g. via HDMI input on TV. 962 /** @hide */ 963 public static final int CHANNEL_IN_BACK_LEFT = 0x10000; 964 /** @hide */ 965 public static final int CHANNEL_IN_BACK_RIGHT = 0x20000; 966 /** @hide */ 967 public static final int CHANNEL_IN_CENTER = 0x40000; 968 /** @hide */ 969 public static final int CHANNEL_IN_LOW_FREQUENCY = 0x100000; 970 /** @hide */ 971 public static final int CHANNEL_IN_TOP_LEFT = 0x200000; 972 /** @hide */ 973 public static final int CHANNEL_IN_TOP_RIGHT = 0x400000; 974 public static final int CHANNEL_IN_MONO = CHANNEL_IN_FRONT; 975 public static final int CHANNEL_IN_STEREO = (CHANNEL_IN_LEFT | CHANNEL_IN_RIGHT); 976 // Surround channel masks corresponding to output masks, used for 977 // surround sound inputs. 978 /** @hide */ 979 public static final int CHANNEL_IN_2POINT0POINT2 = ( 980 CHANNEL_IN_LEFT | CHANNEL_IN_RIGHT | CHANNEL_IN_TOP_LEFT | CHANNEL_IN_TOP_RIGHT); 981 /** @hide */ 982 public static final int CHANNEL_IN_2POINT1POINT2 = ( 983 CHANNEL_IN_LEFT | CHANNEL_IN_RIGHT | CHANNEL_IN_TOP_LEFT | CHANNEL_IN_TOP_RIGHT 984 | CHANNEL_IN_LOW_FREQUENCY); 985 /** @hide */ 986 public static final int CHANNEL_IN_3POINT0POINT2 = ( 987 CHANNEL_IN_LEFT | CHANNEL_IN_CENTER | CHANNEL_IN_RIGHT | CHANNEL_IN_TOP_LEFT 988 | CHANNEL_IN_TOP_RIGHT); 989 /** @hide */ 990 public static final int CHANNEL_IN_3POINT1POINT2 = ( 991 CHANNEL_IN_LEFT | CHANNEL_IN_CENTER | CHANNEL_IN_RIGHT | CHANNEL_IN_TOP_LEFT 992 | CHANNEL_IN_TOP_RIGHT | CHANNEL_IN_LOW_FREQUENCY); 993 /** @hide */ 994 public static final int CHANNEL_IN_5POINT1 = ( 995 CHANNEL_IN_LEFT | CHANNEL_IN_CENTER | CHANNEL_IN_RIGHT | CHANNEL_IN_BACK_LEFT 996 | CHANNEL_IN_BACK_RIGHT | CHANNEL_IN_LOW_FREQUENCY); 997 /** @hide */ 998 public static final int CHANNEL_IN_FRONT_BACK = CHANNEL_IN_FRONT | CHANNEL_IN_BACK; 999 // CHANNEL_IN_ALL is not yet defined; if added then it should match AUDIO_CHANNEL_IN_ALL 1000 1001 /** @hide */ 1002 @TestApi getBytesPerSample(int audioFormat)1003 public static int getBytesPerSample(int audioFormat) 1004 { 1005 switch (audioFormat) { 1006 case ENCODING_PCM_8BIT: 1007 return 1; 1008 case ENCODING_PCM_16BIT: 1009 case ENCODING_IEC61937: 1010 case ENCODING_DEFAULT: 1011 return 2; 1012 case ENCODING_PCM_24BIT_PACKED: 1013 return 3; 1014 case ENCODING_PCM_FLOAT: 1015 case ENCODING_PCM_32BIT: 1016 return 4; 1017 case ENCODING_INVALID: 1018 default: 1019 throw new IllegalArgumentException("Bad audio format " + audioFormat); 1020 } 1021 } 1022 1023 /** @hide */ isValidEncoding(int audioFormat)1024 public static boolean isValidEncoding(int audioFormat) 1025 { 1026 switch (audioFormat) { 1027 case ENCODING_PCM_16BIT: 1028 case ENCODING_PCM_8BIT: 1029 case ENCODING_PCM_FLOAT: 1030 case ENCODING_AC3: 1031 case ENCODING_E_AC3: 1032 case ENCODING_DTS: 1033 case ENCODING_DTS_HD: 1034 case ENCODING_MP3: 1035 case ENCODING_AAC_LC: 1036 case ENCODING_AAC_HE_V1: 1037 case ENCODING_AAC_HE_V2: 1038 case ENCODING_IEC61937: 1039 case ENCODING_DOLBY_TRUEHD: 1040 case ENCODING_AAC_ELD: 1041 case ENCODING_AAC_XHE: 1042 case ENCODING_AC4: 1043 case ENCODING_AC4_L4: 1044 case ENCODING_E_AC3_JOC: 1045 case ENCODING_DOLBY_MAT: 1046 case ENCODING_OPUS: 1047 case ENCODING_PCM_24BIT_PACKED: 1048 case ENCODING_PCM_32BIT: 1049 case ENCODING_MPEGH_BL_L3: 1050 case ENCODING_MPEGH_BL_L4: 1051 case ENCODING_MPEGH_LC_L3: 1052 case ENCODING_MPEGH_LC_L4: 1053 case ENCODING_DTS_UHD_P1: 1054 case ENCODING_DRA: 1055 case ENCODING_DTS_HD_MA: 1056 case ENCODING_DTS_UHD_P2: 1057 case ENCODING_DSD: 1058 case ENCODING_IAMF_BASE_ENHANCED_PROFILE_AAC: 1059 case ENCODING_IAMF_BASE_ENHANCED_PROFILE_FLAC: 1060 case ENCODING_IAMF_BASE_ENHANCED_PROFILE_OPUS: 1061 case ENCODING_IAMF_BASE_ENHANCED_PROFILE_PCM: 1062 case ENCODING_IAMF_BASE_PROFILE_AAC: 1063 case ENCODING_IAMF_BASE_PROFILE_FLAC: 1064 case ENCODING_IAMF_BASE_PROFILE_OPUS: 1065 case ENCODING_IAMF_BASE_PROFILE_PCM: 1066 case ENCODING_IAMF_SIMPLE_PROFILE_AAC: 1067 case ENCODING_IAMF_SIMPLE_PROFILE_FLAC: 1068 case ENCODING_IAMF_SIMPLE_PROFILE_OPUS: 1069 case ENCODING_IAMF_SIMPLE_PROFILE_PCM: 1070 return true; 1071 default: 1072 return false; 1073 } 1074 } 1075 1076 /** @hide */ isPublicEncoding(int audioFormat)1077 public static boolean isPublicEncoding(int audioFormat) 1078 { 1079 switch (audioFormat) { 1080 case ENCODING_PCM_16BIT: 1081 case ENCODING_PCM_8BIT: 1082 case ENCODING_PCM_FLOAT: 1083 case ENCODING_AC3: 1084 case ENCODING_E_AC3: 1085 case ENCODING_DTS: 1086 case ENCODING_DTS_HD: 1087 case ENCODING_MP3: 1088 case ENCODING_AAC_LC: 1089 case ENCODING_AAC_HE_V1: 1090 case ENCODING_AAC_HE_V2: 1091 case ENCODING_IEC61937: 1092 case ENCODING_DOLBY_TRUEHD: 1093 case ENCODING_AAC_ELD: 1094 case ENCODING_AAC_XHE: 1095 case ENCODING_AC4: 1096 case ENCODING_AC4_L4: 1097 case ENCODING_E_AC3_JOC: 1098 case ENCODING_DOLBY_MAT: 1099 case ENCODING_OPUS: 1100 case ENCODING_PCM_24BIT_PACKED: 1101 case ENCODING_PCM_32BIT: 1102 case ENCODING_MPEGH_BL_L3: 1103 case ENCODING_MPEGH_BL_L4: 1104 case ENCODING_MPEGH_LC_L3: 1105 case ENCODING_MPEGH_LC_L4: 1106 case ENCODING_DTS_UHD_P1: 1107 case ENCODING_DRA: 1108 case ENCODING_DTS_HD_MA: 1109 case ENCODING_DTS_UHD_P2: 1110 case ENCODING_DSD: 1111 case ENCODING_IAMF_BASE_ENHANCED_PROFILE_AAC: 1112 case ENCODING_IAMF_BASE_ENHANCED_PROFILE_FLAC: 1113 case ENCODING_IAMF_BASE_ENHANCED_PROFILE_OPUS: 1114 case ENCODING_IAMF_BASE_ENHANCED_PROFILE_PCM: 1115 case ENCODING_IAMF_BASE_PROFILE_AAC: 1116 case ENCODING_IAMF_BASE_PROFILE_FLAC: 1117 case ENCODING_IAMF_BASE_PROFILE_OPUS: 1118 case ENCODING_IAMF_BASE_PROFILE_PCM: 1119 case ENCODING_IAMF_SIMPLE_PROFILE_AAC: 1120 case ENCODING_IAMF_SIMPLE_PROFILE_FLAC: 1121 case ENCODING_IAMF_SIMPLE_PROFILE_OPUS: 1122 case ENCODING_IAMF_SIMPLE_PROFILE_PCM: 1123 return true; 1124 default: 1125 return false; 1126 } 1127 } 1128 1129 /** @hide */ 1130 @TestApi isEncodingLinearPcm(int audioFormat)1131 public static boolean isEncodingLinearPcm(int audioFormat) 1132 { 1133 switch (audioFormat) { 1134 case ENCODING_PCM_16BIT: 1135 case ENCODING_PCM_8BIT: 1136 case ENCODING_PCM_FLOAT: 1137 case ENCODING_PCM_24BIT_PACKED: 1138 case ENCODING_PCM_32BIT: 1139 case ENCODING_DEFAULT: 1140 return true; 1141 case ENCODING_AC3: 1142 case ENCODING_E_AC3: 1143 case ENCODING_DTS: 1144 case ENCODING_DTS_HD: 1145 case ENCODING_MP3: 1146 case ENCODING_AAC_LC: 1147 case ENCODING_AAC_HE_V1: 1148 case ENCODING_AAC_HE_V2: 1149 case ENCODING_IEC61937: // wrapped in PCM but compressed 1150 case ENCODING_DOLBY_TRUEHD: 1151 case ENCODING_AAC_ELD: 1152 case ENCODING_AAC_XHE: 1153 case ENCODING_AC4: 1154 case ENCODING_AC4_L4: 1155 case ENCODING_E_AC3_JOC: 1156 case ENCODING_DOLBY_MAT: 1157 case ENCODING_OPUS: 1158 case ENCODING_MPEGH_BL_L3: 1159 case ENCODING_MPEGH_BL_L4: 1160 case ENCODING_MPEGH_LC_L3: 1161 case ENCODING_MPEGH_LC_L4: 1162 case ENCODING_DTS_UHD_P1: 1163 case ENCODING_DRA: 1164 case ENCODING_DTS_HD_MA: 1165 case ENCODING_DTS_UHD_P2: 1166 case ENCODING_IAMF_BASE_ENHANCED_PROFILE_AAC: 1167 case ENCODING_IAMF_BASE_ENHANCED_PROFILE_FLAC: 1168 case ENCODING_IAMF_BASE_ENHANCED_PROFILE_OPUS: 1169 case ENCODING_IAMF_BASE_ENHANCED_PROFILE_PCM: // PCM but inside compressed stream 1170 case ENCODING_IAMF_BASE_PROFILE_AAC: 1171 case ENCODING_IAMF_BASE_PROFILE_FLAC: 1172 case ENCODING_IAMF_BASE_PROFILE_OPUS: 1173 case ENCODING_IAMF_BASE_PROFILE_PCM: // PCM but inside compressed stream 1174 case ENCODING_IAMF_SIMPLE_PROFILE_AAC: 1175 case ENCODING_IAMF_SIMPLE_PROFILE_FLAC: 1176 case ENCODING_IAMF_SIMPLE_PROFILE_OPUS: 1177 case ENCODING_IAMF_SIMPLE_PROFILE_PCM: // PCM but inside compressed stream 1178 return false; 1179 case ENCODING_INVALID: 1180 default: 1181 throw new IllegalArgumentException("Bad audio format " + audioFormat); 1182 } 1183 } 1184 1185 /** @hide */ isEncodingLinearFrames(int audioFormat)1186 public static boolean isEncodingLinearFrames(int audioFormat) 1187 { 1188 switch (audioFormat) { 1189 case ENCODING_PCM_16BIT: 1190 case ENCODING_PCM_8BIT: 1191 case ENCODING_PCM_FLOAT: 1192 case ENCODING_IEC61937: // same size as stereo PCM 1193 case ENCODING_PCM_24BIT_PACKED: 1194 case ENCODING_PCM_32BIT: 1195 case ENCODING_DEFAULT: 1196 return true; 1197 case ENCODING_AC3: 1198 case ENCODING_E_AC3: 1199 case ENCODING_DTS: 1200 case ENCODING_DTS_HD: 1201 case ENCODING_MP3: 1202 case ENCODING_AAC_LC: 1203 case ENCODING_AAC_HE_V1: 1204 case ENCODING_AAC_HE_V2: 1205 case ENCODING_DOLBY_TRUEHD: 1206 case ENCODING_AAC_ELD: 1207 case ENCODING_AAC_XHE: 1208 case ENCODING_AC4: 1209 case ENCODING_AC4_L4: 1210 case ENCODING_E_AC3_JOC: 1211 case ENCODING_DOLBY_MAT: 1212 case ENCODING_OPUS: 1213 case ENCODING_MPEGH_BL_L3: 1214 case ENCODING_MPEGH_BL_L4: 1215 case ENCODING_MPEGH_LC_L3: 1216 case ENCODING_MPEGH_LC_L4: 1217 case ENCODING_DTS_UHD_P1: 1218 case ENCODING_DRA: 1219 case ENCODING_DTS_HD_MA: 1220 case ENCODING_DTS_UHD_P2: 1221 case ENCODING_IAMF_BASE_ENHANCED_PROFILE_AAC: 1222 case ENCODING_IAMF_BASE_ENHANCED_PROFILE_FLAC: 1223 case ENCODING_IAMF_BASE_ENHANCED_PROFILE_OPUS: 1224 case ENCODING_IAMF_BASE_ENHANCED_PROFILE_PCM: 1225 case ENCODING_IAMF_BASE_PROFILE_AAC: 1226 case ENCODING_IAMF_BASE_PROFILE_FLAC: 1227 case ENCODING_IAMF_BASE_PROFILE_OPUS: 1228 case ENCODING_IAMF_BASE_PROFILE_PCM: 1229 case ENCODING_IAMF_SIMPLE_PROFILE_AAC: 1230 case ENCODING_IAMF_SIMPLE_PROFILE_FLAC: 1231 case ENCODING_IAMF_SIMPLE_PROFILE_OPUS: 1232 case ENCODING_IAMF_SIMPLE_PROFILE_PCM: 1233 return false; 1234 case ENCODING_INVALID: 1235 default: 1236 throw new IllegalArgumentException("Bad audio format " + audioFormat); 1237 } 1238 } 1239 /** 1240 * Returns an array of public encoding values extracted from an array of 1241 * encoding values. 1242 * @hide 1243 */ filterPublicFormats(int[] formats)1244 public static int[] filterPublicFormats(int[] formats) { 1245 if (formats == null) { 1246 return null; 1247 } 1248 int[] myCopy = Arrays.copyOf(formats, formats.length); 1249 int size = 0; 1250 for (int i = 0; i < myCopy.length; i++) { 1251 if (isPublicEncoding(myCopy[i])) { 1252 if (size != i) { 1253 myCopy[size] = myCopy[i]; 1254 } 1255 size++; 1256 } 1257 } 1258 return Arrays.copyOf(myCopy, size); 1259 } 1260 1261 /** @removed */ AudioFormat()1262 public AudioFormat() 1263 { 1264 throw new UnsupportedOperationException("There is no valid usage of this constructor"); 1265 } 1266 1267 /** 1268 * Constructor used by the JNI. Parameters are not checked for validity. 1269 */ 1270 // Update sound trigger JNI in core/jni/android_hardware_SoundTrigger.cpp when modifying this 1271 // constructor 1272 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) AudioFormat(int encoding, int sampleRate, int channelMask, int channelIndexMask)1273 private AudioFormat(int encoding, int sampleRate, int channelMask, int channelIndexMask) { 1274 this( 1275 AUDIO_FORMAT_HAS_PROPERTY_ENCODING 1276 | AUDIO_FORMAT_HAS_PROPERTY_SAMPLE_RATE 1277 | AUDIO_FORMAT_HAS_PROPERTY_CHANNEL_MASK 1278 | AUDIO_FORMAT_HAS_PROPERTY_CHANNEL_INDEX_MASK, 1279 encoding, sampleRate, channelMask, channelIndexMask 1280 ); 1281 } 1282 AudioFormat(int propertySetMask, int encoding, int sampleRate, int channelMask, int channelIndexMask)1283 private AudioFormat(int propertySetMask, 1284 int encoding, int sampleRate, int channelMask, int channelIndexMask) { 1285 mPropertySetMask = propertySetMask; 1286 mEncoding = (propertySetMask & AUDIO_FORMAT_HAS_PROPERTY_ENCODING) != 0 1287 ? encoding : ENCODING_INVALID; 1288 mSampleRate = (propertySetMask & AUDIO_FORMAT_HAS_PROPERTY_SAMPLE_RATE) != 0 1289 ? sampleRate : SAMPLE_RATE_UNSPECIFIED; 1290 mChannelMask = (propertySetMask & AUDIO_FORMAT_HAS_PROPERTY_CHANNEL_MASK) != 0 1291 ? channelMask : CHANNEL_INVALID; 1292 mChannelIndexMask = (propertySetMask & AUDIO_FORMAT_HAS_PROPERTY_CHANNEL_INDEX_MASK) != 0 1293 ? channelIndexMask : CHANNEL_INVALID; 1294 1295 // Compute derived values. 1296 1297 final int channelIndexCount = Integer.bitCount(getChannelIndexMask()); 1298 int channelCount = channelCountFromOutChannelMask(getChannelMask()); 1299 if (channelCount == 0) { 1300 channelCount = channelIndexCount; 1301 } else if (channelCount != channelIndexCount && channelIndexCount != 0) { 1302 channelCount = 0; // position and index channel count mismatch 1303 } 1304 mChannelCount = channelCount; 1305 1306 int frameSizeInBytes = 1; 1307 try { 1308 frameSizeInBytes = getBytesPerSample(mEncoding) * channelCount; 1309 } catch (IllegalArgumentException iae) { 1310 // ignored 1311 } 1312 // it is possible that channel count is 0, so ensure we return 1 for 1313 // mFrameSizeInBytes for consistency. 1314 mFrameSizeInBytes = frameSizeInBytes != 0 ? frameSizeInBytes : 1; 1315 } 1316 1317 /** @hide */ 1318 public final static int AUDIO_FORMAT_HAS_PROPERTY_NONE = 0x0; 1319 /** @hide */ 1320 public final static int AUDIO_FORMAT_HAS_PROPERTY_ENCODING = 0x1 << 0; 1321 /** @hide */ 1322 public final static int AUDIO_FORMAT_HAS_PROPERTY_SAMPLE_RATE = 0x1 << 1; 1323 /** @hide */ 1324 public final static int AUDIO_FORMAT_HAS_PROPERTY_CHANNEL_MASK = 0x1 << 2; 1325 /** @hide */ 1326 public final static int AUDIO_FORMAT_HAS_PROPERTY_CHANNEL_INDEX_MASK = 0x1 << 3; 1327 1328 // This is an immutable class, all member variables are final. 1329 1330 // Essential values. 1331 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 1332 private final int mEncoding; 1333 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 1334 private final int mSampleRate; 1335 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 1336 private final int mChannelMask; 1337 private final int mChannelIndexMask; 1338 private final int mPropertySetMask; 1339 1340 // Derived values computed in the constructor, cached here. 1341 private final int mChannelCount; 1342 private final int mFrameSizeInBytes; 1343 1344 /** 1345 * Return the encoding. 1346 * See the section on <a href="#encoding">encodings</a> for more information about the different 1347 * types of supported audio encoding. 1348 * @return one of the values that can be set in {@link Builder#setEncoding(int)} or 1349 * {@link AudioFormat#ENCODING_INVALID} if not set. 1350 */ getEncoding()1351 public @EncodingCanBeInvalid int getEncoding() { 1352 return mEncoding; 1353 } 1354 1355 /** 1356 * Return the sample rate. 1357 * @return one of the values that can be set in {@link Builder#setSampleRate(int)} or 1358 * {@link #SAMPLE_RATE_UNSPECIFIED} if not set. 1359 */ getSampleRate()1360 public int getSampleRate() { 1361 return mSampleRate; 1362 } 1363 1364 /** 1365 * Return the channel mask. 1366 * See the section on <a href="#channelMask">channel masks</a> for more information about 1367 * the difference between index-based masks(as returned by {@link #getChannelIndexMask()}) and 1368 * the position-based mask returned by this function. 1369 * @return one of the values that can be set in {@link Builder#setChannelMask(int)} or 1370 * {@link AudioFormat#CHANNEL_INVALID} if not set. 1371 */ getChannelMask()1372 public int getChannelMask() { 1373 return mChannelMask; 1374 } 1375 1376 /** 1377 * Return the channel index mask. 1378 * See the section on <a href="#channelMask">channel masks</a> for more information about 1379 * the difference between index-based masks, and position-based masks (as returned 1380 * by {@link #getChannelMask()}). 1381 * @return one of the values that can be set in {@link Builder#setChannelIndexMask(int)} or 1382 * {@link AudioFormat#CHANNEL_INVALID} if not set or an invalid mask was used. 1383 */ getChannelIndexMask()1384 public int getChannelIndexMask() { 1385 return mChannelIndexMask; 1386 } 1387 1388 /** 1389 * Return the channel count. 1390 * @return the channel count derived from the channel position mask or the channel index mask. 1391 * Zero is returned if both the channel position mask and the channel index mask are not set. 1392 */ getChannelCount()1393 public int getChannelCount() { 1394 return mChannelCount; 1395 } 1396 1397 /** 1398 * Return the frame size in bytes. 1399 * 1400 * For PCM or PCM packed compressed data this is the size of a sample multiplied 1401 * by the channel count. For all other cases, including invalid/unset channel masks, 1402 * this will return 1 byte. 1403 * As an example, a stereo 16-bit PCM format would have a frame size of 4 bytes, 1404 * an 8 channel float PCM format would have a frame size of 32 bytes, 1405 * and a compressed data format (not packed in PCM) would have a frame size of 1 byte. 1406 * 1407 * Both {@link AudioRecord} or {@link AudioTrack} process data in multiples of 1408 * this frame size. 1409 * 1410 * @return The audio frame size in bytes corresponding to the encoding and the channel mask. 1411 */ getFrameSizeInBytes()1412 public @IntRange(from = 1) int getFrameSizeInBytes() { 1413 return mFrameSizeInBytes; 1414 } 1415 1416 /** @hide */ getPropertySetMask()1417 public int getPropertySetMask() { 1418 return mPropertySetMask; 1419 } 1420 1421 /** @hide */ toLogFriendlyString()1422 public String toLogFriendlyString() { 1423 return String.format("%dch %dHz %s", 1424 mChannelCount, mSampleRate, toLogFriendlyEncoding(mEncoding)); 1425 } 1426 1427 /** 1428 * Builder class for {@link AudioFormat} objects. 1429 * Use this class to configure and create an AudioFormat instance. By setting format 1430 * characteristics such as audio encoding, channel mask or sample rate, you indicate which 1431 * of those are to vary from the default behavior on this device wherever this audio format 1432 * is used. See {@link AudioFormat} for a complete description of the different parameters that 1433 * can be used to configure an <code>AudioFormat</code> instance. 1434 * <p>{@link AudioFormat} is for instance used in 1435 * {@link AudioTrack#AudioTrack(AudioAttributes, AudioFormat, int, int, int)}. In this 1436 * constructor, every format characteristic set on the <code>Builder</code> (e.g. with 1437 * {@link #setSampleRate(int)}) will alter the default values used by an 1438 * <code>AudioTrack</code>. In this case for audio playback with <code>AudioTrack</code>, the 1439 * sample rate set in the <code>Builder</code> would override the platform output sample rate 1440 * which would otherwise be selected by default. 1441 */ 1442 public static class Builder { 1443 private int mEncoding = ENCODING_INVALID; 1444 private int mSampleRate = SAMPLE_RATE_UNSPECIFIED; 1445 private int mChannelMask = CHANNEL_INVALID; 1446 private int mChannelIndexMask = 0; 1447 private int mPropertySetMask = AUDIO_FORMAT_HAS_PROPERTY_NONE; 1448 1449 /** 1450 * Constructs a new Builder with none of the format characteristics set. 1451 */ Builder()1452 public Builder() { 1453 } 1454 1455 /** 1456 * Constructs a new Builder from a given {@link AudioFormat}. 1457 * @param af the {@link AudioFormat} object whose data will be reused in the new Builder. 1458 */ Builder(AudioFormat af)1459 public Builder(AudioFormat af) { 1460 mEncoding = af.mEncoding; 1461 mSampleRate = af.mSampleRate; 1462 mChannelMask = af.mChannelMask; 1463 mChannelIndexMask = af.mChannelIndexMask; 1464 mPropertySetMask = af.mPropertySetMask; 1465 } 1466 1467 /** 1468 * Combines all of the format characteristics that have been set and return a new 1469 * {@link AudioFormat} object. 1470 * @return a new {@link AudioFormat} object 1471 */ build()1472 public AudioFormat build() { 1473 AudioFormat af = new AudioFormat( 1474 mPropertySetMask, 1475 mEncoding, 1476 mSampleRate, 1477 mChannelMask, 1478 mChannelIndexMask 1479 ); 1480 return af; 1481 } 1482 1483 /** 1484 * Sets the data encoding format. 1485 * @param encoding the specified encoding or default. 1486 * @return the same Builder instance. 1487 * @throws java.lang.IllegalArgumentException 1488 */ setEncoding(@ncoding int encoding)1489 public Builder setEncoding(@Encoding int encoding) throws IllegalArgumentException { 1490 switch (encoding) { 1491 case ENCODING_DEFAULT: 1492 mEncoding = ENCODING_PCM_16BIT; 1493 break; 1494 case ENCODING_PCM_16BIT: 1495 case ENCODING_PCM_8BIT: 1496 case ENCODING_PCM_FLOAT: 1497 case ENCODING_AC3: 1498 case ENCODING_E_AC3: 1499 case ENCODING_DTS: 1500 case ENCODING_DTS_HD: 1501 case ENCODING_MP3: 1502 case ENCODING_AAC_LC: 1503 case ENCODING_AAC_HE_V1: 1504 case ENCODING_AAC_HE_V2: 1505 case ENCODING_IEC61937: 1506 case ENCODING_DOLBY_TRUEHD: 1507 case ENCODING_AAC_ELD: 1508 case ENCODING_AAC_XHE: 1509 case ENCODING_AC4: 1510 case ENCODING_AC4_L4: 1511 case ENCODING_E_AC3_JOC: 1512 case ENCODING_DOLBY_MAT: 1513 case ENCODING_OPUS: 1514 case ENCODING_PCM_24BIT_PACKED: 1515 case ENCODING_PCM_32BIT: 1516 case ENCODING_MPEGH_BL_L3: 1517 case ENCODING_MPEGH_BL_L4: 1518 case ENCODING_MPEGH_LC_L3: 1519 case ENCODING_MPEGH_LC_L4: 1520 case ENCODING_DTS_UHD_P1: 1521 case ENCODING_DRA: 1522 case ENCODING_DTS_HD_MA: 1523 case ENCODING_DTS_UHD_P2: 1524 case ENCODING_DSD: 1525 case ENCODING_IAMF_BASE_ENHANCED_PROFILE_AAC: 1526 case ENCODING_IAMF_BASE_ENHANCED_PROFILE_FLAC: 1527 case ENCODING_IAMF_BASE_ENHANCED_PROFILE_OPUS: 1528 case ENCODING_IAMF_BASE_ENHANCED_PROFILE_PCM: 1529 case ENCODING_IAMF_BASE_PROFILE_AAC: 1530 case ENCODING_IAMF_BASE_PROFILE_FLAC: 1531 case ENCODING_IAMF_BASE_PROFILE_OPUS: 1532 case ENCODING_IAMF_BASE_PROFILE_PCM: 1533 case ENCODING_IAMF_SIMPLE_PROFILE_AAC: 1534 case ENCODING_IAMF_SIMPLE_PROFILE_FLAC: 1535 case ENCODING_IAMF_SIMPLE_PROFILE_OPUS: 1536 case ENCODING_IAMF_SIMPLE_PROFILE_PCM: 1537 mEncoding = encoding; 1538 break; 1539 case ENCODING_INVALID: 1540 default: 1541 throw new IllegalArgumentException("Invalid encoding " + encoding); 1542 } 1543 mPropertySetMask |= AUDIO_FORMAT_HAS_PROPERTY_ENCODING; 1544 return this; 1545 } 1546 1547 /** 1548 * Sets the channel position mask. 1549 * The channel position mask specifies the association between audio samples in a frame 1550 * with named endpoint channels. The samples in the frame correspond to the 1551 * named set bits in the channel position mask, in ascending bit order. 1552 * See {@link #setChannelIndexMask(int)} to specify channels 1553 * based on endpoint numbered channels. This <a href="#channelPositionMask">description of 1554 * channel position masks</a> covers the concept in more details. 1555 * @param channelMask describes the configuration of the audio channels. 1556 * <p> For output, the channelMask can be an OR-ed combination of 1557 * channel position masks, e.g. 1558 * {@link AudioFormat#CHANNEL_OUT_FRONT_LEFT}, 1559 * {@link AudioFormat#CHANNEL_OUT_FRONT_RIGHT}, 1560 * {@link AudioFormat#CHANNEL_OUT_FRONT_CENTER}, 1561 * {@link AudioFormat#CHANNEL_OUT_LOW_FREQUENCY} 1562 * {@link AudioFormat#CHANNEL_OUT_BACK_LEFT}, 1563 * {@link AudioFormat#CHANNEL_OUT_BACK_RIGHT}, 1564 * {@link AudioFormat#CHANNEL_OUT_BACK_CENTER}, 1565 * {@link AudioFormat#CHANNEL_OUT_SIDE_LEFT}, 1566 * {@link AudioFormat#CHANNEL_OUT_SIDE_RIGHT}. 1567 * <p> For output or {@link AudioTrack}, channel position masks which do not contain 1568 * matched left/right pairs are invalid. 1569 * <p> For input or {@link AudioRecord}, the mask should be 1570 * {@link AudioFormat#CHANNEL_IN_MONO} or 1571 * {@link AudioFormat#CHANNEL_IN_STEREO}. {@link AudioFormat#CHANNEL_IN_MONO} is 1572 * guaranteed to work on all devices. 1573 * @return the same <code>Builder</code> instance. 1574 * @throws IllegalArgumentException if the channel mask is invalid or 1575 * if both channel index mask and channel position mask 1576 * are specified but do not have the same channel count. 1577 */ setChannelMask(int channelMask)1578 public @NonNull Builder setChannelMask(int channelMask) { 1579 if (channelMask == CHANNEL_INVALID) { 1580 throw new IllegalArgumentException("Invalid zero channel mask"); 1581 } else if (/* channelMask != 0 && */ mChannelIndexMask != 0 && 1582 Integer.bitCount(channelMask) != Integer.bitCount(mChannelIndexMask)) { 1583 throw new IllegalArgumentException("Mismatched channel count for mask " + 1584 Integer.toHexString(channelMask).toUpperCase()); 1585 } 1586 mChannelMask = channelMask; 1587 mPropertySetMask |= AUDIO_FORMAT_HAS_PROPERTY_CHANNEL_MASK; 1588 return this; 1589 } 1590 1591 /** 1592 * Sets the channel index mask. 1593 * A channel index mask specifies the association of audio samples in the frame 1594 * with numbered endpoint channels. The i-th bit in the channel index 1595 * mask corresponds to the i-th endpoint channel. 1596 * For example, an endpoint with four channels is represented 1597 * as index mask bits 0 through 3. This <a href="#channelIndexMask>description of channel 1598 * index masks</a> covers the concept in more details. 1599 * See {@link #setChannelMask(int)} for a positional mask interpretation. 1600 * <p> Both {@link AudioTrack} and {@link AudioRecord} support 1601 * a channel index mask. 1602 * If a channel index mask is specified it is used, 1603 * otherwise the channel position mask specified 1604 * by <code>setChannelMask</code> is used. 1605 * For <code>AudioTrack</code> and <code>AudioRecord</code>, 1606 * a channel position mask is not required if a channel index mask is specified. 1607 * 1608 * @param channelIndexMask describes the configuration of the audio channels. 1609 * <p> For output, the <code>channelIndexMask</code> is an OR-ed combination of 1610 * bits representing the mapping of <code>AudioTrack</code> write samples 1611 * to output sink channels. 1612 * For example, a mask of <code>0xa</code>, or binary <code>1010</code>, 1613 * means the <code>AudioTrack</code> write frame consists of two samples, 1614 * which are routed to the second and the fourth channels of the output sink. 1615 * Unmatched output sink channels are zero filled and unmatched 1616 * <code>AudioTrack</code> write samples are dropped. 1617 * <p> For input, the <code>channelIndexMask</code> is an OR-ed combination of 1618 * bits representing the mapping of input source channels to 1619 * <code>AudioRecord</code> read samples. 1620 * For example, a mask of <code>0x5</code>, or binary 1621 * <code>101</code>, will read from the first and third channel of the input 1622 * source device and store them in the first and second sample of the 1623 * <code>AudioRecord</code> read frame. 1624 * Unmatched input source channels are dropped and 1625 * unmatched <code>AudioRecord</code> read samples are zero filled. 1626 * @return the same <code>Builder</code> instance. 1627 * @throws IllegalArgumentException if the channel index mask is invalid or 1628 * if both channel index mask and channel position mask 1629 * are specified but do not have the same channel count. 1630 */ setChannelIndexMask(int channelIndexMask)1631 public @NonNull Builder setChannelIndexMask(int channelIndexMask) { 1632 if (channelIndexMask == 0) { 1633 throw new IllegalArgumentException("Invalid zero channel index mask"); 1634 } else if (/* channelIndexMask != 0 && */ mChannelMask != 0 && 1635 Integer.bitCount(channelIndexMask) != Integer.bitCount(mChannelMask)) { 1636 throw new IllegalArgumentException("Mismatched channel count for index mask " + 1637 Integer.toHexString(channelIndexMask).toUpperCase()); 1638 } 1639 mChannelIndexMask = channelIndexMask; 1640 mPropertySetMask |= AUDIO_FORMAT_HAS_PROPERTY_CHANNEL_INDEX_MASK; 1641 return this; 1642 } 1643 1644 /** 1645 * Sets the sample rate. 1646 * @param sampleRate the sample rate expressed in Hz 1647 * @return the same Builder instance. 1648 * @throws java.lang.IllegalArgumentException 1649 */ setSampleRate(int sampleRate)1650 public Builder setSampleRate(int sampleRate) throws IllegalArgumentException { 1651 // TODO Consider whether to keep the MIN and MAX range checks here. 1652 // It is not necessary and poses the problem of defining the limits independently from 1653 // native implementation or platform capabilities. 1654 if (((sampleRate < SAMPLE_RATE_HZ_MIN) || (sampleRate > SAMPLE_RATE_HZ_MAX)) && 1655 sampleRate != SAMPLE_RATE_UNSPECIFIED) { 1656 throw new IllegalArgumentException("Invalid sample rate " + sampleRate); 1657 } 1658 mSampleRate = sampleRate; 1659 mPropertySetMask |= AUDIO_FORMAT_HAS_PROPERTY_SAMPLE_RATE; 1660 return this; 1661 } 1662 } 1663 1664 @Override equals(Object o)1665 public boolean equals(Object o) { 1666 if (this == o) return true; 1667 if (o == null || getClass() != o.getClass()) return false; 1668 1669 AudioFormat that = (AudioFormat) o; 1670 1671 if (mPropertySetMask != that.mPropertySetMask) return false; 1672 1673 // return false if any of the properties is set and the values differ 1674 return !((((mPropertySetMask & AUDIO_FORMAT_HAS_PROPERTY_ENCODING) != 0) 1675 && (mEncoding != that.mEncoding)) 1676 || (((mPropertySetMask & AUDIO_FORMAT_HAS_PROPERTY_SAMPLE_RATE) != 0) 1677 && (mSampleRate != that.mSampleRate)) 1678 || (((mPropertySetMask & AUDIO_FORMAT_HAS_PROPERTY_CHANNEL_MASK) != 0) 1679 && (mChannelMask != that.mChannelMask)) 1680 || (((mPropertySetMask & AUDIO_FORMAT_HAS_PROPERTY_CHANNEL_INDEX_MASK) != 0) 1681 && (mChannelIndexMask != that.mChannelIndexMask))); 1682 } 1683 1684 @Override hashCode()1685 public int hashCode() { 1686 return Objects.hash(mPropertySetMask, mSampleRate, mEncoding, mChannelMask, 1687 mChannelIndexMask); 1688 } 1689 1690 @Override describeContents()1691 public int describeContents() { 1692 return 0; 1693 } 1694 1695 @Override writeToParcel(Parcel dest, int flags)1696 public void writeToParcel(Parcel dest, int flags) { 1697 dest.writeInt(mPropertySetMask); 1698 dest.writeInt(mEncoding); 1699 dest.writeInt(mSampleRate); 1700 dest.writeInt(mChannelMask); 1701 dest.writeInt(mChannelIndexMask); 1702 } 1703 AudioFormat(Parcel in)1704 private AudioFormat(Parcel in) { 1705 this( 1706 in.readInt(), // propertySetMask 1707 in.readInt(), // encoding 1708 in.readInt(), // sampleRate 1709 in.readInt(), // channelMask 1710 in.readInt() // channelIndexMask 1711 ); 1712 } 1713 1714 public static final @android.annotation.NonNull Parcelable.Creator<AudioFormat> CREATOR = 1715 new Parcelable.Creator<AudioFormat>() { 1716 public AudioFormat createFromParcel(Parcel p) { 1717 return new AudioFormat(p); 1718 } 1719 public AudioFormat[] newArray(int size) { 1720 return new AudioFormat[size]; 1721 } 1722 }; 1723 1724 @Override toString()1725 public String toString () { 1726 return new String("AudioFormat:" 1727 + " props=" + mPropertySetMask 1728 + " enc=" + mEncoding 1729 + " chan=0x" + Integer.toHexString(mChannelMask).toUpperCase() 1730 + " chan_index=0x" + Integer.toHexString(mChannelIndexMask).toUpperCase() 1731 + " rate=" + mSampleRate); 1732 } 1733 1734 /** @hide */ 1735 @IntDef(flag = false, prefix = "ENCODING", value = { 1736 ENCODING_DEFAULT, 1737 ENCODING_PCM_16BIT, 1738 ENCODING_PCM_8BIT, 1739 ENCODING_PCM_FLOAT, 1740 ENCODING_AC3, 1741 ENCODING_E_AC3, 1742 ENCODING_DTS, 1743 ENCODING_DTS_HD, 1744 ENCODING_MP3, 1745 ENCODING_AAC_LC, 1746 ENCODING_AAC_HE_V1, 1747 ENCODING_AAC_HE_V2, 1748 ENCODING_IEC61937, 1749 ENCODING_DOLBY_TRUEHD, 1750 ENCODING_AAC_ELD, 1751 ENCODING_AAC_XHE, 1752 ENCODING_AC4, 1753 ENCODING_AC4_L4, 1754 ENCODING_E_AC3_JOC, 1755 ENCODING_DOLBY_MAT, 1756 ENCODING_OPUS, 1757 ENCODING_PCM_24BIT_PACKED, 1758 ENCODING_PCM_32BIT, 1759 ENCODING_MPEGH_BL_L3, 1760 ENCODING_MPEGH_BL_L4, 1761 ENCODING_MPEGH_LC_L3, 1762 ENCODING_MPEGH_LC_L4, 1763 ENCODING_DTS_UHD_P1, 1764 ENCODING_DRA, 1765 ENCODING_DTS_HD_MA, 1766 ENCODING_DTS_UHD_P2, 1767 ENCODING_DSD, 1768 ENCODING_IAMF_BASE_ENHANCED_PROFILE_AAC, 1769 ENCODING_IAMF_BASE_ENHANCED_PROFILE_FLAC, 1770 ENCODING_IAMF_BASE_ENHANCED_PROFILE_OPUS, 1771 ENCODING_IAMF_BASE_ENHANCED_PROFILE_PCM, 1772 ENCODING_IAMF_BASE_PROFILE_AAC, 1773 ENCODING_IAMF_BASE_PROFILE_FLAC, 1774 ENCODING_IAMF_BASE_PROFILE_OPUS, 1775 ENCODING_IAMF_BASE_PROFILE_PCM, 1776 ENCODING_IAMF_SIMPLE_PROFILE_AAC, 1777 ENCODING_IAMF_SIMPLE_PROFILE_FLAC, 1778 ENCODING_IAMF_SIMPLE_PROFILE_OPUS, 1779 ENCODING_IAMF_SIMPLE_PROFILE_PCM } 1780 ) 1781 @Retention(RetentionPolicy.SOURCE) 1782 public @interface Encoding {} 1783 1784 /** @hide same as @Encoding, but adding ENCODING_INVALID */ 1785 @IntDef(flag = false, prefix = "ENCODING", value = { 1786 ENCODING_INVALID, 1787 ENCODING_DEFAULT, 1788 ENCODING_PCM_16BIT, 1789 ENCODING_PCM_8BIT, 1790 ENCODING_PCM_FLOAT, 1791 ENCODING_AC3, 1792 ENCODING_E_AC3, 1793 ENCODING_DTS, 1794 ENCODING_DTS_HD, 1795 ENCODING_MP3, 1796 ENCODING_AAC_LC, 1797 ENCODING_AAC_HE_V1, 1798 ENCODING_AAC_HE_V2, 1799 ENCODING_IEC61937, 1800 ENCODING_DOLBY_TRUEHD, 1801 ENCODING_AAC_ELD, 1802 ENCODING_AAC_XHE, 1803 ENCODING_AC4, 1804 ENCODING_AC4_L4, 1805 ENCODING_E_AC3_JOC, 1806 ENCODING_DOLBY_MAT, 1807 ENCODING_OPUS, 1808 ENCODING_PCM_24BIT_PACKED, 1809 ENCODING_PCM_32BIT, 1810 ENCODING_MPEGH_BL_L3, 1811 ENCODING_MPEGH_BL_L4, 1812 ENCODING_MPEGH_LC_L3, 1813 ENCODING_MPEGH_LC_L4, 1814 ENCODING_DTS_UHD_P1, 1815 ENCODING_DRA, 1816 ENCODING_DTS_HD_MA, 1817 ENCODING_DTS_UHD_P2, 1818 ENCODING_DSD, 1819 ENCODING_IAMF_BASE_ENHANCED_PROFILE_AAC, 1820 ENCODING_IAMF_BASE_ENHANCED_PROFILE_FLAC, 1821 ENCODING_IAMF_BASE_ENHANCED_PROFILE_OPUS, 1822 ENCODING_IAMF_BASE_ENHANCED_PROFILE_PCM, 1823 ENCODING_IAMF_BASE_PROFILE_AAC, 1824 ENCODING_IAMF_BASE_PROFILE_FLAC, 1825 ENCODING_IAMF_BASE_PROFILE_OPUS, 1826 ENCODING_IAMF_BASE_PROFILE_PCM, 1827 ENCODING_IAMF_SIMPLE_PROFILE_AAC, 1828 ENCODING_IAMF_SIMPLE_PROFILE_FLAC, 1829 ENCODING_IAMF_SIMPLE_PROFILE_OPUS, 1830 ENCODING_IAMF_SIMPLE_PROFILE_PCM } 1831 ) 1832 @Retention(RetentionPolicy.SOURCE) 1833 public @interface EncodingCanBeInvalid {} 1834 1835 /** @hide */ 1836 public static final int[] SURROUND_SOUND_ENCODING = { 1837 ENCODING_AC3, 1838 ENCODING_E_AC3, 1839 ENCODING_DTS, 1840 ENCODING_DTS_HD, 1841 ENCODING_AAC_LC, 1842 ENCODING_DOLBY_TRUEHD, 1843 ENCODING_AC4, 1844 ENCODING_AC4_L4, 1845 ENCODING_E_AC3_JOC, 1846 ENCODING_DOLBY_MAT, 1847 ENCODING_MPEGH_BL_L3, 1848 ENCODING_MPEGH_BL_L4, 1849 ENCODING_MPEGH_LC_L3, 1850 ENCODING_MPEGH_LC_L4, 1851 ENCODING_DTS_UHD_P1, 1852 ENCODING_DRA, 1853 ENCODING_DTS_HD_MA, 1854 ENCODING_DTS_UHD_P2 1855 }; 1856 1857 /** @hide */ 1858 @IntDef(flag = false, prefix = "ENCODING", value = { 1859 ENCODING_AC3, 1860 ENCODING_E_AC3, 1861 ENCODING_DTS, 1862 ENCODING_DTS_HD, 1863 ENCODING_AAC_LC, 1864 ENCODING_DOLBY_TRUEHD, 1865 ENCODING_AC4, 1866 ENCODING_AC4_L4, 1867 ENCODING_E_AC3_JOC, 1868 ENCODING_DOLBY_MAT, 1869 ENCODING_MPEGH_BL_L3, 1870 ENCODING_MPEGH_BL_L4, 1871 ENCODING_MPEGH_LC_L3, 1872 ENCODING_MPEGH_LC_L4, 1873 ENCODING_DTS_UHD_P1, 1874 ENCODING_DRA, 1875 ENCODING_DTS_HD_MA, 1876 ENCODING_DTS_UHD_P2 } 1877 ) 1878 @Retention(RetentionPolicy.SOURCE) 1879 public @interface SurroundSoundEncoding {} 1880 1881 /** 1882 * @hide 1883 * 1884 * Return default name for a surround format. This is not an International name. 1885 * It is just a default to use if an international name is not available. 1886 * 1887 * @param audioFormat a surround format 1888 * @return short default name for the format. 1889 */ toDisplayName(@urroundSoundEncoding int audioFormat)1890 public static String toDisplayName(@SurroundSoundEncoding int audioFormat) { 1891 switch (audioFormat) { 1892 case ENCODING_AC3: 1893 return "Dolby Digital"; 1894 case ENCODING_E_AC3: 1895 return "Dolby Digital Plus"; 1896 case ENCODING_DTS: 1897 return "DTS"; 1898 case ENCODING_DTS_HD: 1899 return "DTS HD"; 1900 case ENCODING_AAC_LC: 1901 return "AAC"; 1902 case ENCODING_DOLBY_TRUEHD: 1903 return "Dolby TrueHD"; 1904 case ENCODING_AC4: 1905 return "Dolby AC-4 levels 0-3"; 1906 case ENCODING_AC4_L4: 1907 return "Dolby AC-4 level 4"; 1908 case ENCODING_E_AC3_JOC: 1909 return "Dolby Atmos in Dolby Digital Plus"; 1910 case ENCODING_DOLBY_MAT: 1911 return "Dolby MAT"; 1912 case ENCODING_MPEGH_BL_L3: 1913 return "MPEG-H 3D Audio baseline profile level 3"; 1914 case ENCODING_MPEGH_BL_L4: 1915 return "MPEG-H 3D Audio baseline profile level 4"; 1916 case ENCODING_MPEGH_LC_L3: 1917 return "MPEG-H 3D Audio low complexity profile level 3"; 1918 case ENCODING_MPEGH_LC_L4: 1919 return "MPEG-H 3D Audio low complexity profile level 4"; 1920 case ENCODING_DTS_UHD_P1: 1921 return "DTS UHD Profile 1"; 1922 case ENCODING_DRA: 1923 return "DRA"; 1924 case ENCODING_DTS_HD_MA: 1925 return "DTS HD Master Audio"; 1926 case ENCODING_DTS_UHD_P2: 1927 return "DTS UHD Profile 2"; 1928 default: 1929 return "Unknown surround sound format"; 1930 } 1931 } 1932 1933 } 1934