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

📄 dec_par.c

📁 MPEG2/MPEG4编解码参考程序(实现了MPEG4的部分功能)
💻 C
📖 第 1 页 / 共 2 页
字号:
/**********************************************************************MPEG-4 Audio VMDecoder core (parametric)This software module was originally developed byHeiko Purnhagen (University of Hannover / Deutsche Telekom Berkom)Bernd Edler (University of Hannover / Deutsche Telekom Berkom)Masayuki Nishiguchi, Kazuyuki Iijima, Jun Matsumoto (Sony Corporation)and edited byAkira Inoue (Sony Corporation) andYuji Maeda (Sony Corporation)in 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: dec_par.c$Id: dec_par.c,v 1.41 1999/08/09 16:21:39 purnhage Exp $Required modules:common.o		common modulecmdline.o		command line modulebitstream.o		bits stream moduleindilinedec.o		indiline bitstream decoder moduleindilinesyn.o		indiline synthesiser moduleAuthors:HP    Heiko Purnhagen, Uni Hannover <purnhage@tnt.uni-hannover.de>BE    Bernd Edler, Uni Hannover <edler@tnt.uni-hannover.de>MN    Masayuki Nishiguchi, Sony IPC <nishi@pcrd.sony.co.jp>AI    Akira Inoue, Sony IPC <akira@pal.arch.sony.co.jp>Changes:18-jun-96   HP    first version (dummy)25-jun-96   HP    implemented "individual spectral lines"28-jun-96   HP    joined with HVXC code by Sony IPC01-jul-96   HP    added HVXC header file, included modifications by IPC15-aug-96   HP    added DecParInfo(), DecParFree()                  adapted to new dec.h26-aug-96   HP    CVS03-sep-96   HP    added speed change & pitch change for "individual lines"06-sep-96   HP    incorporated changes by Sony IPC for a new HVXC with                  speed change & pitch change functionality10-sep-96   BE12-sep-96   HP    incorporated indiline modules as source code26-sep-96   HP    adapted to new indiline module interfaces26-sep-96   HP    incorporated changes by Sony IPC15-nov-96   HP    adapted to new bitstream module04-dec-96   HP    fix call to BsGetBitChar(), included ISO copyright03-feb-97   HP    splitting enc/dec06-jul-97   HP    switch/mix17-jul-97   HP    HXVC delayNumSample23-oct-97   HP    merged IL/HVXC switching07-nov-97   MN    bug-fixes11-nov-97   HP    added HVXC variable rate switches12-nov-97   HP    fixed mixed HVXC/IL mode05-feb-99   HP    marked HILN as Version 2XX-feb-99   AI    HVXC status variables defined,                  DecHvxcFrame(), DecHvxcInit(), DecHvxcFree() implementedVMIL stuff10-apr-97   HP    harmonic stuff ...22-apr-97   HP    noisy stuff ...10-jun-97   HP    added para file support23-jun-97   HP    ANSI-C para file fixes24-jun-97   HP    adapted env/harm/noise interface29-aug-97   HP    added random start phase13-nov-97   HP    fixed harm speech change16-nov-97   HP    adapted HILN decoder config header16-dec-97   HP    noise para factor30-mar-98   BE/HP initPrevNumLine06-apr-98   HP    ILD/ILS config11-jun-98   HP    enha support for para file02-dec-98   HP    new noise quant as dflt.18-jun-98   HP    CD-nx bsFormat noise quant**********************************************************************/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include "common_m4a.h"		/* common module */#include "cmdline.h"		/* command line module */#include "bitstream.h"		/* bit stream module */#include "obj_descr.h"		/* AI 990616 */#include "dec_par.h"		/* decoder cores */#include "dec_hvxc.h"		/* HVXC decoder core */#include "mp4_par.h"		/* parametric core common declarations */#include "hvxc.h"		/* hvxcDec module */#include "hvxcDec.h"		/* hvxcDec module *//* ---------- declarations ---------- */#define PROGVER "parametric decoder core DIS V0.1 05-feb-99"#define SEPACHAR " ,="#define MAXSAMPLE 32768		/* full scale sample value */#define STRLEN 255#define MINSPEEDFACT (0.2)	/* expected min. value: speedFact=0.2 */				/* AI 990128 / HP 990422 *//* ---------- variables ---------- */static float DPfSample;static float DPbitRate;static int DPmode;		/* enum MP4ModePar */static int DPframeMaxNumSample;static int DPframeTypNumSample;static int DPdelayNumSample;/* command line module */static int DPdelayMode;static int DPdebugLevel;static int DPdebugLevelIl;/* HILN decoder control HP970514 */static int DPnoIL;static int DPnoHarm;static int DPnoNoise;static int DPmaxNumLine;static int DPmaxNumHarm;static int DPmaxNumHarmLine;static int DPmaxNumNoisePara;static int DPmaxNumSynth;static float DPnoiseParaFact;static int DPenhaFlag;static int DPinitPrevNumLine;/* HVXC decoder configuration (AI 990210) */static int DPvarMode;static int DPrateMode;static int DPextensionFlag;static int DPdecMode;static int DPtestMode;	/* HVXC test_mode for decoder conformance testing *//* 0000 0000 0000 0000 : normal operation *//* xxxx xxxx xxxx xxx1 : postfilter and post processing are skipped *//* xxxx xxxx xxxx xx1x : initial values of harmonic phase are reset to zeros *//* xxxx xxxx xxxx x1xx : noise component addition are disabled *//* xxxx xxxx xxxx 1xxx : the output of Time Domain Decoder is disabled *//* HVXC decoder handle(used in DecParFrame() currently) */static HvxcDecStatus *decHvxcHandle;static int DPtest;static int DPfree;static int sysFlag;	/* a flag to use system interface(flexmux) (AI 990616) */static CmdLineSwitch switchList[] = {  {"h",NULL,NULL,NULL,NULL,"print help"},  {"dm",&DPdelayMode,"%i","1",NULL,"HVXC delay mode (0=short 1=normal)"},  {"dl",&DPdebugLevel,"%i","0",NULL,"debug level"},  {"tm",&DPtestMode,"%d","0",NULL,"HVXC test_mode (for decoder conformance testing)"},  {"-hvxc_sys",&sysFlag,NULL,NULL,NULL,"use system interface(flexmux)"},	/* AI 990616 */  {NULL,NULL,NULL,NULL,NULL,NULL}};/* switch/mix stuff */static float *tmpSampleBuf;static float *mixSampleBuf;static int mixSampleBufSize = 0;static BsBitBuffer *dmyBuf;static int ILdelayNumSample = 0;static int HVXdelayNumSample = 0;static BsBitBuffer *tmpBSbuf;static BsBitStream *tmpBSstream;/* ---------- internal functions ---------- *//* DecParInitHvx() *//* Init: harmonic vector exitation */static void DecParInitHvx (  BsBitStream *hdrStream)	/* in: header for bit stream */{  if (BsGetBitInt(hdrStream,(unsigned int*)&DPvarMode,1))    CommonExit(1,"DecParInitHvx: error reading bit stream header");  if (BsGetBitInt(hdrStream,(unsigned int*)&DPrateMode,2))    CommonExit(1,"DecParInitHvx: error reading bit stream header");  if (BsGetBitInt(hdrStream,(unsigned int*)&DPextensionFlag,1))    CommonExit(1,"DecParInitHvx: error reading bit stream header");  /*  DPframeMaxNumSample = 160 * (int) ceil(1.0 / DPspeedFact);  */  /* DPframeMaxNumSample = 320;	*//* expected max.value, speedFact=0.5 (AI 990128) */  DPframeMaxNumSample = 160 * (int) ceil(1.0 / MINSPEEDFACT);    if (DPdelayMode == DM_LONG)	/* HP 971023 */    DPdelayNumSample = 80;	/* 10 ms */  else    DPdelayNumSample = 60;	/* 7.5 ms */  decHvxcHandle = hvxc_decode_init(DPvarMode,				   DPrateMode,				   DPextensionFlag,				   DPdelayMode,				   DPtestMode);}/* DecParFrameHvx() *//* Decode frame: harmonic vector exitation */void DecParFrameHvx (  BsBitStream *stream,		/* in: bit stream */  float *sampleBuf,		/* out: frameNumSample audio samples */  int *frameBufNumSample,	/* out: num samples in sampleBuf[] */  float speedFact,		/* in: speed change factor(AI 990209) */  float pitchFact		/* in: pitch change factor(AI 990209) */  ){    int	i, j;    unsigned char tmpIdVUV;    unsigned char tmpEncBit;    unsigned char encBit[10];    if (speedFact<MINSPEEDFACT) {      speedFact = MINSPEEDFACT;      CommonWarning("DecParFrameHvx: speedFact below %f",MINSPEEDFACT);    }    {      /* HP 970706 970708 970709 */      if (!stream){        DPdecMode = DEC0K;       }      else if (!BsEof(stream,80-1)){  /* MN 971107 */        DPdecMode = DEC4K;       }      else if (!BsEof(stream,80-6-1)){ /* MN 971107 */        DPdecMode = DEC3K;      }      else{        DPdecMode = DEC2K;      }    }    if (DPdebugLevel >= 2) {      printf("DecParFrameHvx: stream=%s\n",stream?"valid":"NULL");      printf("DecParFrameHvx: decMode=");      switch (DPdecMode) {      case DEC0K : printf("DEC0K\n"); break;      case DEC2K : printf("DEC2K\n"); break;      case DEC3K : printf("DEC3K\n"); break;      case DEC4K : printf("DEC4K\n"); break;      default : printf("ERROR!!!\n");      }    }    for (i = 0; i < 5; i++) encBit[i] = 0;        if(DPdecMode == DEC4K || DPdecMode == DEC3K)	/* Modified on 07/04/97 by Y.Maeda */    {      {        for(j = 0; j < 9; j++)          if(BsGetBitChar(stream, &encBit[j], 8))	    CommonExit(1,"DecParFrameHvx: error reading bit stream");        if (DPdecMode == DEC4K) {	  if(BsGetBitChar(stream, &encBit[9], 8)) /* MN 971106 */	    CommonExit(1,"DecParFrameHvx: error reading bit stream");        }        else {	  /* MN 971107 */	  if(BsGetBitChar(stream, &tmpEncBit, 8-6))	    CommonExit(1,"DecParFrameHvx: error reading bit stream");	  encBit[9] = (tmpEncBit & 0x3) << 6;        }      }    }    else if(DPdecMode == DEC2K)    {      if(DPvarMode == BM_VARIABLE)      {        if(BsGetBitChar(stream, &tmpIdVUV, 2))          CommonExit(1,"DecParFrameHvx: error reading bit stream");	encBit[0] = (tmpIdVUV << 6) & 0xc0;	/* HP 971111 */	if (DPdebugLevel >= 2)	  printf("DecParFrameHvx: tmpIdVUV=%d\n", tmpIdVUV);	switch(tmpIdVUV)        {        case 0:	  if(BsGetBitChar(stream, &tmpEncBit, 6))            CommonExit(1,"DecParFrameHvx: error reading bit stream");	  encBit[0] |= (tmpEncBit & 0x3f);          for(j = 1; j < 3; j++)            if(BsGetBitChar(stream, &encBit[j], 8))	      CommonExit(1,"DecParFrameHvx: error reading bit stream");	  if(BsGetBitChar(stream, &tmpEncBit, 4))            CommonExit(1,"DecParFrameHvx: error reading bit stream");	  encBit[3] = (tmpEncBit & 0xf) << 4;	  break;	case 1:	  /*** reading padded bits necessary(AI 990528) ***/	  if(BsGetBitChar(stream, &tmpEncBit, 6))		    CommonExit(1,"DecParFrameHvx: error reading bit stream");	  break;	case 2:	case 3:	  if(BsGetBitChar(stream, &tmpEncBit, 6))            CommonExit(1,"DecParFrameHvx: error reading bit stream");	  encBit[0] |= (tmpEncBit & 0x3f);          for(j = 1; j < 5; j++)            if(BsGetBitChar(stream, &encBit[j], 8))	      CommonExit(1,"DecParFrameHvx: error reading bit stream");	  break;	}      }      else      {        for(j = 0; j < 5; j++)          if(BsGetBitChar(stream, &encBit[j], 8))	    CommonExit(1,"DecParFrameHvx: error reading bit stream");      }    }    hvxc_decode(decHvxcHandle,		encBit,		sampleBuf,		frameBufNumSample,		speedFact,		pitchFact,		DPdecMode		);}/* DecParFreeHvx() *//* Free memory: harmonic vector exitation */void DecParFreeHvx (){  hvxc_decode_free(decHvxcHandle);}/* ---------- functions ---------- */char *DecParInfo (  FILE *helpStream)		/* in: print decPara help text to helpStream */				/*     if helpStream not NULL */				/* returns: core version string */{  if (helpStream != NULL) {    fprintf(helpStream,	    PROGVER "\n"	    "decoder parameter string format:\n"	    "  list of tokens (tokens separated by characters in \"%s\")\n",	    SEPACHAR);    CmdLineHelp(NULL,NULL,switchList,helpStream);  }  return PROGVER;}/* DecParInit() *//* Init parametric decoder core. */void DecParInit (  int numChannel,		/* in: num audio channels */  float fSample,		/* in: sampling frequency [Hz] */  float bitRate,		/* in: total bit rate [bit/sec] */  char *decPara,		/* in: decoder parameter string */  BsBitBuffer *bitHeader,	/* in: header from bit stream */  int *frameMaxNumSample,	/* out: max num samples per frame */  int *delayNumSample		/* out: decoder delay (num samples) */  ){  int parac;  char **parav;  int result;  BsBitStream *hdrStream;  char *paraMode;  int i;  /* evaluate decoder parameter string */  parav = CmdLineParseString(decPara,SEPACHAR,&parac);  result = CmdLineEval(parac,parav,NULL,switchList,1,NULL);  if (result) {    if (result==1) {      DecParInfo(stdout);      CommonExit(1,"decoder core aborted ...");    }    else      CommonExit(1,"decoder parameter string error");  }  if (DPdebugLevel >= 1) {    printf("DecParInit: numChannel=%d  fSample=%f  bitRate=%f\n",	   numChannel,fSample,bitRate);    printf("DecParInit: decPara=\"%s\"\n",	   decPara);    printf("DecParInit: debugLevel=%d\n",	   DPdebugLevel);  }  if (numChannel != 1)    CommonExit(1,"DecParInit: audio data has more the one channel (%d)",	       numChannel);  CmdLineParseFree(parav);  DPfSample = fSample;  DPbitRate = bitRate;  hdrStream = BsOpenBufferRead(bitHeader);  if (BsGetBitInt(hdrStream,(unsigned int*)&DPmode,2))    CommonExit(1,"DecParInit: error reading bit stream header");  if (DPmode<0 || DPmode>MODEPAR_NUM)    CommonExit(1,"DecParInit: unknown parametric codec mode %d",DPmode);  paraMode = MP4ModeParName[DPmode];  if (DPdebugLevel >= 1)    printf("DecParInit: modeInt=%d  mode=\"%s\"\n",DPmode,paraMode);  switch (DPmode) {  case MODEPAR_HVX:    DecParInitHvx(hdrStream);    break;  }  BsClose(hdrStream);  *frameMaxNumSample = DPframeMaxNumSample;  *delayNumSample = DPdelayNumSample;  mixSampleBufSize = DPframeMaxNumSample+

⌨️ 快捷键说明

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