ALACAudioTypes.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. File: ALACAudioTypes.h
  22. */
  23. #ifndef ALACAUDIOTYPES_H
  24. #define ALACAUDIOTYPES_H
  25. #if PRAGMA_ONCE
  26. #pragma once
  27. #endif
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. #if PRAGMA_STRUCT_ALIGN
  32. #pragma options align=mac68k
  33. #elif PRAGMA_STRUCT_PACKPUSH
  34. #pragma pack(push, 2)
  35. #elif PRAGMA_STRUCT_PACK
  36. #pragma pack(2)
  37. #endif
  38. #include <stdint.h>
  39. #if defined(__ppc__)
  40. #define TARGET_RT_BIG_ENDIAN 1
  41. #elif defined(__ppc64__)
  42. #define TARGET_RT_BIG_ENDIAN 1
  43. #endif
  44. #define kChannelAtomSize 12
  45. #pragma GCC diagnostic push
  46. #pragma GCC diagnostic ignored "-Wmultichar"
  47. enum
  48. {
  49. kALAC_UnimplementedError = -4,
  50. kALAC_FileNotFoundError = -43,
  51. kALAC_ParamError = -50,
  52. kALAC_MemFullError = -108
  53. };
  54. enum
  55. {
  56. kALACFormatAppleLossless = 'alac',
  57. kALACFormatLinearPCM = 'lpcm'
  58. };
  59. enum
  60. {
  61. kALACMaxChannels = 8,
  62. kALACMaxEscapeHeaderBytes = 8,
  63. kALACMaxSearches = 16,
  64. kALACMaxCoefs = 16,
  65. kALACDefaultFramesPerPacket = 4096
  66. };
  67. typedef uint32_t ALACChannelLayoutTag;
  68. enum
  69. {
  70. kALACFormatFlagIsFloat = (1 << 0), // 0x1
  71. kALACFormatFlagIsBigEndian = (1 << 1), // 0x2
  72. kALACFormatFlagIsSignedInteger = (1 << 2), // 0x4
  73. kALACFormatFlagIsPacked = (1 << 3), // 0x8
  74. kALACFormatFlagIsAlignedHigh = (1 << 4), // 0x10
  75. };
  76. enum
  77. {
  78. #if TARGET_RT_BIG_ENDIAN
  79. kALACFormatFlagsNativeEndian = kALACFormatFlagIsBigEndian
  80. #else
  81. kALACFormatFlagsNativeEndian = 0
  82. #endif
  83. };
  84. // this is required to be an IEEE 64bit float
  85. typedef double alac_float64_t;
  86. // These are the Channel Layout Tags used in the Channel Layout Info portion of the ALAC magic cookie
  87. enum
  88. {
  89. kALACChannelLayoutTag_Mono = (100<<16) | 1, // C
  90. kALACChannelLayoutTag_Stereo = (101<<16) | 2, // L R
  91. kALACChannelLayoutTag_MPEG_3_0_B = (113<<16) | 3, // C L R
  92. kALACChannelLayoutTag_MPEG_4_0_B = (116<<16) | 4, // C L R Cs
  93. kALACChannelLayoutTag_MPEG_5_0_D = (120<<16) | 5, // C L R Ls Rs
  94. kALACChannelLayoutTag_MPEG_5_1_D = (124<<16) | 6, // C L R Ls Rs LFE
  95. kALACChannelLayoutTag_AAC_6_1 = (142<<16) | 7, // C L R Ls Rs Cs LFE
  96. kALACChannelLayoutTag_MPEG_7_1_B = (127<<16) | 8 // C Lc Rc L R Ls Rs LFE (doc: IS-13818-7 MPEG2-AAC)
  97. };
  98. // ALAC currently only utilizes these channels layouts. There is a one for one correspondance between a
  99. // given number of channels and one of these layout tags
  100. static const ALACChannelLayoutTag ALACChannelLayoutTags[kALACMaxChannels] =
  101. {
  102. kALACChannelLayoutTag_Mono, // C
  103. kALACChannelLayoutTag_Stereo, // L R
  104. kALACChannelLayoutTag_MPEG_3_0_B, // C L R
  105. kALACChannelLayoutTag_MPEG_4_0_B, // C L R Cs
  106. kALACChannelLayoutTag_MPEG_5_0_D, // C L R Ls Rs
  107. kALACChannelLayoutTag_MPEG_5_1_D, // C L R Ls Rs LFE
  108. kALACChannelLayoutTag_AAC_6_1, // C L R Ls Rs Cs LFE
  109. kALACChannelLayoutTag_MPEG_7_1_B // C Lc Rc L R Ls Rs LFE (doc: IS-13818-7 MPEG2-AAC)
  110. };
  111. // AudioChannelLayout from CoreAudioTypes.h. We never need the AudioChannelDescription so we remove it
  112. struct ALACAudioChannelLayout
  113. {
  114. ALACChannelLayoutTag mChannelLayoutTag;
  115. uint32_t mChannelBitmap;
  116. uint32_t mNumberChannelDescriptions;
  117. };
  118. typedef struct ALACAudioChannelLayout ALACAudioChannelLayout;
  119. struct AudioFormatDescription
  120. {
  121. alac_float64_t mSampleRate;
  122. uint32_t mFormatID;
  123. uint32_t mFormatFlags;
  124. uint32_t mBytesPerPacket;
  125. uint32_t mFramesPerPacket;
  126. uint32_t mBytesPerFrame;
  127. uint32_t mChannelsPerFrame;
  128. uint32_t mBitsPerChannel;
  129. uint32_t mReserved;
  130. };
  131. typedef struct AudioFormatDescription AudioFormatDescription;
  132. /* Lossless Definitions */
  133. enum
  134. {
  135. kALACCodecFormat = 'alac',
  136. kALACVersion = 0,
  137. kALACCompatibleVersion = kALACVersion,
  138. kALACDefaultFrameSize = 4096
  139. };
  140. // note: this struct is wrapped in an 'alac' atom in the sample description extension area
  141. // note: in QT movies, it will be further wrapped in a 'wave' atom surrounded by 'frma' and 'term' atoms
  142. typedef struct ALACSpecificConfig
  143. {
  144. uint32_t frameLength;
  145. uint8_t compatibleVersion;
  146. uint8_t bitDepth; // max 32
  147. uint8_t pb; // 0 <= pb <= 255
  148. uint8_t mb;
  149. uint8_t kb;
  150. uint8_t numChannels;
  151. uint16_t maxRun;
  152. uint32_t maxFrameBytes;
  153. uint32_t avgBitRate;
  154. uint32_t sampleRate;
  155. } ALACSpecificConfig;
  156. // The AudioChannelLayout atom type is not exposed yet so define it here
  157. enum
  158. {
  159. AudioChannelLayoutAID = 'chan'
  160. };
  161. #pragma GCC diagnostic pop
  162. #if PRAGMA_STRUCT_ALIGN
  163. #pragma options align=reset
  164. #elif PRAGMA_STRUCT_PACKPUSH
  165. #pragma pack(pop)
  166. #elif PRAGMA_STRUCT_PACK
  167. #pragma pack()
  168. #endif
  169. #ifdef __cplusplus
  170. }
  171. #endif
  172. #endif /* ALACAUDIOTYPES_H */