#define	   BS_FORMAT		BINARY
#define	   FSINGLE			1
#define	   OPTIMIZE			1
#define	   BUILTIN_TABLES	1
#define	   DETECT_CLIP		1


#ifndef COMMON_H
#define COMMON_H

/***********************************************************************
*
*  Global Conditional Compile Switches
*
***********************************************************************/

/* #define	UNIX		Unix conditional compile switch */
/* #define	MACINTOSH	Macintosh conditional compile switch */
/* #define	MS_DOS		IBM PC conditional compile switch */
/* #define	MSC60		Compiled for MS_DOS with MSC v6.0 */
/* #define	AIX		AIX conditional compile switch    */
/* #define	CONVEX		CONVEX conditional compile switch */

#if defined(MSC60) 
#ifndef MS_DOS
#define MS_DOS
#endif
#ifndef PROTO_ARGS
#define PROTO_ARGS
#endif
#endif

#ifdef  UNIX
#define         TABLES_PATH     "tables"  /* to find data files */
/* name of environment variable holding path of table files */
#define         MPEGTABENV      "MPEGTABLES"
#define         PATH_SEPARATOR  "/"        /* how to build paths */
#endif  /* UNIX */

#ifdef  MACINTOSH
#define      TABLES_PATH ":tables:"  /* where to find data files */
#endif  /* MACINTOSH */

/* 
 * Don't define FAR to far unless you're willing to clean up the 
 * prototypes
 */
#define FAR /*far*/

#ifdef __STDC__
#ifndef PROTO_ARGS
#define PROTO_ARGS 
#endif
#endif

#ifdef CONVEX
#define SEEK_SET        0
#define SEEK_CUR        1
#define SEEK_END        2
#endif

/* MS_DOS and VMS do not define TABLES_PATH, so OpenTableFile will default
   to finding the data files in the default directory */

/***********************************************************************
*
*  Global Include Files
*
***********************************************************************/

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ieeefloat.h"
#include "portableio.h"

#ifdef  UNIX
# include	<unistd.h>
#endif

#ifdef SOLARIS_SPARC
# include	<fcntl.h>
# include	<sys/file.h>
# include	<prof.h>
#endif

#ifdef SOLARIS_X86
# include	<fcntl.h>
# include	<sys/file.h>
#endif

#ifdef SUNOS
# include	<fcntl.h>
# include	<sys/file.h>
#endif

#ifdef LINUX
# include	<sys/types.h>
# include	<sys/stat.h>
# include	<fcntl.h>
#endif

#ifdef HPUX
# include	<sys/ioctl.h>
# include	<sys/fcntl.h>
#endif

#ifdef AIX
# include	<fcntl.h>
# include	<sys/audio.h>
#endif

#ifdef __sgi
# include	<stdlib.h>
#endif

#ifdef  MACINTOSH
# include	<stdlib.h>
# include	<console.h>
#endif

#ifdef  MS_DOS
#include        <stdlib.h>
#ifdef MSC60
#include        <memory.h>
#else
#include        <alloc.h>
#include        <mem.h>
#endif  /* MSC60 */
#endif  /* MS_DOS */

/***********************************************************************
*
*  Global Definitions
*
***********************************************************************/

/* General Definitions */

#ifdef  MS_DOS
#define         FLOAT                   double
#else
#define         FLOAT                   float
#endif

#ifndef FALSE
# define	FALSE                   0
#endif
#ifndef TRUE
# define	TRUE                    1
#endif
#define         NULL_CHAR               '\0'

#define         MAX_U_32_NUM            0xFFFFFFFF
#ifndef PI
#define         PI                      3.14159265358979
#endif

/*#define	PI4			PI/4*/
/*#define	PI64			PI/64*/
#define 	PI4			0.78539816339744
#define 	PI12			0.261799388
#define 	PI36			0.087266463
#define 	PI64			0.049087385
#define 	LN_TO_LOG10		0.2302585093

#define 	VOL_REF_NUM		0
#define 	MAC_WINDOW_SIZE 	24

#define 	MONO			1
#define 	STEREO			2
#define 	BITS_IN_A_BYTE		8
#define 	WORD			16
#define 	MAX_NAME_SIZE		81
#define 	SBLIMIT 		32
#define 	SSLIMIT 		18
#define 	FFT_SIZE		1024
#define 	HAN_SIZE		512
#define 	SCALE_BLOCK		12
#define 	SCALE_RANGE		64
#define 	SCALE			32767	/* was 32768 */
#define 	CRC16_POLYNOMIAL	0x8005

/* MPEG Header Definitions - ID Bit Values */
#define 	MPEG_AUDIO_ID		1
#define		MPEG_PHASE2_LSF		0	/* 1995-07-11 SHN */

/* MPEG Header Definitions - Mode Values */

#define         MPG_MD_STEREO           0
#define         MPG_MD_JOINT_STEREO     1
#define         MPG_MD_DUAL_CHANNEL     2
#define         MPG_MD_MONO             3

/* Mode Extention */

#define         MPG_MD_LR_LR             0
#define         MPG_MD_LR_I              1
#define         MPG_MD_MS_LR             2
#define         MPG_MD_MS_I              3

/* AIFF Definitions */

#define IFF_ID_FORM 0x464f524d /* "FORM" */
#define IFF_ID_AIFF 0x41494646 /* "AIFF" */
#define IFF_ID_COMM 0x434f4d4d /* "COMM" */
#define IFF_ID_SSND 0x53534e44 /* "SSND" */
#define IFF_ID_MPEG 0x4d504547 /* "MPEG" */

#define AIFF_FORM_HEADER_SIZE 12
#define AIFF_SSND_HEADER_SIZE 16



/* "bit_stream.h" Definitions */

#define         MINIMUM         4    /* Minimum size of the buffer in bytes */
#define         MAX_LENGTH      32   /* Maximum length of word written or
                                        read from bit stream */
#define         READ_MODE       0
#define         WRITE_MODE      1
#define         ALIGNING        8
#define         BINARY          0
#define         ASCII           1
#ifndef BS_FORMAT
#define         BS_FORMAT       ASCII /* BINARY or ASCII = 2x bytes */
#endif
#define         BUFFER_SIZE     4096

#ifndef MIN
#define         MIN(A, B)       ((A) < (B) ? (A) : (B))
#endif
#ifndef MAX
#define         MAX(A, B)       ((A) > (B) ? (A) : (B))
#endif

/* Select float or double precision*/
#ifdef FSINGLE
# define	REAL		float
#else
# define	REAL		double
#endif

/* Double and SANE Floating Point Type Definitions */

typedef struct  IEEE_DBL_struct {
    unsigned long   hi;
    unsigned long   lo;
} IEEE_DBL;

typedef struct  SANE_EXT_struct {
    unsigned long   l1;
    unsigned long   l2;
    unsigned short  s1;
} SANE_EXT;


/* "bit_stream.h" Type Definitions */
extern REAL FAR multiple[64];

/***********************************************************************
*
*  Global Function Prototype Declarations
*
***********************************************************************/

/* The following functions are in the file "common.c" */

#ifdef  PROTO_ARGS
extern FILE           *OpenTableFile(char*);
extern int            memcheck(char*, int, int);
extern void           FAR *mem_alloc(unsigned long, char*);
extern void           mem_free(void**);



#ifdef  MACINTOSH
extern void           set_mac_file_attr(char[MAX_NAME_SIZE], short, OsType,
                        OsType);
#endif
#ifdef MS_DOS
extern char           *new_ext(char *filename, char *extname); 
#endif

#else
extern FILE           *OpenTableFile();
extern int            memcheck();
extern void           FAR *mem_alloc();
extern void           mem_free();

#ifdef MS_DOS
extern char           *new_ext(); 
#endif
#endif
#endif
/* #define write my_write */
