ref: f3efa3e1323d0539ebdd2d41a78522c6ece7bc98
parent: 6f7e83d8f46cc0f8fb220c4c21f3966c3abf1787
author: Jean-Marc Valin <[email protected]>
date: Fri Nov 30 20:55:17 EST 2007
Some improvements to the pitch period estimation
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -34,7 +34,9 @@
#include "vq.h"
const int qbank[NBANDS+2] = {0, 2, 4, 6, 8, 12, 16, 20, 24, 28, 36, 44, 52, 68, 84, 116, 128};
-int qpulses[] = {4, 5, 4, 4, 3, 3, 3, 3, 3, 4, 4, 4, 0, 0, 0}; //c: 134 bits
+
+const int qpulses[NBANDS ] = {7, 5, 4, 4, 3, 3, 3, 3, 3, 4, 4, 4, 0, 0, 0};
+
#define WAVEFORM_END 52
/* Start frequency of each band */
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -181,7 +181,7 @@
in[i] *= st->window[i];
in[B*N+i] *= st->window[N+i];
}
- find_spectral_pitch(st->fft, in, st->out_mem, MAX_PERIOD, (B+1)*N, &pitch_index, NULL);
+ find_spectral_pitch(st->fft, in, st->out_mem, MAX_PERIOD, (B+1)*N, &pitch_index);
/* Compute MDCTs of the pitch part */
compute_mdcts(&st->mdct_lookup, st->window, st->out_mem+pitch_index, P, N, B);
@@ -212,6 +212,10 @@
for (i=0;i<B*N;i++)
X[i] -= P[i];
+ /*float sum=0;
+ for (i=0;i<B*N;i++)
+ sum += X[i]*X[i];
+ printf ("%f\n", sum);*/
/* Residual quantisation */
#if 1
quant_bands(X, B, P);
--- a/libcelt/pitch.c
+++ b/libcelt/pitch.c
@@ -24,13 +24,15 @@
#include <stdio.h>
#include <math.h>
#include "fftwrap.h"
+#include "pitch.h"
-
-void find_spectral_pitch(void *fft, float *x, float *y, int lag, int len, int *pitch, float *curve)
+void find_spectral_pitch(void *fft, float *x, float *y, int lag, int len, int *pitch)
{
+ int n2 = lag/2;
float xx[lag];
float X[lag];
float Y[lag];
+ float curve[n2];
int i;
for (i=0;i<lag;i++)
@@ -40,14 +42,24 @@
spx_fft(fft, xx, X);
spx_fft(fft, y, Y);
- X[0] = X[0]*Y[0];
+ curve[0] = 1;
+ for (i=1;i<n2;i++)
+ {
+ curve[i] = sqrt((X[2*i-1]*X[2*i-1] + X[2*i ]*X[2*i ])*(Y[2*i-1]*Y[2*i-1] + Y[2*i ]*Y[2*i ]));
+ curve[i] = curve[i]+.7*curve[i];
+ }
+ for (i=n2-2;i>=0;i--)
+ curve[i] = curve[i] + .7*curve[i+1];
+
+ X[0] = 0;
for (i=1;i<lag/2;i++)
{
- float n = 1.f/(1e1+sqrt(sqrt((X[2*i-1]*X[2*i-1] + X[2*i ]*X[2*i ])*(Y[2*i-1]*Y[2*i-1] + Y[2*i ]*Y[2*i ]))));
+ float n;
+ //n = 1.f/(1e1+sqrt(sqrt((X[2*i-1]*X[2*i-1] + X[2*i ]*X[2*i ])*(Y[2*i-1]*Y[2*i-1] + Y[2*i ]*Y[2*i ]))));
//n = 1;
- //n = 1.f/(1+curve[i]);
- if (i>lag/6)
- n=0;
+ n = 1.f/pow(1+curve[i],.8)/(i+60);
+ //if (i>lag/6)
+ // n *= .5;
float tmp = X[2*i-1];
X[2*i-1] = (X[2*i-1]*Y[2*i-1] + X[2*i ]*Y[2*i ])*n;
X[2*i ] = (- X[2*i ]*Y[2*i-1] + tmp*Y[2*i ])*n;
--- a/libcelt/pitch.h
+++ b/libcelt/pitch.h
@@ -23,6 +23,6 @@
#ifndef _PITCH_H
#define _PITCH_H
-void find_spectral_pitch(void *fft, float *x, float *y, int lag, int len, int *pitch, float *curve);
+void find_spectral_pitch(void *fft, float *x, float *y, int lag, int len, int *pitch);
#endif