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

📄 ntt_tf_quantize_spectrum.c

📁 MPEG2/MPEG4编解码参考程序(实现了MPEG4的部分功能)
💻 C
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************//* This software module was originally developed by                          *//*   Naoki Iwakami (NTT)                                                     *//* and edited by                                                             *//*   Naoki Iwakami (NTT) on 1997-07-17,                                      *//* in the course of development of the                                       *//* MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, 14496-1,2 and 3.        *//* This software module is an implementation of a part of one or more        *//* MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4 Audio *//* standard. ISO/IEC  gives users of the MPEG-2 NBC/MPEG-4 Audio standards   *//* free license to this software module or modifications thereof for use in  *//* hardware or software products claiming conformance to the MPEG-2 NBC/     *//* MPEG-4 Audio  standards. Those intending to use this software module in   *//* hardware or software products are advised that this use may infringe      *//* existing patents. The original developer of this software module and      *//* his/her company, the subsequent editors and their companies, and ISO/IEC  *//* have no liability for use of this software module or modifications        *//* thereof in an implementation. Copyright is not released for non           *//* MPEG-2 NBC/MPEG-4 Audio conforming products. The original developer       *//* retains full right to use the code for his/her  own purpose, assign or    *//* donate the code to a third party and to inhibit third party from using    *//* the code for non MPEG-2 NBC/MPEG-4 Audio conforming products.             *//* This copyright notice must be included in all copies or derivative works. *//* Copyright (c)1996.                                                        *//*****************************************************************************/#include <stdio.h>#include "block.h"               /* handler, defines, enums */#include "buffersHandle.h"       /* handler, defines, enums */#include "interface.h"           /* handler, defines, enums */#include "mod_bufHandle.h"       /* handler, defines, enums */#include "resilienceHandle.h"    /* handler, defines, enums */#include "tf_mainHandle.h"       /* handler, defines, enums */#include "nok_bwp_enc.h"         /* structs */#include "nok_ltp_common.h"      /* structs */#include "tf_mainStruct.h"       /* structs */#include "tns.h"                 /* structs */#include "ntt_conf.h"#include "ntt_encode.h"#include "all.h"void ntt_tf_quantize_spectrum(double spectrum[],          /* Input : spectrum*/			      double lpc_spectrum[],      /* Input : LPC spectrum*/			      double bark_env[],          /* Input : Bark-scale envelope*/			      double pitch_sequence[],    /* Input : periodic peak components*/			      double gain[],              /* Input : gain factor*/			      double perceptual_weight[], /* Input : perceptual weight*/			      ntt_INDEX *ntt_index)           /* In/Out : VQ code indices */{  /*--- Variables ---*/  int    ismp, nfr, nsf, n_can, vq_bits;  double add_signal[ntt_T_FR_MAX];  double *sp_cv0, *sp_cv1;  int    cb_len_max, isf;  int nfrlim;  float ftmp;  /*--- Parameter settings ---*/  switch (ntt_index->w_type){  case ONLY_LONG_SEQUENCE:  case LONG_START_SEQUENCE:  case LONG_STOP_SEQUENCE:    /* available bits */    vq_bits = ntt_index->nttDataBase->ntt_VQTOOL_BITS;    /* codebooks */    sp_cv0 = ntt_index->nttDataBase->ntt_codev0;    sp_cv1 = ntt_index->nttDataBase->ntt_codev1;    cb_len_max = ntt_CB_LEN_READ + ntt_CB_LEN_MGN;    /* number of pre-selection candidates */    n_can = ntt_N_CAN;    /* frame size */    nfr = ntt_index->block_size_samples;    nsf = ntt_index->numChannel;    /* additional signal */    for (ismp=0; ismp<ntt_index->block_size_samples*ntt_index->numChannel; ismp++){      add_signal[ismp] = pitch_sequence[ismp] / lpc_spectrum[ismp];    }    break;    case EIGHT_SHORT_SEQUENCE:    /* available bits */    vq_bits = ntt_index->nttDataBase->ntt_VQTOOL_BITS_S;    /* codebooks */    sp_cv0 = ntt_index->nttDataBase->ntt_codev0s;     sp_cv1 = ntt_index->nttDataBase->ntt_codev1s;    cb_len_max = ntt_CB_LEN_READ_S + ntt_CB_LEN_MGN;    /* number of pre-selection candidates */    n_can = ntt_N_CAN_S;    /* number of subframes in a frame */    nfr = ntt_index->block_size_samples/8;    nsf = ntt_index->numChannel * ntt_N_SHRT;    /* additional signal */    ntt_zerod(ntt_index->block_size_samples*ntt_index->numChannel, add_signal);    break;  default:    fprintf(stderr, "ntt_sencode(): %d: Window mode error.\n", ntt_index->w_type);    exit(1);  }      ftmp = (float)(ntt_index->nttDataBase->bandUpper);      ftmp *= (float)nfr;      nfrlim= (int)ftmp;  for(isf=1; isf<nsf; isf++){      ntt_movdd(nfrlim,spectrum+isf*nfr, spectrum+isf*nfrlim);      ntt_movdd(nfrlim, lpc_spectrum+isf*nfr, lpc_spectrum+isf*nfrlim);      ntt_movdd(nfrlim,bark_env+isf*nfr, bark_env+isf*nfrlim);      ntt_movdd(nfrlim, perceptual_weight+isf*nfr,perceptual_weight+isf*nfrlim);      ntt_movdd(nfrlim,add_signal+isf*nfr, add_signal+isf*nfrlim);  }  /*--- Vector quantization process ---*/     if(tvq_debug_level>6)       fprintf(stderr, "UUUUU %5d \n", vq_bits);     ntt_vq_pn( nfrlim,	    nsf, vq_bits, n_can,	    sp_cv0, sp_cv1, cb_len_max,	    spectrum, lpc_spectrum, bark_env, add_signal, gain,	    perceptual_weight,	    ntt_index->wvq, ntt_index->pow);#if 1 /* requntize gain */   {    int top, data_len, i_ch, numChannel, iptop, gtop, subtop;    double g_opt[16], tmp, nume[16], denom[16],sig_l[2048], norm;    double g_gain, g_norm, pwr, nume0[2], denom0[2], pwrtmp, glgain[2];        if(nsf==2 || nsf==16) numChannel =2;    else numChannel =1;    data_len = nfrlim * nsf;    if(nsf>3){      double dmu_power, dec_power;      for (i_ch=0; i_ch<numChannel; i_ch++){       iptop = i_ch * (nsf/numChannel + 1);           dmu_power = ntt_index->pow[iptop] * ntt_STEP +ntt_STEP/2.;           dec_power = ntt_mulawinv(dmu_power, ntt_AMP_MAX, ntt_MU);	   glgain[i_ch] = dec_power  / ntt_AMP_NM;      }    }    ntt_vex_pn(ntt_index->wvq, sp_cv0, sp_cv1, cb_len_max,	     nsf, data_len, vq_bits, sig_l);    nume0[0]=denom0[0]=0.;    if(numChannel == 2) nume0[1]=denom0[1]=0.;    for(isf=0; isf<nsf; isf++){       nume[isf]=denom[isf]=0.0;       top = isf*nfrlim;       for(ismp=0; ismp<nfrlim; ismp++){	  tmp=sig_l[top+ismp]*perceptual_weight[top+ismp]*	      bark_env[ismp+top] / lpc_spectrum[ismp+top];	  nume[isf]+= tmp*	  (spectrum[top+ismp] -add_signal[top+ismp])	  *perceptual_weight[top+ismp];	  denom[isf] +=  tmp*tmp;	 /*	  if(nsf >=8){fprintf(stderr, "PPP %2d %3d %7.2f %8.2f %5.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n", 	    isf, ismp, spectrum[top+ismp], sig_l[top+ismp],	    perceptual_weight[ismp+top], 	    tmp, tmp*spectrum[top+ismp]*perceptual_weight[top+ismp],	    tmp*tmp, nume0[isf/8], denom0[isf/8]);	  }*/       }      if(nsf >=8){	if(tvq_debug_level>6  )	fprintf(stderr, "%5d %12.3f %12.3f opt_gainZZ\n", 	isf, nume[isf]/(denom[isf]+0.0001)*glgain[isf/8], gain[isf]);      }       g_opt[isf] = nume[isf]/(denom[isf]+0.0001);       if(tvq_debug_level>6  )	fprintf(stderr, "%5d %12.3f %12.3f opt_gainZZ\n", 	isf, g_opt[isf], gain[isf]);    }    for(i_ch=0; i_ch<numChannel; i_ch++){    if (nsf < 3){ /* long*/      /* global gain */      if(tvq_debug_level>6 )         fprintf(stderr, "%12.3f %5d ->",   gain[i_ch],         ntt_index->pow[i_ch]);      ntt_enc_gain(g_opt[i_ch]*1024, &(ntt_index->pow[i_ch]),      &gain[i_ch],&g_norm);      if(tvq_debug_level>6 )         fprintf(stderr, "%5d %12.3f  %5d ZZZZZlong \n", i_ch,  gain[i_ch],         ntt_index->pow[i_ch]);    }    else{      /* global gain */      iptop = (8+1)*i_ch;      gtop  = 8*i_ch;      nume0[i_ch]=0.;      denom0[i_ch]=0.0;      for(pwr=0.,isf=0; isf<nsf/numChannel; isf++){        nume0[i_ch]+= gain[isf+gtop]/glgain[i_ch]*nume[gtop+isf];        denom0[i_ch]+= gain[isf+gtop]/glgain[i_ch]*gain[isf+gtop]/glgain[i_ch]			 *denom[gtop+isf];      }      pwr = nume0[i_ch]/(denom0[i_ch]+0.001)*1024.;	  	  if(tvq_debug_level>6  )          fprintf(stderr, "%5d %12.3f %5d index_pow[i_ch]ZZZZZ %12.3f %12.3f\n",              i_ch,  g_gain, ntt_index->pow[iptop], pwr, 	     1024.*nume0[i_ch]/denom0[i_ch]);      ntt_enc_gain(pwr,&(ntt_index->pow[iptop]),&g_gain,&g_norm);	  if(tvq_debug_level>6  )          fprintf(stderr, "%5d %12.3f  %5d index_pow[i_ch]ZZZZZQ %12.3f\n",              i_ch,  g_gain, ntt_index->pow[iptop], glgain[i_ch]);      /* subframe gain */      for(isf=0; isf<nsf/numChannel; isf++){          if(tvq_debug_level>6)          fprintf(stderr, "%5d %12.3f %5d %12.4f %12.4f zzzzzzzsub \n",                i_ch,  gain[isf+gtop], ntt_index->pow[iptop+isf+1], g_norm, g_gain);       ntt_enc_gaim(g_opt[gtop+isf]/g_gain*1024.,&(ntt_index->pow[iptop+isf+1]),                    &gain[gtop+isf], &norm);       gain[gtop+isf] *= g_gain;          if(tvq_debug_level>6)          fprintf(stderr, "%5d %12.3f %5d %12.4f %12.4f zzzzzzzsub \n",                i_ch,  gain[isf+gtop], ntt_index->pow[iptop+isf+1], g_norm, g_gain);      }    }   }  } #endif}void ntt_div_vec(int nfr,                         /* Param. : block length */		 int nsf,                         /* Param. : number of sub frames */		 int cb_len,                      /* Param. : codebook length */		 int cb_len0,                     /* Param.*/		 int idiv,                        /* Param. */		 int ndiv,                        /* Param. : number of interleave division */		 double target[],                 /* Input */		 double d_target[],               /* Output */		 double weight[],                 /* Input */		 double d_weight[],               /* Output */		 double add_signal[],             /* Input */		 double d_add_signal[],           /* Output */		 double perceptual_weight[],      /* Input */		 double d_perceptual_weight[])    /* Output */{  /*--- Variables ---*/  int  icv, ismp, itmp;  /*--- Parameter settings ---*/  for (icv=0; icv<cb_len; icv++) {    /*--- Set interleave ---*/    if ((icv<cb_len0-1) &&	((ndiv%nsf==0 && nsf>1) || ((ndiv&0x1)==0 && (nsf&0x1)==0)))

⌨️ 快捷键说明

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