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

📄 mp4auenc.c

📁 语音压缩算法
💻 C
📖 第 1 页 / 共 3 页
字号:
/**********************************************************************MPEG-4 Audio VMEncoder frame workThis software module was originally developed byHeiko Purnhagen (University of Hannover / ACTS-MoMuSys)and edited byin the course of development of the MPEG-2 NBC/MPEG-4 Audio standardISO/IEC 13818-7, 14496-1,2 and 3. This software module is animplementation of a part of one or more MPEG-2 NBC/MPEG-4 Audio toolsas specified by the MPEG-2 NBC/MPEG-4 Audio standard. ISO/IEC givesusers of the MPEG-2 NBC/MPEG-4 Audio standards free license to thissoftware module or modifications thereof for use in hardware orsoftware products claiming conformance to the MPEG-2 NBC/ MPEG-4 Audiostandards. Those intending to use this software module in hardware orsoftware products are advised that this use may infringe existingpatents. The original developer of this software module and his/hercompany, the subsequent editors and their companies, and ISO/IEC haveno liability for use of this software module or modifications thereofin an implementation. Copyright is not released for non MPEG-2NBC/MPEG-4 Audio conforming products. The original developer retainsfull right to use the code for his/her own purpose, assign or donatethe code to a third party and to inhibit third party from using thecode for non MPEG-2 NBC/MPEG-4 Audio conforming products. Thiscopyright notice must be included in all copies or derivative works.Copyright (c) 1997.Source file: mp4enc.c$Id: mp4auenc.c,v 1.6 1999/07/28 14:08:13 purnhage Exp $Required modules:common.o		common modulecmdline.o		command line modulebitstream.o		bit stream moduleaudio.o			audio i/o moduleenc_par.o		encoder core (parametric)enc_lpc.o		encoder core (CELP)enc_tf.o		encoder core (T/F)enc_g729.o		encoder core (G729)enc_g723.o		encoder core (G723)Authors:HP    Heiko Purnhagen, Uni Hannover <purnhage@tnt.uni-hannover.de>BG    Bernhard Grill, Uni Erlangen <grl@titan.lte.e-technik.uni-erlangen.de>NI    Naoki Iwakami, NTT <iwakami@splab.hil.ntt.jp>SE    Sebastien ETienne, Jean Bernard Rault CCETT <jbrault@ccett.fr>Changes:13-jun-96   HP    first version14-jun-96   HP    added debug code17-jun-96   HP    added bit reservoir control / switches -r -b18-jun-96   HP    added delay compensation19-jun-96   HP    using new ComposeFileName()25-jun-96   HP    changed frameNumBit26-jun-96   HP    improved handling of switch -o04-jul-96   HP    joined with t/f code by BG (check "DISABLE_TF")14-aug-96   HP    adapted to new cmdline module, added mp4.h16-aug-96   HP    adapted to new enc.h		  added multichannel signal handling21-aug-96   HP    added NBC_RM4 switches by BG26-aug-96   HP    CVS28-aug-96   NI    moved "static CmdLineSwitch switchList[]" into main routine.29-aug-96   HP    moved "switchlist[]" back again		  NI stated, that it just was a locally required bug-fix:		  This table is moved into the main routine,		  because there was a run-time problem on a		  SGI (IRIX-5.3) system (using g++).30-oct-96   HP    additional frame work options15-nov-96   HP    adapted to new bitstream module18-nov-96   HP    changed int to long where required		  added bit stream header options		  removed NBC_RM4 switches (new -nh, -ms, -bi options)10-dec-96   HP    new -ni, -vr options, added variable bit rate23-jan-97   HP    added audio i/o module07-apr-97   HP    i/o filename handling improved / "-" supported08-apr-97   SE    added G729-based coder15-may-97   HP    clean up30-jun-97   HP    fixed totNumSample bug / calc encNumFrame05-nov-97   HP    update by FhG/UER12-nov-97   HP    added options -n & -s02-dec-98   HP    merged most FDIS contributions ...20-jan-99   HP    due to the nature of some of the modifications merged                  into this code, I disclaim any responsibility for this		  code and/or its readability -- sorry ...21-jan-99   HP	  trying to clean up a bit ...22-jan-99   HP    stdin/stdout "-" support, -d 1 uses stderr22-apr-99   HP    merging all contributions**********************************************************************/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include "buffersHandle.h"       /* handler, defines, enums */#include "common_m4a.h"	/* common module */#include "cmdline.h"	/* command line module */#include "bitstream.h"	/* bit stream module */#include "audio.h"	/* audio i/o module */#include "mp4au.h"	/* frame work declarations */#include "enc_par.h"	/* encoder cores ... */#include "enc_lpc.h"#include "enc_tf.h"#include "enc_g723.h"#include "enc_g729.h"#include "fir_filt.h"	/* fir lowpass filter */#include "tf_main.h"	/* TM9902 *//* ---------- declarations ---------- */#define PROGVER "MPEG-4 Natural Audio Encoder V1.0 30-Jul-1999"#define CVSID "$Id: mp4auenc.c,v 1.6 1999/07/28 14:08:13 purnhage Exp $"/* the framework should be independent from files in the codec *//* core directories    HP 970515*//* #include "tf_main.h" */#ifndef MONO_CHAN#define MONO_CHAN 0#endif#define max(a,b) ((a) > (b) ? (a) : (b))/* ---------- variables ---------- *//* command line module */static char *codecMode;static float bitRate;static int varBitRate;static int bitReservSize;static int bitReservInit;static int bitReservInitUsed;static float regionStart;static float regionDurat;static int regionDuratUsed;static char *encPara;static char *outFileName;static int outFileNameUsed;static int numChannelOut;static float fSampleOut;static char *oriPath,*bitPath;static int oriPathUsed,bitPathUsed;static char *oriExt,*bitExt;static int oriExtUsed;static int noInfo;static int noHeader;static char *magicString;static int bitBufSize;static int mainDebugLevel;static int audioDebugLevel;static int bitDebugLevel;static int cmdDebugLevel;static int quantDebugLevel;static int *varArgIdx;static ENC_FRAME_DATA encFrameData;static OBJECT_DESCRIPTOR objDescr;#ifdef DEBUGPLOTint frame; /* global for debugging */#else static  int frame;#endif static CmdLinePara paraList[] = {  {&varArgIdx,NULL,"<audio file(s) (- = stdin)>"},  {NULL,NULL,NULL}};static CmdLineSwitch switchList[] = {  {"h",NULL,NULL,NULL,NULL,"print help"},  {"m",&codecMode,"%s",MODENAME_HVXC,NULL,"codec mode (" MODENAME_LIST ")"},  {"r",&bitRate,"%f","2000",NULL,"bit rate [bit/s]"},  {"vr",&varBitRate,NULL,NULL,NULL,"enable variable bit rate"},  {"b",&bitReservSize,"%d","0",NULL,"bit reservoir size [bit]"},  {"bi",&bitReservInit,"%d",NULL,&bitReservInitUsed,   "initial bit reservoir bits\n"  "(dflt: bit reservoir size)"},  {"c",&encPara,"%s","",NULL,   "encoder parameter string"},  {"ts",&regionStart,"%f","0",NULL,"start time of encoded region [sec]"},  {"td",&regionDurat,"%f",NULL,&regionDuratUsed,   "duration of encoded region [sec]\n"   "(dflt: until end of file)"},  {"o",&outFileName,"%s",NULL,&outFileNameUsed,   "output file name (- = stdout)"},  {"n",&numChannelOut,"%d","0",NULL,   "number of audio channels for bit stream header\n"   "(0=as input file)"},  {"s",&fSampleOut,"%f","0",NULL,   "sampling frequency [Hz] for bit stream header\n"   "(0=as input file)"},  {"po",&oriPath,"%s",NULL,&oriPathUsed,   "default path original audio files (dflt: $" MP4_ORI_PATH_ENV ")"},  {"pb",&bitPath,"%s",NULL,&bitPathUsed,   "default path bit stream files (dflt: $" MP4_BIT_PATH_ENV ")"},  {"eo",&oriExt,"%s",NULL,&oriExtUsed,   "original audio file extension\n"   "supported file formats: .au, .snd, .wav, .aif, .raw\n"   "(dflt: $" MP4_ORI_FMT_ENV " / " MP4_ORI_EXT ")\n"   "(raw format: $" MP4_ORI_RAW_ENV ")"},  {"eb",&bitExt,"%s",MP4_BIT_EXT,NULL,"bit stream file extension"},  {"ni",&noInfo,NULL,NULL,NULL,"disable bit info string"},  {"nh",&noHeader,NULL,NULL,NULL,"disable mp4 bit stream header"},  {"ms",&magicString,"%s",MP4_MAGIC,NULL,"bit stream magic string"},  {"bb",&bitBufSize,"%i","0",NULL,"bitstream buffer size [bit] (0=auto)"},  {"d",&mainDebugLevel,"%i","0",NULL,"main debug level"},  {"da",&audioDebugLevel,"%i","0",NULL,"audio file debug level"},  {"db",&bitDebugLevel,"%i","0",NULL,"bit stream debug level"},  {"dc",&cmdDebugLevel,"%i","0",NULL,"cmd line debug level"},  {"dq",&quantDebugLevel,"%i","0",NULL,"quantizer  debug level"},  {NULL,NULL,NULL,NULL,NULL,NULL}};ntt_DATA  nttData;TF_DATA   tfData;/* ---------- functions ---------- *//* Encode() *//* Encode audio file and generate bit stream. *//* (This function evaluates the global xxxDebugLevel variables !!!) */static int Encode (  char *audioFileName,		/* in: audio file name */  char *bitFileName,		/* in: bit stream file name */  char *codecMode,		/* in: codec mode string */  float bitRate,		/* in: bit rate [bit/sec] */  int varBitRate,		/* in: variable bit rate */  int bitReservSize,		/* in: bit reservoir size [bit] */  int bitReservInit,		/* in: initial bit reservoir bits */  char *encPara,		/* in: encoder parameter string */  char *info,			/* in: info string for bit stream */  int noHeader,			/* in: disable bit stream header */  char *magicString,		/* in: bit stream magic string */  float regionStart,		/* in: start time of region */  float regionDurat,		/* in: duration of region */  int numChannelOut,		/* in: number of channels (0 = as input) */  float fSampleOut)		/* in: sampling frequency (0 = as input) */				/* returns: 0=OK  1=error */{  int mode;			/* enum MP4Mode */  float fSample;  long fileNumSample;  long totNumSample;  int numChannel;  int frameNumSample,delayNumSample;  int frameMinNumBit,frameMaxNumBit;  long fSampleLong,bitRateLong;  BsBitBuffer *bitBuf;  float **sampleBuf;  BsBitStream *bitStream;  AudioFile *audioFile;  BsBitBuffer *bitHeader;  FILE *tmpFile;  int startupNumFrame,startupFrame;  int numSample;  int frameNumBit,frameAvailNumBit,usedNumBit;  int headerNumBit;  int padNumBit;  long totDataNumBit,totPadNumBit;  int minUsedNumBit,maxUsedNumBit;  int minPadNumBit,maxPadNumBit;  int minReservNumBit,maxReservNumBit;  long totReservNumBit;  int ch,i;  long startSample;  long encNumSample;  int numChannelBS;  long fSampleLongBS;  ENC_FRAME_DATA* frameData=NULL;  FIR_FILT *lowpassFilt = NULL;  int downsamplFac = 1;  float *tmpBuff;  int celp_sys_align;  /* init */  if (mainDebugLevel >= 3) {    printf("Encode:\n");    printf("audioFileName=\"%s\"\n",audioFileName);    printf("bitFileName=\"%s\"\n",bitFileName);    printf("codecMode=\"%s\"\n",codecMode);    printf("bitRate=%.3f\n",bitRate);    printf("varBitRate=%d\n",varBitRate);    printf("bitReservSize=%d\n",bitReservSize);    printf("bitReservInit=%d\n",bitReservInit);    printf("encPara=\"%s\"\n",encPara?encPara:"(NULL)");    printf("info=\"%s\"\n",info);    printf("noHeader=%d\n",noHeader);    printf("magicString=\"%s\"\n",magicString);    printf("regionStart=%.6f\n",regionStart);    printf("regionDurat=%.6f\n",regionDurat);  }  BsInit(bitBufSize,bitDebugLevel,0);  AudioInit(getenv(MP4_ORI_RAW_ENV),	   /* headerless file format */	    audioDebugLevel);  mode = 0;  do    mode++;  while (mode < MODE_NUM && strcmp(codecMode,MP4ModeName[mode]) != 0);  if (mode >= MODE_NUM)    CommonExit(1,"Encode: unknown codec mode %s",codecMode);  /* check audio file */  if ((tmpFile=fopen(audioFileName,"rb"))==NULL) {

⌨️ 快捷键说明

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