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

📄 nok_ltp_enc.c

📁 MPEG2/MPEG4编解码参考程序(实现了MPEG4的部分功能)
💻 C
📖 第 1 页 / 共 3 页
字号:
/**************************************************************************This software module was originally developed byNokia in the course of development of the MPEG-2 AAC/MPEG-4 Audio standard ISO/IEC13818-7, 14496-1, 2 and 3.This software module is an implementation of a partof one or more MPEG-2 AAC/MPEG-4 Audio tools as specified by theMPEG-2 aac/MPEG-4 Audio standard. ISO/IEC  gives users of theMPEG-2aac/MPEG-4 Audio standards free license to this software moduleor modifications thereof for use in hardware or software productsclaiming conformance to the MPEG-2 aac/MPEG-4 Audio  standards. Thoseintending to use this software module in hardware or software productsare advised that this use may infringe existing patents. The originaldeveloper of this software module, the subsequenteditors and their companies, and ISO/IEC have no liability for use ofthis software module or modifications thereof in animplementation. Copyright is not released for non MPEG-2 aac/MPEG-4Audio conforming products. The original developer retains full right touse the code for the developer's own purpose, assign or donate the code to athird party and to inhibit third party from using the code for nonMPEG-2 aac/MPEG-4 Audio conforming products. This copyright noticemust be included in all copies or derivative works.Copyright (c)1997.  ***************************************************************************//**************************************************************************  nok_ltp_enc.c  -  Performs Long Term Prediction for the MPEG-4                     T/F Encoder.  Author(s): Mikko Suonio, Juha Ojanpera  	     Nokia Research Center, Speech and Audio Systems, 1997.  *************************************************************************//**************************************************************************  Version Control Information			Method: CVS  Identifiers:  $Revision: 1.15 $  $Date: 1999/04/23 16:02:07 $ (check in)  $Author: purnhage $  *************************************************************************//**************************************************************************  External Objects Needed  *************************************************************************//*  Standard library declarations.  */#include <stdio.h>#include "block.h"               /* handler, defines, enums */#include "buffersHandle.h"       /* handler, defines, enums */#include "concealmentHandle.h"   /* handler, defines, enums */#include "interface.h"           /* handler, defines, enums */#include "mod_bufHandle.h"       /* handler, defines, enums */#include "reorderspecHandle.h"   /* handler, defines, enums */#include "resilienceHandle.h"    /* handler, defines, enums */#include "tf_mainHandle.h"       /* handler, defines, enums */#include "nok_ltp_common.h"      /* structs */#include "obj_descr.h"           /* structs */#include "tf_mainStruct.h"       /* structs *//*  Interface to related modules.  */#include "common_m4a.h"	/* HP 980211 */#include "nttNew.h"#include "tf_main.h"#include "interface.h"#include "bitstream.h"#include "nok_ltp_common.h"#include "nok_pitch.h"#include "tns3.h"/*  Macro:	PRINT  Purpose:	Interface to function for printing error messages.  *//*  Variable:	debug  Purpose:	Provided debug options.  Explanation:	If element debug['p'] is true, we give debug information  		on long term prediction.  *//*  Function:	buffer2freq  Call:		buffer2freq (p_in_data, p_out_mdct, p_overlap, windowSequence,  			     wfun_select, nlong, nmed, nshort, overlap_select,			     num_short_win, save_window);  Purpose:	Modified discrete cosine transform  Input:	p_in_data[]	- input signal (length: 2*shift length)		p_overlap[]	- buffer containing the previous frame				  in OVERLAPPED_MODE (length: 2*shift length)		windowSequence	- selects the type of window to use  		wfun_select	- select window function  		nlong		- shift length for long windows                nmed		- shift length for medium windows		nshort		- shift length for short windows		overlap_select	- OVERLAPPED_MODE select		num_short_win	- number of short windows to transform		save_window	- if true, save the windowSequence				  for future use  Output:	p_out_mdct[]	- transformed signal (length: shift length)		p_overlap[]	- a copy of p_in_data in OVERLAPPED_MODE  				  (length: shift length)  Explanation:	-  *//*  Function:	freq2buffer  Call:		freq2buffer (p_in_data, p_out_data, p_overlap, windowSequence,  			     nlong, nmed, nshort, wfun_select, fun_select_prev,			     overlap_select, num_short_win);  Purpose:	Inverse of modified discrete cosine transform  Input:	p_in_data[]	- input signal (length: shift length)		p_overlap[]	- the overlap buffer; does not have				  an effect in NON_OVERLAPPED_MODE,				  but have to be allocated				  (length: shift length)		windowSequence	- selects the type of window to use  		nlong		- shift length for long windows                nmed		- shift length for medium windows		nshort		- shift length for short windows  		wfun_select	- select window function		overlap_select	- OVERLAPPED_MODE select		num_short_win	- number of short windows to transform 		save_window	- if true, save windowSequence for future use  Output:	p_out_data[]	- transformed signal (length: 2*shift length)		p_overlap[]	- the overlap buffer; always modified				  (length: shift length)  Explanation:	-  *//*  Function:	BsPutBit  Purpose:	Writes specified number of bits to the open  		output bitstream.  *//**************************************************************************  External Objects Provided  *************************************************************************/#include "nok_ltp_enc.h"/**************************************************************************  Internal Objects  *************************************************************************/#include "nok_ltp_common_internal.h"static short double_to_int (double sig_in);/*  Purpose:	Encoding mode of short blocks.  Explanation:	- *//*#define NOK_LTP_SHORT_FAST*//*  Purpose:	Debug switch for LTP.  Explanation:	- *//*#define LTP_DEBUG*//**************************************************************************  Object Definitions  *************************************************************************//**************************************************************************  Title:	nok_init_lt_pred  Purpose:	Initialize the history buffer for long term prediction  Usage:        nok_init_lt_pred (lt_status)  Input:	lt_status :  		 buffer              - history buffer		 weight_idx          - 3 bit number indicating the LTP 		                       coefficient in the codebook                  sbk_prediction_used - 1 bit for each subblock indicating 		                       whether LTP is used in that subblock                  sfb_prediction_used - 1 bit for each scalefactor band (sfb)                                        where LTP  can be used indicating 				       whether LTP is switched on (1) /off (0)				       in that sfb.                 delay               - LTP lag                 side_info           - LTP side information		 mdct_predicted      - predicted spectrum  Output:	lt_status :  		 buffer              - filled with 0		 weight_idx          - filled with 0		 sbk_prediction_used - filled with 0		 sfb_prediction_used - filled with 0		 delay               - filled with 0		 side_info           - filled with 1		 mdct_predicted      - filled with 0  References:	-  Explanation:	-  Author(s):	Mikko Suonio  *************************************************************************/voidnok_init_lt_pred (NOK_LT_PRED_STATUS *lt_status){  int i;  for (i = 0; i < NOK_LT_BLEN; i++)    lt_status->buffer[i] = 0;  lt_status->weight_idx = 0;  for(i=0; i<NSHORT; i++)    lt_status->sbk_prediction_used[i] = lt_status->delay[i] = 0;  for(i=0; i<MAXBANDS; i++)    lt_status->sfb_prediction_used[i] = 0;  lt_status->side_info = LEN_LTP_DATA_PRESENT;  for(i = 0; i < 2 * NOK_MAX_BLOCK_LEN_LONG; i++)    lt_status->mdct_predicted[i] = 0.0;}/**************************************************************************  Title:	ltp_enc_tf  Purpose:      Transfers the predicted time domain signal into frequency                 domain and determines whether coding gain can be achieved.  Usage:        ltp_enc_tf(p_spectrum, predicted_samples, mdct_predicted, 	                   win_type, win_shape, win_shape_prev, 			   block_size_long, block_size_medium, 			   block_size_short, sfb_offset, num_of_sfb, 			   last_band, side_info, sfb_prediction_used, 			   tnsInfo, sw)  Input:        p_spectrum        - spectral coefficients                predicted_samples - predicted time domain samples	                       win_type          - window sequence (frame, block) type                win_shape         - shape of the mdct window		win_shape_prev    - shape from previous block		block_size_long   - size of the long block		block_size_medium - size of the medium block		block_size_short  - size of the short block                sfb_offset        - scalefactor band boundaries                num_of_sfb        - number of scalefactor bands in each block		last_band         - last scalefactor band where LTP is used		side_info         - LTP side information bits		tnsInfo           - TNS encoding parameters		sw                - subblock number  Output:	y                   - prediction gain                mdct_predicted      - predicted spectrum                p_spectrum          - error spectrum (if LTP used)		sfb_prediction_used - 1 bit for each scalefactor band (sfb) 		                      where LTP can be used indicating whether 				      LTP is switched on (1) /off (0) in 				      that sfb.                          References:	1.) buffer2freq in imdct.c                2.) TnsEncode2 in tns3.c		3.) TnsEncodeShortBlock in tns3.c                4.) snr_pred in nok_pitch.c  Explanation:  -  Author(s):	Juha Ojanpera  *************************************************************************/static doubleltp_enc_tf(double *p_spectrum, double *predicted_samples, 	   double *mdct_predicted, WINDOW_SEQUENCE win_type, 	   WINDOW_SHAPE win_shape, WINDOW_SHAPE win_shape_prev, 	   int block_size_long, int block_size_medium, int block_size_short, 	   int *sfb_offset, int num_of_sfb, int last_band, int side_info, 	   int *sfb_prediction_used, TNS_INFO *tnsInfo, int sw){  int frame_len;  double bit_gain;    /* Transform prediction to frequency domain. */  buffer2freq (predicted_samples, mdct_predicted, NULL,                win_type, win_shape, win_shape_prev,	       block_size_long, block_size_medium, block_size_short, 	       NON_OVERLAPPED_MODE, 1);    /* Apply TNS analysis filter to the predicted spectrum. */  if(tnsInfo != NULL)  {    if(win_type != EIGHT_SHORT_SEQUENCE)      TnsEncode2(num_of_sfb, num_of_sfb, win_type, sfb_offset, 		 mdct_predicted, tnsInfo, 0);    else      /* Filter this subblock. */      TnsEncodeShortBlock(/**TM last_band, last_band,*/			  num_of_sfb, num_of_sfb, sw, sfb_offset, 			  mdct_predicted, tnsInfo);  }  if(win_type != EIGHT_SHORT_SEQUENCE)    frame_len = block_size_long;  else    frame_len = block_size_short;    /* Get the prediction gain. */  bit_gain = snr_pred (p_spectrum, mdct_predicted, sfb_prediction_used, 		       sfb_offset, win_type, side_info, last_band, frame_len);  return (bit_gain);}/**************************************************************************  Title:	nok_ltp_enc  Purpose:      Performs long term prediction.  Usage:	y = nok_ltp_enc(p_spectrum, p_time_signal, win_type, win_shape,                                win_shape_prev, block_size_long, 				block_size_medium, block_size_short, 				sfb_offset, num_of_sfb, lt_status, tnsInfo, 				qc_select)

⌨️ 快捷键说明

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