• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2003 - 2016 Sony Corporation
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 #ifndef _LDAC_H
18 #define _LDAC_H
19 
20 #include "ldaclib.h"
21 #include "struct_ldac.h"
22 
23 
24 
25 
26 
27 /***************************************************************************************************
28     Macro Definitions
29 ***************************************************************************************************/
30 /* Configuration */
31 #define LDAC_SYNCWORDBITS      8
32 #define LDAC_SYNCWORD       0xAA
33 /** Sampling Rate **/
34 #define LDAC_SMPLRATEBITS      3
35 #define LDAC_NSMPLRATEID       6
36 #define LDAC_NSUPSMPLRATEID    4
37 #define LDAC_SMPLRATEID_0    0x0
38 #define LDAC_SMPLRATEID_1    0x1
39 #define LDAC_SMPLRATEID_2    0x2
40 #define LDAC_SMPLRATEID_3    0x3
41 /** Channel **/
42 #define LDAC_CHCONFIG1BITS     3
43 #define LDAC_CHCONFIG2BITS     2
44 #define LDAC_NCHCONFIGID       8
45 #define LDAC_MAXNCH            2
46 #define LDAC_CHANNEL_1CH       1
47 #define LDAC_CHANNEL_2CH       2
48 #define LDAC_CHCONFIGID_MN     0
49 #define LDAC_CHCONFIGID_DL     1
50 #define LDAC_CHCONFIGID_ST     2
51 /** Frame Length **/
52 #define LDAC_FRAMELEN1BITS    11
53 #define LDAC_FRAMELEN2BITS     9
54 #define LDAC_MAXNBYTES      1024
55 #define LDAC_MAXSUPNBYTES    512
56 #define LDAC_MINSUPNBYTES     22
57 /** Frame Status **/
58 #define LDAC_FRAMESTATBITS     2
59 #define LDAC_FRMSTAT_LEV_0     0
60 #define LDAC_FRMSTAT_LEV_1     1
61 #define LDAC_FRMSTAT_LEV_2     2
62 #define LDAC_FRMSTAT_LEV_3     3
63 /** Other **/
64 #define LDAC_RESERVE1BITS      2
65 #define LDAC_RESERVE2BITS      5
66 #define LDAC_DUMMYCODE      0x00
67 
68 /* Signal Processing */
69 #define LDAC_NFRAME            2
70 #define LDAC_NSFTSTEP          5
71 /** Frame Samples (log base 2 of) **/
72 #define LDAC_NUMLNN            2
73 #define LDAC_MAXLNN            8
74 #define LDAC_2FSLNN            8
75 #define LDAC_1FSLNN            7
76 /** Frame Samples **/
77 #define LDAC_MAXLSU (1<<LDAC_MAXLNN)
78 #define LDAC_2FSLSU (1<<LDAC_2FSLNN)
79 #define LDAC_1FSLSU (1<<LDAC_1FSLNN)
80 /** Band **/
81 #define LDAC_MAXNBANDS        16
82 #define LDAC_2FSNBANDS        16
83 #define LDAC_1FSNBANDS        12
84 /** QU **/
85 #define LDAC_MAXGRADQU        50
86 #define LDAC_MAXNQUS          34
87 #define LDAC_2FSNQUS          34
88 #define LDAC_1FSNQUS          26
89 #define LDAC_MAXNSPS          16
90 /** Frame Status Analysis **/
91 #define LDAC_NSP_PSEUDOANA   128
92 #define LDAC_NSP_LOWENERGY    12
93 #define LDAC_TH_ZCROSNUM      90
94 #define LDAC_MAXCNT_FRMANA    10
95 
96 /* Stream Syntax */
97 #define LDAC_BLKID_MONO        0
98 #define LDAC_BLKID_STEREO      1
99 #define LDAC_FILLCODE       0x01
100 /** Band Info **/
101 #define LDAC_NBANDBITS         4
102 #define LDAC_BAND_OFFSET       2
103 /** Gradient Data **/
104 #define LDAC_GRADMODEBITS      2
105 #define LDAC_GRADOSBITS        5
106 #define LDAC_MAXGRADOS        31
107 #define LDAC_DEFGRADOSH       31
108 #define LDAC_GRADQU0BITS       6
109 #define LDAC_GRADQU1BITS       5
110 #define LDAC_DEFGRADQUH       26
111 #define LDAC_NADJQUBITS        5
112 #define LDAC_MAXNADJQUS       32
113 /** Scale Factor Data **/
114 #define LDAC_IDSFBITS          5
115 #define LDAC_NIDSF            32
116 #define LDAC_SFCMODEBITS       1
117 #define LDAC_NSFCMODE          2
118 #define LDAC_SFCWTBLBITS       3
119 #define LDAC_NSFCWTBL          8
120 #define LDAC_SFCBLENBITS       2
121 #define LDAC_MINSFCBLEN_0      3
122 #define LDAC_MAXSFCBLEN_0      6
123 #define LDAC_MINSFCBLEN_1      2
124 #define LDAC_MAXSFCBLEN_1      5
125 #define LDAC_MINSFCBLEN_2      2
126 #define LDAC_MAXSFCBLEN_2      5
127 /** Spectrum/Residual Data **/
128 #define LDAC_NIDWL            16
129 #define LDAC_MINIDWL1          1
130 #define LDAC_MAXIDWL1         15
131 #define LDAC_MAXIDWL2         15
132 #define LDAC_2DIMSPECBITS      3
133 #define LDAC_N2DIMSPECENCTBL  16
134 #define LDAC_N2DIMSPECDECTBL   8
135 #define LDAC_4DIMSPECBITS      7
136 #define LDAC_N4DIMSPECENCTBL 256
137 #define LDAC_N4DIMSPECDECTBL  81
138 /** Bit Operation **/
139 #define LDAC_LOC_SHIFT         3
140 #define LDAC_LOC_MASK        0x7
141 #define LDAC_BYTESIZE          8
142 #define LDAC_MAXBITNUM      8192
143 
144 /* Flag */
145 #define LDAC_FLAGBITS          1
146 #define LDAC_TRUE              1
147 #define LDAC_FALSE             0
148 
149 /* Mode */
150 #define LDAC_MODE_0            0
151 #define LDAC_MODE_1            1
152 #define LDAC_MODE_2            2
153 #define LDAC_MODE_3            3
154 
155 /***************************************************************************************************
156     Structure Definitions
157 ***************************************************************************************************/
158 typedef struct _sfinfo_ldac SFINFO;
159 typedef struct _config_info_ldac CFG;
160 typedef struct _audio_block_ldac AB;
161 typedef struct _audio_channel_ldac AC;
162 typedef struct _audio_channel_sub_ldac ACSUB;
163 
164 /* Configuration Information Structure */
165 struct _config_info_ldac {
166     int syncword;
167     int smplrate_id;
168     int chconfig_id;
169     int ch;
170     int frame_length;
171     int frame_status;
172 };
173 
174 /* Audio Channel (AC) Sub Structure */
175 #ifndef _32BIT_FIXED_POINT
176 struct _audio_channel_sub_ldac {
177     SCALAR a_time[LDAC_MAXLSU*LDAC_NFRAME];
178     SCALAR a_spec[LDAC_MAXLSU];
179 };
180 #else /* _32BIT_FIXED_POINT */
181 struct _audio_channel_sub_ldac {
182     INT32 a_time[LDAC_MAXLSU*LDAC_NFRAME];
183     INT32 a_spec[LDAC_MAXLSU];
184 };
185 #endif /* _32BIT_FIXED_POINT */
186 
187 /* Audio Channel (AC) Structure */
188 struct _audio_channel_ldac {
189     int ich;
190     int frmana_cnt;
191     int sfc_mode;
192     int sfc_bitlen;
193     int sfc_offset;
194     int sfc_weight;
195     int a_idsf[LDAC_MAXNQUS];
196     int a_idwl1[LDAC_MAXNQUS];
197     int a_idwl2[LDAC_MAXNQUS];
198     int a_addwl[LDAC_MAXNQUS];
199     int a_tmp[LDAC_MAXNQUS];
200     int a_qspec[LDAC_MAXLSU];
201     int a_rspec[LDAC_MAXLSU];
202     AB *p_ab;
203     ACSUB *p_acsub;
204 };
205 
206 /* Audio Block (AB) Structure */
207 struct _audio_block_ldac {
208     int blk_type;
209     int blk_nchs;
210     int nbands;
211     int nqus;
212     int grad_mode;
213     int grad_qu_l;
214     int grad_qu_h;
215     int grad_os_l;
216     int grad_os_h;
217     int a_grad[LDAC_MAXGRADQU];
218     int nadjqus;
219     int abc_status;
220     int nbits_ab;
221     int nbits_band;
222     int nbits_grad;
223     int nbits_scfc;
224     int nbits_spec;
225     int nbits_avail;
226     int nbits_used;
227     int *p_smplrate_id;
228     int *p_error_code;
229     AC  *ap_ac[2];
230 };
231 
232 /* Sound Frame Structure */
233 struct _sfinfo_ldac {
234     CFG cfg;
235     AB *p_ab;
236     AC *ap_ac[LDAC_MAXNCH];
237     char *p_mempos;
238     int error_code;
239 };
240 
241 /* LDAC Handle */
242 typedef struct _handle_ldac_struct {
243     int nlnn;
244     int nbands;
245     int grad_mode;
246     int grad_qu_l;
247     int grad_qu_h;
248     int grad_os_l;
249     int grad_os_h;
250     int abc_status;
251     int error_code;
252     SFINFO sfinfo;
253 } HANDLE_LDAC_STRUCT;
254 
255 /* Huffman Codeword */
256 typedef struct {
257     unsigned char word;
258     unsigned char len;
259 } HC;
260 
261 /* Huffman Encoding Structure */
262 typedef struct _hcenc_ldac HCENC;
263 struct _hcenc_ldac {
264     const HC *p_tbl;
265     unsigned char ncodes;
266     unsigned char wl;
267     unsigned char mask;
268 };
269 
270 
271 /*******************************************************************************
272     Function Declarations
273 *******************************************************************************/
274 #define npow2_ldac(n)  (1 << (n))
275 #define min_ldac(a, b) (((a)<(b)) ? (a) : (b))
276 #define max_ldac(a, b) (((a)>(b)) ? (a) : (b))
277 
278 /* Get Huffman Codeword Property */
279 #define hc_len_ldac(p)  ((p)->len)
280 #define hc_word_ldac(p) ((p)->word)
281 
282 /* Convert a Signed Number with nbits to a Signed Integer */
283 #define bs_to_int_ldac(bs, nbits) (((bs)&(0x1<<((nbits)-1))) ? ((bs)|((~0x0)<<(nbits))) : bs)
284 
285 #ifdef _32BIT_FIXED_POINT
286 #include "fixp_ldac.h"
287 #endif /* _32BIT_FIXED_POINT */
288 #include "proto_ldac.h"
289 
290 
291 #endif /* _LDAC_H */
292 
293