display more quantizer infos, display motion vector blocks as v,V.
[swftools.git] / lib / bladeenc / common.h
1 /*
2                         (c) Copyright 1998-2000 - Tord Jansson
3                         ======================================
4
5                 This file is part of the BladeEnc MP3 Encoder, based on
6                 ISO's reference code for MPEG Layer 3 compression, and might
7                 contain smaller or larger sections that are directly taken
8                 from ISO's reference code.
9
10                 All changes to the ISO reference code herein are either
11                 copyrighted by Tord Jansson (tord.jansson@swipnet.se)
12                 or sublicensed to Tord Jansson by a third party.
13
14         BladeEnc is free software; you can redistribute this file
15         and/or modify it under the terms of the GNU Lesser General Public
16         License as published by the Free Software Foundation; either
17         version 2.1 of the License, or (at your option) any later version.
18
19
20
21         ------------    Changes    ------------
22
23         2000-02-07  Andre Piotrowski
24
25         -       reformatted
26 */
27
28 #ifndef         __COMMON__
29 #define         __COMMON__
30
31
32
33
34
35 /***********************************************************************
36 *
37 *  Global Include Files
38 *
39 ***********************************************************************/
40
41 #include        <stdio.h>
42 #include        <string.h>
43 #include        <math.h>
44
45 #include        "tables.h"
46
47
48
49
50
51 #define         MIN(A, B)                               ((A) < (B) ? (A) : (B))
52 #define         MAX(A, B)                               ((A) > (B) ? (A) : (B))
53
54
55
56
57
58 #ifndef EXIT_SUCCESS
59 #define         EXIT_SUCCESS                    0
60 #endif
61
62 #ifndef EXIT_FAILURE
63 #define         EXIT_FAILURE                    1
64 #endif
65
66
67
68
69
70 /***********************************************************************
71 *
72 *  Global Definitions
73 *
74 ***********************************************************************/
75
76 /* General Definitions */
77
78 #define         FLOAT                                   float
79 #ifndef FALSE
80 #define         FALSE                                   0
81 #endif
82
83 #ifndef TRUE
84 #define         TRUE                                    1
85 #endif
86
87 #define         NULL_CHAR                               '\0'
88
89 #define         MAX_U_32_NUM                    0xFFFFFFFF
90
91 #ifndef PI
92 #define         PI                                              3.14159265358979
93 #endif
94 #define         PI4                                             PI/4
95 #define         PI64                                    PI/64
96
97 #define         LN_TO_LOG10                             0.2302585093
98
99 #define         VOL_REF_NUM                             0
100 #define         MPEG_AUDIO_ID                   1
101 #define         MPEG_PHASE2_LSF                 0       /* 1995-07-11 SHN */
102
103 #if 0
104 #define         MONO                                    1
105 #define         STEREO                                  2
106 #endif
107
108 #define         BITS_IN_A_BYTE                  8
109 #define         WORD                                    16
110 #define         MAX_NAME_SIZE                   81
111 #define         SBLIMIT                                 32
112 #define         SSLIMIT                                 18
113 #define         FFT_SIZE                                1024
114 #define         HAN_SIZE                                512
115 #define         SCALE_BLOCK                             12
116 #define         SCALE_RANGE                             64
117 #define         SCALE                                   32768
118 #define         CRC16_POLYNOMIAL                0x8005
119
120
121 /* MPEG Header Definitions - Mode Values */
122
123 #define         MPG_MD_STEREO                   0
124 #define         MPG_MD_DUAL_CHANNEL             2
125 #define         MPG_MD_MONO                             3
126
127
128 /* Mode Extention */
129
130 #define         MPG_MD_LR_LR                    0
131 #define         MPG_MD_LR_I                             1
132 #define         MPG_MD_MS_LR                    2
133 #define         MPG_MD_MS_I                             3
134
135
136 /* "bit_stream.h" Definitions */
137
138 #define         MINIMUM                                 4    /* Minimum size of the buffer in bytes */
139 #define         MAX_LENGTH                              32   /* Maximum length of word written or
140                                                                         read from bit stream */
141
142 #define         READ_MODE                               0
143 #define         WRITE_MODE                              1
144 #define         ALIGNING                                8
145
146
147
148 #define         BUFFER_SIZE                             4096
149
150
151
152
153
154 /***********************************************************************
155 *
156 *  Global Type Definitions
157 *
158 ***********************************************************************/
159
160
161 /* Structure for Reading Layer II Allocation Tables from File */
162
163 typedef         struct
164                         {
165                                 unsigned int                    steps;
166                                 unsigned int                    bits;
167                                 unsigned int                    group;
168                                 unsigned int                    quant;
169                         } sb_alloc, *alloc_ptr;
170
171 typedef         sb_alloc                                al_table[SBLIMIT][16];
172
173
174 /* Header Information Structure */
175
176 typedef         struct
177                         {
178                                 int                                             version;
179                                 int                                             error_protection;
180                                 int                                             bitrate_index;
181                                 int                                             sampling_frequency;
182                                 int                                             padding;
183                                 int                                             extension;
184                                 int                                             mode;
185                                 int                                             mode_ext;
186                                 int                                             copyright;
187                                 int                                             original;
188                                 int                                             emphasis;
189 /*                              int                                             freq; */
190                         } layer, *the_layer;
191
192
193 /* Parent Structure Interpreting some Frame Parameters in Header */
194
195 typedef         struct
196                         {
197                                 layer                                   *header;       /* raw header information */
198                                 int                                             actual_mode;   /* when writing IS, may forget if 0 chs */
199                                 al_table                                *alloc;        /* bit allocation table read in */
200                                 int                                             tab_num;       /* number of table as loaded */
201                                 int                                             stereo;        /* 1 for mono, 2 for stereo */
202                                 int                                             jsbound;       /* first band of joint stereo coding */
203                                 int                                             sblimit;       /* total number of sub bands */
204                         } frame_params;
205
206
207
208 enum byte_order { order_unknown, order_bigEndian, order_littleEndian };
209 extern enum byte_order NativeByteOrder;
210
211
212 /* "bit_stream.h" Type Definitions */
213
214 typedef         struct bit_stream_struc
215                         {
216                                 FILE                                    *pt;            /* pointer to bit stream device */
217                                 unsigned char                   *buf;           /* bit stream buffer */
218                                 int                                             buf_size;       /* size of buffer (in number of bytes) */
219                                 int                                             totbit;         /* bit counter of bit stream */
220                                 int                                             buf_byte_idx;   /* pointer to top byte in buffer */
221                                 int                                             buf_bit_idx;    /* pointer to top bit of top byte in buffer */
222                                 int                                             mode;           /* bit stream open in read or write mode */
223                                 int                                             eob;            /* end of buffer index */
224                                 int                                             eobs;           /* end of bit stream flag */
225                                 char                                    format;         /* format of file in rd mode (BINARY/ASCII) */
226                         } Bit_stream_struc;
227
228
229
230
231
232 #include        "l3side.h"
233
234 /***********************************************************************
235 *
236 *  Global Variable External Declarations
237 *
238 ***********************************************************************/
239
240 /*
241 extern  char                    *mode_names[4]; 
242 extern  char                    *layer_names[3]; 
243 extern  char                    *version_names[2];
244 */
245 extern  double                  s_freq[2][4];
246 extern  int                             bitratex[2][15];
247
248
249
250
251
252 /***********************************************************************
253 *
254 *  Global Function Prototype Declarations
255 *
256 ***********************************************************************/
257
258 /* The following functions are in the file "common.c" */
259
260 extern  void                    *mem_alloc (unsigned int block, char *item);
261 extern  void                    mem_free (void **ptr_addr);
262
263
264
265
266
267 #endif          /* __COMMON__ */