X-Git-Url: http://git.xiph.org/?p=speexdsp.git;a=blobdiff_plain;f=libspeex%2Fcb_search.c;h=dcdf72a8bd927ae8f94a1c8fad2bb711b4a6841c;hp=30b1131560df00c9985a55acaa9926bf4cd01053;hb=9ff3e049dfceafedb8d7d67524399daed7d799d1;hpb=132fe8a2d7fd66323a08e951ad01e8b90ae24a08 diff --git a/libspeex/cb_search.c b/libspeex/cb_search.c index 30b1131..dcdf72a 100644 --- a/libspeex/cb_search.c +++ b/libspeex/cb_search.c @@ -36,8 +36,19 @@ #include #include "stack_alloc.h" #include "vq.h" +#include "matrix.h" + +static float scal_gains4[16] = { + 0.27713, + 0.49282, + 0.69570, + 0.90786, + 1.14235, + 1.42798, + 1.80756, + 2.42801 +}; -extern float exc_gains_wb2_table[]; /*---------------------------------------------------------------------------*\ void overlap_cb_search() @@ -83,7 +94,7 @@ int nsf /* number of samples in subframe */ bscore = 0.0; impulse[0] = 1.0; - /* Calculate impulse response of A(z/g2) / ( A(z)*(z/g1) ) */ + /* Calculate impulse response of A(z/g1) / ( A(z)*(z/g2) ) */ residue_zero(impulse, awk1, h, nsf, p); syn_filt_zero(h, ak, h, nsf, p); syn_filt_zero(h, awk2, h, nsf,p); @@ -127,6 +138,7 @@ int nsf /* number of samples in subframe */ } + void split_cb_search( float target[], /* target vector */ float ak[], /* LPCs for this subframe */ @@ -142,11 +154,12 @@ float *stack { int i,j; float *resp, *E, *Ee; - float *t, *r, *e; + float *t, *r, *e, *tresp; float *gains; int *ind; - float *shape_cb, *gain_cb; - int shape_cb_size, gain_cb_size, subvect_size, nb_subvect; + float *shape_cb; + int shape_cb_size, subvect_size, nb_subvect; + float exc_energy=0; split_cb_params *params; params = (split_cb_params *) par; @@ -154,9 +167,8 @@ float *stack nb_subvect = params->nb_subvect; shape_cb_size = 1<shape_bits; shape_cb = params->shape_cb; - gain_cb_size = 1<gain_bits; - gain_cb = params->gain_cb; resp = PUSH(stack, shape_cb_size*subvect_size); + tresp = PUSH(stack, shape_cb_size*nsf); E = PUSH(stack, shape_cb_size); Ee = PUSH(stack, shape_cb_size); t = PUSH(stack, nsf); @@ -164,7 +176,28 @@ float *stack e = PUSH(stack, nsf); gains = PUSH(stack, nb_subvect); ind = (int*)PUSH(stack, nb_subvect); - + + syn_filt_zero(target, awk1, e, nsf, p); + residue_zero(e, ak, e, nsf, p); + residue_zero(e, awk2, e, nsf, p); + for (i=0;i15) + q=15; + id = (int)q; + frame_bits_pack(bits, id, 4); + exc_energy=exp(.5*q+2); + } for (i=0;ishape_bits); - if (best_gain>0) - frame_bits_pack(bits,0,1); - else - frame_bits_pack(bits,1,1); + { + int s=0, best_id, j; + float best_dist; + best_gain /= .01+exc_energy; + if (best_gain<0) + { + best_gain=-best_gain; + s=1; + } + best_dist=(best_gain-scal_gains4[0])*(best_gain-scal_gains4[0]); + best_id=0; + for (j=1;j<8;j++) + { + float dist; + dist=(best_gain-scal_gains4[j])*(best_gain-scal_gains4[j]); + if (distmax_gain) - max_gain=gains[i]; - log_max=log(max_gain+1); - max_index = (int)(floor(.5+log_max-3)); - if (max_index>7) - max_index=7; - if (max_index<0) - max_index=0; - max_gain=1/exp(max_index+3.0); - for (i=0;igain_bits); - printf ("best_gains_vq_index %d %f %d\n", best_vq_index, min_dist, max_index); - for (i=0;igain_bits); - printf ("best_gains_vq_index %d %f %d\n", best_vq_index, min_dist, max_index); - for (i=0;igain_bits); - for (i=0;i<5;i++) - tmp[i]=gains[i+5]-gain_cb[best_vq_index*nb_subvect/2+i]; - best_vq_index2 = vq_index(tmp, exc_gains_wb2_table, nb_subvect/2, 256); - - printf ("best_gains_vq_index %d %f %d\n", best_vq_index, min_dist, max_index); - for (i=0;inb_subvect; shape_cb_size = 1<shape_bits; shape_cb = params->shape_cb; - gain_cb_size = 1<gain_bits; - gain_cb = params->gain_cb; ind = (int*)PUSH(stack, nb_subvect); gains = PUSH(stack, nb_subvect); sign = PUSH(stack, nb_subvect); - Ee=PUSH(stack, nb_subvect); + + /* Decode global (average) gain */ + { + int id; + id = frame_bits_unpack_unsigned(bits, 4); + exc_energy=exp(.5*id+2); + } for (i=0;ishape_bits); if (frame_bits_unpack_unsigned(bits, 1)) sign[i]=-1; else sign[i]=1; - Ee[i]=.001; - for (j=0;jgain_bits); - printf ("unquant gains ind: %d %d\n", max_gain_ind, vq_gain_ind); - - max_gain=exp(max_gain_ind+3.0); - for (i=0;i