home *** CD-ROM | disk | FTP | other *** search
/ Da Capo / da_capo_vol1.bin / programs / amiga / misc / mpegaudio / musicin.c < prev    next >
C/C++ Source or Header  |  1994-03-21  |  39KB  |  1,016 lines

  1. /**********************************************************************
  2. Copyright (c) 1991 MPEG/audio software simulation group, All Rights Reserved
  3. musicin.c
  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@3d.enet.dec.com             *
  10.  *                                                                    *
  11.  * VERSION 4.0                                                        *
  12.  *   changes made since last update:                                  *
  13.  *   date   programmers         comment                               *
  14.  * 3/01/91  Douglas Wong,       start of version 1.1 records          *
  15.  *          Davis Pan                                                 *
  16.  * 3/06/91  Douglas Wong,       rename: setup.h to endef.h            *
  17.  *                              removed extraneous variables          *
  18.  * 3/21/91  J.Georges Fritsch   introduction of the bit-stream        *
  19.  *                              package. This package allows you      *
  20.  *                              to generate the bit-stream in a       *
  21.  *                              binary or ascii format                *
  22.  * 3/31/91  Bill Aspromonte     replaced the read of the SB matrix    *
  23.  *                              by an "code generated" one            *
  24.  * 5/10/91  W. Joseph Carter    Ported to Macintosh and Unix.         *
  25.  *                              Incorporated Jean-Georges Fritsch's   *
  26.  *                              "bitstream.c" package.                *
  27.  *                              Modified to strictly adhere to        *
  28.  *                              encoded bitstream specs, including    *
  29.  *                              "Berlin changes".                     *
  30.  *                              Modified user interface dialog & code *
  31.  *                              to accept any input & output          *
  32.  *                              filenames desired.  Also added        *
  33.  *                              de-emphasis prompt and final bail-out *
  34.  *                              opportunity before encoding.          *
  35.  *                              Added AIFF PCM sound file reading     *
  36.  *                              capability.                           *
  37.  *                              Modified PCM sound file handling to   *
  38.  *                              process all incoming samples and fill *
  39.  *                              out last encoded frame with zeros     *
  40.  *                              (silence) if needed.                  *
  41.  *                              Located and fixed numerous software   *
  42.  *                              bugs and table data errors.           *
  43.  * 27jun91  dpwe (Aware Inc)    Used new frame_params struct.         *
  44.  *                              Clear all automatic arrays.           *
  45.  *                              Changed some variable names,          *
  46.  *                              simplified some code.                 *
  47.  *                              Track number of bits actually sent.   *
  48.  *                              Fixed padding slot, stereo bitrate    *
  49.  *                              Added joint-stereo : scales L+R.      *
  50.  * 6/12/91  Earle Jennings      added fix for MS_DOS in obtain_param  *
  51.  * 6/13/91  Earle Jennings      added stack length adjustment before  *
  52.  *                              main for MS_DOS                       *
  53.  * 7/10/91  Earle Jennings      conversion of all float to FLOAT      *
  54.  *                              port to MsDos from MacIntosh completed*
  55.  * 8/ 8/91  Jens Spille         Change for MS-C6.00                   *
  56.  * 8/22/91  Jens Spille         new obtain_parameters()               *
  57.  *10/ 1/91  S.I. Sudharsanan,   Ported to IBM AIX platform.           *
  58.  *          Don H. Lee,                                               *
  59.  *          Peter W. Farrett                                          *
  60.  *10/ 3/91  Don H. Lee          implemented CRC-16 error protection   *
  61.  *                              newly introduced functions are        *
  62.  *                              I_CRC_calc, II_CRC_calc and encode_CRC*
  63.  *                              Additions and revisions are marked    *
  64.  *                              with "dhl" for clarity                *
  65.  *11/11/91 Katherine Wang       Documentation of code.                *
  66.  *                                (variables in documentation are     *
  67.  *                                surround by the # symbol, and an '*'*
  68.  *                                denotes layer I or II versions)     *
  69.  * 2/11/92  W. Joseph Carter    Ported new code to Macintosh.  Most   *
  70.  *                              important fixes involved changing     *
  71.  *                              16-bit ints to long or unsigned in    *
  72.  *                              bit alloc routines for quant of 65535 *
  73.  *                              and passing proper function args.     *
  74.  *                              Removed "Other Joint Stereo" option   *
  75.  *                              and made bitrate be total channel     *
  76.  *                              bitrate, irrespective of the mode.    *
  77.  *                              Fixed many small bugs & reorganized.  *
  78.  * 2/25/92  Masahiro Iwadare    made code cleaner and more consistent *
  79.  * 8/07/92  Mike Coleman        make exit() codes return error status *
  80.  *                              made slight changes for portability   *
  81.  *19 aug 92 Soren H. Nielsen    Changed MS-DOS file name extensions.  *
  82.  * 8/25/92  Shaun Astarabadi    Replaced rint() function with explicit*
  83.  *                              rounding for portability with MSDOS.  *
  84.  * 9/22/92  jddevine@aware.com  Fixed _scale_factor_calc() calls.     *
  85.  *10/19/92  Masahiro Iwadare    added info->mode and info->mode_ext   *
  86.  *                              updates for AIFF format files         *
  87.  * 3/10/93  Kevin Peterson      In parse_args, only set non default   *
  88.  *                              bit rate if specified in arg list.    *
  89.  *                              Use return value from aiff_read_hdrs  *
  90.  *                              to fseek to start of sound data       *
  91.  * 7/26/93  Davis Pan           fixed bug in printing info->mode_ext  *
  92.  *                              value for joint stereo condition      *
  93.  * 8/27/93 Seymour Shlien,      Fixes in Unix and MSDOS ports,        *
  94.  *         Daniel Lauzon, and                                         *
  95.  *         Bill Truerniet                                             *
  96.  **********************************************************************/
  97.  
  98. #ifdef MS_DOS
  99. #include <dos.h>
  100. #endif
  101. #include "common.h"
  102. #include "encoder.h"
  103.  
  104. #ifdef UNIX
  105. #include <time.h>
  106. #endif
  107.  
  108. /* Global variable definitions for "musicin.c" */
  109.  
  110. FILE               *musicin;
  111. Bit_stream_struc   bs;
  112. char               *programName;
  113.  
  114. /* Implementations */
  115.  
  116. /************************************************************************
  117. /*
  118. /* obtain_parameters
  119. /*
  120. /* PURPOSE:  Prompts for and reads user input for encoding parameters
  121. /*
  122. /* SEMANTICS:  The parameters read are:
  123. /* - input and output filenames
  124. /* - sampling frequency (if AIFF file, will read from the AIFF file header)
  125. /* - layer number
  126. /* - mode (stereo, joint stereo, dual channel or mono)
  127. /* - psychoacoustic model (I or II)
  128. /* - total bitrate, irrespective of the mode
  129. /* - de-emphasis, error protection, copyright and original or copy flags
  130. /*
  131. /************************************************************************/
  132.  
  133. void
  134. obtain_parameters(fr_ps,psy,num_samples,original_file_name,encoded_file_name)
  135. frame_params    *fr_ps;
  136. int             *psy;
  137. unsigned long   *num_samples;
  138. char            original_file_name[MAX_NAME_SIZE];
  139. char            encoded_file_name[MAX_NAME_SIZE];
  140. {
  141.     int j;
  142.     long int freq;
  143.     int model, brt;
  144.     char t[50];
  145.     IFF_AIFF pcm_aiff_data;
  146.     layer *info = fr_ps->header;
  147.     long soundPosition;
  148.  
  149.     do  {
  150.