1 /* 2 * Copyright (c) 2011 Apple Inc. All rights reserved. 3 * 4 * @APPLE_APACHE_LICENSE_HEADER_START@ 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License") ; 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 * @APPLE_APACHE_LICENSE_HEADER_END@ 19 */ 20 21 /* 22 File: ALACAudioTypes.h 23 */ 24 25 #ifndef ALACAUDIOTYPES_H 26 #define ALACAUDIOTYPES_H 27 28 /* Force these Mac OS specific things to zero. */ 29 #define PRAGMA_STRUCT_ALIGN 0 30 #define PRAGMA_STRUCT_PACKPUSH 0 31 #define PRAGMA_STRUCT_PACK 0 32 #define PRAGMA_ONCE 0 33 #define PRAGMA_MARK 0 34 35 36 #if PRAGMA_ONCE 37 #pragma once 38 #endif 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 #include <stdint.h> 45 46 #include "sfendian.h" 47 48 #if CPU_IS_BIG_ENDIAN == 1 49 #define TARGET_RT_BIG_ENDIAN 1 50 #else 51 #define TARGET_RT_BIG_ENDIAN 0 52 #endif 53 54 #define kChannelAtomSize 12 55 56 enum 57 { 58 kALAC_UnimplementedError = -4, 59 kALAC_FileNotFoundError = -43, 60 kALAC_ParamError = -50, 61 kALAC_MemFullError = -108, 62 fALAC_FrameLengthError = -666, 63 64 /* Add for libsndfile */ 65 kALAC_BadBitWidth = -0x100000, 66 kALAC_IncompatibleVersion = -0x100001, 67 kALAC_BadSpecificConfigSize = -0x100002, 68 kALAC_ZeroChannelCount = -0x100003, 69 kALAC_NumSamplesTooBig = -0x100004, 70 kALAC_UnsupportedElement = -0x100005, 71 } ; 72 73 enum 74 { 75 kALACFormatAppleLossless = MAKE_MARKER ('a', 'l', 'a', 'c'), 76 kALACFormatLinearPCM = MAKE_MARKER ('l', 'p', 'c', 'm') 77 } ; 78 79 enum 80 { 81 kALACMaxChannels = 8, 82 kALACMaxEscapeHeaderBytes = 8, 83 kALACMaxSearches = 16, 84 kALACMaxCoefs = 16, 85 kALACDefaultFramesPerPacket = 4096 86 } ; 87 88 typedef uint32_t ALACChannelLayoutTag ; 89 90 enum 91 { 92 kALACFormatFlagIsFloat = (1 << 0), // 0x1 93 kALACFormatFlagIsBigEndian = (1 << 1), // 0x2 94 kALACFormatFlagIsSignedInteger = (1 << 2), // 0x4 95 kALACFormatFlagIsPacked = (1 << 3), // 0x8 96 kALACFormatFlagIsAlignedHigh = (1 << 4), // 0x10 97 } ; 98 99 enum 100 { 101 #if TARGET_RT_BIG_ENDIAN 102 kALACFormatFlagsNativeEndian = kALACFormatFlagIsBigEndian 103 #else 104 kALACFormatFlagsNativeEndian = 0 105 #endif 106 } ; 107 108 // this is required to be an IEEE 64bit float 109 typedef double alac_float64_t ; 110 111 // These are the Channel Layout Tags used in the Channel Layout Info portion of the ALAC magic cookie 112 enum 113 { kALACChannelLayoutTag_Mono = (100 << 16) | 1, // C 114 kALACChannelLayoutTag_Stereo = (101 << 16) | 2, // L R 115 kALACChannelLayoutTag_MPEG_3_0_B = (113 << 16) | 3, // C L R 116 kALACChannelLayoutTag_MPEG_4_0_B = (116 << 16) | 4, // C L R Cs 117 kALACChannelLayoutTag_MPEG_5_0_D = (120 << 16) | 5, // C L R Ls Rs 118 kALACChannelLayoutTag_MPEG_5_1_D = (124 << 16) | 6, // C L R Ls Rs LFE 119 kALACChannelLayoutTag_AAC_6_1 = (142 << 16) | 7, // C L R Ls Rs Cs LFE 120 kALACChannelLayoutTag_MPEG_7_1_B = (127 << 16) | 8 // C Lc Rc L R Ls Rs LFE (doc: IS-13818-7 MPEG2-AAC) 121 } ; 122 123 // ALAC currently only utilizes these channels layouts. There is a one for one correspondance between a 124 // given number of channels and one of these layout tags 125 static const ALACChannelLayoutTag ALACChannelLayoutTags [kALACMaxChannels] = 126 { 127 kALACChannelLayoutTag_Mono, // C 128 kALACChannelLayoutTag_Stereo, // L R 129 kALACChannelLayoutTag_MPEG_3_0_B, // C L R 130 kALACChannelLayoutTag_MPEG_4_0_B, // C L R Cs 131 kALACChannelLayoutTag_MPEG_5_0_D, // C L R Ls Rs 132 kALACChannelLayoutTag_MPEG_5_1_D, // C L R Ls Rs LFE 133 kALACChannelLayoutTag_AAC_6_1, // C L R Ls Rs Cs LFE 134 kALACChannelLayoutTag_MPEG_7_1_B // C Lc Rc L R Ls Rs LFE (doc: IS-13818-7 MPEG2-AAC) 135 } ; 136 137 // AudioChannelLayout from CoreAudioTypes.h. We never need the AudioChannelDescription so we remove it 138 struct ALACAudioChannelLayout 139 { ALACChannelLayoutTag mChannelLayoutTag ; 140 uint32_t mChannelBitmap ; 141 uint32_t mNumberChannelDescriptions ; 142 } ; 143 typedef struct ALACAudioChannelLayout ALACAudioChannelLayout ; 144 145 struct AudioFormatDescription 146 { 147 alac_float64_t mSampleRate ; 148 uint32_t mFormatID ; 149 uint32_t mFormatFlags ; 150 uint32_t mBytesPerPacket ; 151 uint32_t mFramesPerPacket ; 152 uint32_t mBytesPerFrame ; 153 uint32_t mChannelsPerFrame ; 154 uint32_t mBitsPerChannel ; 155 uint32_t mReserved ; 156 } ; 157 typedef struct AudioFormatDescription AudioFormatDescription ; 158 159 /* Lossless Definitions */ 160 161 enum 162 { 163 kALACCodecFormat = MAKE_MARKER ('a', 'l', 'a', 'c'), 164 kALACVersion = 0, 165 kALACCompatibleVersion = kALACVersion, 166 kALACDefaultFrameSize = 4096 167 } ; 168 169 // note: this struct is wrapped in an 'alac' atom in the sample description extension area 170 // note: in QT movies, it will be further wrapped in a 'wave' atom surrounded by 'frma' and 'term' atoms 171 typedef struct ALACSpecificConfig 172 { 173 uint32_t frameLength ; 174 uint8_t compatibleVersion ; 175 uint8_t bitDepth ; // max 32 176 uint8_t pb ; // 0 <= pb <= 255 177 uint8_t mb ; 178 uint8_t kb ; 179 uint8_t numChannels ; 180 uint16_t maxRun ; 181 uint32_t maxFrameBytes ; 182 uint32_t avgBitRate ; 183 uint32_t sampleRate ; 184 185 } ALACSpecificConfig ; 186 187 188 // The AudioChannelLayout atom type is not exposed yet so define it here 189 enum 190 { 191 AudioChannelLayoutAID = MAKE_MARKER ('c', 'h', 'a', 'n') 192 } ; 193 194 #if PRAGMA_STRUCT_ALIGN 195 #pragma options align = reset 196 #elif PRAGMA_STRUCT_PACKPUSH 197 #pragma pack (pop) 198 #elif PRAGMA_STRUCT_PACK 199 #pragma pack () 200 #endif 201 202 #ifdef __cplusplus 203 } 204 #endif 205 206 #endif /* ALACAUDIOTYPES_H */ 207