#include <sp/lpc.h>
#define LPCTEST_BUF_LENGTH 2048
long buf_length = LPCTEST_BUF_LENGTH;
long order;
long frame_start;
long frame_length;
int debug_level;
{"-order", NULL, "analysis order", NULL,
SP_TYPE_LONG, &order, "10"},
{"-st", "-start", "analysis start point", NULL,
SP_TYPE_LONG, &frame_start, "0"},
{"-frame", NULL, "frame length", NULL,
SP_TYPE_LONG, &frame_length, "256"},
{"-debug", NULL, "debug level", NULL,
SP_TYPE_INT, &debug_level, NULL},
{"-h", "-help", "display this message", NULL,
};
static char *filelabel[] = {
"<input file>",
};
int spMain(int argc, char *argv[])
{
long k;
const char *input_file;
long read_length;
long fftl;
double resid;
spDVector cor, cor2, alpha, parcor, psd, psdfft, vtar, logvtar, vta;
spDVector ovtar, ovta, oparcor, oalpha, ocor;
if (frame_length <= 0) {
spError(1,
"Frame length must be larger than 0.");
}
if (order <= 0) {
spError(1,
"Analysis order must be larger than 0.");
}
frame_start = MAX(frame_start, 0);
spDebug(-1,
"main",
"input_file = %s\n", input_file);
spInitWaveInfo(&wave_info);
if ((i_plugin = spOpenFilePluginArg(NULL, input_file, "r",
&wave_info, NULL, 0, NULL, NULL)) != NULL) {
ana_buf = xdvalloc(frame_length);
spSeekPlugin(i_plugin, frame_start);
if ((read_length = spReadPluginDouble(i_plugin, ana_buf->
data, ana_buf->
length)) > 0) {
spDebug(-1,
"main",
"read_length = %ld, frame_length = %ld\n", read_length, frame_length);
for (k = read_length; k < ana_buf->
length; k++) {
}
#if 0
for (k = 0; k < read_length; k++) {
printf(
"%f\n", ana_buf->
data[k]);
}
#endif
cor = xdvalloc(order + 1);
alpha = xdvalloc(order);
psd = xdvalloc(fftl / 2 + 1);
psdfft = xdvalloc(fftl);
parcor = xdvalloc(order);
vtar = xdvalloc(order);
logvtar = xdvalloc(order);
vta = xdvalloc(order);
ovtar = xdvalloc(order);
ovta = xdvalloc(order);
oparcor = xdvalloc(order);
oalpha = xdvalloc(order);
ocor = xdvalloc(order + 1);
window = xdvhamming(frame_length);
dvoper(ana_buf, "*", window);
spSigToCor(ana_buf->
data, frame_length, cor->
data, order + 1);
#if 1
cor2 = xdvalloc(order + 1);
#if 0
spSigToCorFFT(fftrec, ana_buf->
data, frame_length, cor2->
data, order + 1);
#else
{
#if 0
for (k = 0; k < spec->
length; k++) {
printf(
"%f\n", spec->
data[k]);
}
#endif
xdvfree(spec);
}
#endif
#if 0
for (k = 0; k < cor->
length; k++) {
printf(
"%f %f\n", cor->
data[k], cor2->
data[k]);
}
#endif
xdvfree(cor2);
}
#endif
spCorToParcor(cor->
data, alpha->
data, parcor->
data, order, &resid);
spDebug(-1,
"main",
"resid = %f\n", resid);
spAlphaToPSDFFT(alpha->
data, order, 1.0, psdfft->
data, psdfft->
length);
#if 0
for (k = 0; k < psd->
length; k++) {
printf(
"%f %f\n", psd->
data[k], psdfft->
data[k]);
}
#endif
#if 0
spParcorToVTAreaRatio(parcor->
data, vtar->
data, order,
SP_TRUE);
spParcorToVTAreaRatio(parcor->
data, logvtar->
data, order,
SP_FALSE);
spParcorToVTArea(parcor->
data, ovta->
data, order, 1.0);
spVTRatioToArea(vtar->
data, vta->
data, order, 1.0, SP_TRUE);
spVTAreaToRatio(vta->
data, ovtar->
data, order, 1.0, SP_TRUE);
spVTAreaRatioToParcor(ovtar->
data, oparcor->
data, order, SP_TRUE);
#else
spParcorToVTAreaRatio(parcor->
data, vtar->
data, order, SP_TRUE);
spParcorToVTArea(parcor->
data, vta->
data, order, 1.0);
spVTAreaToRatio(vta->
data, ovtar->
data, order, 1.0, SP_TRUE);
spVTAreaToRatio(vta->
data, logvtar->
data, order, 1.0, SP_FALSE);
spVTRatioToArea(ovtar->
data, ovta->
data, order, 1.0, SP_TRUE);
spVTAreaToParcor(ovta->
data, oparcor->
data, order, 1.0);
#endif
spParcorToCor(oparcor->
data, oalpha->
data, order, cor->
data[0], ocor->
data, order + 1, NULL);
#if 1
for (k = 0; k < order; k++) {
printf("%f %f %f %f %f %f %f %f %f %f %f\n",
}
printf(
"%f %f\n", cor->
data[k], ocor->
data[k]);
#endif
xdvfree(window);
xdvfree(cor);
xdvfree(alpha);
xdvfree(psd);
xdvfree(psdfft);
xdvfree(parcor);
xdvfree(vtar);
xdvfree(logvtar);
xdvfree(vta);
xdvfree(ovtar);
xdvfree(ovta);
xdvfree(oparcor);
xdvfree(ocor);
xdvfree(oalpha);
}
xdvfree(ana_buf);
}
return 0;
}
A class to handle FFT execution.
#define SP_FFT_DOUBLE_PRECISION
Definition fft.h:28
long spGetFFTLength(spFFTRec fftrec)
spFFTRec spInitFFT(long order, spFFTPrecision precision)
spBool spFreeFFT(spFFTRec fftrec)
void spError(int status, const char *format,...)
void spSetDebugLevel(int level)
void spDebug(int level, const char *func_name, const char *format,...)
#define spGetOptions(argc, argv, option, file_label)
void spCheckNumFile(spOptions options)
struct _spOptions * spOptions
void spGetOptionsValue(int argc, char **argv, spOptions options)
const char * spGetFile(spOptions options)
void spSetHelpMessage(spBool *flag, const char *format,...)
Vector type that contains the elements of double type.
Definition vector.h:248
double * data
Definition vector.h:256
long length
Definition vector.h:251