📄 lp_anal.c
字号:
/* Copyright 2001,2002,2003 NAH6
* All Rights Reserved
*
* Parts Copyright DoD, Parts Copyright Starium
*
*/
#include "main.h"
#ifdef FLOATING_POINT
#include "showdata.h"
#endif
#include <stdlib.h>
#include <stdio.h>
//#include <math.h>
#include "lp_anal.h"
#include "pctolsf.h"
#include "bwexp.h"
#include "celp_sup.h"
#include "code_lsf.h"
#include "zero_array16.h"
#include "auto_cor.h"
STATIC void ApplyWindow(
fxpt_16 SpeechIn[F_LEN],
fxpt_16 HamSpeech[F_LEN]);
#if 0 /* function now defined in auto_cor.c */
STATIC void AutoCor(
fxpt_16 speech_in[F_LEN],
fxpt_32 ac[ORDER+1]);
#endif
STATIC void ACtoPC(
fxpt_32 ac[ORDER+1],
fxpt_32 pc[ORDER+1]);
#ifdef FLOATING_POINT
STATIC void ACtoRC(
float ac[ORDER+1],
float rc[ORDER],
float *err);
STATIC void HighFreqCorrect(
float ac[ORDER+1],
float alpha);
STATIC void RCtoPC(
float k[ORDER],
float pc[ORDER]);
#endif
STATIC void Durbin(
fxpt_32 ac[],
fxpt_32 pc[]);
/**************************************************************************
* *
* ROUTINE
* LP_Analysis
*
* FUNCTION
* Linear Predictive analysis
* SYNOPSIS
* LP_Analysis(SpeechIn, qlsf, frame_num)
*
* formal
*
* data I/O
* name type type function
* -------------------------------------------------------------------
* SpeechIn fxpt_16 i Frame of input speech
* qlsf fxpt_16 o Frame of quantized LSFs
* frame_num int i CELP frame number
*
**************************************************************************
*
* DESCRIPTION
*
* This performs an autocorrelation LP analysis of speech
* returning a set of line spectral frequencies representing
* the spectrum of the input speech signal.
*
**************************************************************************
*
* CALLED BY
*
* Analysis
*
* CALLS
*
* ApplyWindow AutoCor ACtoPC BWexp_PCs PCtoLSF QuanLSF
*
*
**************************************************************************/
#define TRUE 1
#define FALSE 0
void LP_Analysis(
fxpt_16 SpeechIn[F_LEN], /* 15.0 format */
fxpt_16 qlsf[ORDER] /* 0.15 format */
)
{
fxpt_32 ac[ORDER+1]; /* 30.1 format */
fxpt_16 lsf[ORDER+1]; /* 0.15 format */
fxpt_32 newpc[ORDER+1]; /* 5.16 format */
// fxpt_16 pc[ORDER+1]; /* 2.13 format */
fxpt_16 pcexp[ORDER+1]; /* 2.13 format */
fxpt_16 HamSpeech[F_LEN]; /* 15.0 format */
int findex[ORDER];
// DUMPARR0(SpeechIn,F_LEN)
FXPT_PUSHSTATE("LP_Analysis", -1.0, -1.0);
/* Apply Hamming window to Input Speech */
ApplyWindow(SpeechIn, HamSpeech);
DUMPARR0(HamSpeech,F_LEN)
/* Calculate Autocorrelations */
AutoCor(HamSpeech, ac);
DUMPARR(ac,1,ORDER+1)
/* Convert ACs to PCs */
ACtoPC(ac, newpc);
DUMPARR(newpc,26,ORDER+1)
/* Bandwidth Expand PCs */
BWExpand32(OMEGA32, newpc, pcexp);
DUMPARR(pcexp,13,ORDER+1)
/* Convert PCs to LSFs */
PCtoLSF(pcexp, lsf);
DUMPARR(lsf,15,ORDER+1)
/* Quantize the LSFs */
QuanLSF(lsf, qlsf, findex);
DUMPARR(qlsf,15,ORDER)
DUMPARR0(findex,ORDER);
FXPT_POPSTATE();
}
/**************************************************************************
* *
* ROUTINE
* ApplyWindow
*
* FUNCTION
* Apply a Hamming Window to input speech
* SYNOPSIS
* ApplyWindow(SpeechIn, HamSpeech)
*
* formal
*
* data I/O
* name type type function
* -------------------------------------------------------------------
* SpeechIn fxpt_16 i Frame of input speech
* HamSpeech fxpt_16 o Frame of output speech
*
**************************************************************************/
void ApplyWindow(
fxpt_16 SpeechIn[F_LEN], /* 15.0 format */
fxpt_16 HamSpeech[F_LEN]) /* 15.0 format */
{
static int first=TRUE;
static fxpt_16 HamWindow[F_LEN]; /* 0.15 format */
int i;
/* Generate Hamming window */
if (first) {
first=FALSE;
CreateHam(HamWindow, F_LEN);
}
/* Apply Hamming window to input speech */
for (i=0;i<F_LEN;i++) {
/*HamSpeech[i] = SpeechIn[i] * HamWindow[i];*/
HamSpeech[i] = fxpt_mult16_round(SpeechIn[i], HamWindow[i], 15);
}
}
/**************************************************************************
* *
* ROUTINE
* AutoCor
*
* FUNCTION
* Calculate the autocorrelations for a frame of speech
* SYNOPSIS
* AutoCor(speech_in, ac)
*
* formal
*
* data I/O
* name type type function
* -------------------------------------------------------------------
* speech_in fxpt_16 i Frame of input speech
* ac fxpt_32 o Autocorrelations
*
**************************************************************************/
#if 0 /* function now defined in auto_cor.c */
void AutoCor(
fxpt_16 speech_in[F_LEN], /* 15.0 format */
fxpt_32 ac[ORDER+1]) /* 30.1 format */
{
int i, j;
/* Calculate autocorrelations */
for (i=0; i<ORDER+1; i++) {
ac[i] = 0;
for (j=i; j<F_LEN; j++)
/*ac[i]+=speech_in[j]*speech_in[j-i];*/
/* The right shifts are for normalization.
* F_LEN is 60, so we want to multiply each
* value by 1/60 before accumulating it. The
* right shifts approximate this by effectively
* multiplying each value by 1/64.
*/
#if 0
ac[i] = fxpt_mac32(ac[i],
fxpt_shr16_round(speech_in[j], 3),
fxpt_shr16_round(speech_in[j-i], 3));
#else
ac[i] = fxpt_add32(ac[i], fxpt_shr32_fast(
fxpt_mult32(speech_in[j], speech_in[j-i]), 6));
#endif
}
}
#endif
/**************************************************************************
* *
* ROUTINE
* ACtoPC
*
* FUNCTION
* Calculate the Predictor Coefficients for a frame of speech
* SYNOPSIS
* ACtoPC(ac, pc)
*
* formal
*
* data I/O
* name type type function
* -------------------------------------------------------------------
* ac fxpt_32 i Autocorrelations
* pc fxpt_16 o Predictor Coefficients
*
**************************************************************************/
void ACtoPC(
fxpt_32 ac[ORDER+1],
fxpt_32 pc[ORDER+1])
{
#ifdef DURBIN
/* Use Durbin recursion to convert from ACs to PCs */
pc[0] = 67108864L; /* 1.0 in 5.16 format */
ZeroArray32(&pc[1], ORDER);
Durbin(ac, pc);
#else
float alpha;
float rc[ORDER];
/* Convert ACs to RCs */
ACtoRC(ac, rc, &alpha);
/* Perform high frequency correction */
HighFreqCorrect(ac, alpha);
/* Convert corrected ACs to RCs */
ACtoRC(ac, rc, &alpha);
/* Convert corrected RCs to PCs */
RCtoPC(rc, pc);
#endif
}
/*****************************************************************************
*
* NAME
* Durbin
*
*
* SYNOPSIS
*
* subroutine Durbin (ac, pc)
*
* formal
* data I/O
* name type type function
* -------------------------------------------------------------------
* ac[ORDER] fxpt_32 i auto-correlation coefficients
* pc[ORDER+1] fxpt_16 o prediction coeffs (voiced-> +pc[1])
*
****************************************************************************
*
* DESCRIPTION
*
* This performs the classical Durbin recursion
* on the correlation sequence c[0], c[1], c[2] . . .
* to obtain n reflection coefficients (rc).
*
* The sign convention used defines the first reflection coefficient
* as the normalized first autocorrelation coefficient, which results
* in positive values of rc[0] for voiced speech.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -