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