home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / resources / mpeg / mpegdec / audiompeg / !AudioMPEG_h_common < prev    next >
Encoding:
Text File  |  1995-05-23  |  13.5 KB  |  342 lines

  1. /**********************************************************************
  2. Copyright (c) 1991 MPEG/audio software simulation group, All Rights Reserved
  3. common.h
  4. **********************************************************************/
  5. /**********************************************************************
  6.  * MPEG/audio coding/decoding software, work in progress              *
  7.  *   NOT for public distribution until verified and approved by the   *
  8.  *   MPEG/audio committee.  For further information, please contact   *
  9.  *   Davis Pan, 508-493-2241, e-mail: pan@gauss.enet.dec.com          *
  10.  *                                                                    *
  11.  * VERSION 4.0                                                        *
  12.  *   changes made since last update:                                  *
  13.  *   date   programmers         comment                               *
  14.  * 2/25/91  Doulas Wong,        start of version 1.0 records          *
  15.  *          Davis Pan                                                 *
  16.  * 5/10/91  W. Joseph Carter    Reorganized & renamed all ".h" files  *
  17.  *                              into "common.h" and "encoder.h".      *
  18.  *                              Ported to Macintosh and Unix.         *
  19.  *                              Added additional type definitions for *
  20.  *                              AIFF, double/SANE and "bitstream.c".  *
  21.  *                              Added function prototypes for more    *
  22.  *                              rigorous type checking.               *
  23.  * 27jun91  dpwe (Aware)        Added "alloc_*" defs & prototypes     *
  24.  *                              Defined new struct 'frame_params'.    *
  25.  *                              Changed info.stereo to info.mode_ext  *
  26.  *                              #define constants for mode types      *
  27.  *                              Prototype arguments if PROTO_ARGS     *
  28.  * 5/28/91  Earle Jennings      added MS_DOS definition               *
  29.  *                              MsDos function prototype declarations *
  30.  * 7/10/91  Earle Jennings      added FLOAT definition as double      *
  31.  *10/ 3/91  Don H. Lee          implemented CRC-16 error protection   *
  32.  * 2/11/92  W. Joseph Carter    Ported new code to Macintosh.  Most   *
  33.  *                              important fixes involved changing     *
  34.  *                              16-bit ints to long or unsigned in    *
  35.  *                              bit alloc routines for quant of 65535 *
  36.  *                              and passing proper function args.     *
  37.  *                              Removed "Other Joint Stereo" option   *
  38.  *                              and made bitrate be total channel     *
  39.  *                              bitrate, irrespective of the mode.    *
  40.  *                              Fixed many small bugs & reorganized.  *
  41.  *                              Modified some function prototypes.    *
  42.  *                              Changed BUFFER_SIZE back to 4096.     *
  43.  * 7/27/92  Michael Li          (re-)Ported to MS-DOS                 *
  44.  * 7/27/92  Masahiro Iwadare    Ported to Convex                      *
  45.  * 8/07/92  mc@tv.tek.com                                             *
  46.  * 8/10/92  Amit Gulati         Ported to the AIX Platform (RS6000)   *
  47.  *                              AIFF string constants redefined       *
  48.  * 8/27/93 Seymour Shlien,      Fixes in Unix and MSDOS ports,        *
  49.  *         Daniel Lauzon, and                                         *
  50.  *         Bill Truerniet                                             *
  51.  **********************************************************************/
  52.  
  53. /***********************************************************************
  54. *
  55. *  Global Conditional Compile Switches
  56. *
  57. ***********************************************************************/
  58.  
  59.  
  60. #define PROTO_ARGS
  61.  
  62. #define         TABLES_PATH     "<AudioMPEG$Dir>.tables"  /* to find data files */
  63.  
  64. /* 
  65.  * Don't define FAR to far unless you're willing to clean up the 
  66.  * prototypes
  67.  */
  68. #define FAR /*far*/
  69.  
  70. #ifdef __STDC__
  71. #ifndef PROTO_ARGS
  72. #define PROTO_ARGS
  73. #endif
  74. #endif
  75.  
  76.  
  77. /* MS_DOS and VMS do not define TABLES_PATH, so OpenTableFile will default
  78.    to finding the data files in the default directory */
  79.  
  80. /***********************************************************************
  81. *
  82. *  Global Include Files
  83. *
  84. ***********************************************************************/
  85.  
  86. #include        <stdio.h>
  87. #include        <string.h>
  88. #include        <math.h>
  89.  
  90. #include        <stdlib.h>
  91. #include        <mem.h>
  92.  
  93. /***********************************************************************
  94. *
  95. *  Global Definitions
  96. *
  97. ***********************************************************************/
  98.  
  99. /* General Definitions */
  100.  
  101. #define         FLOAT                   float
  102.  
  103. #define         FALSE                   0
  104. #define         TRUE                    1
  105. #define         NULL_CHAR               '\0'
  106.  
  107. #define         MAX_U_32_NUM            0xFFFFFFFF
  108. #define         PI                      3.14159265358979
  109. #define         PI4                     PI/4
  110. #define         PI64                    PI/64
  111. #define         LN_TO_LOG10             0.2302585093
  112.  
  113. #define         VOL_REF_NUM             0
  114. #define         MPEG_AUDIO_ID           1
  115. #define         MAC_WINDOW_SIZE         24
  116.  
  117. #define         MONO                    1
  118. #define         STEREO                  2
  119. #define         BITS_IN_A_BYTE          8
  120. #define         WORD                    16
  121. #define         MAX_NAME_SIZE           81
  122. #define         SBLIMIT                 32
  123. #define         FFT_SIZE                1024
  124. #define         HAN_SIZE                512
  125. #define         SCALE_BLOCK             12
  126. #define         SCALE_RANGE             64
  127. #define         SCALE                   32768
  128. #define         CRC16_POLYNOMIAL        0x8005
  129.  
  130. /* MPEG Header Definitions - Mode Values */
  131.  
  132. #define         MPG_MD_STEREO           0
  133. #define         MPG_MD_JOINT_STEREO     1
  134. #define         MPG_MD_DUAL_CHANNEL     2
  135. #define         MPG_MD_MONO             3
  136.  
  137. /* "bit_stream.h" Definitions */
  138.  
  139. #define         MINIMUM         4    /* Minimum size of the buffer in bytes */
  140. #define         MAX_LENGTH      32   /* Maximum length of word written or
  141.                                         read from bit stream */
  142. #define         READ_MODE       0
  143. #define         WRITE_MODE      1
  144. #define         ALIGNING        8
  145. #define         BINARY          0
  146. #define         ASCII           1
  147. #define         BS_FORMAT       BINARY /* BINARY or ASCII = 2x bytes */
  148. #define         BUFFER_SIZE     4096
  149.  
  150. /***********************************************************************
  151. *
  152. *  Global Type Definitions
  153. *
  154. ***********************************************************************/
  155.  
  156. /* Structure for Reading Layer II Allocation Tables from File */
  157.  
  158. typedef struct {
  159.     unsigned int    steps;
  160.     unsigned int    bits;
  161.     unsigned int    group;
  162.     unsigned int    quant;
  163. } sb_alloc, *alloc_ptr;
  164.  
  165. typedef sb_alloc        al_table[SBLIMIT][16];
  166.  
  167. /* Header Information Structure */
  168.  
  169. typedef struct {
  170.     int version;
  171.     int lay;
  172.     int error_protection;
  173.     int bitrate_index;
  174.     int sampling_frequency;
  175.     int padding;
  176.     int extension;
  177.     int mode;
  178.     int mode_ext;
  179.     int copyright;
  180.     int original;
  181.     int emphasis;
  182. } layer, *the_layer;
  183.  
  184. /* Parent Structure Interpreting some Frame Parameters in Header */
  185.  
  186. typedef struct {
  187.     layer       *header;        /* raw header information */
  188.     int         actual_mode;    /* when writing IS, may forget if 0 chs */
  189.     al_table    *alloc;         /* bit allocation table read in */
  190.     int         tab_num;        /* number of table as loaded */
  191.     int         stereo;         /* 1 for mono, 2 for stereo */
  192.     int         jsbound;        /* first band of joint stereo coding */
  193.     int         sblimit;        /* total number of sub bands */
  194. } frame_params;
  195.  
  196. /* Double and SANE Floating Point Type Definitions */
  197.  
  198. typedef struct  IEEE_DBL_struct {
  199.     unsigned long   hi;
  200.     unsigned long   lo;
  201. } IEEE_DBL;
  202.  
  203. typedef struct  SANE_EXT_struct {
  204.     unsigned long   l1;
  205.     unsigned long   l2;
  206.     unsigned short  s1;
  207. } SANE_EXT;
  208.  
  209. /* "bit_stream.h" Type Definitions */
  210.  
  211. typedef struct  bit_stream_struc {
  212.     FILE        *pt;            /* pointer to bit stream device */
  213.     unsigned char *buf;         /* bit stream buffer */
  214.     int         buf_size;       /* size of buffer (in number of bytes) */
  215.     long        totbit;         /* bit counter of bit stream */
  216.     int         buf_byte_idx;   /* pointer to top byte in buffer */
  217.     int         buf_bit_idx;    /* pointer to top bit of top byte in buffer */
  218.     int         mode;           /* bit stream open in read or write mode */
  219.     int         eob;            /* end of buffer index */
  220.     int         eobs;           /* end of bit stream flag */
  221.     char        format;
  222.     
  223.     /* format of file in rd mode (BINARY/ASCII) */
  224. } Bit_stream_struc;
  225.  
  226. /***********************************************************************
  227. *
  228. *  Global Variable External Declarations
  229. *
  230. ***********************************************************************/
  231.  
  232. extern char     *mode_names[4];
  233. extern char     *layer_names[3];
  234. extern double   s_freq[4];
  235. extern int      bitrate[3][15];
  236. extern double FAR multiple[64];
  237. extern int      highbytefirst;
  238.  
  239. /***********************************************************************
  240. *
  241. *  Global Function Prototype Declarations
  242. *
  243. ***********************************************************************/
  244.  
  245. /* The following functions are in the file "common.c" */
  246.  
  247. #ifdef  PROTO_ARGS
  248. extern FILE           *OpenTableFile(char*);
  249. extern int            read_bit_alloc(int, al_table*);
  250. extern int            pick_table(frame_params*);
  251. extern int            js_bound(int, int);
  252. extern void           hdr_to_frps(frame_params*);
  253. extern void           WriteHdr(frame_params*, FILE*);
  254. extern void           WriteBitAlloc(unsigned int[2][SBLIMIT], frame_params*,
  255.                         FILE*);
  256. extern void           WriteScale(unsigned int[2][SBLIMIT],
  257.                         unsigned int[2][SBLIMIT], unsigned int[2][3][SBLIMIT],
  258.                         frame_params*, FILE*);
  259. extern void           WriteSamples(int, unsigned int FAR [SBLIMIT],
  260.                         unsigned int[SBLIMIT], frame_params*, FILE*);
  261. extern int            NumericQ(char*);
  262. extern int            BitrateIndex(int, int);
  263. extern int            SmpFrqIndex(long);
  264. extern int            memcheck(char*, int, int);
  265. extern void           FAR *mem_alloc(unsigned long, char*);
  266. extern void           mem_free(void**);
  267. extern void           double_to_extended(double*, char[10]);
  268. extern void           extended_to_double(char[10], double*);
  269. extern int            refill_buffer(Bit_stream_struc*);
  270. extern void           empty_buffer(Bit_stream_struc*, int);
  271. extern void           open_bit_stream_w(Bit_stream_struc*, char*, int);
  272. extern void           open_bit_stream_r(Bit_stream_struc*, char*, int);
  273. extern void           close_bit_stream_r(Bit_stream_struc*);
  274. extern void           close_bit_stream_w(Bit_stream_struc*);
  275. extern void           alloc_buffer(Bit_stream_struc*, int);
  276. extern void           desalloc_buffer(Bit_stream_struc*);
  277. extern void           back_track_buffer(Bit_stream_struc*, int);
  278. extern unsigned int   get1bit(Bit_stream_struc*);
  279. extern void           put1bit(Bit_stream_struc*, int);
  280. extern unsigned long  look_ahead(Bit_stream_struc*, int);
  281. extern unsigned long  getbits(Bit_stream_struc*, int);
  282. extern void           putbits(Bit_stream_struc*, unsigned int, int);
  283. extern void           byte_ali_putbits(Bit_stream_struc*, unsigned int, int);
  284. extern unsigned long  byte_ali_getbits(Bit_stream_struc*, int);
  285. extern unsigned long  sstell(Bit_stream_struc*);
  286. extern int            end_bs(Bit_stream_struc*);
  287. extern int            seek_sync(Bit_stream_struc*, long, int);
  288. extern void           I_CRC_calc(frame_params*, unsigned int[2][SBLIMIT],
  289.                         unsigned int*);
  290. extern void           II_CRC_calc(frame_params*, unsigned int[2][SBLIMIT],
  291.                         unsigned int[2][SBLIMIT], unsigned int*);
  292. extern void           update_CRC(unsigned int, unsigned int, unsigned int*);
  293. extern void           read_absthr(FLOAT*, int);
  294.  
  295. extern char           *new_ext(char *filename, char *extname); 
  296.  
  297. #else
  298.  
  299. extern FILE           *OpenTableFile();
  300. extern int            read_bit_alloc();
  301. extern int            pick_table();
  302. extern int            js_bound();
  303. extern void           hdr_to_frps();
  304. extern void           WriteHdr();
  305. extern void           WriteBitAlloc();
  306. extern void           WriteScale();
  307. extern void           WriteSamples();
  308. extern int            NumericQ();
  309. extern int            BitrateIndex();
  310. extern int            SmpFrqIndex();
  311. extern int            memcheck();
  312. extern void           FAR *mem_alloc();
  313. extern void           mem_free();
  314. extern void           double_to_extended();
  315. extern void           extended_to_double();
  316. extern int            refill_buffer();
  317. extern void           empty_buffer();
  318. extern void           open_bit_stream_w();
  319. extern void           open_bit_stream_r();
  320. extern void           close_bit_stream_r();
  321. extern void           close_bit_stream_w();
  322. extern void           alloc_buffer();
  323. extern void           desalloc_buffer();
  324. extern void           back_track_buffer();
  325. extern unsigned int   get1bit();
  326. extern void           put1bit();
  327. extern unsigned long  look_ahead();
  328. extern unsigned long  getbits();
  329. extern void           putbits();
  330. extern void           byte_ali_putbits();
  331. extern unsigned long  byte_ali_getbits();
  332. extern unsigned long  sstell();
  333. extern int            end_bs();
  334. extern int            seek_sync();
  335. extern void           I_CRC_calc();
  336. extern void           II_CRC_calc();
  337. extern void           update_CRC();
  338. extern void           read_absthr();
  339.  
  340. extern char           *new_ext(); 
  341. #endif
  342.