readsamplesjoint.inc revision ce24765fe7620c34e8d88ed4f826c8a6917582b2
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 * @file readsamplesjoint.inc
22 *
23 * This is the body of the generic version of OI_SBC_ReadSamplesJoint().
24 * It is designed to be \#included into a function as follows:
25    \code
26    void OI_SBC_ReadSamplesJoint4(OI_CODEC_SBC_COMMON_CONTEXT *common, OI_BITSTREAM *global_bs)
27    {
28        #define NROF_SUBBANDS 4
29        #include "readsamplesjoint.inc"
30        #undef NROF_SUBBANDS
31    }
32
33    void OI_SBC_ReadSamplesJoint8(OI_CODEC_SBC_COMMON_CONTEXT *common, OI_BITSTREAM *global_bs)
34    {
35        #define NROF_SUBBANDS 8
36        #include "readsamplesjoint.inc"
37        #undef NROF_SUBBANDS
38    }
39    \endcode
40 * Or to make a generic version:
41    \code
42    void OI_SBC_ReadSamplesJoint(OI_CODEC_SBC_COMMON_CONTEXT *common, OI_BITSTREAM *global_bs)
43    {
44        OI_UINT nrof_subbands = common->frameInfo.nrof_subbands;
45
46        #define NROF_SUBBANDS nrof_subbands
47        #include "readsamplesjoint.inc"
48        #undef NROF_SUBBANDS
49    }
50    \endcode
51 * @ingroup codec_internal
52 *******************************************************************************/
53
54/**********************************************************************************
55  $Revision: #1 $
56***********************************************************************************/
57
58{
59    OI_CODEC_SBC_COMMON_CONTEXT *common = &context->common;
60    OI_UINT bl = common->frameInfo.nrof_blocks;
61    OI_INT32 * RESTRICT s = common->subdata;
62    OI_UINT8 *ptr = global_bs->ptr.w;
63    OI_UINT32 value = global_bs->value;
64    OI_UINT bitPtr = global_bs->bitPtr;
65    OI_UINT8 jmask = common->frameInfo.join << (8 - NROF_SUBBANDS);
66
67    do {
68        OI_INT8 *sf_array = &common->scale_factor[0];
69        OI_UINT8 *bits_array = &common->bits.uint8[0];
70        OI_UINT8 joint = jmask;
71        OI_UINT sb;
72        /*
73         * Left channel
74         */
75        sb = NROF_SUBBANDS;
76        do {
77            OI_UINT32 raw;
78            OI_INT32 dequant;
79            OI_UINT8 bits = *bits_array++;
80            OI_INT sf = *sf_array++;
81
82            OI_BITSTREAM_READUINT(raw, bits, ptr, value, bitPtr);
83            dequant = OI_SBC_Dequant(raw, sf, bits);
84            *s++ = dequant;
85        } while (--sb);
86        /*
87         * Right channel
88         */
89        sb = NROF_SUBBANDS;
90        do {
91            OI_UINT32 raw;
92            OI_INT32 dequant;
93            OI_UINT8 bits = *bits_array++;
94            OI_INT sf = *sf_array++;
95
96            OI_BITSTREAM_READUINT(raw, bits, ptr, value, bitPtr);
97            dequant = OI_SBC_Dequant(raw, sf, bits);
98            /*
99             * Check if we need to do mid/side
100             */
101            if (joint & 0x80) {
102                OI_INT32 mid = *(s - NROF_SUBBANDS);
103                OI_INT32 side = dequant;
104                *(s - NROF_SUBBANDS) = mid + side;
105                dequant = mid - side;
106            }
107            joint <<= 1;
108            *s++ = dequant;
109        } while (--sb);
110    } while (--bl);
111}
112