1
/* Copyright (C) Andree Buschmann and Frank Klemm
2
* Modified Raphael MARINIER
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
//// Macros typical for Compilers:
21
// __TURBOC__ Turbo-C, Borland-C
22
// __BORLANDC__ Borland-C
24
// _MSC_VER Microsoft-C
25
// __EMX__ Eberhard Mattes EMX (GNU based)
26
// __GNUC__ GNU C based compiler (also Cygwin)
27
// __CYGWIN__ Cygnus Windows C-Compiler (GNU based)
30
//// Macros typical for Operating Systems
34
// __FreeBSD__ FreeBSD
36
// __OpenBSD__ OpenBSD
37
// __unix__ Unix ????????
38
// _WIN16 16 bit-Windows
39
// _WIN32 32 bit-Windows (WIN32 is wrong, not defined by not MSC) (also __GNUC__ + _WIN32 is possible)
42
// ??????? MS-DOS and relatives
45
//// Macros typical for special conformances
46
// System 5 Release 4 (SVr4)
56
// Makros zum Manipulieren von Sockets + Files in einem rein (+0x4000)
57
// Zeiten wieder raus TIME/TIME_T/DTIME
59
#ifndef MPPDEC_MPPDEC_H
60
#define MPPDEC_MPPDEC_H
62
//// optimization/feature defines //////////////////////////////////
63
/*#ifndef NOT_INCLUDE_CONFIG_H
69
//// portable system includes //////////////////////////////////////
79
//// system dependent system includes //////////////////////////////
80
// low level I/O, where are prototypes and constants?
81
#if defined _WIN32 || defined __TURBOC__ || defined __ZTC__ || defined _MSC_VER
85
# include <sys/types.h>
86
# include <sys/stat.h>
87
#elif defined __unix__ || defined __linux__
90
# include <sys/time.h>
91
# include <sys/ioctl.h>
92
# include <sys/types.h>
93
# include <sys/stat.h>
95
// .... hier Includes f�r neues Betriebssystem einf�gen (mit vorgestellten: #elif defined)
98
# include <sys/ioctl.h>
99
# include <sys/stat.h>
103
#if defined __linux__
104
# include <fpu_control.h>
105
#elif defined __FreeBSD__
106
# include <machine/floatingpoint.h>
107
#elif defined _MSC_VER
113
# undef USE_OSS_AUDIO
114
# undef USE_ESD_AUDIO
115
# undef USE_SUN_AUDIO
117
# undef USE_WIN_AUDIO
120
#if defined __TURBOC__
121
# undef USE_OSS_AUDIO
122
# undef USE_ESD_AUDIO
123
# undef USE_SUN_AUDIO
128
#if defined MAKE_32BIT_FPU
129
# undef USE_OSS_AUDIO
130
# undef USE_ESD_AUDIO
131
# undef USE_SUN_AUDIO
134
#if defined USE_DIET || defined MAKE_24BIT || defined MAKE_32BIT || defined MAKE_32BIT_FPU
135
# undef USE_ESD_AUDIO
138
#if defined MAKE_16BIT || defined MAKE_24BIT || defined MAKE_32BIT || defined MAKE_32BIT_FPU
142
#if INT_MAX < 2147483647L
147
#if defined USE_OSS_AUDIO
148
# include <sys/ioctl.h>
149
# include <sys/time.h>
150
# if defined __linux__
151
# include <linux/soundcard.h>
152
# elif defined __bsdi__
153
# include <sys/soundcard.h>
154
# elif defined __FreeBSD__
155
# include <machine/soundcard.h>
156
# elif defined __NetBSD__ || defined __OpenBSD__
157
# include <soundcard.h>
159
# include <soundcard.h>
161
#endif /* USE_OSS_AUDIO */
163
#if defined USE_ESD_AUDIO
168
#if defined USE_SUN_AUDIO
169
# include <sys/audioio.h>
178
# include <winsock2.h>
180
# include <sys/socket.h>
184
#if defined USE_WIN_AUDIO
185
# include <windows.h>
186
# define WINAUDIO_FD ((FILE_T)-128)
187
#elif defined USE_IRIX_AUDIO
188
# define IRIXAUDIO_FD ((FILE_T)-127)
190
#define NULL_FD ((FILE_T)-126)
192
#if defined USE_NICE && !defined _WIN32
193
# include <sys/resource.h>
197
#if defined USE_REALTIME && !defined _WIN32
204
# define O_BINARY _O_BINARY
210
#if defined _WIN32 || defined __TURBOC__
211
# define strncasecmp(__s1,__s2,__n) strnicmp ((__s1), (__s2), (__n))
212
# define strcasecmp(__s1,__s2) stricmp ((__s1), (__s2))
213
# define MKDIR(__dir,__attr) mkdir ((__dir))
215
# define MKDIR(__dir,__attr) mkdir ((__dir), (__attr))
220
# define snprintf _snprintf
221
# define getcwd(__buff,__len) _getcwd ((__buff), (__len))
222
# define sleep(__sec) Sleep ((__sec) * 1000)
227
# define TIME(__x) time ( &(__x) )
228
# define DTIME(__x,__y) ( (double)(__y) - (__x) )
230
# define TIME_T struct timeval
231
# define TIME(__x) gettimeofday ( &(__x), NULL )
232
# define DTIME(__x,__y) ( ((double)(__y).tv_sec - (__x).tv_sec) + 1.e-6 * ((double)(__y).tv_usec - (__x).tv_usec) )
236
# define inline __inline__
239
# define inline __inline
249
//// Binary/Low-Level-IO ///////////////////////////////////////////
251
// All file I/O is basicly handled via an ANSI file pointer (type: FILE*) in
252
// FILEIO-Mode 1 and via a POSIX file descriptor (type: int) in
253
// FILEIO-Mode 2 and 3.
255
// Some operation are only available via the POSIX interface (fcntl, setmode,
256
// ...) so we need a function to get the file descriptor from a file pointer.
257
// In FILEIO-Mode 2 and 3 this is a dummy function because we always working
258
// with this file descriptors.
262
# if defined __BORLANDC__ || defined _WIN32
263
# define FILENO(__fp) _fileno ((__fp))
264
# elif defined __CYGWIN__ || defined __TURBOC__ || defined __unix__ || defined __EMX__ || defined _MSC_VER
265
# define FILENO(__fp) fileno ((__fp))
267
# define FILENO(__fp) fileno ((__fp))
270
# define FILENO(__fd) (__fd)
275
// If we have access to a file via file name, we can open the file with an
276
// additional "b" or a O_BINARY within the (f)open function to get a
277
// transparent untranslated data stream which is necessary for audio bitstream
278
// data and also for PCM data. If we are working with
279
// stdin/stdout/FILENO_STDIN/FILENO_STDOUT we can't open the file with this
280
// attributes, because the files are already open. So we need a non
281
// standardized sequence to switch to this mode (not necessary for Unix).
282
// Mostly the sequency is the same for incoming and outgoing streams, but only
283
// mostly so we need one for IN and one for OUT.
284
// Macros are called with the file pointer and you get back the untransalted file
285
// pointer which can be equal or different from the original.
289
# define SETBINARY_IN(__fp) (_fsetmode ( (__fp), "b" ), (__fp))
290
# define SETBINARY_OUT(__fp) (_fsetmode ( (__fp), "b" ), (__fp))
291
#elif defined __TURBOC__ || defined __BORLANDC__
292
# define SETBINARY_IN(__fp) (setmode ( FILENO ((__fp)), O_BINARY ), (__fp))
293
# define SETBINARY_OUT(__fp) (setmode ( FILENO ((__fp)), O_BINARY ), (__fp))
294
#elif defined __CYGWIN__
295
# define SETBINARY_IN(__fp) (setmode ( FILENO ((__fp)), _O_BINARY ), (__fp))
296
# define SETBINARY_OUT(__fp) (setmode ( FILENO ((__fp)), _O_BINARY ), (__fp))
298
# define SETBINARY_IN(__fp) (_setmode ( FILENO ((__fp)), _O_BINARY ), (__fp))
299
# define SETBINARY_OUT(__fp) (_setmode ( FILENO ((__fp)), _O_BINARY ), (__fp))
300
#elif defined _MSC_VER
301
# define SETBINARY_IN(__fp) (setmode ( FILENO ((__fp)), O_BINARY ), (__fp))
302
# define SETBINARY_OUT(__fp) (setmode ( FILENO ((__fp)), O_BINARY ), (__fp))
303
#elif defined __unix__
304
# define SETBINARY_IN(__fp) (__fp)
305
# define SETBINARY_OUT(__fp) (__fp)
307
# define SETBINARY_IN(__fp) (freopen ( NULL, "rb", (__fp) ), (__fp))
308
# define SETBINARY_OUT(__fp) (freopen ( NULL, "wb", (__fp) ), (__fp))
310
# define SETBINARY_IN(__fp) (__fp)
311
# define SETBINARY_OUT(__fp) (__fp)
314
// file I/O using ANSI buffered file I/O via file pointer FILE* (fopen, fread, fwrite, fclose)
316
# define OFF_T signed long
317
# define FILE_T FILE*
318
# define OPEN(name) fopen (name, "rb" )
319
# define OPENRW(name) fopen (name, "r+b")
320
# define CREATE(name) fopen (name, "wb" )
321
# define INVALID_FILEDESC NULL
322
# define CLOSE(fp) fclose (fp) // CLOSE returns -1 on error, otherwise 0
323
# define READ(fp,ptr,len) fread (ptr, 1, len, fp) // READ returns -1 or 0 on error/EOF, otherwise > 0
324
# define READ1(fp,ptr) fread (ptr, 1, 1, fp) // READ returns -1 or 0 on error/EOF, otherwise > 0
325
# define WRITE(fp,ptr,len) fwrite (ptr, 1, len, fp) // WRITE returns -1 or 0 on error/EOF, otherwise > 0
326
# define SEEK(fp,offs,lbl) fseek (fp, offs, lbl) // SEEK returns -1 on error, otherwise >= 0
327
# define FILEPOS(fp) ftell (fp) // FILEPOS returns -1 on error, otherwise >= 0
329
# define STDOUT stdout
330
# define STDERR stderr
331
# define FDOPEN(fd,mode) fdopen (fd, mode)
332
# define FLUSH(fp) fflush (fp)
333
# define FEOF(fp) feof (fp)
334
#endif /* FILEIO==1 */
336
// file I/O using POSIX unbuffered file I/O via file descriptors (open, read, write, close)
339
# define OFF_T _off_t
344
# define OPEN(name) open (name, O_RDONLY|O_BINARY)
345
# define OPENRW(name) open (name, O_RDWR |O_BINARY)
346
# define CREATE(name) open (name, O_WRONLY|O_BINARY|O_TRUNC|O_CREAT, 0644)
347
# define INVALID_FILEDESC (-1)
348
# define CLOSE(fd) close (fd) // CLOSE returns -1 on error, otherwise 0
349
# if defined HAVE_INCOMPLETE_READ
350
# define READ(fd,ptr,len) complete_read (fd, ptr, len) // READ returns -1 or 0 on error/EOF, otherwise > 0
352
# define READ(fd,ptr,len) (size_t)read (fd, ptr, len)// READ returns -1 or 0 on error/EOF, otherwise > 0
354
# define READ1(fd,ptr) (size_t)read (fd, ptr, 1) // READ returns -1 or 0 on error/EOF, otherwise > 0
355
# define WRITE(fd,ptr,len) (size_t)write (fd, ptr, len)// WRITE returns -1 or 0 on error/EOF, otherwise > 0
356
# define SEEK(fd,offs,lbl) lseek (fd, offs, lbl) // SEEK returns -1 on error, otherwise >= 0
357
# define FILEPOS(fd) lseek (fd, 0L, SEEK_CUR) // FILEPOS returns -1 on error, otherwise >= 0
361
# define FDOPEN(fd,mode) (fd)
362
# define FLUSH(fd) (void)(fd)
364
# define FEOF(fd) _eof (fd)
366
# define FEOF(fd) ((void)fd,0)
368
#endif /* FILEIO==2 */
370
// file I/O using Turbo-C lowest level unbuffered file I/O via file descriptors (_open, _read, _write, _close)
372
# define OFF_T signed long
374
# define OPEN(name) _open (name, O_RDONLY)
375
# define OPENRW(name) _open (name, O_RDWR )
376
# define CREATE(name) _creat(name, 0)
377
# define INVALID_FILEDESC (-1)
378
# define CLOSE(fd) _close (fd) // CLOSE returns -1 on error, otherwise 0
379
# define READ(fd,ptr,len) (size_t)_read (fd, ptr, len)// READ returns -1 or 0 on error/EOF, otherwise > 0
380
# define READ1(fd,ptr) (size_t)_read (fd, ptr, 1) // READ returns -1 or 0 on error/EOF, otherwise > 0
381
# define WRITE(fd,ptr,len) (size_t)_write (fd, ptr, len)// WRITE returns -1 or 0 on error/EOF, otherwise > 0
382
# define SEEK(fd,offs,lbl) lseek (fd, offs, lbl) // SEEK returns -1 on error, otherwise >= 0
383
# define FILEPOS(fd) lseek (fd, 0L, SEEK_CUR) // FILEPOS returns -1 on error, otherwise >= 0
388
# undef SETBINARY_OUT
389
# define SETBINARY_IN(fd) (fd)
390
# define SETBINARY_OUT(fd) (fd)
391
# define FDOPEN(fd,mode) (fd)
392
# define FLUSH(fd) (void)(fd)
393
# define FEOF(fd) ((void)fd,0)
394
#endif /* FILEIO==3 */
397
#if FILEIO != 2 && defined USE_HTTP
398
# error HTTP can only be used by FILEIO==2
401
#if defined _WIN32 || defined __BEOS__
402
# define WRITE_SOCKET(sock,ptr,len) send (sock, ptr, len, 0)
403
# define READ_SOCKET(sock,ptr,len) recv (sock, ptr, len, 0)
405
# define WRITE_SOCKET(sock,ptr,len) write (sock, ptr, len)
406
# define READ_SOCKET(sock,ptr,len) read (sock, ptr, len)
410
# define POPEN_READ_BINARY_OPEN(cmd) _popen ((cmd), "rb")
411
# define POPEN_WRITE_BINARY_OPEN(cmd) _popen ((cmd), "wb")
412
# define PCLOSE(fp) _pclose(fp)
414
# define POPEN_READ_BINARY_OPEN(cmd) popen ((cmd), "r")
415
# define POPEN_WRITE_BINARY_OPEN(cmd) popen ((cmd), "w")
416
# define PCLOSE(fp) pclose(fp)
419
#if defined __unix__ || defined __bsdi__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__ || defined __TURBOC__ || defined _WIN32
420
# define ISATTY(fd) isatty (fd)
422
# define ISATTY(fd) 0
426
#if defined __unix__ || defined __bsdi__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__
427
# define PATH_SEP '/'
428
# define DRIVE_SEP '\0'
430
# define DEV_NULL "/dev/null"
431
# define ENVPATH_SEP ':'
432
#elif defined _WIN32 || defined __TURBOC__ || defined __ZTC__ || defined _MSC_VER
433
# define PATH_SEP '\\'
434
# define DRIVE_SEP ':'
435
# define EXE_EXT ".exe"
436
# define DEV_NULL "\\nul"
437
# define ENVPATH_SEP ';'
439
# define PATH_SEP '/' // Amiga: C:/
440
# define DRIVE_SEP ':'
442
# define DEV_NULL "nul"
443
# define ENVPATH_SEP ';'
447
// maximum length of file names
449
# if defined FILENAME_MAX
450
# define PATHLEN_MAX FILENAME_MAX
451
# elif INT_MAX < 2147483647L
452
# define PATHLEN_MAX 128
454
# define PATHLEN_MAX 1024
456
#endif /* !PATHLEN_MAX */
459
# define TitleBar(text) SetConsoleTitle (text)
461
# define TitleBar(text) (void) (text)
465
#define SPEAKER_FRONT_LEFT 0x00000001
466
#define SPEAKER_FRONT_RIGHT 0x00000002
467
#define SPEAKER_FRONT_CENTER 0x00000004
468
#define SPEAKER_LOW_FREQUENCY 0x00000008
469
#define SPEAKER_BACK_LEFT 0x00000010
470
#define SPEAKER_BACK_RIGHT 0x00000020
471
#define SPEAKER_FRONT_LEFT_OF_CENTER 0x00000040
472
#define SPEAKER_FRONT_RIGHT_OF_CENTER 0x00000080
473
#define SPEAKER_BACK_CENTER 0x00000100
474
#define SPEAKER_SIDE_LEFT 0x00000200
475
#define SPEAKER_SIDE_RIGHT 0x00000400
476
#define SPEAKER_TOP_CENTER 0x00000800
477
#define SPEAKER_TOP_FRONT_LEFT 0x00001000
478
#define SPEAKER_TOP_FRONT_CENTER 0x00002000
479
#define SPEAKER_TOP_FRONT_RIGHT 0x00004000
480
#define SPEAKER_TOP_BACK_LEFT 0x00008000
481
#define SPEAKER_TOP_BACK_CENTER 0x00010000
482
#define SPEAKER_TOP_BACK_RIGHT 0x00020000
483
#define SPEAKER_RESERVED 0x80000000
487
//// constants /////////////////////////////////////////////////////
493
# define MAX_SV "SV8"
495
# define MAX_SV "SV7"
499
# define BUILD "3DNow/SSE"
505
#define COPYRIGHT "(C) 1999-2003 Buschmann/Klemm/Piecha/Wolf"
507
#define DECODER_DELAY (512 - 32 + 1)
508
#define BLK_SIZE (36 * 32)
511
//// logging defines, for development only /////////////////////////
512
#if defined _WIN32 || defined __TURBOC__
513
# define LOGPATH ".\\"
514
# define MUSICPATH "D:\\AUDIO\\"
516
# define LOGPATH "./"
517
# define MUSICPATH "/Archive/Audio/"
519
#define _(x) (void)(fprintf(stderr,"<%d>\n",(x)),fflush(stderr))
522
# define REP(x) (void)(x)
528
//// numerical constants ///////////////////////////////////////////
529
#define C00 (Float) 0.500000000000000000000000L // Cxx = 0.5 / cos (xx*M_PI/64)
530
#define C01 (Float) 0.500602998235196301334178L
531
#define C02 (Float) 0.502419286188155705518560L
532
#define C03 (Float) 0.505470959897543659956626L
533
#define C04 (Float) 0.509795579104159168925062L
534
#define C05 (Float) 0.515447309922624546962323L
535
#define C06 (Float) 0.522498614939688880640101L
536
#define C07 (Float) 0.531042591089784174473998L
537
#define C08 (Float) 0.541196100146196984405269L
538
#define C09 (Float) 0.553103896034444527838540L
539
#define C10 (Float) 0.566944034816357703685831L
540
#define C11 (Float) 0.582934968206133873665654L
541
#define C12 (Float) 0.601344886935045280535340L
542
#define C13 (Float) 0.622504123035664816182728L
543
#define C14 (Float) 0.646821783359990129535794L
544
#define C15 (Float) 0.674808341455005746033820L
545
#define C16 (Float) 0.707106781186547524436104L
546
#define C17 (Float) 0.744536271002298449773679L
547
#define C18 (Float) 0.788154623451250224773056L
548
#define C19 (Float) 0.839349645415527038721463L
549
#define C20 (Float) 0.899976223136415704611808L
550
#define C21 (Float) 0.972568237861960693780520L
551
#define C22 (Float) 1.060677685990347471323668L
552
#define C23 (Float) 1.169439933432884955134476L
553
#define C24 (Float) 1.306562964876376527851784L
554
#define C25 (Float) 1.484164616314166277319733L
555
#define C26 (Float) 1.722447098238333927796261L
556
#define C27 (Float) 2.057781009953411550808880L
557
#define C28 (Float) 2.562915447741506178719328L
558
#define C29 (Float) 3.407608418468718785698107L
559
#define C30 (Float) 5.101148618689163857960189L
560
#define C31 (Float)10.190008123548056810994678L
562
#define SS05 (Float) 0.840896415253714543018917L // 0.5^0.25
566
# define M_PI 3.1415926535897932384626433832795029 // 4*atan(1)
567
# define M_PIl 3.1415926535897932384626433832795029L
568
# define M_LN2 0.6931471805599453094172321214581766 // ln(2)
569
# define M_LN2l 0.6931471805599453094172321214581766L
570
# define M_LN10 2.3025850929940456840179914546843642 // ln 10 */
571
# define M_LN10l 2.3025850929940456840179914546843642L
575
//// 'Cdecl' forces to use standard C/C++ calling convention ///////
577
# define Cdecl __cdecl
578
#elif defined __ZTC__
579
# define Cdecl _cdecl
580
#elif defined __TURBOC__
586
//// expect handling of GCC ////////////////////////////////////////
589
# define __builtin_expect(cond,exp) (cond)
591
# define expect(cond,exp) __builtin_expect(cond,exp)
595
# define expect(cond,exp) __builtin_expect(cond,exp)
599
# define __builtin_expect(cond,exp) (cond)
601
# define expect(cond,exp) __builtin_expect(cond,exp)
605
#define if0(x) if (expect(x,0))
606
#define if1(x) if (expect(x,1))
607
#define while0(x) while (expect(x,0))
608
#define while1(x) while (expect(x,1))
611
# define __attribute__(x)
613
# define __attribute__(x)
616
//// Remaining macros //////////////////////////////////////////////
617
// selects input buffer size and some constants needed for input buffer handling
618
#ifndef IBUFLOG2 // must be at least 10 (bitrate always <626 kbps) or better 11 ( <1253 kbps)
619
# if INT_MAX < 2147483647L
620
# define IBUFLOG2 11 // 8 KByte buffer, possible 11...13 (32 KByte limit)
622
# define IBUFLOG2 21 // 8 MByte buffer, possible 11...29 ( 2 GByte limit)
625
#define IBUFSIZE ((size_t)(1LU<<(IBUFLOG2)))
626
#define IBUFSIZE2 ((size_t)((IBUFSIZE)/2))
627
#define IBUFMASK ((size_t)((IBUFSIZE)-1))
629
// save memory space for 16 bit compiler (data + stack < 64 KByte)
630
#if INT_MAX < 2147483647L
633
# define VIRT_SHIFT 6
639
# define USE_HUFF_PACK
640
# define USE_ARRAY_PACK
643
// generate a macro which contains information about compile time settings
644
#define STR(x) _STR(x)
649
# define _T1 "DEBUG "
651
#if defined USE_OSS_AUDIO || defined USE_ESD_AUDIO || defined USE_SUN_AUDIO || defined USE_WIN_AUDIO
661
#if defined USE_REALTIME
666
#ifdef HAVE_IEEE754_FLOAT
671
#define _T6 "IO=" STR(FILEIO) " "
673
# define _T7 "H-PCK "
677
#ifdef USE_ARRAY_PACK
678
# define _T8 "A-PCK "
682
#define _T9 "SHFT=" STR(VIRT_SHIFT) " "
683
#define _T10 "IBUF=" STR(IBUFLOG2) " "
685
#define COMPILER_FLAGS _T1 _T2 _T3 _T4 _T5 _T6 _T7 _T8 _T9 _T10
687
// align a pointer by maybe incrementing it
688
#define ALIGN(ptr,alignment) \
689
(void*)((((ptrdiff_t)(ptr)) & (-(ptrdiff_t)(alignment))) + (alignment)) // alignt einen Zeiger mit alignment, das Quellarray sollte mindestens alignment-1 Bytes l�nger als die erforderliche L�nge sein
692
//// Simple types //////////////////////////////////////////////////
694
#if CHAR_BIT == 8 && SCHAR_MAX == 127L
695
typedef unsigned char Uint8_t; // guaranteed 8 bit unsigned integer type with range 0...255
696
typedef signed char Int8_t; // guaranteed 8 bit signed integer type with range -128...127
698
# error No 8 bit int type found. Tested: char
701
#if SHRT_MAX == 32767L
702
typedef unsigned short int Uint16_t; // guaranteed 16 bit unsigned integer type with range 0...65535
703
typedef signed short int Int16_t; // guaranteed 16 bit signed integer type with range -32768...32767
705
# error No 16 bit int type found. Tested: short
708
#if INT_MAX == 2147483647L
709
typedef unsigned int Uint32_t; // guaranteed 32 bit unsigned integer type with range 0...4294967295
710
typedef signed int Int32_t; // guaranteed 32 bit signed integer type with range -2147483648...2147483647
711
#elif LONG_MAX == 2147483647L
712
typedef unsigned long int Uint32_t; // guaranteed 32 bit unsigned integer type with range 0...4294967295
713
typedef signed long int Int32_t; // guaranteed 32 bit signed integer type with range -2147483648...2147483647
715
# error No 32 bit int type found. Tested: int, long
718
#if defined __C99__ // C9x has a type which is exact 64 bit
719
typedef int64_t Int64_t;
720
typedef uint64_t Uint64_t;
721
#elif defined __GNUC__ // GCC uses long long as 64 bit
722
typedef signed long long Int64_t;
723
typedef unsigned long long Uint64_t;
724
#elif defined LLONG_MAX // long long (when existing) is normally 64 bit
725
typedef signed long long Int64_t;
726
typedef unsigned long long Uint64_t;
727
#elif LONG_MAX > 0xFFFFFFFFLU // long is longer than 33 bit, assume 64 bit
728
typedef signed long Int64_t;
729
typedef unsigned long Uint64_t;
730
#elif defined _WIN32 // Microsoft and Intel call it __int64
731
typedef signed __int64 Int64_t;
732
typedef unsigned __int64 Uint64_t;
734
# define NO_INT64_T // no type mapped to 64 bit integer
738
#if defined _WIN32 && !defined __GNUC__ && !defined __C99__
739
typedef signed long ssize_t;
742
#ifdef USE_ARRAY_PACK
743
typedef signed char Bool_t; // ==0: false, !=0: true
745
typedef signed int Bool_t; // ==0: false, !=0: true
747
typedef Uint32_t Ibuf_t; // type for input buffer, currently this type must be 32 bit
748
typedef signed char Schar; // at least -127...+127
749
typedef unsigned char Uchar; // at least 0...255
750
typedef signed short int Short; // at least -32767...+32767, memory economic type
751
typedef unsigned short int Ushort; // at least 0...65535, memory economic type
752
typedef signed int Int; // at least -32767...+32767, fast type
753
typedef unsigned int Uint; // at least 0...65535, fast type
754
typedef signed long int Long; // at least -2147483647...+2147483647, but more is better
755
typedef unsigned long int Ulong; // at least 0...4294967295, but more is better
756
// size_t; // size of memory objects
757
// ptrdiff_t; // pointer differences, may be larger than size_t
758
typedef float Float32_t; // guaranteed 32 bit floating point type
759
typedef double Float64_t; // guaranteed 64 bit floating point type
760
typedef float Float; // fastest floating point type, memory economic (used for all PCM calculations)
761
#define SIZEOF_Float 4 // size of the type 'Float' in sizeof units
762
typedef double Double; // floating point with extended precision (more than 32 bit mantissa)
763
typedef long double Ldouble; // most exact floating point format
765
#if defined MAKE_16BIT || defined MAKE_24BIT || defined MAKE_32BIT
767
# error No 64 bit int type found, needed for HQ 16...32 bit output
769
typedef Int32_t IntSample_t;
770
# if defined MAKE_32BIT
771
# define SAMPLE_SIZE 32
772
# define PROG_NAME "mppdec32"
773
# define SAMPLE_SIZE_STRING " (32 bit HQ)"
774
# define Write_PCM(fd,p,b) Write_PCM_HQ_32bit ( fd, p, b )
775
# define Synthese_Filter(Stream,offset,Vi,Yi,chs,ch) \
776
Synthese_Filter_32_C ( Stream, offset, Vi, Yi, chs, ch )
777
# undef USE_ESD_AUDIO
778
# elif defined MAKE_24BIT
779
# define SAMPLE_SIZE 24
780
# define PROG_NAME "mppdec24"
781
# define SAMPLE_SIZE_STRING " (24 bit HQ)"
782
# define Write_PCM(fd,p,b) Write_PCM_HQ_24bit ( fd, p, b )
783
# define Synthese_Filter(Stream,offset,Vi,Yi,chs,ch) \
784
Synthese_Filter_32_C ( Stream, offset, Vi, Yi, chs, ch )
785
# undef USE_ESD_AUDIO
786
# elif defined MAKE_16BIT
787
# define SAMPLE_SIZE 16
788
# define PROG_NAME "mppdec16"
789
# define SAMPLE_SIZE_STRING " (16 bit HQ)"
790
# define Write_PCM(fd,p,b) Write_PCM_HQ_16bit ( fd, p, b )
791
# define Synthese_Filter(Stream,offset,Vi,Yi,chs,ch) \
792
Synthese_Filter_32_C ( Stream, offset, Vi, Yi, chs, ch )
794
#elif defined MAKE_32BIT_FPU
795
typedef Float32_t IntSample_t;
796
# define SAMPLE_SIZE 32
797
# define PROG_NAME "mppdec32FP"
798
# define SAMPLE_SIZE_STRING " (32 bit FP)"
799
# define Write_PCM(fd,p,b) Write_PCM_32bit ( fd, p, b )
800
# define Synthese_Filter(Stream,offset,Vi,Yi,chs,ch) \
801
Synthese_Filter_32FP_C ( Stream, offset, Vi, Yi, chs )
803
typedef Int16_t IntSample_t;
804
# define SAMPLE_SIZE 16
805
# define PROG_NAME "mppdec"
806
# define SAMPLE_SIZE_STRING ""
807
# define Write_PCM(fd,p,b) Write_PCM_16bit ( fd, p, b )
809
# define Synthese_Filter(Stream,offset,Vi,Yi,chs,ch) \
810
Synthese_Filter_16 ( Stream, offset, Vi, Yi, chs )
812
# define Synthese_Filter(Stream,offset,Vi,Yi,chs,ch) \
813
Synthese_Filter_16_C ( Stream, offset, Vi, Yi, chs )
814
# endif /* USE_ASM */
818
//// More complex types ////////////////////////////////////////////
820
typedef Int quant_t ;
821
#ifdef USE_ARRAY_PACK
822
typedef Schar scf_t ;
823
typedef Schar res_t ;
824
typedef Uchar pack_t;
833
Uint32_t Code; // >=32 bit
834
# ifdef USE_HUFF_PACK
835
Schar Value; // >= 7 bit
836
Uchar Length; // >= 4 bit
842
# ifdef USE_HUFF_PACK
843
Uint8_t Length; // >= 4 bit
845
Uint16_t Code; // >= 14 bit
854
Uint Code : 16; // >= 14 bit
855
Uint Length : 8; // >= 4 bit
871
typedef void (*SyntheseFilter16_t) ( Int16_t* Stream, Int* const offset, Float* Vi, const Float Yi[36][32], Uint channels );
872
typedef void (*SyntheseFilter32_t) ( Int32_t* Stream, Int* const offset, Float* Vi, const Float Yi[36][32], Uint channels, Uint ch );
873
typedef Int (*HeaderWriter_t) ( FILE_T outputFile, Ldouble SampleFreq, Uint BitsPerSample, Uint Channels, Double SamplesPerChannel );
875
#if defined MAKE_16BIT || defined MAKE_24BIT || defined MAKE_32BIT
877
const Float* FilterCoeff;
884
Float ErrorHistory [MAXCH] [16]; // max. 2 channels, 16th order Noise shaping
885
Float DitherHistory [MAXCH] [16];
886
Int32_t LastRandomNumber [MAXCH];
896
//// Variables /////////////////////////////////////////////////////
899
extern Ibuf_t InputBuff [IBUFSIZE]; // Lesebuffer f�r den MP+-Datenstrom
900
extern size_t InputCnt; // aktueller Offset in diesem Buffer
903
extern Huffman_t HuffHdr [10];
904
extern Huffman_t HuffSCFI [ 4];
905
extern Huffman_t HuffDSCF [16];
906
extern Huffman_t HuffQ1 [2] [ 3*3*3];
907
extern Huffman_t HuffQ2 [2] [ 5*5];
908
extern Huffman_t HuffQ3 [2] [ 7];
909
extern Huffman_t HuffN3 [2] [ 7*7];
910
extern Huffman_t HuffQ4 [2] [ 9];
911
extern Huffman_t HuffQ5 [2] [15];
912
extern Huffman_t HuffQ6 [2] [31];
913
extern Huffman_t HuffQ7 [2] [63];
914
extern Huffman_t HuffN8 [2][127];
915
extern const Huffman_t* HuffQ [2] [ 8];
916
extern const Huffman_t* HuffN [2] [ 9];
917
extern Uint8_t LUT1_0 [1<< 6];
918
extern Uint8_t LUT1_1 [1<< 9];
919
extern Uint8_t LUT2_0 [1<< 7];
920
extern Uint8_t LUT2_1 [1<<10];
921
extern Uint8_t LUT3_0 [1<< 4];
922
extern Uint8_t LUT3_1 [1<< 5];
923
extern Uint8_t LUT4_0 [1<< 4];
924
extern Uint8_t LUT4_1 [1<< 5];
925
extern Uint8_t LUT5_0 [1<< 6];
926
extern Uint8_t LUT5_1 [1<< 8];
927
extern Uint8_t LUT6_0 [1<< 7];
928
extern Uint8_t LUT6_1 [1<< 7];
929
extern Uint8_t LUT7_0 [1<< 8];
930
extern Uint8_t LUT7_1 [1<< 8];
931
extern Uint8_t LUTDSCF [1<< 6];
934
extern const Huffman_t* Entropie [18];
935
extern const Huffman_t* Region [32];
936
extern Huffman_t SCFI_Bundle [ 8];
937
extern Huffman_t DSCF_Entropie [13];
940
extern Float YY [MAXCH] [36] [32];
941
extern scf_t SCF_Index[MAXCH] [32] [ 3]; // Skalierungsfaktor
942
extern res_t Res [MAXCH] [32]; // Aufl�sungsstufen der Teilb�nder
943
extern quant_t QQ [MAXCH] [32] [36]; // quantisierte Samples
944
extern Bool_t MS_Band [32]; // subbandweiser Flag f�r M/S-Signalf�hrung
945
extern Bool_t MS_used; // globaler Flag f�r M/S-Signalf�hrung
946
extern Bool_t IS_used;
947
extern Uint DUMPSELECT;
951
extern Bool_t output_endianess;
952
#if defined HAVE_LITTLE_ENDIAN
953
# define machine_endianess LITTLE
954
#elif defined HAVE_BIG_ENDIAN
955
# define machine_endianess BIG
959
extern Float __SCF [8 + 128]; // tabellierte Skalenfaktoren von -8 bis +127
960
#define SCF ( __SCF + 8 )
961
extern Int8_t Q_bit [32]; // Anzahl Bits f�r Speicherung der Aufl�sung (SV6)
962
extern Int8_t Q_res [32] [16]; // Index -> Aufl�sung (SV6)
965
extern Float __Cc7 [1 + 18];
966
extern const Uint __Dc7 [1 + 18];
967
#define Cc7 ( __Cc7 + 1 )
968
#define Dc7 ( __Dc7 + 1 )
969
extern Float Cc8 [20];
970
extern const Uint Dc8 [20];
973
extern const Float Cos64 [32];
974
extern const Float Di_opt [32] [16];
977
extern Bool_t stderr_silent;
980
//// procedures/functions //////////////////////////////////////////
982
Bool_t Cdecl Has_MMX ( void );
983
Bool_t Cdecl Has_SIMD ( void );
984
Bool_t Cdecl Has_SIMD2 ( void );
985
Bool_t Cdecl Has_3DNow ( void );
988
void Bitstream_init ( void );
989
Ulong BitsRead ( void );
990
Uint32_t Bitstream_read ( Int bits );
991
Uint32_t Bitstream_peek ( Uint pos, Int bits );
992
void Bitstream_skip ( Uint bits );
993
Uint32_t Bitstream_preview ( Int bits ); // dto., aber Daten werden noch nicht abquitiert
994
int Read_Bitstream ( Uint StreamVersion, Uint channels );
997
int IsDirectory ( const char* path );
1000
int http_open ( const char* URL );
1003
void Init_Huffman_Decoder_SV7 ( void );
1004
void Init_Huffman_Encoder_SV7 ( void );
1007
void Init_Huffman_Decoder_SV4_6 ( void );
1010
Int Read_ID3V1_Tags ( FILE_T fp, TagInfo_t* tip );
1011
Int Read_APE_Tags ( FILE_T fp, TagInfo_t* tip );
1013
// codetable_enc.c/codetable_dec.c
1014
void Init_Decoder_Huffman_Tables ( void );
1015
void Init_Encoder_Huffman_Tables ( void );
1018
void Init_QuantTab ( Int maximum_Band, Bool_t used_IS, Double amplification, Uint StreamVersion );
1021
Uint32_t random_int ( void );
1023
void Cdecl Calculate_New_V_i387 ( const Float* Sample, Float* V );
1024
void Cdecl Calculate_New_V_3DNow ( const Float* Sample, Float* V );
1025
void Cdecl New_V_Helper2 ( Float* A, const Float* Sample );
1026
void Cdecl New_V_Helper3 ( Float* A, const Float* Sample );
1027
void Cdecl New_V_Helper4 ( Float* V );
1029
void Cdecl VectorMult_i387 ( void* buff, const Float* V );
1030
void Cdecl VectorMult_3DNow ( void* buff, const Float* V );
1031
void Cdecl VectorMult_SIMD ( void* buff, const Float* V );
1033
void Synthese_Filter_16_C ( Int16_t* Stream, Int* const offset, Float* Vi, const Float Yi[36][32], Uint channels );
1034
void Synthese_Filter_32_C ( Int32_t* Stream, Int* const offset, Float* Vi, const Float Yi[36][32], Uint channels, Uint channel );
1036
void Cdecl Reset_FPU ( void );
1037
void Cdecl Reset_FPU_3DNow ( void );
1038
void Cdecl memcpy_dn_MMX ( void* dst, const void* src, size_t words64byte );
1039
void Cdecl memcpy_dn_SIMD ( void* dst, const void* src, size_t words128byte );
1041
void Init_Dither ( Int bits, int shapingtype, Double dither );
1042
void OverdriveReport ( void );
1044
Get_Synthese_Filter ( void );
1047
size_t Read_LittleEndians ( FILE_T fp, Uint32_t* dst, size_t words32bit );
1048
void Requantize_MidSideStereo ( Int Stop_Band, const Bool_t* used_MS, unsigned int StreamVersion );
1049
void Requantize_IntensityStereo ( Int Start_Band, Int Stop_Band );
1050
void Resort_HuffTable ( Huffman_t* const Table, const size_t elements, Int offset );
1051
void Make_HuffTable ( Huffman_t* dst, const HuffSrc_t* src, size_t len );
1052
void Make_LookupTable ( Uint8_t* LUT, size_t LUT_len, const Huffman_t* const Table, const size_t elements );
1053
size_t complete_read ( int fd, void* dest, size_t bytes );
1057
void Init_FPU ( void );
1061
Int Write_WAVE_Header ( FILE_T outputFile, Ldouble SampleFreq, Uint BitsPerSample, Uint Channels, Double SamplesPerChannel );
1062
Int Write_AIFF_Header ( FILE_T outputFile, Ldouble SampleFreq, Uint BitsPerSample, Uint Channels, Double SamplesPerChannel );
1063
Int Write_Raw_Header ( FILE_T outputFile, Ldouble SampleFreq, Uint BitsPerSample, Uint Channels, Double SamplesPerChannel );
1064
Int Set_DSP_OSS_Params ( FILE_T outputFile, Ldouble SampleFreq, Uint BitsPerSample, Uint Channels );
1065
Int Set_DSP_Sun_Params ( FILE_T outputFile, Ldouble SampleFreq, Uint BitsPerSample, Uint Channels );
1066
Int Set_ESD_Params ( FILE_T dummyFile , Ldouble SampleFreq, Uint BitsPerSample, Uint Channels );
1067
Int Set_WIN_Params ( FILE_T dummyFile , Ldouble SampleFreq, Uint BitsPerSample, Uint Channels );
1068
Int Set_IRIX_Params ( FILE_T dummyFile , Ldouble SampleFreq, Uint BitsPerSample, Uint Channels );
1069
size_t Write_PCM_16bit ( FILE_T outputFile, const Int16_t* data, size_t len );
1070
size_t Write_PCM_HQ_16bit ( FILE_T outputFile, const Int32_t* data, size_t len );
1071
size_t Write_PCM_HQ_24bit ( FILE_T outputFile, const Int32_t* data, size_t len );
1072
size_t Write_PCM_HQ_32bit ( FILE_T outputFile, const Int32_t* data, size_t len );
1073
int WIN_Play_Samples ( const void* buff, size_t len );
1074
int IRIX_Play_Samples ( const void* buff, size_t len );
1075
int WIN_Audio_close ( void );
1076
int IRIX_Audio_close ( void );
1079
void DisableSUID ( void );
1080
void EnableSUID ( void );
1081
int SetPriority ( unsigned int prio );
1084
FILE* pipeopen ( const char* command, const char* filename );
1087
void SetStderrSilent ( Bool_t state );
1088
Bool_t GetStderrSilent ( void );
1089
int Cdecl stderr_printf ( const char* format, ... );
1092
long treewalk ( const char* start, const char** mask, int (*fn)(const char* filename, void* aux), void* aux );
1093
void mysetargv ( int* argc, char*** argv, const char** extentions );
1096
#if ENDIAN == HAVE_BIG_ENDIAN
1098
# define swab32(dst,psrc) dst = *(uint32_t*)(psrc)
1102
# if defined __i386__ /* 486+ */
1104
# define swab32(dst,psrc) __asm__ ( "bswap %0" : "=r" (dst) : "0" (*(uint32_t*)(psrc)) )
1108
# define swab32(dst,psrc) \
1109
((uint8_t*)&(dst))[0] = ((uint8_t*)(psrc))[3], \
1110
((uint8_t*)&(dst))[1] = ((uint8_t*)(psrc))[2], \
1111
((uint8_t*)&(dst))[2] = ((uint8_t*)(psrc))[1], \
1112
((uint8_t*)&(dst))[3] = ((uint8_t*)(psrc))[0]
1119
#endif /* MPPDEC_MPPDEC_H */
1121
/* end of mppdec.h */