www.pudn.com > CryptoPhone-src-031122.zip > delay.c
/* Copyright 2001,2002,2003 NAH6
* All Rights Reserved
*
* Parts Copyright DoD, Parts Copyright Starium
*
*/
/*LINTLIBRARY*/
/*PROTOLIB1*/
#include "main.h"
#include
#include
#include "delay.h"
#include "celp_sup.h"
static void Resample(
float sig_in[],
float wsinc[MAX_M1+MAX_M2+1][MAX_NFRAC],
int q_frac_pit,
int out_len,
int out_start,
int int_pit,
int m1,
int m2,
float sig_out[]);
static void GenHam(
int nfrac,
float frac[MAX_NFRAC],
int m1,
int m2,
int twelfths[MAX_NFRAC],
float wsinc[MAX_M1+MAX_M2+1][MAX_NFRAC]);
static int quan_frac(
float frac_pit,
int nfrac,
float frac[MAX_NFRAC]);
float sinc(
float arg);
/*************************************************************************
*
* ROUTINE
* delay
*
* FUNCTION
* Time delay a bandlimited signal of either 8 or 40 points
* using point-by-point recursion
*
* SYNOPSIS
* delay(SigIn, SigInLen, SigOutStart, SigOutLen, FracPit,
* IntPit, IntLow, IntUp, NumFracDelay, SigOut)
*
* formal
* data I/O
* name type type function
* -------------------------------------------------------------------
* SigIn float i/o signal input (output in last 60)
* SigInLen int i length of input sequence x(n)
* SigOutStart int i beginning of output sequence
* SigOutLen int i length of output sequence
* FracPit float i fractional pitch
* IntPit int i integer pitch
* IntLow int i Lower interpolation bound
* IntUp int i Upper interpolation bound
* NumFracDelay int i Number of fractional delays
* SigOut float o delayed input signal
*==========================================================================
*
* DESCRIPTION
*
* Subroutine to time delay a bandlimited signal by resampling the
* reconstructed data (aka sinc interpolation). The well known
* reconstruction formula is:
*
* | M2 sin[pi(t-nT)/T] M2
* y(n) = X(t)| = SUM x(n) --------------- = SUM x(n) sinc[(t-nT)/T]
* | n=M1 pi(t-nT)/T n=M1
* |t=n+d
*
* The interpolating (sinc) function is Hamming windowed to bandlimit
* the signal to reduce aliasing.
*
* Multiple simultaneous time delays may be efficiently calculated
* by polyphase filtering. Polyphase filters decimate the unused
* filter coefficients. See Chapter 6 in C&R for details.
*==========================================================================
*
* REFERENCES
*
* Crochiere & Rabiner, Multirate Digital Signal Processing,
* P-H 1983, Chapters 2 and 6.
*
* Kroon & Atal, "Pitch Predictors with High Temporal Resolution,"
* ICASSP '90, S12.6
*
***************************************************************************/
void delay(
float SigIn[],
int SigInLen,
int SigOutStart,
int SigOutLen,
float FracPit,
int IntPit,
int IntLow,
int IntUp,
int NumFracDelay,
float SigOut[])
{
static int LongFirst=TRUE, ShortFirst=TRUE;
static float Longwsinc[MAX_M1+MAX_M2+1][MAX_NFRAC];
static float Shortwsinc[MAX_M1+MAX_M2+1][MAX_NFRAC];
int twelfths[MAX_NFRAC] = {3,4,6,8,9};
float frac[MAX_NFRAC] = {0.25, 0.3333333, 0.5, 0.66666667, 0.75};
int q_frac_pit;
int ldelay;
/* Determine whether this is a long or short delay */
if(IntLow == -20)
ldelay = TRUE;
else
ldelay = FALSE;
/* Generate appropriate Hamming windowed sinc interpolating functions */
if (LongFirst) {
if(ldelay) {
LongFirst = FALSE;
/* Generate Hamming windowed sinc interpolating function for each
allowable fraction */
GenHam(NumFracDelay, frac, IntLow, IntUp, twelfths, Longwsinc);
}
}
if (ShortFirst) {
if(!ldelay) {
ShortFirst = FALSE;
/* Generate Hamming windowed sinc interpolating function for each
allowable fraction */
GenHam(NumFracDelay, frac, IntLow, IntUp, twelfths, Shortwsinc);
}
}
/* Quantize the fractional pitch */
q_frac_pit = quan_frac(FracPit, NumFracDelay, frac);
/* Resample */
if(ldelay)
Resample(SigIn, Longwsinc, q_frac_pit, SigOutLen, SigOutStart,
IntPit, IntLow, IntUp, SigOut);
else
Resample(SigIn, Shortwsinc, q_frac_pit, SigOutLen, SigOutStart,
IntPit, IntLow, IntUp, SigOut);
}
/*
************************************************************************
*
* ROUTINE
* GenHam
*
* FUNCTION
*
* Generate Hamming windowed sinc interpolating function
*
* SYNOPSIS
* GenHam(nfrac, frac, m1, m2, twelfths, wsinc, hwin)
*
* formal
* data I/O
* name type type function
* -------------------------------------------------------------------
* nfrac int i number of fractional delays
* frac float i "nfrac" fractional delays calculated
* over interpolation of M1 to M2
* m1 int i Lower interpolation bound
* m2 int i Upper interpolation bound
* twelfths int i ???
* wsinc float o Hamming windowed sinc interpolating
* function
* hwin float o Hamming window
**************************************************************************
*
* Generate Hamming windowed sinc interpolating function
* for each allowable fraction. The interpolating functions
* are stored in time reverse order (i.e., delay appears as
* advance) to align with the adaptive code book v0 array.
* The interp filters are:
* wsinc(.,1) frac = 1/4 (3/12)
* wsinc(.,2) frac = 1/3 (4/12)
* . .
* wsinc(.,5) frac = 3/4 (9/12)
*
**************************************************************************/
void GenHam(
int nfrac,
float frac[MAX_NFRAC],
int m1,
int m2,
int twelfths[MAX_NFRAC],
float wsinc[MAX_M1+MAX_M2+1][MAX_NFRAC])
{
int i,j;
float hwin[MAX_WINDOW_WIDTH+1];
CreateHam(hwin, 12*(m2-m1+1)+1);
for(i=0; i