1 /******************************************************************************
2 *
3 * Copyright (C) 2014 The Android Open Source Project
4 * Copyright 2003 - 2004 Open Interface North America, Inc. All rights reserved.
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 ******************************************************************************/
19
20 /**********************************************************************************
21 $Revision: #1 $
22 ***********************************************************************************/
23
24 /**
25 @file
26 Functions for manipulating input bitstreams.
27
28 @ingroup codec_internal
29 */
30
31 /**
32 @addtogroup codec_internal
33 @{
34 */
35
36 #include "common/bt_target.h"
37 #include "oi_stddefs.h"
38 #include "oi_bitstream.h"
39 #include "oi_assert.h"
40
41 #if (defined(SBC_DEC_INCLUDED) && SBC_DEC_INCLUDED == TRUE)
42
OI_BITSTREAM_ReadInit(OI_BITSTREAM * bs,const OI_BYTE * buffer)43 PRIVATE void OI_BITSTREAM_ReadInit(OI_BITSTREAM *bs,
44 const OI_BYTE *buffer)
45 {
46 bs->value = ((OI_INT32)buffer[0] << 16) | ((OI_INT32)buffer[1] << 8) | (buffer[2]);
47 bs->ptr.r = buffer + 3;
48 bs->bitPtr = 8;
49 }
50
OI_BITSTREAM_ReadUINT(OI_BITSTREAM * bs,OI_UINT bits)51 PRIVATE OI_UINT32 OI_BITSTREAM_ReadUINT(OI_BITSTREAM *bs, OI_UINT bits)
52 {
53 OI_UINT32 result;
54
55 OI_BITSTREAM_READUINT(result, bits, bs->ptr.r, bs->value, bs->bitPtr);
56
57 return result;
58 }
59
OI_BITSTREAM_ReadUINT4Aligned(OI_BITSTREAM * bs)60 PRIVATE OI_UINT8 OI_BITSTREAM_ReadUINT4Aligned(OI_BITSTREAM *bs)
61 {
62 OI_UINT32 result;
63
64 OI_ASSERT(bs->bitPtr < 16);
65 OI_ASSERT(bs->bitPtr % 4 == 0);
66
67 if (bs->bitPtr == 8) {
68 result = bs->value << 8;
69 bs->bitPtr = 12;
70 } else {
71 result = bs->value << 12;
72 bs->value = (bs->value << 8) | *bs->ptr.r++;
73 bs->bitPtr = 8;
74 }
75 result >>= 28;
76 OI_ASSERT(result < (1u << 4));
77 return (OI_UINT8)result;
78 }
79
OI_BITSTREAM_ReadUINT8Aligned(OI_BITSTREAM * bs)80 PRIVATE OI_UINT8 OI_BITSTREAM_ReadUINT8Aligned(OI_BITSTREAM *bs)
81 {
82 OI_UINT32 result;
83 OI_ASSERT(bs->bitPtr == 8);
84
85 result = bs->value >> 16;
86 bs->value = (bs->value << 8) | *bs->ptr.r++;
87
88 return (OI_UINT8)result;
89 }
90
91 /**
92 @}
93 */
94
95 #endif /* #if (defined(SBC_DEC_INCLUDED) && SBC_DEC_INCLUDED == TRUE) */
96