/*====================================================================*/
/* MPEG-4 Audio (ISO/IEC 14496-3) Copyright Header */
/*====================================================================*/
/*
This software module was originally developed by Rakesh Taori and Andy
Gerrits (Philips Research Laboratories, Eindhoven, The Netherlands) in
the course of development of the MPEG-4 Audio (ISO/IEC 14496-3). This
software module is an implementation of a part of one or more MPEG-4
Audio (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/IEC
14496-3) free license to this software module or modifications thereof
for use in hardware or software products claiming conformance to the
MPEG-4 Audio (ISO/IEC 14496-3). Those intending to use this software
module in hardware or software products are advised that its 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-4 Audio (ISO/IEC 14496-3) conforming products.
CN1 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 parties from
using the code for non MPEG-4 Audio (ISO/IEC 14496-3) conforming
products. This copyright notice must be included in all copies or
derivative 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 rel='nofollow' onclick='return false;'>
#include "phi_cons.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
/*======================================================================*/
/* L O C A L D A T A D E F I N I T I O N S */
/*======================================================================*/
/*----------------------------------------------------------------------*/
/* Variables for bit rate control in VQ mode */
/* ---------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/* Variables for dynamic threshold */
/* ---------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/* Variables for statistics only */
/* ---------------------------------------------------------------------*/
/*======================================================================*/
/* 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(
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(
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) */
);
/*======================================================================*/
/* 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 *