[xiph-cvs] cvs commit: speex/libspeex cb_search.c filters.c filters.h lsp.c ltp.c nb_celp.c sb_celp.c stack_alloc.h testenc.c
Jean-Marc Valin
jm at xiph.org
Mon Oct 21 13:39:38 PDT 2002
jm 02/10/21 16:39:38
Modified: libspeex cb_search.c filters.c filters.h lsp.c ltp.c
nb_celp.c sb_celp.c stack_alloc.h testenc.c
Log:
Filter optimizations, cleanup, removed the stack POP to simplify things
and prevent errors
Revision Changes Path
1.67 +24 -37 speex/libspeex/cb_search.c
Index: cb_search.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/cb_search.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -r1.66 -r1.67
--- cb_search.c 11 Oct 2002 03:39:34 -0000 1.66
+++ cb_search.c 21 Oct 2002 20:39:38 -0000 1.67
@@ -95,6 +95,7 @@
r = PUSH(stack, nsf);
e = PUSH(stack, nsf);
E = PUSH(stack, shape_cb_size);
+ /*FIXME: This breaks if sizeof(int) != sizeof(float) */
ind = (int*)PUSH(stack, nb_subvect);
tmp = PUSH(stack, 2*N*nsf);
@@ -106,11 +107,13 @@
tmp += nsf;
}
+ /*FIXME: This breaks if sizeof(int) != sizeof(float) */
best_index = (int*)PUSH(stack, N);
best_dist = PUSH(stack, N);
ndist = PUSH(stack, N);
odist = PUSH(stack, N);
+ /*FIXME: This breaks if sizeof(int) != sizeof(float) */
itmp = (int*)PUSH(stack, 2*N*nb_subvect);
for (i=0;i<N;i++)
{
@@ -132,10 +135,12 @@
e[0]=1;
for (i=1;i<nsf;i++)
e[i]=0;
- residue_zero(e, awk1, r, nsf, p);
+ /*residue_zero(e, awk1, r, nsf, p);
syn_filt_zero(r, ak, r, nsf, p);
syn_filt_zero(r, awk2, r, nsf,p);
-
+ */
+ syn_percep_zero(e, ak, awk1, awk2, r, nsf,p, stack);
+
/* Pre-compute codewords response and energy */
for (i=0;i<shape_cb_size;i++)
{
@@ -248,24 +253,13 @@
exc[j]+=e[j];
/* Update target */
- residue_zero(e, awk1, r, nsf, p);
+ /*residue_zero(e, awk1, r, nsf, p);
syn_filt_zero(r, ak, r, nsf, p);
- syn_filt_zero(r, awk2, r, nsf,p);
+ syn_filt_zero(r, awk2, r, nsf,p);*/
+ syn_percep_zero(e, ak, awk1, awk2, r, nsf,p, stack);
for (j=0;j<nsf;j++)
target[j]-=r[j];
- POP(stack);
- POP(stack);
- POP(stack);
- POP(stack);
- POP(stack);
- POP(stack);
- POP(stack);
- POP(stack);
- POP(stack);
- POP(stack);
- POP(stack);
- POP(stack);
}
@@ -288,7 +282,7 @@
{
int i,j;
float *resp;
- float *t, *r, *e, *E;
+ float *t, *tt, *r, *e, *E;
int *ind, *signs;
float *shape_cb;
int shape_cb_size, subvect_size, nb_subvect;
@@ -301,9 +295,11 @@
shape_cb = params->shape_cb;
resp = PUSH(stack, shape_cb_size*subvect_size);
t = PUSH(stack, nsf);
+ tt= PUSH(stack, nsf);
r = PUSH(stack, nsf);
e = PUSH(stack, nsf);
E = PUSH(stack, shape_cb_size);
+ /*FIXME: This breaks if sizeof(int) != sizeof(float) */
ind = (int*)PUSH(stack, nb_subvect);
signs = (int*)PUSH(stack, nb_subvect);
@@ -313,10 +309,11 @@
e[0]=1;
for (i=1;i<nsf;i++)
e[i]=0;
- residue_zero(e, awk1, r, nsf, p);
+ /*residue_zero(e, awk1, r, nsf, p);
syn_filt_zero(r, ak, r, nsf, p);
- syn_filt_zero(r, awk2, r, nsf,p);
-
+ syn_filt_zero(r, awk2, r, nsf,p);*/
+ syn_percep_zero(e, ak, awk1, awk2, r, nsf,p, stack);
+
/* Pre-compute codewords response and energy */
for (i=0;i<shape_cb_size;i++)
{
@@ -380,9 +377,8 @@
if (i<nb_subvect-1)
{
int nbest;
- float *tt, err[2];
+ float err[2];
float best_score[2];
- tt=PUSH(stack,nsf);
for (nbest=0;nbest<2;nbest++)
{
float s=1;
@@ -447,8 +443,6 @@
best_index[0]=best_index[1];
best_score[0]=best_score[1];
}
- POP(stack);
-
}
ind[i]=best_index[0];
@@ -483,20 +477,15 @@
exc[j]+=e[j];
/* Update target */
- residue_zero(e, awk1, r, nsf, p);
+ /*residue_zero(e, awk1, r, nsf, p);
syn_filt_zero(r, ak, r, nsf, p);
- syn_filt_zero(r, awk2, r, nsf,p);
+ syn_filt_zero(r, awk2, r, nsf,p);*/
+ syn_percep_zero(e, ak, awk1, awk2, r, nsf,p, stack);
+
for (j=0;j<nsf;j++)
target[j]-=r[j];
- POP(stack);
- POP(stack);
- POP(stack);
- POP(stack);
- POP(stack);
- POP(stack);
- POP(stack);
}
@@ -520,6 +509,7 @@
shape_cb_size = 1<<params->shape_bits;
shape_cb = params->shape_cb;
+ /*FIXME: This breaks if sizeof(int) != sizeof(float) */
ind = (int*)PUSH(stack, nb_subvect);
/* Decode codewords and gains */
@@ -532,7 +522,6 @@
for (j=0;j<subvect_size;j++)
exc[subvect_size*i+j]+=shape_cb[ind[i]*subvect_size+j];
- POP(stack);
}
void split_cb_shape_sign_unquant(
@@ -555,6 +544,7 @@
shape_cb_size = 1<<params->shape_bits;
shape_cb = params->shape_cb;
+ /*FIXME: This breaks if sizeof(int) != sizeof(float) */
ind = (int*)PUSH(stack, nb_subvect);
signs = (int*)PUSH(stack, nb_subvect);
@@ -573,8 +563,6 @@
for (j=0;j<subvect_size;j++)
exc[subvect_size*i+j]+=s*shape_cb[ind[i]*subvect_size+j];
}
- POP(stack);
- POP(stack);
}
void noise_codebook_quant(
@@ -602,7 +590,6 @@
for (i=0;i<nsf;i++)
target[i]=0;
- POP(stack);
}
<p><p>1.21 +50 -8 speex/libspeex/filters.c
Index: filters.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/filters.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- filters.c 20 Oct 2002 21:11:13 -0000 1.20
+++ filters.c 21 Oct 2002 20:39:38 -0000 1.21
@@ -83,13 +83,18 @@
bw_lpc(k3, ak, n2, order);
residue_zero(num,n2,num,1+(order<<1),order);
residue_zero(den,d2,den,1+(order<<1),order);
- POP(stack);
- POP(stack);
}
void syn_filt_zero(float *x, float *a, float *y, int N, int ord)
{
+#if 0
+ int i;
+ float mem[10];
+ for (i=0;i<10;i++)
+ mem[i]=0;
+ iir_mem2(x,a,y,N,ord,mem);
+#else
int i,j;
for (i=0;i<N;i++)
{
@@ -97,22 +102,31 @@
for (j=1;j<=min(ord,i);j++)
y[i] -= a[j]*y[i-j];
}
+#endif
}
void residue_zero(float *x, float *a, float *y, int N, int ord)
{
+#if 0
+ int i;
+ float mem[10];
+ for (i=0;i<10;i++)
+ mem[i]=0;
+ fir_mem2(x,a,y,N,ord,mem);
+#else
int i,j;
for (i=N-1;i>=0;i--)
{
y[i]=x[i];
for (j=1;j<=min(ord,i);j++)
y[i] += a[j]*x[i-j];
- }
+ }
+#endif
}
-void filter_mem2(float *x, float *num, float *den, float *y, int N, int ord, float *mem)
+void _filter_mem2(float *x, float *num, float *den, float *y, int N, int ord, float *mem)
{
int i,j;
float xi;
@@ -128,6 +142,23 @@
}
}
+void filter_mem2(float *x, float *num, float *den, float *y, int N, int ord, float *mem)
+{
+ int i,j;
+ float xi,yi;
+ for (i=0;i<N;i++)
+ {
+ xi=x[i];
+ y[i] = num[0]*xi + mem[0];
+ yi=y[i];
+ for (j=0;j<ord-1;j++)
+ {
+ mem[j] = mem[j+1] + num[j+1]*xi - den[j+1]*yi;
+ }
+ mem[ord-1] = num[ord]*xi - den[ord]*yi;
+ }
+}
+
void fir_mem2(float *x, float *num, float *y, int N, int ord, float *mem)
{
int i,j;
@@ -160,19 +191,30 @@
-void syn_percep_zero(float *xx, float *ak, float *awk1, float *awk2, float *y, int N, int ord)
+void syn_percep_zero(float *xx, float *ak, float *awk1, float *awk2, float *y, int N, int ord, float *stack)
{
int i;
- /*FIXME: Should make that dynamic*/
- float mem[10];
+ float *mem = PUSH(stack,ord);
for (i=0;i<ord;i++)
mem[i]=0;
filter_mem2(xx, awk1, ak, y, N, ord, mem);
for (i=0;i<ord;i++)
mem[i]=0;
iir_mem2(y, awk2, y, N, ord, mem);
-
}
+
+void residue_percep_zero(float *xx, float *ak, float *awk1, float *awk2, float *y, int N, int ord, float *stack)
+{
+ int i;
+ float *mem = PUSH(stack,ord);
+ for (i=0;i<ord;i++)
+ mem[i]=0;
+ filter_mem2(xx, ak, awk1, y, N, ord, mem);
+ for (i=0;i<ord;i++)
+ mem[i]=0;
+ fir_mem2(y, awk2, y, N, ord, mem);
+}
+
#if 1
<p><p>1.16 +3 -1 speex/libspeex/filters.h
Index: filters.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/filters.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- filters.h 20 Oct 2002 21:11:13 -0000 1.15
+++ filters.h 21 Oct 2002 20:39:38 -0000 1.16
@@ -62,7 +62,9 @@
/* FIR filter */
void fir_mem(float *x, float *a, float *y, int N, int M, float *mem);
-void syn_percep_zero(float *x, float *ak, float *awk1, float *awk2, float *y, int N, int ord);
+void syn_percep_zero(float *x, float *ak, float *awk1, float *awk2, float *y, int N, int ord, float *stack);
+
+void residue_percep_zero(float *xx, float *ak, float *awk1, float *awk2, float *y, int N, int ord, float *stack);
void comb_filter(
float *exc, /*decoded excitation*/
<p><p>1.13 +1 -4 speex/libspeex/lsp.c
Index: lsp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/lsp.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- lsp.c 11 Oct 2002 03:39:34 -0000 1.12
+++ lsp.c 21 Oct 2002 20:39:38 -0000 1.13
@@ -103,7 +103,6 @@
for(i=0;i<=m/2;i++)
sum+=coef[(m/2)-i]**t++;
- POP(stack);
return sum;
}
@@ -240,8 +239,6 @@
}
}
}
- POP(stack);
- POP(stack);
return(roots);
}
@@ -315,7 +312,7 @@
xin1 = 0.0;
xin2 = 0.0;
}
- POP(stack);
+
}
/*Added by JMV
<p><p>1.57 +32 -33 speex/libspeex/ltp.c
Index: ltp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/ltp.c,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -r1.56 -r1.57
--- ltp.c 11 Oct 2002 03:44:08 -0000 1.56
+++ ltp.c 21 Oct 2002 20:39:38 -0000 1.57
@@ -68,40 +68,54 @@
void open_loop_nbest_pitch(float *sw, int start, int end, int len, int *pitch, float *gain, int N, float *stack)
{
int i,j,k;
- float corr=0;
- float energy;
- float score=0, *best_score;
+ /*float corr=0;*/
+ /*float energy;*/
+ float *best_score;
float e0;
+ float *corr, *energy, *score;
best_score = PUSH(stack,N);
+ corr = PUSH(stack,end-start+1);
+ energy = PUSH(stack,end-start+2);
+ score = PUSH(stack,end-start+1);
for (i=0;i<N;i++)
{
best_score[i]=-1;
gain[i]=0;
}
- energy=inner_prod(sw-start, sw-start, len);
+ energy[0]=inner_prod(sw-start, sw-start, len);
e0=inner_prod(sw, sw, len);
for (i=start;i<=end;i++)
{
- if (0&&score < .3*best_score[N-1])
- score = .9*best_score[N-1];
- else
- {
- corr=inner_prod(sw, sw-i, len);
- score=corr*corr/(energy+1);
- }
- if (score>best_score[N-1])
+ /* Update energy for next pitch*/
+ energy[i-start+1] = energy[i-start] + sw[-i-1]*sw[-i-1] - sw[-i+len-1]*sw[-i+len-1];
+ }
+ for (i=start;i<=end;i++)
+ {
+ corr[i-start]=0;
+ score[i-start]=0;
+ }
+
+ for (i=start;i<=end;i++)
+ {
+ /* Compute correlation*/
+ corr[i-start]=inner_prod(sw, sw-i, len);
+ score[i-start]=corr[i-start]*corr[i-start]/(energy[i-start]+1);
+ }
+ for (i=start;i<=end;i++)
+ {
+ if (score[i-start]>best_score[N-1])
{
float g1, g;
- g1 = corr/(energy+10);
- g = sqrt(g1*corr/(e0+10));
+ g1 = corr[i-start]/(energy[i-start]+10);
+ g = sqrt(g1*corr[i-start]/(e0+10));
if (g>g1)
g=g1;
if (g<0)
g=0;
for (j=0;j<N;j++)
{
- if (score > best_score[j])
+ if (score[i-start] > best_score[j])
{
for (k=N-1;k>j;k--)
{
@@ -109,18 +123,15 @@
pitch[k]=pitch[k-1];
gain[k] = gain[k-1];
}
- best_score[j]=score;
+ best_score[j]=score[i-start];
pitch[j]=i;
gain[j]=g;
break;
}
}
}
- /* Update energy for next pitch*/
- energy+=sw[-i-1]*sw[-i-1] - sw[-i+len-1]*sw[-i+len-1];
}
- POP(stack);
}
@@ -181,14 +192,7 @@
e[i][j]=0;
}
- if (p==10)
- {
- syn_percep_zero(e[i], ak, awk1, awk2, x[i], nsf, p);
- } else {
- residue_zero(e[i],awk1,x[i],nsf,p);
- syn_filt_zero(x[i],ak,x[i],nsf,p);
- syn_filt_zero(x[i],awk2,x[i],nsf,p);
- }
+ syn_percep_zero(e[i], ak, awk1, awk2, x[i], nsf, p, stack);
}
for (i=0;i<3;i++)
@@ -302,8 +306,6 @@
printf ("prediction gain = %f\n",err1/(err2+1));
#endif
- POP(stack);
- POP(stack);
return err2;
}
@@ -344,6 +346,7 @@
if (N>10)
N=10;
+ /*FIXME: This breaks if sizeof(int) != sizeof(float) */
nbest=(int*)PUSH(stack, N);
gains = PUSH(stack, N);
params = (ltp_params*) par;
@@ -377,9 +380,6 @@
for (i=0;i<nsf;i++)
exc[i]=best_exc[i];
- POP(stack);
- POP(stack);
- POP(stack);
return pitch;
}
@@ -460,7 +460,6 @@
for (i=0;i<nsf;i++)
exc[i]=gain[0]*e[2][i]+gain[1]*e[1][i]+gain[2]*e[0][i];
- POP(stack);
}
}
<p><p>1.62 +54 -81 speex/libspeex/nb_celp.c
Index: nb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/nb_celp.c,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -r1.61 -r1.62
--- nb_celp.c 20 Oct 2002 23:56:36 -0000 1.61
+++ nb_celp.c 21 Oct 2002 20:39:38 -0000 1.62
@@ -215,9 +215,12 @@
float ol_pitch_coef;
float ol_gain;
float delta_qual=0;
+ float *res, *target, *mem;
+ float *stack;
st=state;
-
+ stack=st->stack;
+
/* Copy new data in input buffer */
speex_move(st->inBuf, st->inBuf+st->frameSize, (st->bufSize-st->frameSize)*sizeof(float));
st->inBuf[st->bufSize-st->frameSize] = in[0] - st->preemph*st->pre_mem;
@@ -250,10 +253,10 @@
st->lpc[0]=1;
/* LPC to LSPs (x-domain) transform */
- roots=lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 15, 0.2, st->stack);
+ roots=lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 15, 0.2, stack);
if (roots!=st->lpcSize)
{
- roots = lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 11, 0.02, st->stack);
+ roots = lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 11, 0.02, stack);
if (roots!=st->lpcSize) {
/*fprintf (stderr, "roots!=st->lpcSize (found only %d roots)\n", roots);*/
@@ -294,7 +297,7 @@
/* Compute interpolated LPCs (unquantized) for whole frame*/
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,st->stack);
+ lsp_to_lpc(st->interp_lsp, st->interp_lpc, st->lpcSize,stack);
bw_lpc(st->gamma1, st->interp_lpc, st->bw_lpc1, st->lpcSize);
bw_lpc(st->gamma2, st->interp_lpc, st->bw_lpc2, st->lpcSize);
@@ -306,7 +309,7 @@
int nol_pitch[4];
float nol_pitch_coef[4];
open_loop_nbest_pitch(st->sw, st->min_pitch, st->max_pitch, st->frameSize,
- nol_pitch, nol_pitch_coef, 4, st->stack);
+ nol_pitch, nol_pitch_coef, 4, stack);
ol_pitch=nol_pitch[0];
ol_pitch_coef = nol_pitch_coef[0];
/*Try to remove pitch multiples*/
@@ -430,12 +433,18 @@
st->old_qlsp[i] = st->qlsp[i];
}
+ /* Filter response */
+ res = PUSH(stack, st->subframeSize);
+ /* Target signal */
+ target = PUSH(stack, st->subframeSize);
+ mem = PUSH(stack, st->lpcSize);
+
/* Loop on sub-frames */
for (sub=0;sub<st->nbSubframes;sub++)
{
float esig, enoise, snr, tmp;
int offset;
- float *sp, *sw, *res, *exc, *target, *mem, *exc2;
+ float *sp, *sw, *exc, *exc2;
int pitch;
/* Offset relative to start of frame */
@@ -449,11 +458,6 @@
exc2=st->exc2+offset;
- /* Filter response */
- res = PUSH(st->stack, st->subframeSize);
- /* Target signal */
- target = PUSH(st->stack, st->subframeSize);
- mem = PUSH(st->stack, st->lpcSize);
/* LSP interpolation (quantized and unquantized) */
tmp = (1.0 + sub)/st->nbSubframes;
@@ -469,11 +473,11 @@
/* Compute interpolated LPCs (quantized and unquantized) */
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,st->stack);
+ lsp_to_lpc(st->interp_lsp, st->interp_lpc, st->lpcSize,stack);
for (i=0;i<st->lpcSize;i++)
st->interp_qlsp[i] = cos(st->interp_qlsp[i]);
- lsp_to_lpc(st->interp_qlsp, st->interp_qlpc, st->lpcSize, st->stack);
+ lsp_to_lpc(st->interp_qlsp, st->interp_qlpc, st->lpcSize, stack);
/* Compute analysis filter gain at w=pi (for use in SB-CELP) */
tmp=1;
@@ -557,7 +561,7 @@
pitch = SUBMODE(ltp_quant)(target, sw, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2,
exc, SUBMODE(ltp_params), pit_min, pit_max, ol_pitch_coef,
- st->lpcSize, st->subframeSize, bits, st->stack,
+ st->lpcSize, st->subframeSize, bits, stack,
exc2, st->complexity);
/*printf ("cl_pitch: %d\n", pitch);*/
@@ -567,9 +571,10 @@
}
/* Update target for adaptive codebook contribution */
- residue_zero(exc, st->bw_lpc1, res, st->subframeSize, st->lpcSize);
+ /*residue_zero(exc, 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);
+ syn_filt_zero(res, st->bw_lpc2, res, st->subframeSize, st->lpcSize);*/
+ syn_percep_zero(exc, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, res, st->subframeSize, st->lpcSize, stack);
for (i=0;i<st->subframeSize;i++)
target[i]-=res[i];
@@ -588,13 +593,15 @@
{
float *innov;
float ener=0, ener_1;
- /*innov=PUSH(st->stack, st->subframeSize);*/
+
innov = st->innov+sub*st->subframeSize;
for (i=0;i<st->subframeSize;i++)
innov[i]=0;
- syn_filt_zero(target, st->bw_lpc1, res, st->subframeSize, st->lpcSize);
+
+ /*syn_filt_zero(target, st->bw_lpc1, res, st->subframeSize, st->lpcSize);
residue_zero(res, st->interp_qlpc, st->buf2, st->subframeSize, st->lpcSize);
- residue_zero(st->buf2, st->bw_lpc2, st->buf2, st->subframeSize, st->lpcSize);
+ residue_zero(st->buf2, st->bw_lpc2, st->buf2, st->subframeSize, st->lpcSize);*/
+ residue_percep_zero(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, st->buf2, st->subframeSize, st->lpcSize, stack);
for (i=0;i<st->subframeSize;i++)
ener+=st->buf2[i]*st->buf2[i];
ener=sqrt(.1+ener/st->subframeSize);
@@ -645,7 +652,7 @@
/* Normal quantization */
SUBMODE(innovation_quant)(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2,
SUBMODE(innovation_params), st->lpcSize, st->subframeSize,
- innov, bits, st->stack, st->complexity);
+ innov, bits, stack, st->complexity);
for (i=0;i<st->subframeSize;i++)
innov[i]*=ener;
for (i=0;i<st->subframeSize;i++)
@@ -655,22 +662,21 @@
}
if (SUBMODE(double_codebook)) {
- float *innov2 = PUSH(st->stack, st->subframeSize);
+ float *tmp_stack=stack;
+ float *innov2 = PUSH(tmp_stack, st->subframeSize);
for (i=0;i<st->subframeSize;i++)
innov2[i]=0;
for (i=0;i<st->subframeSize;i++)
target[i]*=2.2;
SUBMODE(innovation_quant)(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2,
SUBMODE(innovation_params), st->lpcSize, st->subframeSize,
- innov2, bits, st->stack, st->complexity);
+ innov2, bits, tmp_stack, st->complexity);
for (i=0;i<st->subframeSize;i++)
innov2[i]*=ener*(1/2.2);
for (i=0;i<st->subframeSize;i++)
exc[i] += innov2[i];
- POP(st->stack);
}
- /*POP(st->stack);*/
for (i=0;i<st->subframeSize;i++)
target[i]*=ener;
@@ -695,10 +701,6 @@
filter_mem2(sp, st->bw_lpc1, st->bw_lpc2, sw, st->subframeSize, st->lpcSize, st->mem_sw);
for (i=0;i<st->subframeSize;i++)
exc2[i]=exc[i];
-
- POP(st->stack);
- POP(st->stack);
- POP(st->stack);
}
/* Store the LSPs for interpolation in the next frame */
@@ -798,19 +800,22 @@
speex_free(state);
}
-static void nb_decode_lost(DecState *st, float *out)
+static void nb_decode_lost(DecState *st, float *out, float *stack)
{
int i, sub;
+ float *num, *den;
/*float exc_ener=0,g;*/
/* Shift all buffers by one frame */
speex_move(st->inBuf, st->inBuf+st->frameSize, (st->bufSize-st->frameSize)*sizeof(float));
speex_move(st->excBuf, st->excBuf+st->frameSize, (st->bufSize-st->frameSize)*sizeof(float));
+ num=PUSH(stack, ((st->lpcSize<<1)+1));
+ den=PUSH(stack, ((st->lpcSize<<1)+1));
+
for (sub=0;sub<st->nbSubframes;sub++)
{
int offset;
float *sp, *exc;
- float *num, *den;
/* Offset relative to start of frame */
offset = st->subframeSize*sub;
/* Original signal */
@@ -819,15 +824,13 @@
exc=st->exc+offset;
/* Excitation after post-filter*/
- num=PUSH(st->stack, ((st->lpcSize<<1)+1));
- den=PUSH(st->stack, ((st->lpcSize<<1)+1));
if (st->lpc_enh_enabled)
{
enh_lpc(st->interp_qlpc, st->lpcSize, num, den,
- SUBMODE(lpc_enh_k1), SUBMODE(lpc_enh_k2), st->stack);
+ SUBMODE(lpc_enh_k1), SUBMODE(lpc_enh_k2), stack);
} else {
enh_lpc(st->interp_qlpc, st->lpcSize, num, den,
- SUBMODE(lpc_enh_k2), SUBMODE(lpc_enh_k2), st->stack);
+ SUBMODE(lpc_enh_k2), SUBMODE(lpc_enh_k2), stack);
}
for (i=0;i<st->subframeSize;i++)
@@ -840,14 +843,11 @@
sp[i]=exc[i];
/*pole_zero_mem(sp, num, den, sp, st->subframeSize, (st->lpcSize<<1),
- st->mem_sp+st->lpcSize, st->stack);*/
+ st->mem_sp+st->lpcSize, stack);*/
filter_mem2(sp, num, den, sp, st->subframeSize, (st->lpcSize<<1),
st->mem_sp+st->lpcSize);
iir_mem2(sp, st->interp_qlpc, sp, st->subframeSize, st->lpcSize,
st->mem_sp);
-
- POP(st->stack);
- POP(st->stack);
}
@@ -874,12 +874,14 @@
float best_pitch_gain=-1;
int wideband;
int m;
-
+ float *stack;
+ float *awk1, *awk2, *awk3;
st=state;
+ stack=st->stack;
if (!bits)
{
- nb_decode_lost(st, out);
+ nb_decode_lost(st, out, stack);
return 0;
}
@@ -979,16 +981,16 @@
/*printf ("decode_ol_gain: %f\n", ol_gain);*/
}
+ awk1=PUSH(stack, st->lpcSize+1);
+ awk2=PUSH(stack, st->lpcSize+1);
+ awk3=PUSH(stack, st->lpcSize+1);
+
/*Loop on subframes */
for (sub=0;sub<st->nbSubframes;sub++)
{
int offset;
float *sp, *exc, tmp;
-#if 0
- float *num, *den;
-#else
- float *awk1, *awk2, *awk3;
-#endif
+
/* Offset relative to start of frame */
offset = st->subframeSize*sub;
/* Original signal */
@@ -1008,20 +1010,8 @@
/* Compute interpolated LPCs (unquantized) */
for (i=0;i<st->lpcSize;i++)
st->interp_qlsp[i] = cos(st->interp_qlsp[i]);
- lsp_to_lpc(st->interp_qlsp, st->interp_qlpc, st->lpcSize, st->stack);
+ lsp_to_lpc(st->interp_qlsp, st->interp_qlpc, st->lpcSize, stack);
-#if 0
- num=PUSH(st->stack, ((st->lpcSize<<1)+1));
- den=PUSH(st->stack, ((st->lpcSize<<1)+1));
- if (st->lpc_enh_enabled)
- {
- enh_lpc(st->interp_qlpc, st->lpcSize, num, den,
- SUBMODE(lpc_enh_k1), SUBMODE(lpc_enh_k2), st->stack);
- } else {
- enh_lpc(st->interp_qlpc, st->lpcSize, num, den,
- SUBMODE(lpc_enh_k2), SUBMODE(lpc_enh_k2), st->stack);
- }
-#else
{
float r=.9;
@@ -1034,15 +1024,12 @@
k1=k2;
k3=0;
}
- awk1=PUSH(st->stack, st->lpcSize+1);
- awk2=PUSH(st->stack, st->lpcSize+1);
- awk3=PUSH(st->stack, st->lpcSize+1);
bw_lpc(k1, st->interp_qlpc, awk1, st->lpcSize);
bw_lpc(k2, st->interp_qlpc, awk2, st->lpcSize);
bw_lpc(k3, st->interp_qlpc, awk3, st->lpcSize);
}
-#endif
+
/* Compute analysis filter at w=pi */
tmp=1;
st->pi_gain[sub]=0;
@@ -1081,7 +1068,7 @@
}
SUBMODE(ltp_unquant)(exc, pit_min, pit_max, ol_pitch_coef, SUBMODE(ltp_params),
- st->subframeSize, &pitch, &pitch_gain[0], bits, st->stack, st->count_lost);
+ st->subframeSize, &pitch, &pitch_gain[0], bits, stack, st->count_lost);
tmp = (pitch_gain[0]+pitch_gain[1]+pitch_gain[2]);
if (tmp>best_pitch_gain)
@@ -1105,7 +1092,6 @@
float ener;
float *innov;
- /*innov = PUSH(st->stack, st->subframeSize);*/
innov = st->innov+sub*st->subframeSize;
for (i=0;i<st->subframeSize;i++)
innov[i]=0;
@@ -1127,7 +1113,7 @@
if (SUBMODE(innovation_unquant))
{
/*Fixed codebook contribution*/
- SUBMODE(innovation_unquant)(innov, SUBMODE(innovation_params), st->subframeSize, bits, st->stack);
+ SUBMODE(innovation_unquant)(innov, SUBMODE(innovation_params), st->subframeSize, bits, stack);
} else {
fprintf(stderr, "No fixed codebook\n");
}
@@ -1139,18 +1125,17 @@
if (SUBMODE(double_codebook))
{
- float *innov2 = PUSH(st->stack, st->subframeSize);
+ float *tmp_stack=stack;
+ float *innov2 = PUSH(tmp_stack, st->subframeSize);
for (i=0;i<st->subframeSize;i++)
innov2[i]=0;
- SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), st->subframeSize, bits, st->stack);
+ SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), st->subframeSize, bits, tmp_stack);
for (i=0;i<st->subframeSize;i++)
innov2[i]*=ener*(1/2.2);
for (i=0;i<st->subframeSize;i++)
exc[i] += innov2[i];
- POP(st->stack);
}
- /*POP(st->stack);*/
}
for (i=0;i<st->subframeSize;i++)
@@ -1159,22 +1144,10 @@
if (st->lpc_enh_enabled && SUBMODE(comb_gain>0))
comb_filter(exc, sp, st->interp_qlpc, st->lpcSize, st->subframeSize,
pitch, pitch_gain, .5);
-#if 0
- /*pole_zero_mem(sp, num, den, sp, st->subframeSize, (st->lpcSize<<1),
- st->mem_sp+st->lpcSize, st->stack);*/
- filter_mem2(sp, num, den, sp, st->subframeSize, (st->lpcSize<<1),
- st->mem_sp+st->lpcSize);
- iir_mem2(sp, st->interp_qlpc, sp, st->subframeSize, st->lpcSize,
- st->mem_sp);
-#else
filter_mem2(sp, awk3, awk1, sp, st->subframeSize, st->lpcSize,
st->mem_sp);
filter_mem2(sp, awk2, st->interp_qlpc, sp, st->subframeSize, st->lpcSize,
st->mem_sp+st->lpcSize);
- POP(st->stack);
-#endif
- POP(st->stack);
- POP(st->stack);
}
/*Copy output signal*/
<p><p>1.75 +25 -24 speex/libspeex/sb_celp.c
Index: sb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/sb_celp.c,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -r1.74 -r1.75
--- sb_celp.c 11 Oct 2002 03:39:34 -0000 1.74
+++ sb_celp.c 21 Oct 2002 20:39:38 -0000 1.75
@@ -269,8 +269,11 @@
{
SBEncState *st;
int i, roots, sub;
+ float *stack;
+ float *mem, *innov;
st = state;
+ stack=st->stack;
/* Compute the two sub-bands by filtering with h0 and h1*/
fir_mem(in, h0, st->x0, st->full_frame_size, QMF_ORDER, st->h0_mem);
@@ -316,10 +319,10 @@
st->lpc[0]=1;
/* LPC to LSPs (x-domain) transform */
- roots=lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 15, 0.2, st->stack);
+ roots=lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 15, 0.2, stack);
if (roots!=st->lpcSize)
{
- roots = lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 11, 0.02, st->stack);
+ roots = lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 11, 0.02, stack);
if (roots!=st->lpcSize) {
/*fprintf (stderr, "roots!=st->lpcSize (found only %d roots)\n", roots);*/
@@ -388,9 +391,12 @@
st->old_qlsp[i] = st->qlsp[i];
}
+ mem=PUSH(stack, st->lpcSize);
+ innov = PUSH(stack, st->subframeSize);
+
for (sub=0;sub<st->nbSubframes;sub++)
{
- float *exc, *sp, *mem, *res, *target, *sw, tmp, filter_ratio;
+ float *exc, *sp, *res, *target, *sw, tmp, filter_ratio;
int offset;
float rl, rh, eh=0, el=0;
int fold;
@@ -401,8 +407,6 @@
res=st->res+offset;
target=st->target+offset;
sw=st->sw+offset;
-
- mem=PUSH(st->stack, st->lpcSize);
/* LSP interpolation (quantized and unquantized) */
tmp = (1.0 + sub)/st->nbSubframes;
@@ -420,8 +424,8 @@
lsp_enforce_margin(st->interp_lsp, st->lpcSize, .002);
lsp_enforce_margin(st->interp_qlsp, st->lpcSize, .002);
- lsp_to_lpc(st->interp_lsp, st->interp_lpc, st->lpcSize,st->stack);
- lsp_to_lpc(st->interp_qlsp, st->interp_qlpc, st->lpcSize, st->stack);
+ lsp_to_lpc(st->interp_lsp, st->interp_lpc, st->lpcSize,stack);
+ lsp_to_lpc(st->interp_qlsp, st->interp_qlpc, st->lpcSize, stack);
bw_lpc(st->gamma1, st->interp_lpc, st->bw_lpc1, st->lpcSize);
bw_lpc(st->gamma2, st->interp_lpc, st->bw_lpc2, st->lpcSize);
@@ -477,13 +481,10 @@
} else {
float gc, scale, scale_1;
- float *innov;
for (i=0;i<st->subframeSize;i++)
el+=sqr(((EncState*)st->st_low)->exc[offset+i]);
/*speex_bits_pack(bits, 0, 1);*/
- innov = PUSH(st->stack, st->subframeSize);
-
gc = sqrt(1+eh)*filter_ratio/sqrt((1+el)*st->subframeSize);
{
@@ -565,26 +566,26 @@
/*print_vec(target, st->subframeSize, "\ntarget");*/
SUBMODE(innovation_quant)(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2,
SUBMODE(innovation_params), st->lpcSize, st->subframeSize,
- innov, bits, st->stack, st->complexity);
+ innov, bits, stack, st->complexity);
/*print_vec(target, st->subframeSize, "after");*/
for (i=0;i<st->subframeSize;i++)
exc[i] += innov[i]*scale;
if (SUBMODE(double_codebook)) {
- float *innov2 = PUSH(st->stack, st->subframeSize);
+ float *tmp_stack=stack;
+ float *innov2 = PUSH(tmp_stack, st->subframeSize);
for (i=0;i<st->subframeSize;i++)
innov2[i]=0;
for (i=0;i<st->subframeSize;i++)
target[i]*=2.5;
SUBMODE(innovation_quant)(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2,
SUBMODE(innovation_params), st->lpcSize, st->subframeSize,
- innov2, bits, st->stack, st->complexity);
+ innov2, bits, tmp_stack, st->complexity);
for (i=0;i<st->subframeSize;i++)
innov2[i]*=scale*(1/2.5);
for (i=0;i<st->subframeSize;i++)
exc[i] += innov2[i];
- POP(st->stack);
}
@@ -598,7 +599,6 @@
printf ("correction high: %f\n", en);
}
- POP(st->stack);
}
#if 1
/*Keep the previous memory*/
@@ -614,8 +614,6 @@
filter_mem2(sp, st->bw_lpc1, st->bw_lpc2, sw, st->subframeSize, st->lpcSize, st->mem_sw);
#endif
-
- POP(st->stack);
}
@@ -721,7 +719,7 @@
speex_free(state);
}
-static void sb_decode_lost(SBDecState *st, float *out)
+static void sb_decode_lost(SBDecState *st, float *out, float *stack)
{
int i;
for (i=0;i<st->frame_size;i++)
@@ -755,8 +753,11 @@
SBDecState *st;
int wideband;
int ret;
+ float *stack;
st = state;
+ stack=st->stack;
+
/* Decode the low-band */
ret = nb_decode(st->st_low, bits, st->x0d);
@@ -768,7 +769,7 @@
if (!bits)
{
- sb_decode_lost(st, out);
+ sb_decode_lost(st, out, stack);
return 0;
}
@@ -847,7 +848,7 @@
lsp_enforce_margin(st->interp_qlsp, st->lpcSize, .002);
/* LSP to LPC */
- lsp_to_lpc(st->interp_qlsp, st->interp_qlpc, st->lpcSize, st->stack);
+ lsp_to_lpc(st->interp_qlsp, st->interp_qlpc, st->lpcSize, stack);
/* Calculate reponse ratio between the low and high filter in the middle
of the band (4000 Hz) */
@@ -896,21 +897,21 @@
SUBMODE(innovation_unquant)(exc, SUBMODE(innovation_params), st->subframeSize,
- bits, st->stack);
+ bits, stack);
for (i=0;i<st->subframeSize;i++)
exc[i]*=scale;
if (SUBMODE(double_codebook)) {
- float *innov2 = PUSH(st->stack, st->subframeSize);
+ float *tmp_stack=stack;
+ float *innov2 = PUSH(tmp_stack, st->subframeSize);
for (i=0;i<st->subframeSize;i++)
innov2[i]=0;
SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), st->subframeSize,
- bits, st->stack);
+ bits, tmp_stack);
for (i=0;i<st->subframeSize;i++)
innov2[i]*=scale*(1/2.5);
for (i=0;i<st->subframeSize;i++)
exc[i] += innov2[i];
- POP(st->stack);
}
}
<p><p>1.4 +5 -1 speex/libspeex/stack_alloc.h
Index: stack_alloc.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/stack_alloc.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- stack_alloc.h 11 Oct 2002 03:39:34 -0000 1.3
+++ stack_alloc.h 21 Oct 2002 20:39:38 -0000 1.4
@@ -34,9 +34,13 @@
#ifndef STACK_ALLOC_H
#define STACK_ALLOC_H
-
+/*
#define PUSH(stack, size) (((int*)stack)[size]=(size),stack+=(size)+1,stack-(size)-1)
#define POP(stack) (stack-=((int*)stack)[-1]+1)
+*/
+
+/*#define PUSH(stack, size) (stack+=(size),stack-(size))*/
+#define PUSH(stack, size) (stack=(float*)(((int)stack)+(size*sizeof(float))),(float*)(((int)stack)-(size*sizeof(float))))
#endif
<p><p>1.42 +3 -3 speex/libspeex/testenc.c
Index: testenc.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/testenc.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- testenc.c 3 Oct 2002 04:00:10 -0000 1.41
+++ testenc.c 21 Oct 2002 20:39:38 -0000 1.42
@@ -42,7 +42,7 @@
speex_encoder_ctl(st, SPEEX_SET_VBR, &tmp);
tmp=8;
speex_encoder_ctl(st, SPEEX_SET_QUALITY, &tmp);
- tmp=4;
+ tmp=1;
speex_encoder_ctl(st, SPEEX_SET_COMPLEXITY, &tmp);
speex_mode_query(&speex_nb_mode, SPEEX_MODE_FRAME_SIZE, &tmp);
@@ -71,7 +71,7 @@
for (i=0;i<FRAME_SIZE;i++)
bak[i]=input[i]=in[i];
speex_bits_reset(&bits);
-
+ /*
speex_bits_pack(&bits, 14, 5);
speex_bits_pack(&bits, SPEEX_INBAND_CHAR, 4);
speex_bits_pack(&bits, 'A', 8);
@@ -83,7 +83,7 @@
speex_bits_pack(&bits, 15, 5);
speex_bits_pack(&bits, 2, 4);
speex_bits_pack(&bits, 0, 16);
-
+ */
speex_encode(st, input, &bits);
nbBits = speex_bits_write(&bits, cbits, 200);
bitCount+=bits.nbBits;
<p><p>--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list