ALACBitUtilities.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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: ALACBitUtilities.h
  22. $NoKeywords: $
  23. =============================================================================*/
  24. #ifndef __ALACBITUTILITIES_H
  25. #define __ALACBITUTILITIES_H
  26. #include <stdint.h>
  27. #ifndef MIN
  28. #define MIN(x, y) ( (x)<(y) ?(x) :(y) )
  29. #endif //MIN
  30. #ifndef MAX
  31. #define MAX(x, y) ( (x)>(y) ?(x): (y) )
  32. #endif //MAX
  33. #ifndef nil
  34. #define nil NULL
  35. #endif
  36. #define RequireAction(condition, action) if (!(condition)) { action }
  37. #define RequireActionSilent(condition, action) if (!(condition)) { action }
  38. #define RequireNoErr(condition, action) if ((condition)) { action }
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. enum
  43. {
  44. ALAC_noErr = 0
  45. };
  46. typedef enum
  47. {
  48. ID_SCE = 0, /* Single Channel Element */
  49. ID_CPE = 1, /* Channel Pair Element */
  50. ID_CCE = 2, /* Coupling Channel Element */
  51. ID_LFE = 3, /* LFE Channel Element */
  52. ID_DSE = 4, /* not yet supported */
  53. ID_PCE = 5,
  54. ID_FIL = 6,
  55. ID_END = 7
  56. } ELEMENT_TYPE;
  57. // types
  58. typedef struct BitBuffer
  59. {
  60. uint8_t * cur;
  61. uint8_t * end;
  62. uint32_t bitIndex;
  63. uint32_t byteSize;
  64. } BitBuffer;
  65. /*
  66. BitBuffer routines
  67. - these routines take a fixed size buffer and read/write to it
  68. - bounds checking must be done by the client
  69. */
  70. void BitBufferInit( BitBuffer * bits, uint8_t * buffer, uint32_t byteSize );
  71. uint32_t BitBufferRead( BitBuffer * bits, uint8_t numBits ); // note: cannot read more than 16 bits at a time
  72. uint8_t BitBufferReadSmall( BitBuffer * bits, uint8_t numBits );
  73. uint8_t BitBufferReadOne( BitBuffer * bits );
  74. uint32_t BitBufferPeek( BitBuffer * bits, uint8_t numBits ); // note: cannot read more than 16 bits at a time
  75. uint32_t BitBufferPeekOne( BitBuffer * bits );
  76. uint32_t BitBufferUnpackBERSize( BitBuffer * bits );
  77. uint32_t BitBufferGetPosition( BitBuffer * bits );
  78. void BitBufferByteAlign( BitBuffer * bits, int32_t addZeros );
  79. void BitBufferAdvance( BitBuffer * bits, uint32_t numBits );
  80. void BitBufferRewind( BitBuffer * bits, uint32_t numBits );
  81. void BitBufferWrite( BitBuffer * bits, uint32_t value, uint32_t numBits );
  82. void BitBufferReset( BitBuffer * bits);
  83. #ifdef __cplusplus
  84. }
  85. #endif
  86. #endif /* __BITUTILITIES_H */