• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/******************************************************************************
2 *
3 *  Copyright 2014 The Android Open Source Project
4 *  Copyright 2003 - 2004 Open Interface North America, Inc. All rights
5 *                        reserved.
6 *
7 *  Licensed under the Apache License, Version 2.0 (the "License");
8 *  you may not use this file except in compliance with the License.
9 *  You may obtain a copy of the License at:
10 *
11 *  http://www.apache.org/licenses/LICENSE-2.0
12 *
13 *  Unless required by applicable law or agreed to in writing, software
14 *  distributed under the License is distributed on an "AS IS" BASIS,
15 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 *  See the License for the specific language governing permissions and
17 *  limitations under the License.
18 *
19 ******************************************************************************/
20
21/*******************************************************************************
22 * @file readsamplesjoint.inc
23 *
24 * This is the body of the generic version of OI_SBC_ReadSamplesJoint().
25 * It is designed to be \#included into a function as follows:
26    \code
27    void OI_SBC_ReadSamplesJoint4(OI_CODEC_SBC_COMMON_CONTEXT *common, OI_BITSTREAM *global_bs)
28    {
29        #define NROF_SUBBANDS 4
30        #include "readsamplesjoint.inc"
31        #undef NROF_SUBBANDS
32    }
33
34    void OI_SBC_ReadSamplesJoint8(OI_CODEC_SBC_COMMON_CONTEXT *common, OI_BITSTREAM *global_bs)
35    {
36        #define NROF_SUBBANDS 8
37        #include "readsamplesjoint.inc"
38        #undef NROF_SUBBANDS
39    }
40    \endcode
41 * Or to make a generic version:
42    \code
43    void OI_SBC_ReadSamplesJoint(OI_CODEC_SBC_COMMON_CONTEXT *common, OI_BITSTREAM *global_bs)
44    {
45        OI_UINT nrof_subbands = common->frameInfo.nrof_subbands;
46
47        #define NROF_SUBBANDS nrof_subbands
48        #include "readsamplesjoint.inc"
49        #undef NROF_SUBBANDS
50    }
51    \endcode
52 * @ingroup codec_internal
53 ******************************************************************************/
54
55/*******************************************************************************
56  $Revision: #1 $
57 ******************************************************************************/
58
59{
60    OI_CODEC_SBC_COMMON_CONTEXT *common = &context->common;
61    OI_UINT bl = common->frameInfo.nrof_blocks;
62    int32_t * RESTRICT s = common->subdata;
63    uint8_t *ptr = global_bs->ptr.w;
64    uint32_t value = global_bs->value;
65    OI_UINT bitPtr = global_bs->bitPtr;
66    uint8_t jmask = common->frameInfo.join << (8 - NROF_SUBBANDS);
67
68    do {
69        int8_t *sf_array = &common->scale_factor[0];
70        uint8_t *bits_array = &common->bits.uint8[0];
71        uint8_t joint = jmask;
72        OI_UINT sb;
73        /*
74         * Left channel
75         */
76        sb = NROF_SUBBANDS;
77        do {
78            uint32_t raw;
79            int32_t dequant;
80            uint8_t bits = *bits_array++;
81            OI_INT sf = *sf_array++;
82
83            OI_BITSTREAM_READUINT(raw, bits, ptr, value, bitPtr);
84            dequant = OI_SBC_Dequant(raw, sf, bits);
85            *s++ = dequant;
86        } while (--sb);
87        /*
88         * Right channel
89         */
90        sb = NROF_SUBBANDS;
91        do {
92            uint32_t raw;
93            int32_t dequant;
94            uint8_t bits = *bits_array++;
95            OI_INT sf = *sf_array++;
96
97            OI_BITSTREAM_READUINT(raw, bits, ptr, value, bitPtr);
98            dequant = OI_SBC_Dequant(raw, sf, bits);
99            /*
100             * Check if we need to do mid/side
101             */
102            if (joint & 0x80) {
103                int32_t mid = *(s - NROF_SUBBANDS);
104                int32_t side = dequant;
105                *(s - NROF_SUBBANDS) = mid + side;
106                dequant = mid - side;
107            }
108            joint <<= 1;
109            *s++ = dequant;
110        } while (--sb);
111    } while (--bl);
112}
113