Glenn Kasten | fe834d3 | 2014-01-08 14:49:08 -0800 | [diff] [blame] | 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 |
Eric Laurent | b4fae5b | 2016-07-07 18:58:11 -0700 | [diff] [blame] | 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 | |
Eric Laurent | ff0d9f0 | 2014-06-09 17:23:02 -0700 | [diff] [blame] | 37 | #define ENCODING_INVALID 0 |
| 38 | #define ENCODING_DEFAULT 1 |
| 39 | |
| 40 | |
Eric Laurent | b69681c | 2014-05-19 19:02:51 -0700 | [diff] [blame] | 41 | |
| 42 | #define CHANNEL_INVALID 0 |
| 43 | #define CHANNEL_OUT_DEFAULT 1 |
Glenn Kasten | fe834d3 | 2014-01-08 14:49:08 -0800 | [diff] [blame] | 44 | |
| 45 | static 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; |
Glenn Kasten | 313f598 | 2014-04-30 18:02:08 -0700 | [diff] [blame] | 52 | case ENCODING_PCM_FLOAT: |
| 53 | return AUDIO_FORMAT_PCM_FLOAT; |
Eric Laurent | ff0d9f0 | 2014-06-09 17:23:02 -0700 | [diff] [blame] | 54 | case ENCODING_AC3: |
| 55 | return AUDIO_FORMAT_AC3; |
| 56 | case ENCODING_E_AC3: |
| 57 | return AUDIO_FORMAT_E_AC3; |
Phil Burk | e12189d | 2015-03-31 14:38:30 -0700 | [diff] [blame] | 58 | case ENCODING_DTS: |
| 59 | return AUDIO_FORMAT_DTS; |
| 60 | case ENCODING_DTS_HD: |
| 61 | return AUDIO_FORMAT_DTS_HD; |
Eric Laurent | cae3466 | 2015-05-19 16:46:52 -0700 | [diff] [blame] | 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; |
Eric Laurent | b4fae5b | 2016-07-07 18:58:11 -0700 | [diff] [blame] | 70 | case ENCODING_DOLBY_TRUEHD: |
| 71 | return AUDIO_FORMAT_DOLBY_TRUEHD; |
Phil Burk | 43f4b27 | 2016-01-27 15:35:20 -0800 | [diff] [blame] | 72 | case ENCODING_IEC61937: |
| 73 | return AUDIO_FORMAT_IEC61937; |
Eric Laurent | b69681c | 2014-05-19 19:02:51 -0700 | [diff] [blame] | 74 | case ENCODING_DEFAULT: |
| 75 | return AUDIO_FORMAT_DEFAULT; |
Glenn Kasten | fe834d3 | 2014-01-08 14:49:08 -0800 | [diff] [blame] | 76 | default: |
| 77 | return AUDIO_FORMAT_INVALID; |
| 78 | } |
| 79 | } |
| 80 | |
Eric Laurent | b69681c | 2014-05-19 19:02:51 -0700 | [diff] [blame] | 81 | static 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; |
Paul McLean | 4e5e9e9 | 2015-06-17 10:10:11 -0700 | [diff] [blame] | 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 | |
Eric Laurent | ff0d9f0 | 2014-06-09 17:23:02 -0700 | [diff] [blame] | 97 | case AUDIO_FORMAT_AC3: |
| 98 | return ENCODING_AC3; |
| 99 | case AUDIO_FORMAT_E_AC3: |
| 100 | return ENCODING_E_AC3; |
Phil Burk | e12189d | 2015-03-31 14:38:30 -0700 | [diff] [blame] | 101 | case AUDIO_FORMAT_DTS: |
| 102 | return ENCODING_DTS; |
| 103 | case AUDIO_FORMAT_DTS_HD: |
| 104 | return ENCODING_DTS_HD; |
Eric Laurent | cae3466 | 2015-05-19 16:46:52 -0700 | [diff] [blame] | 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; |
Phil Burk | 43f4b27 | 2016-01-27 15:35:20 -0800 | [diff] [blame] | 113 | case AUDIO_FORMAT_IEC61937: |
| 114 | return ENCODING_IEC61937; |
Eric Laurent | b4fae5b | 2016-07-07 18:58:11 -0700 | [diff] [blame] | 115 | case AUDIO_FORMAT_DOLBY_TRUEHD: |
| 116 | return ENCODING_DOLBY_TRUEHD; |
Eric Laurent | b69681c | 2014-05-19 19:02:51 -0700 | [diff] [blame] | 117 | case AUDIO_FORMAT_DEFAULT: |
| 118 | return ENCODING_DEFAULT; |
| 119 | default: |
| 120 | return ENCODING_INVALID; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | static 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 | |
| 135 | static 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 | |
| 145 | static inline audio_channel_mask_t inChannelMaskToNative(int channelMask) |
| 146 | { |
| 147 | return (audio_channel_mask_t)channelMask; |
| 148 | } |
| 149 | |
| 150 | static inline int inChannelMaskFromNative(audio_channel_mask_t nativeMask) |
| 151 | { |
| 152 | return (int)nativeMask; |
| 153 | } |
| 154 | |
Glenn Kasten | fe834d3 | 2014-01-08 14:49:08 -0800 | [diff] [blame] | 155 | #endif // ANDROID_MEDIA_AUDIOFORMAT_H |