1 /*
2  * FAAC - Freeware Advanced Audio Coder
3  * Copyright (C) 2001 Menno Bakker
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14 
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  * $Id: coder.h,v 1.13 2005/02/02 07:49:10 sur Exp $
20  */
21 
22 #ifndef CODER_H
23 #define CODER_H
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif /* __cplusplus */
28 
29 /* Allow encoding of Digital Radio Mondiale (DRM) */
30 //#define DRM
31 
32 /* Allow encoding of Digital Radio Mondiale (DRM) with transform length 1024 */
33 //#define DRM_1024
34 
35 #define MAX_CHANNELS 64
36 
37 #ifdef DRM
38 #ifdef DRM_1024
39 # define FRAME_LEN 1024
40 # define BLOCK_LEN_LONG 1024
41 # define BLOCK_LEN_SHORT 128
42 #else
43 # define FRAME_LEN 960
44 # define BLOCK_LEN_LONG 960
45 # define BLOCK_LEN_SHORT 120
46 #endif /* DRM_1024 */
47 #else
48 # define FRAME_LEN 1024
49 # define BLOCK_LEN_LONG 1024
50 # define BLOCK_LEN_SHORT 128
51 #endif
52 
53 #define NSFB_LONG  51
54 #define NSFB_SHORT 15
55 #define MAX_SHORT_WINDOWS 8
56 #define MAX_SCFAC_BANDS ((NSFB_SHORT+1)*MAX_SHORT_WINDOWS)
57 
58 enum WINDOW_TYPE {
59     ONLY_LONG_WINDOW,
60     LONG_SHORT_WINDOW,
61     ONLY_SHORT_WINDOW,
62     SHORT_LONG_WINDOW
63 };
64 
65 #define TNS_MAX_ORDER 20
66 #define DEF_TNS_GAIN_THRESH 1.4
67 #define DEF_TNS_COEFF_THRESH 0.1
68 #define DEF_TNS_COEFF_RES 4
69 #define DEF_TNS_RES_OFFSET 3
70 #define LEN_TNS_NFILTL 2
71 #define LEN_TNS_NFILTS 1
72 
73 #define LPC 2
74 
75 typedef struct {
76     int order;                           /* Filter order */
77     int direction;                       /* Filtering direction */
78     int coefCompress;                    /* Are coeffs compressed? */
79     int length;                          /* Length, in bands */
80     double aCoeffs[TNS_MAX_ORDER+1];     /* AR Coefficients */
81     double kCoeffs[TNS_MAX_ORDER+1];     /* Reflection Coefficients */
82     int index[TNS_MAX_ORDER+1];          /* Coefficient indices */
83 } TnsFilterData;
84 
85 typedef struct {
86     int numFilters;                             /* Number of filters */
87     int coefResolution;                         /* Coefficient resolution */
88     TnsFilterData tnsFilter[1<<LEN_TNS_NFILTL]; /* TNS filters */
89 } TnsWindowData;
90 
91 typedef struct {
92     int tnsDataPresent;
93     int tnsMinBandNumberLong;
94     int tnsMinBandNumberShort;
95     int tnsMaxBandsLong;
96     int tnsMaxBandsShort;
97     int tnsMaxOrderLong;
98     int tnsMaxOrderShort;
99     TnsWindowData windowData[MAX_SHORT_WINDOWS]; /* TNS data per window */
100 } TnsInfo;
101 
102 typedef struct
103 {
104     int psy_init_mc;
105     double dr_mc[LPC][BLOCK_LEN_LONG],e_mc[LPC+1+1][BLOCK_LEN_LONG];
106     double K_mc[LPC+1][BLOCK_LEN_LONG], R_mc[LPC+1][BLOCK_LEN_LONG];
107     double VAR_mc[LPC+1][BLOCK_LEN_LONG], KOR_mc[LPC+1][BLOCK_LEN_LONG];
108     double sb_samples_pred_mc[BLOCK_LEN_LONG];
109     int thisLineNeedsResetting_mc[BLOCK_LEN_LONG];
110     int reset_count_mc;
111 } BwpInfo;
112 
113 
114 typedef struct {
115     int window_shape;
116     int prev_window_shape;
117     int block_type;
118     int desired_block_type;
119 
120     int global_gain;
121     int sf[MAX_SCFAC_BANDS];
122     int book[MAX_SCFAC_BANDS];
123     int bandcnt;
124     int sfbn;
125     int sfb_offset[NSFB_LONG + 1];
126 
127     struct {
128         int n;
129         int len[MAX_SHORT_WINDOWS];
130     } groups;
131 
132     /* worst case: one codeword with two escapes per two spectral lines */
133 #define DATASIZE (3*FRAME_LEN/2)
134 
135     struct {
136         int data;
137         int len;
138     } s[DATASIZE];
139     int datacnt;
140 
141 #ifdef DRM
142     int num_data_cw[FRAME_LEN];
143     int cur_cw;
144     int all_sfb;
145 
146     int iLenLongestCW;
147     int iLenReordSpData;
148 #endif
149 
150     TnsInfo tnsInfo;
151     BwpInfo bwpInfo;
152 } CoderInfo;
153 
154 typedef struct {
155   unsigned long sampling_rate;  /* the following entries are for this sampling rate */
156   int num_cb_long;
157   int num_cb_short;
158   int cb_width_long[NSFB_LONG];
159   int cb_width_short[NSFB_SHORT];
160 } SR_INFO;
161 
162 #ifdef __cplusplus
163 }
164 #endif /* __cplusplus */
165 
166 #endif /* CODER_H */
167