diff options
author | jmvalin <jmvalin@0101bb08-14d6-0310-b084-bc0e0c8e3800> | 2002-03-14 10:32:07 +0300 |
---|---|---|
committer | jmvalin <jmvalin@0101bb08-14d6-0310-b084-bc0e0c8e3800> | 2002-03-14 10:32:07 +0300 |
commit | 6e9bdba1083c436aa28dcf81c5c32e0fa8fe4146 (patch) | |
tree | 8d2bae0414ec85b00021834e9a37a50218109810 /libspeex | |
parent | afc40879ee2560ad9e7b2da23be6b7472e2e7b6f (diff) |
Cleanup mostly done for the encoder. All functions are now in the mode
struct.
git-svn-id: http://svn.xiph.org/trunk/speex@3143 0101bb08-14d6-0310-b084-bc0e0c8e3800
Diffstat (limited to 'libspeex')
-rw-r--r-- | libspeex/cb_search.c | 41 | ||||
-rw-r--r-- | libspeex/modes.c | 5 | ||||
-rw-r--r-- | libspeex/modes.h | 9 | ||||
-rw-r--r-- | libspeex/speex.c | 50 | ||||
-rw-r--r-- | libspeex/speex.h | 2 |
5 files changed, 51 insertions, 56 deletions
diff --git a/libspeex/cb_search.c b/libspeex/cb_search.c index 1c52137..323ecfd 100644 --- a/libspeex/cb_search.c +++ b/libspeex/cb_search.c @@ -170,7 +170,7 @@ float *stack shape_cb = params->shape_cb; gain_cb_size = 1<<params->gain_bits; gain_cb = params->gain_cb; - resp = PUSH(stack, shape_cb_size*8); + resp = PUSH(stack, shape_cb_size*subvect_size); E = PUSH(stack, shape_cb_size); Ee = PUSH(stack, shape_cb_size); t = PUSH(stack, nsf); @@ -185,24 +185,24 @@ float *stack for (i=0;i<shape_cb_size;i++) { float *res = resp+i*subvect_size; - residue_zero(shape_cb+i*subvect_size, awk1, res, 8, p); - syn_filt_zero(res, ak, res, 8, p); - syn_filt_zero(res, awk2, res, 8,p); + residue_zero(shape_cb+i*subvect_size, awk1, res, subvect_size, p); + syn_filt_zero(res, ak, res, subvect_size, p); + syn_filt_zero(res, awk2, res, subvect_size,p); E[i]=0; - for(j=0;j<8;j++) + for(j=0;j<subvect_size;j++) E[i]+=res[j]*res[j]; Ee[i]=0; - for(j=0;j<8;j++) + for(j=0;j<subvect_size;j++) Ee[i]+=shape_cb[i*subvect_size+j]*shape_cb[i*subvect_size+j]; } - for (i=0;i<5;i++) + for (i=0;i<nb_subvect;i++) { int best_index=0; float g, corr, best_gain=0, score, best_score=-1; for (j=0;j<shape_cb_size;j++) { - corr=xcorr(resp+j*subvect_size,t+8*i,8); + corr=xcorr(resp+j*subvect_size,t+subvect_size*i,subvect_size); score=corr*corr/(.001+E[j]); g = corr/(.001+E[j]); if (score>best_score) @@ -222,8 +222,8 @@ float *stack for (j=0;j<nsf;j++) e[j]=0; - for (j=0;j<8;j++) - e[8*i+j]=best_gain*shape_cb[best_index*subvect_size+j]; + for (j=0;j<subvect_size;j++) + e[subvect_size*i+j]=best_gain*shape_cb[best_index*subvect_size+j]; residue_zero(e, awk1, r, nsf, p); syn_filt_zero(r, ak, r, nsf, p); syn_filt_zero(r, awk2, r, nsf,p); @@ -233,9 +233,10 @@ float *stack { int best_vq_index=0, max_index; - float max_gain=0, log_max, min_dist=0, sign[5]; + float max_gain=0, log_max, min_dist=0, *sign; - for (i=0;i<5;i++) + sign = PUSH(stack, nb_subvect); + for (i=0;i<nb_subvect;i++) { if (gains[i]<0) { @@ -245,7 +246,7 @@ float *stack sign[i]=1; } } - for (i=0;i<5;i++) + for (i=0;i<nb_subvect;i++) if (gains[i]>max_gain) max_gain=gains[i]; log_max=log(max_gain+1); @@ -255,7 +256,7 @@ float *stack if (max_index<0) max_index=0; max_gain=1/exp(max_index+3.0); - for (i=0;i<5;i++) + for (i=0;i<nb_subvect;i++) gains[i]*=max_gain; frame_bits_pack(bits,max_index,3); @@ -266,16 +267,18 @@ float *stack printf ("best_gains_vq_index %d %f %d\n", best_vq_index, min_dist, max_index); #if 1 /* If 0, the gains are not quantized */ - for (i=0;i<5;i++) + for (i=0;i<nb_subvect;i++) gains[i]= sign[i]*gain_cb[best_vq_index*nb_subvect+i]/max_gain/(Ee[ind[i]]+.001); #else - for (i=0;i<5;i++) + for (i=0;i<nb_subvect;i++) gains[i]= sign[i]*gains[i]/max_gain/(Ee[ind[i]]+.001); #endif - for (i=0;i<5;i++) - for (j=0;j<8;j++) - exc[8*i+j]+=gains[i]*shape_cb[ind[i]*subvect_size+j]; + for (i=0;i<nb_subvect;i++) + for (j=0;j<subvect_size;j++) + exc[subvect_size*i+j]+=gains[i]*shape_cb[ind[i]*subvect_size+j]; + + POP(stack); } /*TODO: Perform joint optimization of gains*/ diff --git a/libspeex/modes.c b/libspeex/modes.c index bd1c38f..b21c406 100644 --- a/libspeex/modes.c +++ b/libspeex/modes.c @@ -22,6 +22,7 @@ #include "modes.h" #include "ltp.h" #include "quant_lsp.h" +#include "cb_search.h" SpeexMode nb_mode = { 160, /*frameSize*/ @@ -36,5 +37,7 @@ SpeexMode nb_mode = { lsp_quant_nb, lsp_unquant_nb, pitch_search_3tap, - pitch_unquant_3tap + pitch_unquant_3tap, + split_cb_search, + &split_cb_nb }; diff --git a/libspeex/modes.h b/libspeex/modes.h index d6bde37..ef17d5e 100644 --- a/libspeex/modes.h +++ b/libspeex/modes.h @@ -39,6 +39,11 @@ typedef void (*ltp_quant_func)(float *, float *, float *, /*Long-term un-quantize*/ typedef void (*ltp_unquant_func)(float *, int, int, int, FrameBits*, float*); + +typedef void (*innovation_quant_func)(float *, float *, float *, float *, void *, int, int, + float *, FrameBits *, float *); + + /*Struct defining the encoding/decoding mode*/ typedef struct SpeexMode { int frameSize; @@ -59,6 +64,10 @@ typedef struct SpeexMode { ltp_quant_func ltp_quant; ltp_unquant_func ltp_unquant; + /*Quantization of innovation */ + innovation_quant_func innovation_quant; + void *innovation_params; + } SpeexMode; extern SpeexMode nb_mode; diff --git a/libspeex/speex.c b/libspeex/speex.c index 05a9798..6cc013b 100644 --- a/libspeex/speex.c +++ b/libspeex/speex.c @@ -56,6 +56,10 @@ void encoder_init(EncState *st, SpeexMode *mode) st->lsp_quant = mode->lsp_quant; st->ltp_quant = mode->ltp_quant; + st->innovation_quant = mode->innovation_quant; + st->innovation_params = mode->innovation_params; + + /* Over-sampling filter (fractional pitch)*/ st->os_fact=4; st->os_filt_ord2=4*st->os_fact; @@ -195,7 +199,7 @@ void encode(EncState *st, float *in, FrameBits *bits) st->lsp[i] = acos(st->lsp[i]); /* LSP Quantization */ - st->lsp_quant(st->lsp, st->qlsp, 10, bits); + st->lsp_quant(st->lsp, st->qlsp, st->lpcSize, bits); /* Special case for first frame */ if (st->first) @@ -209,9 +213,8 @@ void encode(EncState *st, float *in, FrameBits *bits) /* Loop on sub-frames */ for (sub=0;sub<st->nbSubframes;sub++) { - float tmp, gain[3]; - float esig=0, enoise=0, snr; - int pitch, offset; + float esig, enoise, snr, tmp; + int offset; float *sp, *sw, *res, *exc, *target, *mem; /* Offset relative to start of frame */ @@ -270,7 +273,8 @@ void encode(EncState *st, float *in, FrameBits *bits) for (i=0;i<st->lpcSize;i++) mem[i]=st->mem_sw[i]; syn_filt_mem(sw, st->bw_lpc2, sw, st->subframeSize, st->lpcSize, mem); - + + esig=0; for (i=0;i<st->subframeSize;i++) esig+=sw[i]*sw[i]; @@ -281,6 +285,7 @@ void encode(EncState *st, float *in, FrameBits *bits) for (i=0;i<st->subframeSize;i++) exc[i]=0; + /* Long-term prediction */ st->ltp_quant(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, exc, 20, 147, st->lpcSize, st->subframeSize, bits, st->stack); @@ -292,46 +297,19 @@ void encode(EncState *st, float *in, FrameBits *bits) for (i=0;i<st->subframeSize;i++) target[i]-=res[i]; + /* Compute noise energy and SNR */ enoise=0; for (i=0;i<st->subframeSize;i++) enoise += target[i]*target[i]; snr = 10*log10((esig+1)/(enoise+1)); printf ("pitch SNR = %f\n", snr); -#if 0 /* 1 for stochastic excitation, 0 for split-VQ*/ - for(j=0;j<1;j++){ - /*float stoc2[1080];*/ - float *stoc2 = PUSH(st->stack,1080); - for (i=0;i<1080;i++) - { - stoc2[i]=stoc[i]; - if (i-(pitch-1)>=0) - stoc2[i] += .0*stoc[i-(pitch-1)]; - } - POP(st->stack); - /* Perform stochastic codebook search */ - overlap_cb_search(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, - stoc2, 1024, &gain[0], &pitch, st->lpcSize, - st->subframeSize); - printf ("gain = %f index = %d energy = %f\n",gain[0], pitch, esig); - for (i=0;i<st->subframeSize;i++) - exc[i]+=gain[0]*stoc2[i+pitch]; - - /* Update target for adaptive codebook contribution (Useless for now)*/ - residue_zero(stoc2+pitch, st->bw_lpc1, res, st->subframeSize, st->lpcSize); - syn_filt_zero(res, st->interp_qlpc, res, st->subframeSize, st->lpcSize); - syn_filt_zero(res, st->bw_lpc2, res, st->subframeSize, st->lpcSize); - for (i=0;i<st->subframeSize;i++) - target[i]-=gain[0]*res[i]; - } -#else /* Perform a split-codebook search */ - split_cb_search(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, - &split_cb_nb, st->lpcSize, + st->innovation_quant(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, + st->innovation_params, st->lpcSize, st->subframeSize, exc, bits, st->stack); -#endif - /* Compute weighted noise energy, SNR */ + /* Compute weighted noise energy and SNR */ enoise=0; for (i=0;i<st->subframeSize;i++) enoise += target[i]*target[i]; diff --git a/libspeex/speex.h b/libspeex/speex.h index 6859d58..af718a3 100644 --- a/libspeex/speex.h +++ b/libspeex/speex.h @@ -70,6 +70,8 @@ typedef struct EncState { lsp_quant_func lsp_quant; ltp_quant_func ltp_quant; + innovation_quant_func innovation_quant; + void *innovation_params; } EncState; typedef struct DecState { |