40#include "sigpr/EST_sigpr_frame.h"
41#include "sigpr/EST_fft.h"
42#include "EST_inline_utils.h"
45#include "EST_TBuffer.h"
47#define ALMOST1 0.99999
48#define MAX_ABS_CEPS 4.0
54 float *
acf,
float *ref,
float *
lpc,
56float ogi_lpc(
float *
adc,
int wsize,
int order,
57 float *
acf,
float *ref,
float *
lpc);
77 EST_error(
"Cannot convert coefficient type %s to lpc\n",
101 EST_error(
"Cannot convert coefficient type %s to reflection coefs\n",
125 EST_error(
"Cannot convert coefficient type %s to reflection coefs\n",
155 EST_error(
"Cannot convert coefficient type %s to cepstrum coefs\n",
200 EST_error(
"Cannot convert coefficient type %s to reflection coefs\n",
218 EST_error(
"Cannot convert coefficients to type %s\n",
261 for (
int i = 1; i < ref.
length(); i++)
262 area[i] = (1.0 - ref(i)) / (1.0 + ref(i));
267 int order = ref.
length() -1;
269 for(
int i = 1; i <= order; i++)
271 if (ref(i) > ALMOST1)
272 logarea[i] =
log((1.0 - ALMOST1) / (1.0 + ALMOST1));
273 else if (ref(i) < -ALMOST1)
274 logarea[i] =
log((1.0 + ALMOST1)/(1.0 - ALMOST1));
276 logarea[i] =
log((1.0 - ref(i)) / (1.0 + ref(i)));
282 int order = ref.
length() -1;
284 area[1] = (1.0 - ref(1)) / (1.0 + ref(1));
285 for(
int i = 2; i <= order; i++)
286 area[i] =
area[i - 1] * (1.0 - ref(i)) / (1.0 + ref(i));
293 int order =
lpc.length() - 1;
295 for (n = 1; n <= order && n <=
cep.length(); n++)
298 for (k = 1; k < n; k++)
299 sum += k *
cep(k-1) *
lpc(n - k);
300 cep[n-1] =
lpc(n) + sum / n;
304 for(n = order + 1; n <=
cep.length(); n++)
307 for (k = n - (order - 1); k < n; k++)
308 sum += k *
cep(k-1) *
lpc(n - k);
314 for (n = 0; n <
cep.length(); n++)
317 if (isnanf(
cep[n]) )
cep[n] = 0.0;
319 if (
cep[n] > MAX_ABS_CEPS){
320 cerr <<
"WARNING : cepstral coeff " << n <<
" was " <<
322 cerr <<
"lpc coeff " << n <<
" = " <<
lpc(n + 1) <<
endl;
324 cep[n] = MAX_ABS_CEPS;
326 if (
cep[n] < -MAX_ABS_CEPS) {
327 cerr <<
"WARNING : cepstral coeff " << n <<
" was " <<
329 cep[n] = -MAX_ABS_CEPS;
339 EST_error(
"lpc2ref Code unfinished\n");
351 int order =
lpc.length() - 1;
355 float *
vn =
new float[order];
368 vo =
new float[order];
369 for (i = 0; i < order; ++i)
395 int order = ref.
length() - 1;
399 for (n=0; n < order; n++)
402 for (k=0; 2 * (k+1) <= n + 1; k++)
407 lpc[n-(k+1)] = b-a *
lpc[n];
422 EST_error(
"LSF Code unfinished\n");
429 EST_error(
"LSF Code unfinished\n");
438 int order =
lpc.length() -1;
443 (
acf.length() !=
lpc.length()))
444 EST_error(
"sig2lpc: acf, ref are not of lpc's order");
449 for (i = 0; i <= order; i++)
452 for(
j = 0;
j <
sig.length() - i;
j++)
453 sum +=
sig.a_no_check(
j) *
sig.a_no_check(
j + i);
454 acf.a_no_check(i) = sum;
458 e =
acf.a_no_check(0);
459 lpc.a_no_check(0) = 1.0;
461 for (i = 1; i <= order; i++)
464 for(
j = 1;
j < i;
j++)
465 ci +=
lpc.a_no_check(
j) *
acf.a_no_check(i-
j);
471 if (absval(
ci) < 1.000000)
473 lpc.a_no_check(i) =
ci;
474 for (
j = 1;
j < i;
j++)
475 tmp.a_no_check(
j) =
lpc.a_no_check(
j) -
476 (
ci *
lpc.a_no_check(i-
j));
477 for(
j = 1;
j < i;
j++)
478 lpc.a_no_check(
j) =
tmp.a_no_check(
j);
488 "warning:levinson instability, order restricted to %d\n",
490 for (; i <= order; i++)
491 lpc.a_no_check(i) = 0.0;
495 lpc.a_no_check(0) =
e /
sig.length();
501 for (
int i = 0; i < frame.
length(); i++)
502 power +=
pow(frame(i),
float(2.0));
525 for (i = 0; i <= order; i++)
535 for(i = 1; i <= order; i++) {
537 for(
j = 1;
j < i;
j++)
541 if (absval(
ci) < 1.000000) {
543 for(
j = 1;
j < i;
j++)
545 for(
j = 1;
j < i;
j++)
554 "warning:levinson instability, order restricted to %d\n",
566 const float sample_rate,
579 float mel_high=Hz2Mel(sample_rate / 2);
647 fft_vec[i] = real * real + imag * imag;
683 EST_error(
"Filter centre frequencies length (%i) is not equal to fbank order (%i) plus 2\n",
mel_fbank_frequencies.length(),
703 for(k=0;k<
filter.length();k++)
INLINE int length() const
number of items in vector.
INLINE const T & a_no_check(int n) const
read-only const access operator: without bounds checking