📄 phi_lpc.c
字号:
/*====================================================================*//* MPEG-4 Audio (ISO/IEC 14496-3) Copyright Header *//*====================================================================*//*This software module was originally developed by Rakesh Taori and AndyGerrits (Philips Research Laboratories, Eindhoven, The Netherlands) inthe course of development of the MPEG-4 Audio (ISO/IEC 14496-3). Thissoftware module is an implementation of a part of one or more MPEG-4Audio (ISO/IEC 14496-3) tools as specified by the MPEG-4 Audio(ISO/IEC 14496-3). ISO/IEC gives users of the MPEG-4 Audio (ISO/IEC14496-3) free license to this software module or modifications thereoffor use in hardware or software products claiming conformance to theMPEG-4 Audio (ISO/IEC 14496-3). Those intending to use this softwaremodule in hardware or software products are advised that its use mayinfringe existing patents. The original developer of this softwaremodule and his/her company, the subsequent editors and theircompanies, and ISO/IEC have no liability for use of this softwaremodule or modifications thereof in an implementation. Copyright is notreleased for non MPEG-4 Audio (ISO/IEC 14496-3) conforming products.CN1 retains full right to use the code for his/her own purpose, assignor donate the code to a third party and to inhibit third parties fromusing the code for non MPEG-4 Audio (ISO/IEC 14496-3) conformingproducts. This copyright notice must be included in all copies orderivative works. Copyright 1996.*//*====================================================================*//*======================================================================*//* *//* SOURCE_FILE: PHI_LPC.C *//* PACKAGE: WDBxx *//* COMPONENT: Linear Prediction Subroutines *//* *//*======================================================================*//*======================================================================*//* I N C L U D E S *//*======================================================================*/#include <stdio.h>#include <stdlib.h>#include <math.h>#include <malloc.h> #include <float.h>#include <assert.h>#include "buffersHandle.h" /* handler, defines, enums */#include "bitstream.h"#include "phi_cons.h" #include "phi_priv.h"#include "phi_lpc.h"#include "phi_lpcq.h"#include "phi_lsfr.h"#include "nec_abs_proto.h"#include "pan_celp_const.h"#include "pan_celp_proto.h"#include "att_proto.h"#include "nec_abs_const.h"#include "nec_lspnw20.tbl"#define NEC_PAI 3.141592#define NEC_LSPPRDCT_ORDER 4#define NEC_NUM_LSPSPLIT1 2#define NEC_NUM_LSPSPLIT2 4#define NEC_QLSP_CAND 2#define NEC_LSP_MINWIDTH_FRQ16 0.028#define NEC_MAX_LSPVQ_ORDER 20#define DEBUG_YM /* flag for halting LPC analysis : '98/11/27 *//*======================================================================*//* L O C A L F U N C T I O N S P R O T O T Y P E S */ /*======================================================================*//*======================================================================*//* Modified Panasonic/NEC functions *//*======================================================================*/static void mod_nec_lsp_sort( float x[], long order , PHI_PRIV_TYPE *PHI_Priv);/*======================================================================*/static void mod_nec_psvq( float *, float *, float *, long, long, float *, long *, long );/*======================================================================*/static void mod_nb_abs_lsp_quantizer ( float current_lsp[], /* in: current LSP to be quantized */ float previous_Qlsp[], /* In: previous Quantised LSP */ float current_Qlsp[], /* out: quantized LSP */ long lpc_indices[], /* out: LPC code indices */ long lpc_order, /* in: order of LPC */ long num_lpc_indices, /* in: number of LPC indices */ long n_lpc_analysis /* in: number of LP analysis per frame */);/*======================================================================*/static void mod_nec_bws_lsp_quantizer( float lsp[], /* input */ float qlsp8[], /* input */ float qlsp[], /* output */ long indices[], /* output */ long lpc_order, /* configuration input */ long lpc_order_8, /* configuration input */ long num_lpc_indices, /* configuration input */ float blsp[NEC_LSPPRDCT_ORDER][NEC_MAX_LSPVQ_ORDER], PHI_PRIV_TYPE *PHI_Priv /* In/Out: PHI private data (instance context) */);/*======================================================================*/static void mod_nb_abs_lsp_decode( unsigned long lpc_indices[], /* in: LPC code indices */ float prev_Qlsp[], /* in: previous LSP vector */ float current_Qlsp[], /* out: quantized LSP vector */ long lpc_order, /* in: order of LPC */ long num_lpc_indices /* in: number of LPC indices */); /*======================================================================*/static void mod_nec_bws_lsp_decoder( unsigned long indices[], /* input */ float qlsp8[], /* input */ float qlsp[], /* output */ long lpc_order, /* configuration input */ long lpc_order_8, /* configuration input */ long num_lpc_indices, /* configuration input */ float blsp[NEC_LSPPRDCT_ORDER][NEC_MAX_LSPVQ_ORDER], PHI_PRIV_TYPE *PHI_Priv /* In/Out: PHI private data (instance context) */);/*======================================================================*/ static void mod_wb_celp_lsp_quantizer ( float current_lsp[], /* in: current LSP to be quantized */ float previous_Qlsp[], /* In: previous Quantised LSP */ float current_Qlsp[], /* out: quantized LSP */ long lpc_indices[], /* out: LPC code indices */ long lpc_order, /* in: order of LPC */ long num_lpc_indices, /* in: number of LPC indices */ long n_lpc_analysis /* in: number of LP analysis per frame */);/*======================================================================*/static void mod_wb_celp_lsp_decode( unsigned long lpc_indices[], /* in: LPC code indices */ float prev_Qlsp[], /* in: previous LSP vector */ float current_Qlsp[], /* out: quantized LSP vector */ long lpc_order, /* in: order of LPC */ long num_lpc_indices /* in: number of LPC indices */);/*======================================================================*//* Function Prototype: PHI_Apar2Rfc *//*======================================================================*/static void PHI_Apar2Rfc(int P, /* In: LPC Order */float ap[], /* In: Polynomial coefficients [0..P-1] */float rfc[] /* Out: Reflection coefficients [0..P-1] */);/*======================================================================*//* Function Prototype: PHI_Rfc2Apar *//*======================================================================*/static void PHI_Rfc2Apar(int P, /* In: LPC Order */float rq[], /* In: Reflection coefficients [0..P-1] */float aq[] /* Out: a-parameters [0..P-1] */ );/*======================================================================*//* Function Prototype: PHI_CalcAcf *//*======================================================================*/static void PHI_CalcAcf(double sp_in[], /* In: Input segment [0..N-1] */double acf[], /* Out: Autocorrelation coeffs [0..P] */int N, /* In: Number of samples in the segment */ int P /* In: LPC Order */);/*======================================================================*//* Function Prototype: PHI_LevinsonDurbin *//*======================================================================*/static int PHI_LevinsonDurbin /* Retun Value: 1 if unstable filter */ ( double acf[], /* In: Autocorrelation coeffs [0..P] */ double apar[], /* Out: Polynomial coeffciients [0..P-1] */ double rfc[], /* Out: Reflection coefficients [0..P-1] */int P, /* In: LPC Order */double * E /* Out: Residual energy at the last stage */);/*======================================================================*//* Function Prototype: PHI_Rfc2Lar *//*======================================================================*/static void PHI_Rfc2Lar(int P, /* In: LPC Order */float rfc[], /* In: Array of reflection coeffs[0..P-1] */float lar[] /* Out: Array of log area ratios[0..P-1] */);/*======================================================================*//* Function Prototype: PHI_Lar2Rfc *//*======================================================================*/static int PHI_Lar2Rfc(int P, /* In: LPC Order */float lar[], /* In: Array of log area ratios[0..P-1] */float rfc[] /* Out: Array of reflection coeffs[0..P-1] */);/*======================================================================*//* Function Prototype: PHI_PackLpcCodes *//*======================================================================*/static void PHI_PackLpcCodes(const long lpc_order, /*In: Order of LPC */const long rfc_code[], /*In: Array of Refl. Coeffs[0..order-1] */const long pack_array_size, /*In: Array size after packing */ long packed_code[] /*Out: Packed Array[0..pack_array-size-1] */);/*======================================================================*//* Function Prototype: PHI_UnpackLpcCodes *//*======================================================================*/static void PHI_UnpackLpcCodes(const long lpc_order, /*In: Order of LPC */ long rfc_code[], /*Out: Array of Refl. Coeffs[0..order-1] */const long pack_array_size, /*In: Array size after packing */const long packed_code[] /*In: Packed Array[0..pack_array-size-1] */);/*======================================================================*//* Function Prototype: PHI_lpc_analysis *//*======================================================================*/void PHI_lpc_analysis(float PP_InputSignal[], /* In: Input Signal */float lpc_coefficients[], /* Out: LPC Coefficients[0..lpc_order-1]*/float *first_order_lpc_par, /* Out: a_parameter for 1st-order fit */long frame_size, /* In: Number of samples in frame */float HamWin[], /* In: Hamming Window */long window_offset, /* In: offset for window w.r.t curr. fr*/long window_size, /* In: LPC Analysis-Window Size */float gamma_be[], /* In: Bandwidth expansion coeffs. */long lpc_order /* In: Order of LPC */);/*======================================================================*//* Function Definition:PHI_InitLpcAnalysisEncoder *//*======================================================================*/void PHI_InitLpcAnalysisEncoder(long win_size[], /* In: LPC Analysis-Window Size */long n_lpc_analysis, /* In: Numberof LPC Analysis Frame */long order, /* In: Order of LPC */long order_8, /* In: Order of LPC */float gamma_be, /* In: Bandwidth Expansion Coefficient */long bit_rate, /* In: Bit Rate */long sampling_frequency, /* In: Sampling Frequency */long SampleRateMode, /* In: SampleRateMode */ long frame_size, /* In: Frame Size */long num_lpc_indices, /* In: Number of LPC indices */ long n_subframes, /* In: Number of subframes */long num_shape_cbks, /* In: Number of Shape Codebooks */long num_gain_cbks, /* In: Number of Gain Codebooks */long frame_bit_allocation[], /* In: Frame bit allocation */long num_indices,long QuantizationMode,PHI_PRIV_TYPE *PHI_Priv /* In/Out: PHI private data (instance context) */){ int x; int i,j; /* -----------------------------------------------------------------*/ /* Create Arrays for Hamming Window and gamma array */ /* -----------------------------------------------------------------*/ if ( (( PHI_Priv->PHI_mem_i = (float *)malloc((unsigned int)order * sizeof(float))) == NULL ) || (( PHI_Priv->PHI_current_lar = (float *)malloc((unsigned int)order * sizeof(float))) == NULL )|| (( PHI_Priv->PHI_prev_lar = (float *)malloc((unsigned int)order * sizeof(float))) == NULL )|| (( PHI_Priv->PHI_prev_indices = (long *)malloc((unsigned int)order * sizeof(long))) == NULL ) ) { printf("MALLOC FAILURE in Routine InitLpcAnalysis \n"); exit(1); } /* -----------------------------------------------------------------*/ /* Create Array for Quantiser BLSP */ /* -----------------------------------------------------------------*/ for ( i = 0; i < NEC_LSPPRDCT_ORDER; i++ ) { for ( j = 0; j < (int)order; j++ ) { if ( j >= (int)(order/2) ) PHI_Priv->blsp_previous[i][j]=(float)NEC_PAI/(float)(order+1)*(j+1); else PHI_Priv->blsp_previous[i][j]=(float)0.0; } } /* -----------------------------------------------------------------*/ /* Create Array for Quantiser (narrowband) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -