[xiph-cvs] cvs commit: speex/libspeex cb_search.c lpc.c lpc.h misc.h nb_celp.c nb_celp.h sb_celp.c sb_celp.h testenc.c
Jean-Marc Valin
jm at xiph.org
Tue Oct 7 21:38:54 PDT 2003
jm 03/10/08 00:38:54
Modified: libspeex cb_search.c lpc.c lpc.h misc.h nb_celp.c nb_celp.h
sb_celp.c sb_celp.h testenc.c
Log:
fixed-point: more signal scaling again, some auto-correlation work
Revision Changes Path
1.90 +3 -3 speex/libspeex/cb_search.c
Index: cb_search.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/cb_search.c,v
retrieving revision 1.89
retrieving revision 1.90
diff -u -r1.89 -r1.90
--- cb_search.c 8 Oct 2003 04:35:48 -0000 1.89
+++ cb_search.c 8 Oct 2003 04:38:53 -0000 1.90
@@ -137,7 +137,7 @@
res[j]=0;
for (k=0;k<=j;k++)
res[j] += shape[k]*r[j-k];
- res[j] *= 0.03125;
+ res[j] *= 0.03125*SIG_SCALING;
}
/* Compute codeword energy */
@@ -221,7 +221,7 @@
rind-=shape_cb_size;
}
- g=sign*0.03125*shape_cb[rind*subvect_size+m];
+ g=sign*0.03125*SIG_SCALING*shape_cb[rind*subvect_size+m];
q=subvect_size-m;
for (n=subvect_size*(i+1);n<nsf;n++,q++)
t[n] -= g*r[q];
@@ -290,7 +290,7 @@
}
for (j=0;j<subvect_size;j++)
- e[subvect_size*i+j]=sign*0.03125*shape_cb[rind*subvect_size+j];
+ e[subvect_size*i+j]=sign*0.03125*SIG_SCALING*shape_cb[rind*subvect_size+j];
}
/* Update excitation */
for (j=0;j<nsf;j++)
<p><p>1.16 +4 -4 speex/libspeex/lpc.c
Index: lpc.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/lpc.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- lpc.c 8 Oct 2003 04:33:36 -0000 1.15
+++ lpc.c 8 Oct 2003 04:38:53 -0000 1.16
@@ -117,7 +117,7 @@
*/
#include <stdio.h>
void _spx_autocorr(
-const float *x, /* in: [0...n-1] samples x */
+const spx_word16_t *x, /* in: [0...n-1] samples x */
spx_word16_t *ac, /* out: [0...lag-1] ac values */
int lag,
int n
@@ -129,7 +129,7 @@
int shift, ac_shift;
for (j=0;j<n;j++)
- ac0 += floor(x[j]*x[j])/256;
+ ac0 += MULT16_16(x[j],x[j])/256;
ac0 += n;
shift = 8;
while (shift && ac0<0x40000000)
@@ -150,7 +150,7 @@
d=0;
for (j=i;j<n;j++)
{
- d += ((int)(floor(x[j]) * floor(x[j-i]))) >> shift;
+ d += MULT16_16(x[j],x[j-i]) >> shift;
}
ac[i] = d >> ac_shift;
@@ -212,7 +212,7 @@
* for lags between 0 and lag-1, and x == 0 outside 0...n-1
*/
void _spx_autocorr(
-const float *x, /* in: [0...n-1] samples x */
+const spx_word16_t *x, /* in: [0...n-1] samples x */
float *ac, /* out: [0...lag-1] ac values */
int lag,
int n
<p><p>1.8 +1 -1 speex/libspeex/lpc.h
Index: lpc.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/lpc.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- lpc.h 8 Oct 2003 04:30:25 -0000 1.7
+++ lpc.h 8 Oct 2003 04:38:53 -0000 1.8
@@ -36,7 +36,7 @@
#include "misc.h"
void _spx_autocorr(
- const float * x, /* in: [0...n-1] samples x */
+ const spx_word16_t * x, /* in: [0...n-1] samples x */
spx_word16_t *ac, /* out: [0...lag-1] ac values */
int lag, int n);
<p><p>1.28 +14 -0 speex/libspeex/misc.h
Index: misc.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/misc.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- misc.h 8 Oct 2003 04:35:48 -0000 1.27
+++ misc.h 8 Oct 2003 04:38:53 -0000 1.28
@@ -54,6 +54,12 @@
#define LPC_SCALING 8192.
#define SIG_SCALING 16384.
+#define LPC_SHIFT 13
+#define SIG_SHIFT 14
+
+#define SHR(a,shift) ((a) >> (shift))
+
+#define MULT16_16(a,b) (((signed int)(a))*(b))
#define MULT16_32_Q14(a,b) (((a)*((b)>>14)) + ((a)*((signed int)((b)&0x00003fff))>>14))
#define MULT16_32_Q15(a,b) (((a)*((b)>>15)) + ((a)*((signed int)((b)&0x00007fff))>>15))
@@ -79,6 +85,14 @@
#define LPC_SCALING 1.
#define SIG_SCALING 1.
+
+#define LPC_SHIFT 0
+#define SIG_SHIFT 0
+
+#define SHR(a,shift) (a)
+#define MULT16_16(a,b) ((a)*(b))
+
+
#endif
#ifndef RELEASE
<p><p>1.130 +16 -15 speex/libspeex/nb_celp.c
Index: nb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/nb_celp.c,v
retrieving revision 1.129
retrieving revision 1.130
diff -u -r1.129 -r1.130
--- nb_celp.c 8 Oct 2003 04:36:24 -0000 1.129
+++ nb_celp.c 8 Oct 2003 04:38:53 -0000 1.130
@@ -121,11 +121,11 @@
int part1, part2;
part1=st->frameSize - (st->subframeSize>>1);
part2=(st->frameSize>>1) + (st->subframeSize>>1);
- st->window = PUSH(st->stack, st->windowSize, float);
+ st->window = PUSH(st->stack, st->windowSize, spx_word16_t);
for (i=0;i<part1;i++)
- st->window[i]=.54-.46*cos(M_PI*i/part1);
+ st->window[i]=SIG_SCALING*(.54-.46*cos(M_PI*i/part1));
for (i=0;i<part2;i++)
- st->window[part1+i]=.54+.46*cos(M_PI*i/part2);
+ st->window[part1+i]=SIG_SCALING*(.54+.46*cos(M_PI*i/part2));
}
/* Create the window for autocorrelation (lag-windowing) */
st->lagWindow = PUSH(st->stack, st->lpcSize+1, float);
@@ -223,13 +223,16 @@
speex_move(st->swBuf, st->swBuf+st->frameSize, (st->bufSize-st->frameSize)*sizeof(float));
- /* Window for analysis */
- for (i=0;i<st->windowSize;i++)
- st->buf2[i] = st->frame[i] * st->window[i] / SIG_SCALING;
-
- /* Compute auto-correlation */
- _spx_autocorr(st->buf2, st->autocorr, st->lpcSize+1, st->windowSize);
+ {
+ spx_word16_t *w_sig;
+ w_sig = PUSH(stack, st->windowSize, spx_word16_t);
+ /* Window for analysis */
+ for (i=0;i<st->windowSize;i++)
+ w_sig[i] = SHR(MULT16_16(SHR((spx_word32_t)(st->frame[i]),SIG_SHIFT),st->window[i]),SIG_SHIFT);
+ /* Compute auto-correlation */
+ _spx_autocorr(w_sig, st->autocorr, st->lpcSize+1, st->windowSize);
+ }
st->autocorr[0] *= st->lpc_floor; /* Noise floor in auto-correlation domain */
/* Lag windowing: equivalent to filtering in the power-spectrum domain */
@@ -815,9 +818,8 @@
/* Normalize innovation */
for (i=0;i<st->subframeSize;i++)
- target[i]*=ener_1/SIG_SCALING;
+ target[i]*=ener_1;
- FLOAT_SIGNAL;
for (i=0;i<st->subframeSize;i++)
syn_resp[i]/=SIG_SCALING;
@@ -831,7 +833,7 @@
/* De-normalize innovation and update excitation */
for (i=0;i<st->subframeSize;i++)
- innov[i]*=ener*SIG_SCALING;
+ innov[i]*=ener;
for (i=0;i<st->subframeSize;i++)
exc[i] += innov[i];
} else {
@@ -850,17 +852,16 @@
SUBMODE(innovation_params), st->lpcSize, st->subframeSize,
innov2, syn_resp, bits, tmp_stack, st->complexity);
for (i=0;i<st->subframeSize;i++)
- innov2[i]*=ener*(1/2.2)*SIG_SCALING;
+ innov2[i]*=ener*(1/2.2);
for (i=0;i<st->subframeSize;i++)
exc[i] += innov2[i];
}
- FIXED_SIGNAL;
for (i=0;i<st->subframeSize;i++)
syn_resp[i]*=SIG_SCALING;
for (i=0;i<st->subframeSize;i++)
- target[i]*=ener*SIG_SCALING;
+ target[i]*=ener;
}
<p><p>1.55 +1 -1 speex/libspeex/nb_celp.h
Index: nb_celp.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/nb_celp.h,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -r1.54 -r1.55
--- nb_celp.h 8 Oct 2003 04:35:01 -0000 1.54
+++ nb_celp.h 8 Oct 2003 04:38:53 -0000 1.55
@@ -79,7 +79,7 @@
float *swBuf; /**< Weighted signal buffer */
float *sw; /**< Start of weighted signal frame */
float *innov; /**< Innovation for the frame */
- float *window; /**< Temporary (Hanning) window */
+ spx_word16_t *window; /**< Temporary (Hanning) window */
float *buf2; /**< 2nd temporary buffer */
spx_word16_t *autocorr; /**< auto-correlation */
float *lagWindow; /**< Window applied to auto-correlation */
<p><p>1.131 +15 -13 speex/libspeex/sb_celp.c
Index: sb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/sb_celp.c,v
retrieving revision 1.130
retrieving revision 1.131
diff -u -r1.130 -r1.131
--- sb_celp.c 8 Oct 2003 04:37:23 -0000 1.130
+++ sb_celp.c 8 Oct 2003 04:38:53 -0000 1.131
@@ -181,11 +181,11 @@
int part1, part2;
part1 = st->subframeSize*7/2;
part2 = st->subframeSize*5/2;
- st->window = PUSH(st->stack, st->windowSize, float);
+ st->window = PUSH(st->stack, st->windowSize, spx_word16_t);
for (i=0;i<part1;i++)
- st->window[i]=.54-.46*cos(M_PI*i/part1);
+ st->window[i]=SIG_SCALING*(.54-.46*cos(M_PI*i/part1));
for (i=0;i<part2;i++)
- st->window[part1+i]=.54+.46*cos(M_PI*i/part2);
+ st->window[part1+i]=SIG_SCALING*(.54+.46*cos(M_PI*i/part2));
}
st->lagWindow = PUSH(st->stack, st->lpcSize+1, float);
@@ -282,12 +282,16 @@
else
dtx=0;
- /* Start encoding the high-band */
- for (i=0;i<st->windowSize;i++)
- st->buf[i] = st->high[i] * st->window[i] / SIG_SCALING;
+ {
+ spx_word16_t *w_sig;
+ w_sig = PUSH(stack, st->windowSize, spx_word16_t);
+ /* Window for analysis */
+ for (i=0;i<st->windowSize;i++)
+ w_sig[i] = SHR(MULT16_16(SHR((spx_word32_t)(st->high[i]),SIG_SHIFT),st->window[i]),SIG_SHIFT);
- /* Compute auto-correlation */
- _spx_autocorr(st->buf, st->autocorr, st->lpcSize+1, st->windowSize);
+ /* Compute auto-correlation */
+ _spx_autocorr(w_sig, st->autocorr, st->lpcSize+1, st->windowSize);
+ }
st->autocorr[0] *= st->lpc_floor; /* Noise floor in auto-correlation domain */
/* Lag windowing: equivalent to filtering in the power-spectrum domain */
@@ -599,9 +603,8 @@
for (i=0;i<st->subframeSize;i++)
- target[i]*=scale_1/SIG_SCALING;
+ target[i]*=scale_1;
- FLOAT_SIGNAL;
for (i=0;i<st->subframeSize;i++)
syn_resp[i]/=SIG_SCALING;
@@ -616,7 +619,7 @@
/*print_vec(target, st->subframeSize, "after");*/
for (i=0;i<st->subframeSize;i++)
- exc[i] += innov[i]*scale*SIG_SCALING;
+ exc[i] += innov[i]*scale;
if (SUBMODE(double_codebook)) {
char *tmp_stack=stack;
@@ -629,12 +632,11 @@
SUBMODE(innovation_params), st->lpcSize, st->subframeSize,
innov2, syn_resp, bits, tmp_stack, (st->complexity+1)>>1);
for (i=0;i<st->subframeSize;i++)
- innov2[i]*=scale*(1/2.5)*SIG_SCALING;
+ innov2[i]*=scale*(1/2.5);
for (i=0;i<st->subframeSize;i++)
exc[i] += innov2[i];
}
- FIXED_SIGNAL;
for (i=0;i<st->subframeSize;i++)
syn_resp[i]/=SIG_SCALING;
<p><p>1.43 +1 -1 speex/libspeex/sb_celp.h
Index: sb_celp.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/sb_celp.h,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- sb_celp.h 8 Oct 2003 04:30:25 -0000 1.42
+++ sb_celp.h 8 Oct 2003 04:38:54 -0000 1.43
@@ -69,7 +69,7 @@
float *res; /**< Zero-input response (ringing) */
float *sw; /**< Perceptually weighted signal */
float *target; /**< Weighted target signal (analysis by synthesis) */
- float *window; /**< LPC analysis window */
+ spx_word16_t *window; /**< LPC analysis window */
float *lagWindow; /**< Auto-correlation window */
spx_word16_t *autocorr; /**< Auto-correlation (for LPC analysis) */
spx_coef_t *lpc; /**< LPC coefficients */
<p><p>1.48 +1 -1 speex/libspeex/testenc.c
Index: testenc.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/testenc.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -r1.47 -r1.48
--- testenc.c 8 Oct 2003 04:37:23 -0000 1.47
+++ testenc.c 8 Oct 2003 04:38:54 -0000 1.48
@@ -46,7 +46,7 @@
speex_decoder_ctl(dec, SPEEX_SET_ENH, &tmp);
tmp=0;
speex_encoder_ctl(st, SPEEX_SET_VBR, &tmp);
- tmp=10;
+ tmp=4;
speex_encoder_ctl(st, SPEEX_SET_QUALITY, &tmp);
tmp=5;
speex_encoder_ctl(st, SPEEX_SET_COMPLEXITY, &tmp);
<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