ReactOS 0.4.15-dev-8393-g61b7fb9
tabinit.c File Reference
#include "mpg123lib_intern.h"
#include "debug.h"
Include dependency graph for tabinit.c:

Go to the source code of this file.

Functions

void prepare_decode_tables ()
 
void make_decode_tables (mpg123_handle *fr)
 
int make_conv16to8_table (mpg123_handle *fr)
 

Variables

static real cos64 [16]
 
static real cos32 [8]
 
static real cos16 [4]
 
static real cos8 [2]
 
static real cos4 [1]
 
realpnts [] = { cos64,cos32,cos16,cos8,cos4 }
 
static long intwinbase []
 

Function Documentation

◆ make_conv16to8_table()

int make_conv16to8_table ( mpg123_handle fr)

Definition at line 277 of file tabinit.c.

278{
279 int i;
280 int mode = fr->af.dec_enc;
281
282 /*
283 * ????: 8.0 is right but on SB cards '2.0' is a better value ???
284 */
285 const double mul = 8.0;
286
287 if(!fr->conv16to8_buf){
288 fr->conv16to8_buf = (unsigned char *) malloc(8192);
289 if(!fr->conv16to8_buf) {
291 if(NOQUIET) error("Can't allocate 16 to 8 converter table!");
292 return -1;
293 }
294 fr->conv16to8 = fr->conv16to8_buf + 4096;
295 }
296
297 switch(mode)
298 {
300 {
301 double m=127.0 / log(256.0);
302 int c1;
303
304 for(i=-4096;i<4096;i++)
305 {
306 /* dunno whether this is a valid transformation rule ?!?!? */
307 if(i < 0)
308 c1 = 127 - (int) (log( 1.0 - 255.0 * (double) i*mul / 32768.0 ) * m);
309 else
310 c1 = 255 - (int) (log( 1.0 + 255.0 * (double) i*mul / 32768.0 ) * m);
311 if(c1 < 0 || c1 > 255)
312 {
313 if(NOQUIET) error2("Converror %d %d",i,c1);
314 return -1;
315 }
316 if(c1 == 0)
317 c1 = 2;
318 fr->conv16to8[i] = (unsigned char) c1;
319 }
320 }
321 break;
323 for(i=-4096;i<4096;i++)
324 fr->conv16to8[i] = i>>5;
325 break;
327 for(i=-4096;i<4096;i++)
328 fr->conv16to8[i] = (i>>5)+128;
329 break;
331 {
332 /*
333 Let's believe Wikipedia (http://en.wikipedia.org/wiki/G.711) that this
334 is the correct table:
335
336 s0000000wxyza... n000wxyz [0-31] -> [0-15]
337 s0000001wxyza... n001wxyz [32-63] -> [16-31]
338 s000001wxyzab... n010wxyz [64-127] -> [32-47]
339 s00001wxyzabc... n011wxyz [128-255] -> [48-63]
340 s0001wxyzabcd... n100wxyz [256-511] -> [64-79]
341 s001wxyzabcde... n101wxyz [512-1023] -> [80-95]
342 s01wxyzabcdef... n110wxyz [1024-2047] -> [96-111]
343 s1wxyzabcdefg... n111wxyz [2048-4095] -> [112-127]
344
345 Let's extend to -4096, too.
346 Also, bytes are xored with 0x55 for transmission.
347
348 Since it sounds OK, I assume it is fine;-)
349 */
350 for(i=0; i<64; ++i)
351 fr->conv16to8[i] = ((unsigned int)i)>>1;
352 for(i=64; i<128; ++i)
353 fr->conv16to8[i] = ((((unsigned int)i)>>2) & 0xf) | (2<<4);
354 for(i=128; i<256; ++i)
355 fr->conv16to8[i] = ((((unsigned int)i)>>3) & 0xf) | (3<<4);
356 for(i=256; i<512; ++i)
357 fr->conv16to8[i] = ((((unsigned int)i)>>4) & 0xf) | (4<<4);
358 for(i=512; i<1024; ++i)
359 fr->conv16to8[i] = ((((unsigned int)i)>>5) & 0xf) | (5<<4);
360 for(i=1024; i<2048; ++i)
361 fr->conv16to8[i] = ((((unsigned int)i)>>6) & 0xf) | (6<<4);
362 for(i=2048; i<4096; ++i)
363 fr->conv16to8[i] = ((((unsigned int)i)>>7) & 0xf) | (7<<4);
364
365 for(i=-4095; i<0; ++i)
366 fr->conv16to8[i] = fr->conv16to8[-i] | 0x80;
367
368 fr->conv16to8[-4096] = fr->conv16to8[-4095];
369
370 for(i=-4096;i<4096;i++)
371 {
372 /* fr->conv16to8[i] = - i>>5; */
373 /* fprintf(stderr, "table %i %i\n", i<<AUSHIFT, fr->conv16to8[i]); */
374 fr->conv16to8[i] ^= 0x55;
375 }
376 }
377 break;
378 default:
380 if(NOQUIET) error("Unknown 8 bit encoding choice.");
381 return -1;
382 break;
383 }
384
385 return 0;
386}
#define malloc
Definition: debug_ros.c:4
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
unsigned char
Definition: typeof.h:29
GLenum mode
Definition: glext.h:6217
const GLfloat * m
Definition: glext.h:10848
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
@ MPG123_ENC_ULAW_8
Definition: fmt123.h:66
@ MPG123_ENC_SIGNED_8
Definition: fmt123.h:64
@ MPG123_ENC_ALAW_8
Definition: fmt123.h:68
@ MPG123_ENC_UNSIGNED_8
Definition: fmt123.h:62
@ MPG123_ERR_16TO8TABLE
Definition: mpg123.h:387
#define error(str)
Definition: mkdosfs.c:1605
#define NOQUIET
#define mul(aa, bb)
Definition: mvAesAlg.c:25
#define error2(s, a, b)
Definition: debug.h:126
#define log(outFile, fmt,...)
Definition: util.h:15
unsigned char * conv16to8_buf
Definition: frame.h:134
unsigned char * conv16to8
Definition: frame.h:135
struct audioformat af
Definition: frame.h:268

◆ make_decode_tables()

void make_decode_tables ( mpg123_handle fr)

Definition at line 181 of file tabinit.c.

182{
183 int i,j;
184 int idx = 0;
185 double scaleval;
186#ifdef REAL_IS_FIXED
187 real scaleval_long;
188#endif
189 /* Scale is always based on 1.0 . */
190 scaleval = -0.5*(fr->lastscale < 0 ? fr->p.outscale : fr->lastscale);
191 debug1("decode tables with scaleval %g", scaleval);
192#ifdef REAL_IS_FIXED
193 scaleval_long = DOUBLE_TO_REAL_15(scaleval);
194 debug1("decode table with fixed scaleval %li", (long)scaleval_long);
195 if(scaleval_long > 28618 || scaleval_long < -28618)
196 {
197 /* TODO: Limit the scaleval itself or limit the multiplication afterwards?
198 The former basically disables significant amplification for fixed-point
199 decoders, but avoids (possibly subtle) distortion. */
200 /* This would limit the amplification instead:
201 scaleval_long = scaleval_long < 0 ? -28618 : 28618; */
202 if(NOQUIET) warning("Desired amplification may introduce distortion.");
203 }
204#endif
205 for(i=0,j=0;i<256;i++,j++,idx+=32)
206 {
207 if(idx < 512+16)
208#ifdef REAL_IS_FIXED
209 fr->decwin[idx+16] = fr->decwin[idx] =
210 REAL_SCALE_WINDOW(sat_mul32(intwinbase[j],scaleval_long));
211#else
212 fr->decwin[idx+16] = fr->decwin[idx] = DOUBLE_TO_REAL((double) intwinbase[j] * scaleval);
213#endif
214
215 if(i % 32 == 31)
216 idx -= 1023;
217 if(i % 64 == 63)
218#ifdef REAL_IS_FIXED
219 scaleval_long = - scaleval_long;
220#else
221 scaleval = - scaleval;
222#endif
223 }
224
225 for( /* i=256 */ ;i<512;i++,j--,idx+=32)
226 {
227 if(idx < 512+16)
228#ifdef REAL_IS_FIXED
229 fr->decwin[idx+16] = fr->decwin[idx] =
230 REAL_SCALE_WINDOW(sat_mul32(intwinbase[j],scaleval_long));
231#else
232 fr->decwin[idx+16] = fr->decwin[idx] = DOUBLE_TO_REAL((double) intwinbase[j] * scaleval);
233#endif
234
235 if(i % 32 == 31)
236 idx -= 1023;
237 if(i % 64 == 63)
238#ifdef REAL_IS_FIXED
239 scaleval_long = - scaleval_long;
240#else
241 scaleval = - scaleval;
242#endif
243 }
244#if defined(OPT_X86_64) || defined(OPT_ALTIVEC) || defined(OPT_SSE) || defined(OPT_SSE_VINTAGE) || defined(OPT_ARM) || defined(OPT_NEON) || defined(OPT_NEON64) || defined(OPT_AVX)
245 if( fr->cpu_opts.type == x86_64
246 || fr->cpu_opts.type == altivec
247 || fr->cpu_opts.type == sse
248 || fr->cpu_opts.type == sse_vintage
249 || fr->cpu_opts.type == arm
250 || fr->cpu_opts.type == neon
251 || fr->cpu_opts.type == neon64
252 || fr->cpu_opts.type == avx )
253 { /* for float SSE / AltiVec / ARM decoder */
254 for(i=512; i<512+32; i++)
255 {
256 fr->decwin[i] = (i&1) ? fr->decwin[i] : 0;
257 }
258 for(i=0; i<512; i++)
259 {
260 fr->decwin[512+32+i] = -fr->decwin[511-i];
261 }
262#if defined(OPT_NEON) || defined(OPT_NEON64)
263 if(fr->cpu_opts.type == neon || fr->cpu_opts.type == neon64)
264 {
265 for(i=0; i<512; i+=2)
266 {
267 fr->decwin[i] = -fr->decwin[i];
268 }
269 }
270#endif
271 }
272#endif
273 debug("decode tables done");
274}
unsigned int idx
Definition: utils.c:41
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define debug(msg)
Definition: key_call.c:71
#define DOUBLE_TO_REAL_15(x)
#define real
#define DOUBLE_TO_REAL(x)
@ avx
Definition: optimize.h:112
@ x86_64
Definition: optimize.h:108
@ neon64
Definition: optimize.h:111
@ sse_vintage
Definition: optimize.h:115
@ altivec
Definition: optimize.h:106
@ arm
Definition: optimize.h:109
@ sse
Definition: optimize.h:107
@ neon
Definition: optimize.h:110
#define debug1(s, a)
Definition: debug.h:61
#define warning(s)
Definition: debug.h:83
struct mpg123_handle_struct::@3455 cpu_opts
struct mpg123_pars_struct p
Definition: frame.h:289
double lastscale
Definition: frame.h:237
static long intwinbase[]
Definition: tabinit.c:48

◆ prepare_decode_tables()

void prepare_decode_tables ( void  )

Definition at line 76 of file tabinit.c.

77{
78#if !defined(REAL_IS_FIXED) || !defined(PRECALC_TABLES)
79 int i,k,kr,divv;
80 real *costab;
81
82 for(i=0;i<5;i++)
83 {
84 kr=0x10>>i; divv=0x40>>i;
85 costab = pnts[i];
86 for(k=0;k<kr;k++)
87 costab[k] = DOUBLE_TO_REAL(1.0 / (2.0 * cos(M_PI * ((double) k * 2.0 + 1.0) / (double) divv)));
88 }
89#endif
90}
_STLP_DECLSPEC complex< float > _STLP_CALL cos(const complex< float > &)
#define M_PI
Definition: macros.h:263
int k
Definition: mpi.c:3369
real * pnts[]
Definition: tabinit.c:45

Variable Documentation

◆ cos16

real cos16[4]
static

Definition at line 42 of file tabinit.c.

◆ cos32

real cos32[8]
static

Definition at line 42 of file tabinit.c.

◆ cos4

real cos4[1]
static

Definition at line 42 of file tabinit.c.

◆ cos64

real cos64[16]
static

Definition at line 42 of file tabinit.c.

◆ cos8

real cos8[2]
static

Definition at line 42 of file tabinit.c.

◆ intwinbase

long intwinbase[]
static
Initial value:
= {
0, -1, -1, -1, -1, -1, -1, -2, -2, -2,
-2, -3, -3, -4, -4, -5, -5, -6, -7, -7,
-8, -9, -10, -11, -13, -14, -16, -17, -19, -21,
-24, -26, -29, -31, -35, -38, -41, -45, -49, -53,
-58, -63, -68, -73, -79, -85, -91, -97, -104, -111,
-117, -125, -132, -139, -147, -154, -161, -169, -176, -183,
-190, -196, -202, -208, -213, -218, -222, -225, -227, -228,
-228, -227, -224, -221, -215, -208, -200, -189, -177, -163,
-146, -127, -106, -83, -57, -29, 2, 36, 72, 111,
153, 197, 244, 294, 347, 401, 459, 519, 581, 645,
711, 779, 848, 919, 991, 1064, 1137, 1210, 1283, 1356,
1428, 1498, 1567, 1634, 1698, 1759, 1817, 1870, 1919, 1962,
2001, 2032, 2057, 2075, 2085, 2087, 2080, 2063, 2037, 2000,
1952, 1893, 1822, 1739, 1644, 1535, 1414, 1280, 1131, 970,
794, 605, 402, 185, -45, -288, -545, -814, -1095, -1388,
-1692, -2006, -2330, -2663, -3004, -3351, -3705, -4063, -4425, -4788,
-5153, -5517, -5879, -6237, -6589, -6935, -7271, -7597, -7910, -8209,
-8491, -8755, -8998, -9219, -9416, -9585, -9727, -9838, -9916, -9959,
-9966, -9935, -9863, -9750, -9592, -9389, -9139, -8840, -8492, -8092,
-7640, -7134, -6574, -5959, -5288, -4561, -3776, -2935, -2037, -1082,
-70, 998, 2122, 3300, 4533, 5818, 7154, 8540, 9975, 11455,
12980, 14548, 16155, 17799, 19478, 21189, 22929, 24694, 26482, 28289,
30112, 31947, 33791, 35640, 37489, 39336, 41176, 43006, 44821, 46617,
48390, 50137, 51853, 53534, 55178, 56778, 58333, 59838, 61289, 62684,
64019, 65290, 66494, 67629, 68692, 69679, 70590, 71420, 72169, 72835,
73415, 73908, 74313, 74630, 74856, 74992, 75038 }

Definition at line 48 of file tabinit.c.

Referenced by make_decode_tables().

◆ pnts

real* pnts[] = { cos64,cos32,cos16,cos8,cos4 }

Definition at line 45 of file tabinit.c.

Referenced by prepare_decode_tables().