⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 musicin.c

📁 MP3编码库
💻 C
📖 第 1 页 / 共 2 页
字号:
/********************************************************************** * ISO MPEG Audio Subgroup Software Simulation Group (1996) * ISO 13818-3 MPEG-2 Audio Encoder - Lower Sampling Frequency Extension * * $Id: musicin.c,v 1.2 1997/01/19 22:28:29 rowlands Exp $ * * $Log: musicin.c,v $ * Revision 1.2  1997/01/19 22:28:29  rowlands * Layer 3 bug fixes from Seymour Shlien * * Revision 1.1  1996/02/14 04:04:23  rowlands * Initial revision * * Received from Mike Coleman **********************************************************************//********************************************************************** *   date   programmers         comment                               * * 3/01/91  Douglas Wong,       start of version 1.1 records          * *          Davis Pan                                                 * * 3/06/91  Douglas Wong,       rename: setup.h to endef.h            * *                              removed extraneous variables          * * 3/21/91  J.Georges Fritsch   introduction of the bit-stream        * *                              package. This package allows you      * *                              to generate the bit-stream in a       * *                              binary or ascii format                * * 3/31/91  Bill Aspromonte     replaced the read of the SB matrix    * *                              by an "code generated" one            * * 5/10/91  W. Joseph Carter    Ported to Macintosh and Unix.         * *                              Incorporated Jean-Georges Fritsch's   * *                              "bitstream.c" package.                * *                              Modified to strictly adhere to        * *                              encoded bitstream specs, including    * *                              "Berlin changes".                     * *                              Modified user interface dialog & code * *                              to accept any input & output          * *                              filenames desired.  Also added        * *                              de-emphasis prompt and final bail-out * *                              opportunity before encoding.          * *                              Added AIFF PCM sound file reading     * *                              capability.                           * *                              Modified PCM sound file handling to   * *                              process all incoming samples and fill * *                              out last encoded frame with zeros     * *                              (silence) if needed.                  * *                              Located and fixed numerous software   * *                              bugs and table data errors.           * * 27jun91  dpwe (Aware Inc)    Used new frame_params struct.         * *                              Clear all automatic arrays.           * *                              Changed some variable names,          * *                              simplified some code.                 * *                              Track number of bits actually sent.   * *                              Fixed padding slot, stereo bitrate    * *                              Added joint-stereo : scales L+R.      * * 6/12/91  Earle Jennings      added fix for MS_DOS in obtain_param  * * 6/13/91  Earle Jennings      added stack length adjustment before  * *                              main for MS_DOS                       * * 7/10/91  Earle Jennings      conversion of all float to FLOAT      * *                              port to MsDos from MacIntosh completed* * 8/ 8/91  Jens Spille         Change for MS-C6.00                   * * 8/22/91  Jens Spille         new obtain_parameters()               * *10/ 1/91  S.I. Sudharsanan,   Ported to IBM AIX platform.           * *          Don H. Lee,                                               * *          Peter W. Farrett                                          * *10/ 3/91  Don H. Lee          implemented CRC-16 error protection   * *                              newly introduced functions are        * *                              I_CRC_calc, II_CRC_calc and encode_CRC* *                              Additions and revisions are marked    * *                              with "dhl" for clarity                * *11/11/91 Katherine Wang       Documentation of code.                * *                                (variables in documentation are     * *                                surround by the # symbol, and an '*'* *                                denotes layer I or II versions)     * * 2/11/92  W. Joseph Carter    Ported new code to Macintosh.  Most   * *                              important fixes involved changing     * *                              16-bit ints to long or unsigned in    * *                              bit alloc routines for quant of 65535 * *                              and passing proper function args.     * *                              Removed "Other Joint Stereo" option   * *                              and made bitrate be total channel     * *                              bitrate, irrespective of the mode.    * *                              Fixed many small bugs & reorganized.  * * 2/25/92  Masahiro Iwadare    made code cleaner and more consistent * * 8/07/92  Mike Coleman        make exit() codes return error status * *                              made slight changes for portability   * *19 aug 92 Soren H. Nielsen    Changed MS-DOS file name extensions.  * * 8/25/92  Shaun Astarabadi    Replaced rint() function with explicit* *                              rounding for portability with MSDOS.  * * 9/22/92  jddevine@aware.com  Fixed _scale_factor_calc() calls.     * *10/19/92  Masahiro Iwadare    added info->mode and info->mode_ext   * *                              updates for AIFF format files         * * 3/10/93  Kevin Peterson      In parse_args, only set non default   * *                              bit rate if specified in arg list.    * *                              Use return value from aiff_read_hdrs  * *                              to fseek to start of sound data       * * 7/26/93  Davis Pan           fixed bug in printing info->mode_ext  * *                              value for joint stereo condition      * * 8/27/93 Seymour Shlien,      Fixes in Unix and MSDOS ports,        * *         Daniel Lauzon, and                                         * *         Bill Truerniet                                             * * 11/7/95 Soeren H. Nielsen    LSF added. Bug fix in MSDOS ext.      * * 8/02/95 mc@fivebats.com      Changed default bitrate selection so  * *                              it works with the new LSF stuff       * *10/01/95 mc@fivebats.com      Added layer3                          * **********************************************************************/#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#define WRITE_BUFFER_SIZE 32000			// must be enough to store one frame compress data
										// bit_writer will never check fullness for this buffer

#define         MAX_NAME_SIZE           81
/* Default Input Arguments (for command line control) */

#define DFLT_LAY        2      /* default encoding layer is II */
#define DFLT_MOD        's'    /* default mode is stereo */
#define DFLT_PSY        1      /* default psych model is 1 */
#define DFLT_SFQ        44.1   /* default input sampling rate is 44.1 kHz */
#define DFLT_EMP        'n'    /* default de-emphasis is none */
#define DFLT_EXT        ".mpg" /* default output file extension */

#define FILETYPE_ENCODE 'TEXT'
#define CREATOR_ENCODE  'MpgD'
#ifdef _DEBUG
#include <assert.h>#endif#include "./libmp3enc/libmp3enc.h"
#include "audio_in.h"
/* Global variable definitions for "musicin.c" */FILE               *musicin;
FILE			   *music_out;i8				   *programName;/* The following functions are in the file "musicin.c" */i32    parse_args();void   print_config();void   usage();void   aiff_check();/* Implementations */i32 init_MP3codec(MP3CODEC *mp3codec, layer *input);i32 MP3_encoding(u8 *f_buf, MP3CODEC *mp3codec);
i32 deinit_MP3codec(MP3CODEC *mp3codec, u8 *buf);
/************************************************************************** parse_args** PURPOSE:  Sets encoding parameters to the specifications of the* command line.  Default settings are used for parameters* not specified in the command line.** SEMANTICS:  The command line is parsed according to the following* syntax:** -l  is followed by the layer number* -m  is followed by the mode* -p  is followed by the psychoacoustic model number* -s  is followed by the sampling rate* -b  is followed by the total bitrate, irrespective of the mode* -d  is followed by the emphasis flag* -c  is followed by the copyright/no_copyright flag* -o  is followed by the original/not_original flag* -e  is followed by the error_protection on/off flag** If the input file is in AIFF format, the sampling frequency is read* from the AIFF header.** The input and output filenames are read into #inpath# and #outpath#.*************************************************************************/ i32 parse_args(	i32     argc,	i8		**argv,	layer   *info,	u32		*num_samples,	i8		inPath[MAX_NAME_SIZE],	i8		outPath[MAX_NAME_SIZE]
){   i32   file_type;   i32   srate;   i32   brate;   i32   err = 0, i = 0;
      IFF_AIFF pcm_aiff_data;
   long  samplerate;   long  soundPosition; 
   printf("\nparsing input arguments...\n");   /* preset defaults */   inPath[0] = '\0';   outPath[0] = '\0';   info->lay = DFLT_LAY;   switch(DFLT_MOD) {      case 's': info->mode = MPG_MD_STEREO; info->mode_ext = 0; break;      case 'd': info->mode = MPG_MD_DUAL_CHANNEL; info->mode_ext=0; break;      case 'j': info->mode = MPG_MD_JOINT_STEREO; break;      case 'm': info->mode = MPG_MD_MONO; info->mode_ext = 0; break;      default:         fprintf(stderr, "%s: Bad mode dflt %c\n", programName, DFLT_MOD);         abort();   }   if((info->sampling_frequency = SmpFrqIndex((long)(1000*DFLT_SFQ), &info->version)) < 0) {      fprintf(stderr, "%s: bad sfrq default %.2f\n", programName, DFLT_SFQ);      abort();   }  info->bitrate_index = 14;    brate = 0;   switch(DFLT_EMP) {      case 'n': info->emphasis = 0; break;      case '5': info->emphasis = 1; break;      case 'c': info->emphasis = 3; break;      default:          fprintf(stderr, "%s: Bad emph dflt %c\n", programName, DFLT_EMP);         abort();   }   info->copyright = 0; info->original = 0; info->error_protection = FALSE;    /* process args */   while(++i<argc && err == 0) {      i8 c, *token, *arg, *nextArg;      i32  argUsed;       token = argv[i];      if(*token++ == '-') {         if(i+1 < argc) nextArg = argv[i+1];         else           nextArg = "";         argUsed = 0;         while( (c = *token++) ) {            if(*token /* NumericQ(token) */) 				arg = token;            else				arg = nextArg;            switch(c) {               case 'l':				  info->lay = atoi(arg); argUsed = 1;                  if(info->lay<1 || info->lay>3) {                     fprintf(stderr,"%s: -l layer must be 1, 2, or 3, not %s\n",                          programName, arg);                     err = 1;                  }                  break;               case 'm':				  argUsed = 1;                  if (*arg == 's')                    { info->mode = MPG_MD_STEREO; info->mode_ext = 0; }                  else if (*arg == 'd')                    { info->mode = MPG_MD_DUAL_CHANNEL; info->mode_ext=0; }                  else if (*arg == 'j')                    { info->mode = MPG_MD_JOINT_STEREO; }                  else if (*arg == 'm')                    { info->mode = MPG_MD_MONO; info->mode_ext = 0; }                  else {                    fprintf(stderr,"%s: -m mode must be s/d/j/m not %s\n",                            programName, arg);                    err = 1;                  }                  break;               case 's':                  argUsed = 1;                  srate = atoi( arg );                  /* samplerate = rint( 1000.0 * srate ); $A  */                  samplerate =  100 * srate ;                  if( (info->sampling_frequency =						SmpFrqIndex((long) samplerate, &info->version)) < 0 )                      err = 1;                  break;                                 case 'b':        				  argUsed = 1;				  brate = atoi(arg); 				  break;               case 'd':				  argUsed = 1;                  if (*arg == 'n')                    info->emphasis = 0;                  else if (*arg == '5')               info->emphasis = 1;                  else if (*arg == 'c')               info->emphasis = 3;                  else {                     fprintf(stderr,"%s: -d emp must be n/5/c not %s\n",                             programName, arg);                     err = 1;                  }                  break;                case 'c':       info->copyright = 1; break;                case 'o':       info->original  = 1; break;                case 'e':       info->error_protection = TRUE; break;                default:        fprintf(stderr,"%s: unrec option %c\n",                                        programName, c);                                err = 1; break;            }            if(argUsed) {               if(arg == token)    token = "";   /* no more from token */               else                ++i;          /* skip arg we used */               arg = ""; argUsed = 0;            }         }      }      else {         if(inPath[0] == '\0')       strcpy(inPath, argv[i]);         else if(outPath[0] == '\0') strcpy(outPath, argv[i]);         else {            fprintf(stderr,"%s: excess arg %s\n", programName, argv[i]);            err = 1;         }      }   }   if(err || inPath[0] == '\0') usage();  /* never returns */    if(outPath[0] == '\0') {      strcpy(outPath, inPath);      strcat(outPath, DFLT_EXT);   }   if ((musicin = fopen(inPath, "rb")) == NULL) {      printf("Could not find \"%s\".\n", inPath);      exit(1);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -