diff options
author | jmvalin <jmvalin@0101bb08-14d6-0310-b084-bc0e0c8e3800> | 2002-02-15 23:48:04 +0300 |
---|---|---|
committer | jmvalin <jmvalin@0101bb08-14d6-0310-b084-bc0e0c8e3800> | 2002-02-15 23:48:04 +0300 |
commit | 15689803eaab5eba0f4c72fe0b20f45c38b0c7db (patch) | |
tree | 549f88155202a3fc4fff5e34c1637c1a2f1a27cf /libspeex | |
parent | f6dc19cb691aee06882c4cc9524e59b765997c47 (diff) |
Implementing a 3-tap long-term predictor. Also changed frame size to 160
git-svn-id: http://svn.xiph.org/trunk/speex@3059 0101bb08-14d6-0310-b084-bc0e0c8e3800
Diffstat (limited to 'libspeex')
-rw-r--r-- | libspeex/ltp.c | 66 | ||||
-rw-r--r-- | libspeex/speex.c | 16 | ||||
-rw-r--r-- | libspeex/testenc.c | 2 |
3 files changed, 77 insertions, 7 deletions
diff --git a/libspeex/ltp.c b/libspeex/ltp.c index 8eec360..6ffa174 100644 --- a/libspeex/ltp.c +++ b/libspeex/ltp.c @@ -3,6 +3,11 @@ Lont-Term Prediction functions */ + +/*static float lp4[] = {0.00139, 0.00853, 0.01465, -0.00000, -0.04766, -0.10610, -0.11333, 0.00000, 0.25616, 0.59397, 0.88498, 1.00000, 0.88498, 0.59397, 0.25616, 0.00000, -0.11333, -0.10610, -0.04766, -0.00000, 0.01465, 0.00853, 0.00139}; + */ + + /* Computes the open-loop pitch prediction. Returns pitch period and pitch gain */ int open_loop_ltp(float *x, int len, int start, int end, float *gain) /* x: time-domain signal (note, x[-end] must be valid) @@ -30,6 +35,67 @@ int open_loop_ltp(float *x, int len, int start, int end, float *gain) best_period=period; *gain = corr/(energy+1); } + } return best_period; } + + +int three_tap_ltp(float *x, int len, int start, int end, float *gain) + + /* x: time-domain signal (note, x[-end] must be valid) + len: length of the x signal + start: smallest pitch period possible + end: largest pitch period possible + gain: return value for the pitch predictor gain + */ +{ + int i, period, best_period=0; + float total, score[3]={0,0,0}, best_score=-1, corr[3]={0,0,0}, energy[3]={0,0,0}; + float best_energy[3], best_corr[3]; + float A[3][3]; + for (period = start; period <= end; period++) + { + corr[0]=energy[0]=0; + for (i=0;i<len;i++) + { + corr[0] += x[i]*x[i-period]; + energy[0] += x[i-period]*x[i-period]; + } + score[0] = corr[0]*corr[0]/(energy[0]+1); + total = score[0]+2*score[1]+score[2]; + if (total > best_score && period >= start+3 && period <= end-3) + { + best_score=total; + best_period=period; + for (i=0;i<3;i++) + { + best_corr[i]=corr[i]; + best_energy[i]=energy[i]; + } + *gain = corr[1]/(energy[1]+1); + } + corr[2]=corr[1]; + corr[1]=corr[0]; + energy[2]=energy[1]; + energy[1]=energy[0]; + } + A[0][0]=energy[0]; + A[1][1]=energy[1]; + A[2][2]=energy[2]; + A[0][1]=0; + A[0][2]=0; + for (i=0;i<len;i++) + { + A[0][1] += x[i-best_period]*x[i-best_period-1]; + A[0][2] += x[i-best_period]*x[i-best_period-2]; + } + A[1][0]=A[0][1]; + A[2][0]=A[0][2]; + A[1][2]=A[0][1] - x[-best_period]*x[-best_period-1] + + x[len-best_period]*x[len-best_period-1]; + A[2][1]=A[1][2]; + return best_period-1; +} + + diff --git a/libspeex/speex.c b/libspeex/speex.c index be9d79b..8f6f340 100644 --- a/libspeex/speex.c +++ b/libspeex/speex.c @@ -16,12 +16,12 @@ void encoder_init(EncState *st) { int i; - st->frameSize = 128; - st->windowSize = 256; + st->frameSize = 160; + st->windowSize = 320; st->nbSubframes=4; - st->subframeSize=32; + st->subframeSize=40; st->lpcSize = 10; - st->bufSize = 512; + st->bufSize = 640; st->gamma=.9; st->inBuf = malloc(st->bufSize*sizeof(float)); st->frame = st->inBuf + st->bufSize - st->windowSize; @@ -108,6 +108,8 @@ void encode(EncState *st, float *in, int *outSize, void *bits) fprintf (stderr, "roots!=st->lpcSize\n"); exit(1); } + for (i=0;i<st->lpcSize;i++) + st->lsp[i] = acos(st->lsp[i]); /*for (i=0;i<roots;i++) printf("%f ", st->lsp[i]); printf ("\n\n");*/ @@ -126,12 +128,14 @@ void encode(EncState *st, float *in, int *outSize, void *bits) st->interp_lsp[i] = (1-tmp)*st->old_lsp[i] + tmp*st->lsp[i]; /* Compute interpolated LPCs */ + for (i=0;i<st->lpcSize;i++) + st->interp_lsp[i] = cos(st->interp_lsp[i]); lsp_to_lpc(st->interp_lsp, st->interp_lpc, st->lpcSize); - /*for (i=0;i<st->lpcSize+1;i++) + for (i=0;i<st->lpcSize+1;i++) printf("%f ", st->interp_lpc[i]); printf ("\n"); - */ + /* Compute bandwidth-expanded LPCs for perceptual weighting*/ tmp=1; diff --git a/libspeex/testenc.c b/libspeex/testenc.c index 6a4c188..52d1a45 100644 --- a/libspeex/testenc.c +++ b/libspeex/testenc.c @@ -2,7 +2,7 @@ #include <stdio.h> #include <stdlib.h> -#define FRAME_SIZE 128 +#define FRAME_SIZE 160 int main(int argc, char **argv) { |