1 /* 2 * Copyright (C) 2014 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 #ifndef ANDROID_MEDIA_AUDIOFORMAT_H 18 #define ANDROID_MEDIA_AUDIOFORMAT_H 19 20 #include <system/audio.h> 21 22 // keep these values in sync with AudioFormat.java 23 #define ENCODING_PCM_16BIT 2 24 #define ENCODING_PCM_8BIT 3 25 #define ENCODING_PCM_FLOAT 4 26 #define ENCODING_AC3 5 27 #define ENCODING_E_AC3 6 28 #define ENCODING_DTS 7 29 #define ENCODING_DTS_HD 8 30 #define ENCODING_MP3 9 31 #define ENCODING_AAC_LC 10 32 #define ENCODING_AAC_HE_V1 11 33 #define ENCODING_AAC_HE_V2 12 34 #define ENCODING_IEC61937 13 35 #define ENCODING_DOLBY_TRUEHD 14 36 37 #define ENCODING_INVALID 0 38 #define ENCODING_DEFAULT 1 39 40 41 42 #define CHANNEL_INVALID 0 43 #define CHANNEL_OUT_DEFAULT 1 44 audioFormatToNative(int audioFormat)45static inline audio_format_t audioFormatToNative(int audioFormat) 46 { 47 switch (audioFormat) { 48 case ENCODING_PCM_16BIT: 49 return AUDIO_FORMAT_PCM_16_BIT; 50 case ENCODING_PCM_8BIT: 51 return AUDIO_FORMAT_PCM_8_BIT; 52 case ENCODING_PCM_FLOAT: 53 return AUDIO_FORMAT_PCM_FLOAT; 54 case ENCODING_AC3: 55 return AUDIO_FORMAT_AC3; 56 case ENCODING_E_AC3: 57 return AUDIO_FORMAT_E_AC3; 58 case ENCODING_DTS: 59 return AUDIO_FORMAT_DTS; 60 case ENCODING_DTS_HD: 61 return AUDIO_FORMAT_DTS_HD; 62 case ENCODING_MP3: 63 return AUDIO_FORMAT_MP3; 64 case ENCODING_AAC_LC: 65 return AUDIO_FORMAT_AAC_LC; 66 case ENCODING_AAC_HE_V1: 67 return AUDIO_FORMAT_AAC_HE_V1; 68 case ENCODING_AAC_HE_V2: 69 return AUDIO_FORMAT_AAC_HE_V2; 70 case ENCODING_DOLBY_TRUEHD: 71 return AUDIO_FORMAT_DOLBY_TRUEHD; 72 case ENCODING_IEC61937: 73 return AUDIO_FORMAT_IEC61937; 74 case ENCODING_DEFAULT: 75 return AUDIO_FORMAT_DEFAULT; 76 default: 77 return AUDIO_FORMAT_INVALID; 78 } 79 } 80 audioFormatFromNative(audio_format_t nativeFormat)81static inline int audioFormatFromNative(audio_format_t nativeFormat) 82 { 83 switch (nativeFormat) { 84 case AUDIO_FORMAT_PCM_16_BIT: 85 return ENCODING_PCM_16BIT; 86 case AUDIO_FORMAT_PCM_8_BIT: 87 return ENCODING_PCM_8BIT; 88 case AUDIO_FORMAT_PCM_FLOAT: 89 return ENCODING_PCM_FLOAT; 90 91 // map these to ENCODING_PCM_FLOAT 92 case AUDIO_FORMAT_PCM_8_24_BIT: 93 case AUDIO_FORMAT_PCM_24_BIT_PACKED: 94 case AUDIO_FORMAT_PCM_32_BIT: 95 return ENCODING_PCM_FLOAT; 96 97 case AUDIO_FORMAT_AC3: 98 return ENCODING_AC3; 99 case AUDIO_FORMAT_E_AC3: 100 return ENCODING_E_AC3; 101 case AUDIO_FORMAT_DTS: 102 return ENCODING_DTS; 103 case AUDIO_FORMAT_DTS_HD: 104 return ENCODING_DTS_HD; 105 case AUDIO_FORMAT_MP3: 106 return ENCODING_MP3; 107 case AUDIO_FORMAT_AAC_LC: 108 return ENCODING_AAC_LC; 109 case AUDIO_FORMAT_AAC_HE_V1: 110 return ENCODING_AAC_HE_V1; 111 case AUDIO_FORMAT_AAC_HE_V2: 112 return ENCODING_AAC_HE_V2; 113 case AUDIO_FORMAT_IEC61937: 114 return ENCODING_IEC61937; 115 case AUDIO_FORMAT_DOLBY_TRUEHD: 116 return ENCODING_DOLBY_TRUEHD; 117 case AUDIO_FORMAT_DEFAULT: 118 return ENCODING_DEFAULT; 119 default: 120 return ENCODING_INVALID; 121 } 122 } 123 outChannelMaskToNative(int channelMask)124static inline audio_channel_mask_t outChannelMaskToNative(int channelMask) 125 { 126 switch (channelMask) { 127 case CHANNEL_OUT_DEFAULT: 128 case CHANNEL_INVALID: 129 return AUDIO_CHANNEL_NONE; 130 default: 131 return (audio_channel_mask_t)(channelMask>>2); 132 } 133 } 134 outChannelMaskFromNative(audio_channel_mask_t nativeMask)135static inline int outChannelMaskFromNative(audio_channel_mask_t nativeMask) 136 { 137 switch (nativeMask) { 138 case AUDIO_CHANNEL_NONE: 139 return CHANNEL_OUT_DEFAULT; 140 default: 141 return (int)nativeMask<<2; 142 } 143 } 144 inChannelMaskToNative(int channelMask)145static inline audio_channel_mask_t inChannelMaskToNative(int channelMask) 146 { 147 return (audio_channel_mask_t)channelMask; 148 } 149 inChannelMaskFromNative(audio_channel_mask_t nativeMask)150static inline int inChannelMaskFromNative(audio_channel_mask_t nativeMask) 151 { 152 return (int)nativeMask; 153 } 154 155 #endif // ANDROID_MEDIA_AUDIOFORMAT_H 156