1 /*
2 ** Copyright 2003-2010, VisualOn, Inc.
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 ** http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16 /*******************************************************************************
17 File: channel_map.c
18
19 Content: channel mapping functions
20
21 *******************************************************************************/
22
23 #include "channel_map.h"
24 #include "bitenc.h"
25 #include "psy_const.h"
26 #include "qc_data.h"
27
28 static const Word16 maxChannelBits = MAXBITS_COEF;
29
initElement(ELEMENT_INFO * elInfo,ELEMENT_TYPE elType)30 static Word16 initElement(ELEMENT_INFO* elInfo, ELEMENT_TYPE elType)
31 {
32 Word16 error=0;
33
34 elInfo->elType=elType;
35
36 switch(elInfo->elType) {
37
38 case ID_SCE:
39 elInfo->nChannelsInEl=1;
40
41 elInfo->ChannelIndex[0]=0;
42
43 elInfo->instanceTag=0;
44 break;
45
46 case ID_CPE:
47
48 elInfo->nChannelsInEl=2;
49
50 elInfo->ChannelIndex[0]=0;
51 elInfo->ChannelIndex[1]=1;
52
53 elInfo->instanceTag=0;
54 break;
55
56 default:
57 error=1;
58 }
59
60 return error;
61 }
62
63
InitElementInfo(Word16 nChannels,ELEMENT_INFO * elInfo)64 Word16 InitElementInfo (Word16 nChannels, ELEMENT_INFO* elInfo)
65 {
66 Word16 error;
67 error = 0;
68
69 switch(nChannels) {
70
71 case 1:
72 initElement(elInfo, ID_SCE);
73 break;
74
75 case 2:
76 initElement(elInfo, ID_CPE);
77 break;
78
79 default:
80 error=4;
81 }
82
83 return error;
84 }
85
86
InitElementBits(ELEMENT_BITS * elementBits,ELEMENT_INFO elInfo,Word32 bitrateTot,Word16 averageBitsTot,Word16 staticBitsTot)87 Word16 InitElementBits(ELEMENT_BITS *elementBits,
88 ELEMENT_INFO elInfo,
89 Word32 bitrateTot,
90 Word16 averageBitsTot,
91 Word16 staticBitsTot)
92 {
93 Word16 error;
94 error = 0;
95
96 switch(elInfo.nChannelsInEl) {
97 case 1:
98 elementBits->chBitrate = bitrateTot;
99 elementBits->averageBits = averageBitsTot - staticBitsTot;
100 elementBits->maxBits = maxChannelBits;
101
102 elementBits->maxBitResBits = maxChannelBits - averageBitsTot;
103 elementBits->maxBitResBits = elementBits->maxBitResBits - (elementBits->maxBitResBits & 7);
104 elementBits->bitResLevel = elementBits->maxBitResBits;
105 elementBits->relativeBits = 0x4000; /* 1.0f/2 */
106 break;
107
108 case 2:
109 elementBits->chBitrate = bitrateTot >> 1;
110 elementBits->averageBits = averageBitsTot - staticBitsTot;
111 elementBits->maxBits = maxChannelBits << 1;
112
113 elementBits->maxBitResBits = (maxChannelBits << 1) - averageBitsTot;
114 elementBits->maxBitResBits = elementBits->maxBitResBits - (elementBits->maxBitResBits & 7);
115 elementBits->bitResLevel = elementBits->maxBitResBits;
116 elementBits->relativeBits = 0x4000; /* 1.0f/2 */
117 break;
118
119 default:
120 error = 1;
121 }
122 return error;
123 }
124