spLib
Loading...
Searching...
No Matches
lpc.h
1/*
2 * lpc.h
3 */
4
5#ifndef SPLIB_LPC_H
6#define SPLIB_LPC_H
7
8#include <sp/spDefs.h>
9#include <sp/fft.h>
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15/* Basic parameters:
16 * cor[]: Autocorrelation from 0th to order-th. The size must be larger than (order+1).
17 * ncor[]: Normalized autocorrelation from 1st to order-th. The size must be larger than order.
18 * alpha[]: LPC coefficients from 1st to order-th. The size must be larger than order.
19 * alpha(0) is assumed to be 1.0.
20 * parcor[]: PARCOR coefficients (reflection coefficients) from 1st to order-th.
21 * The size must be larger than order.
22 * psd[]: Power spectrum density from 0 to pi radian (not normalized by 2PI). The size must be larger than (N/2+1).
23 * (N is total spectrum points from 0 to 2pi)
24 * vta[]: Vocal tract area ratio function (vta[0]: case of lips). The size must be larger than order.
25 * lsp[]: LSP frequencies ranging between 0.0 and 1.0,
26 * increasingly ordered, i.e.,lsp(0)<lsp(1)<..<lsp(lp-1).
27 * The size must be larger than order.
28 */
29
30/* Autocorrelation */
31extern long spSigToCor(double *sig, long siglen, double *cor, long corlen);
32extern long spSigToNCor(double *sig, long siglen, double *ncor, long ncorlen, double *cor0 /* can be NULL*/);
33extern long spSigToCorFFT(spFFTRec fftrec, double *sig, long siglen, double *cor, long corlen);
34extern long spSigToNCorFFT(spFFTRec fftrec, double *sig, long siglen, double *ncor, long ncorlen, double *cor0 /* can be NULL*/);
35/* preemph_db: preemphasis value in dB/oct */
36extern long spSpecToCorFFT(spFFTRec fftrec, double *spec, long speclen, double *cor, long corlen, double preemph_db);
37extern long spSpecToNCorFFT(spFFTRec fftrec, double *spec, long speclen, double *ncor, long ncorlen, double preemph_db, double *cor0 /* can be NULL */);
38/* deemph_db: deemphasis value in dB/oct */
39extern long spCorToSpecFFT(spFFTRec fftrec, double *cor, long corlen, double *spec, long speclen, double deemph_db);
40extern long spNCorToSpecFFT(spFFTRec fftrec, double *ncor, long ncorlen, double cor0,
41 double *spec, long speclen, double deemph_db);
42
43/* LPC computation from autocorrelation. */
44extern long spCorToParcor(double *cor, /* input. */
45 double *alpha, /* output. */
46 double *parcor, /* output. can be NULL. */
47 long order, /* input. */
48 double *resid); /* output. can be NULL. */
49extern long spNCorToParcor(double *ncor, /* input. */
50 double *alpha, /* output. */
51 double *parcor, /* output. can be NULL. */
52 long order, /* input. */
53 double *resid); /* output. can be NULL. */
54extern long spCorToAlpha(double *cor, /* input. */
55 double *alpha, /* output. */
56 long order, /* input. */
57 double *resid); /* output. can be NULL. */
58extern long spNCorToAlpha(double *ncor, /* input. */
59 double *alpha, /* output. */
60 long order, /* input. */
61 double *resid); /* output. can be NULL. */
62
63/* Convertion between parameters. */
64extern long spParcorToAlpha(double *parcor, double *alpha, long order);
65extern long spAlphaToParcor(double *alpha, double *parcor, long order, double *resid, spBool *is_stable);
66extern long spAlphaToLSP(double *alpha, double *lsp, long order);
67extern long spLSPToAlpha(double *alpha, double *lsp, long order);
68extern long spParcorToCor(double *parcor, double *alpha, long order, double cor0, double *cor, long n, double *resid);
69extern long spParcorToNCor(double *parcor, double *alpha, long order, double *ncor, long ncorlen, double *resid);
70
71extern long spAlphaToPSD(double *alpha, long order, double resid, double *psd, long Nhalf);
72extern long spAlphaToPSDFFT(double *alpha, long order, double resid, double *psd, long fftl);
73extern long spParcorToVTAreaRatio(double *parcor, double *vtar, long order, spBool linear);
74extern long spVTAreaRatioToParcor(double *vtar, double *parcor, long order, spBool linear);
75
76/* vtar and vta can be identical (can be same address) */
77extern long spVTRatioToArea(double *vtar, double *vta, long order, double ref_area, spBool linear);
78extern long spVTAreaToRatio(double *vta, double *vtar, long order, double ref_area, spBool linear);
79
80/* vta and parcor can be identical (can be same address) */
81extern long spParcorToVTArea(double *parcor, double *vta, long order, double ref_area);
82extern long spVTAreaToParcor(double *vta, double *parcor, long order, double ref_area);
83
84/* LPC-based filtering for synthesis.
85 * Output: response from
86 * state (input/output): inner status of the synthesis filter.
87 * The size must be larger than order.
88 * state2, state2plus1: inner status of the synthesis filter.
89 * The size must be larger than (2*order) or (2*order+1).
90 */
91extern double spAlphaSynFiltering(double *alpha, double *state, long order, double insig);
92extern double spParcorSynFiltering(double *parcor, double *state, long order, double insig);
93
94/* signal & alpha --> residual signal */
95extern long spSigAlphaToRessig(double *sig, long siglen, double *alpha, long order, double *ressig /* output */);
96/* residual signal & alpha --> signal */
97extern long spRessigAlphaToSig(double *ressig, long siglen, double *alpha, long order, double *sig /* output */);
98
99/*
100 * lag window (pascal) data generation.
101 * hb : input. real.
102 * 0.0 < hb < 1.0 . If hb=0, wdata(i)=1.0 for all i.
103 * window half value band width to sampling frequency ratio.
104 * example: lag window half value band width = 100 hz, and
105 * sampling frequency = 8 khz, then hb = 100/8k = 1/80 =0.0125
106 */
107extern long spLagWindow(double *wdata, long length, double hb);
108
109/* alpha <--> LPC cepstrum */
110extern long spAlphaToCep(double *alpha, long order, double *cep, long ceplen);
111extern long spCepToAlpha(double *cep, long ceplen, double *alpha, long order);
112
113/* alpha <--> pole <--> frequency & band width */
114extern long spAlphaToPole(double *alpha, double *polere, double *poleim, long order, double eps);
115extern long spPoleToFreq(double *polere, double *poleim, double *freq /* output */, double *bw /* output, can be NULL */, long order, double fs, spBool sort_flag);
116extern long spFreqToPole(double *freq, double *bw, double *polere, double *poleim, long order, double fs);
117extern long spPoleToAlpha(double *polere, double *poleim, double *alpha, long order);
118
119extern double spCepSynFiltering(double *cep, double *state2, long order, double insig);
120extern double spLSPSynFiltering(double *lsp, double *state2plus1, long order, double insig);
121
122#ifdef __cplusplus
123} /* Close scope of 'extern "C"' declaration */
124#endif
125
126#endif /* SPLIB_LPC_H */
A class to handle FFT execution.
int spBool