[xiph-commits] r11115 - trunk/speex/libspeex
jm at svn.xiph.org
jm at svn.xiph.org
Mon Apr 10 07:30:58 PDT 2006
Author: jm
Date: 2006-04-10 07:30:54 -0700 (Mon, 10 Apr 2006)
New Revision: 11115
Modified:
trunk/speex/libspeex/nb_celp.c
trunk/speex/libspeex/nb_celp.h
trunk/speex/libspeex/sb_celp.c
trunk/speex/libspeex/sb_celp.h
Log:
innovation is saved directly to the sb_celp en/decoder, so a buffer is
no longer required. This saves a total of 1.2 kB for the narrowband encoder+
decoder.
Modified: trunk/speex/libspeex/nb_celp.c
===================================================================
--- trunk/speex/libspeex/nb_celp.c 2006-04-10 00:35:38 UTC (rev 11114)
+++ trunk/speex/libspeex/nb_celp.c 2006-04-10 14:30:54 UTC (rev 11115)
@@ -161,8 +161,6 @@
st->swBuf = speex_alloc((mode->frameSize+mode->pitchEnd+1)*sizeof(spx_word16_t));
st->sw = st->swBuf + mode->pitchEnd + 1;
- st->innov = speex_alloc((st->frameSize)*sizeof(spx_sig_t));
-
st->window= lpc_window;
/* Create the window for autocorrelation (lag-windowing) */
@@ -198,7 +196,8 @@
st->mem_exc2 = speex_alloc((st->lpcSize)*sizeof(spx_mem_t));
st->pi_gain = speex_alloc((st->nbSubframes)*sizeof(spx_word32_t));
-
+ st->innov_save = NULL;
+
st->pitch = speex_alloc((st->nbSubframes)*sizeof(int));
st->vbr = speex_alloc(sizeof(VBRState));
@@ -231,7 +230,6 @@
speex_free (st->winBuf);
speex_free (st->excBuf);
- speex_free (st->innov);
speex_free (st->interp_qlpc);
speex_free (st->qlsp);
speex_free (st->old_qlsp);
@@ -278,6 +276,7 @@
spx_word32_t ol_gain;
VARDECL(spx_word16_t *ringing);
VARDECL(spx_sig_t *target);
+ VARDECL(spx_sig_t *innov);
VARDECL(spx_mem_t *mem);
char *stack;
VARDECL(spx_word16_t *syn_resp);
@@ -685,6 +684,7 @@
/* Target signal */
ALLOC(target, st->subframeSize, spx_sig_t);
+ ALLOC(innov, st->subframeSize, spx_sig_t);
ALLOC(ringing, st->subframeSize, spx_word16_t);
ALLOC(syn_resp, st->subframeSize, spx_word16_t);
ALLOC(real_exc, st->subframeSize, spx_sig_t);
@@ -696,6 +696,7 @@
int offset;
spx_word16_t *sw;
spx_sig_t *exc;
+ spx_sig_t *innov_save = NULL;
int pitch;
int response_bound = st->subframeSize;
#ifdef EPIC_48K
@@ -714,7 +715,10 @@
exc=st->exc+offset;
/* Weighted signal */
sw=st->sw+offset;
-
+ /* Pointer for saving innovation */
+ if (st->innov_save)
+ innov_save = st->innov_save+offset;
+
/* LSP interpolation (quantized and unquantized) */
lsp_interpolate(st->old_lsp, st->lsp, st->interp_lsp, st->lpcSize, sub, st->nbSubframes);
lsp_interpolate(st->old_qlsp, st->qlsp, st->interp_qlsp, st->lpcSize, sub, st->nbSubframes);
@@ -878,11 +882,9 @@
/* Quantization of innovation */
{
- spx_sig_t *innov;
spx_word32_t ener=0;
spx_word16_t fine_gain;
- innov = st->innov+sub*st->subframeSize;
for (i=0;i<st->subframeSize;i++)
innov[i]=0;
@@ -943,6 +945,11 @@
speex_error("No fixed codebook");
}
+ if (innov_save)
+ {
+ for (i=0;i<st->subframeSize;i++)
+ innov_save[i] = innov[i];
+ }
/* In some (rare) modes, we do a second search (more bits) to reduce noise even more */
if (SUBMODE(double_codebook)) {
char *tmp_stack=stack;
@@ -958,6 +965,11 @@
signal_mul(innov2, innov2, (spx_word32_t) (ener*(1.f/2.2f)), st->subframeSize);
for (i=0;i<st->subframeSize;i++)
exc[i] = ADD32(exc[i],innov2[i]);
+ if (innov_save)
+ {
+ for (i=0;i<st->subframeSize;i++)
+ innov_save[i] = ADD32(innov_save[i],innov2[i]);
+ }
stack = tmp_stack;
}
@@ -1060,7 +1072,6 @@
st->exc = st->excBuf + PITCH_PERIODS*st->max_pitch + 1;
for (i=0;i<st->frameSize + st->max_pitch + 1;i++)
st->excBuf[i]=0;
- st->innov = speex_alloc((st->frameSize)*sizeof(spx_sig_t));
st->interp_qlpc = speex_alloc(st->lpcSize*sizeof(spx_coef_t));
st->old_qlsp = speex_alloc(st->lpcSize*sizeof(spx_lsp_t));
@@ -1102,7 +1113,6 @@
#endif
speex_free (st->excBuf);
- speex_free (st->innov);
speex_free (st->interp_qlpc);
speex_free (st->old_qlsp);
speex_free (st->mem_sp);
@@ -1198,7 +1208,9 @@
/* FIXME: THIS CAN BE IMPROVED */
/*if (pitch_gain>.95)
pitch_gain=.95;*/
- innov_gain = compute_rms(st->innov, st->frameSize);
+
+ /* FIXME: This was rms of innovation (not exc) */
+ innov_gain = compute_rms(st->exc, st->frameSize);
pitch_val = st->last_pitch + SHR32((spx_int32_t)speex_rand(1+st->count_lost, &st->seed),SIG_SHIFT);
if (pitch_val > st->max_pitch)
pitch_val = st->max_pitch;
@@ -1249,6 +1261,7 @@
int wideband;
int m;
char *stack;
+ VARDECL(spx_sig_t *innov);
VARDECL(spx_coef_t *ak);
VARDECL(spx_coef_t *awk1);
VARDECL(spx_coef_t *awk2);
@@ -1374,7 +1387,8 @@
float pgain=GAIN_SCALING_1*st->last_pitch_gain;
if (pgain>.6)
pgain=.6;
- innov_gain = compute_rms(st->innov, st->frameSize);
+ /* This was innov, not exc */
+ innov_gain = compute_rms(st->exc, st->frameSize);
for (i=0;i<st->frameSize;i++)
st->exc[i]=VERY_SMALL;
speex_rand_vec(innov_gain, st->exc, st->frameSize);
@@ -1469,6 +1483,7 @@
ALLOC(awk1, st->lpcSize, spx_coef_t);
ALLOC(awk2, st->lpcSize, spx_coef_t);
ALLOC(awk3, st->lpcSize, spx_coef_t);
+ ALLOC(innov, st->subframeSize, spx_sig_t);
if (st->submodeID==1)
{
@@ -1592,9 +1607,7 @@
{
int q_energy;
spx_word32_t ener;
- spx_sig_t *innov;
- innov = st->innov+sub*st->subframeSize;
for (i=0;i<st->subframeSize;i++)
innov[i]=0;
@@ -1967,17 +1980,12 @@
e[i]=st->exc[i];
}
break;
- case SPEEX_GET_INNOV:
- {
- int i;
- spx_sig_t *e = (spx_sig_t*)ptr;
- for (i=0;i<st->frameSize;i++)
- e[i]=st->innov[i];
- }
- break;
case SPEEX_GET_RELATIVE_QUALITY:
(*(float*)ptr)=st->relative_quality;
break;
+ case SPEEX_SET_INNOVATION_SAVE:
+ st->innov_save = ptr;
+ break;
default:
speex_warning_int("Unknown nb_ctl request: ", request);
return -1;
@@ -2067,17 +2075,12 @@
e[i]=st->exc[i];
}
break;
- case SPEEX_GET_INNOV:
- {
- int i;
- spx_sig_t *e = (spx_sig_t*)ptr;
- for (i=0;i<st->frameSize;i++)
- e[i]=st->innov[i];
- }
- break;
case SPEEX_GET_DTX_STATUS:
*((int*)ptr) = st->dtx_enabled;
break;
+ case SPEEX_SET_INNOVATION_SAVE:
+ st->innov_save = ptr;
+ break;
default:
speex_warning_int("Unknown nb_ctl request: ", request);
return -1;
Modified: trunk/speex/libspeex/nb_celp.h
===================================================================
--- trunk/speex/libspeex/nb_celp.h 2006-04-10 00:35:38 UTC (rev 11114)
+++ trunk/speex/libspeex/nb_celp.h 2006-04-10 14:30:54 UTC (rev 11115)
@@ -84,7 +84,6 @@
spx_sig_t *exc; /**< Start of excitation frame */
spx_word16_t *swBuf; /**< Weighted signal buffer */
spx_word16_t *sw; /**< Start of weighted signal frame */
- spx_sig_t *innov; /**< Innovation for the frame */
const spx_word16_t *window; /**< Temporary (Hanning) window */
spx_word16_t *autocorr; /**< auto-correlation */
spx_word16_t *lagWindow; /**< Window applied to auto-correlation */
@@ -105,7 +104,8 @@
spx_mem_t *mem_exc; /**< Filter memory for excitation (whole frame) */
spx_mem_t *mem_exc2; /**< Filter memory for excitation (whole frame) */
spx_word32_t *pi_gain; /**< Gain of LPC filter at theta=pi (fe/2) */
-
+ spx_sig_t *innov_save; /** If non-NULL, innovation is copied here */
+
VBRState *vbr; /**< State of the VBR data */
float vbr_quality; /**< Quality setting for VBR encoding */
float relative_quality; /**< Relative quality that will be needed by VBR */
@@ -148,12 +148,12 @@
char *stack; /**< Pseudo-stack allocation for temporary memory */
spx_sig_t *excBuf; /**< Excitation buffer */
spx_sig_t *exc; /**< Start of excitation frame */
- spx_sig_t *innov; /**< Innovation for the frame */
spx_lsp_t *qlsp; /**< Quantized LSPs for current frame */
spx_lsp_t *old_qlsp; /**< Quantized LSPs for previous frame */
spx_coef_t *interp_qlpc; /**< Interpolated quantized LPCs */
spx_mem_t *mem_sp; /**< Filter memory for synthesis signal */
spx_word32_t *pi_gain; /**< Gain of LPC filter at theta=pi (fe/2) */
+ spx_sig_t *innov_save; /** If non-NULL, innovation is copied here */
/* This is used in packet loss concealment */
int last_pitch; /**< Pitch of last correctly decoded frame */
Modified: trunk/speex/libspeex/sb_celp.c
===================================================================
--- trunk/speex/libspeex/sb_celp.c 2006-04-10 00:35:38 UTC (rev 11114)
+++ trunk/speex/libspeex/sb_celp.c 2006-04-10 14:30:54 UTC (rev 11115)
@@ -299,7 +299,10 @@
st->interp_lpc = speex_alloc(st->lpcSize*sizeof(spx_coef_t));
st->interp_qlpc = speex_alloc(st->lpcSize*sizeof(spx_coef_t));
st->pi_gain = speex_alloc((st->nbSubframes)*sizeof(spx_word32_t));
-
+ st->low_innov = speex_alloc((st->frame_size)*sizeof(spx_word32_t));
+ speex_encoder_ctl(st->st_low, SPEEX_SET_INNOVATION_SAVE, st->low_innov);
+ st->innov_save = NULL;
+
st->mem_sp = speex_alloc((st->lpcSize)*sizeof(spx_mem_t));
st->mem_sp2 = speex_alloc((st->lpcSize)*sizeof(spx_mem_t));
st->mem_sw = speex_alloc((st->lpcSize)*sizeof(spx_mem_t));
@@ -378,7 +381,6 @@
VARDECL(spx_word16_t *syn_resp);
VARDECL(spx_word32_t *low_pi_gain);
VARDECL(spx_sig_t *low_exc);
- VARDECL(spx_sig_t *low_innov);
const SpeexSBMode *mode;
int dtx;
spx_word16_t *in = vin;
@@ -414,10 +416,8 @@
ALLOC(low_pi_gain, st->nbSubframes, spx_word32_t);
ALLOC(low_exc, st->frame_size, spx_sig_t);
- ALLOC(low_innov, st->frame_size, spx_sig_t);
speex_encoder_ctl(st->st_low, SPEEX_GET_PI_GAIN, low_pi_gain);
speex_encoder_ctl(st->st_low, SPEEX_GET_EXC, low_exc);
- speex_encoder_ctl(st->st_low, SPEEX_GET_INNOV, low_innov);
speex_encoder_ctl(st->st_low, SPEEX_GET_LOW_MODE, &dtx);
@@ -595,7 +595,7 @@
for (sub=0;sub<st->nbSubframes;sub++)
{
- spx_sig_t *exc, *sp, *res, *target, *sw;
+ spx_sig_t *exc, *sp, *res, *target, *sw, *innov_save=NULL;
spx_word16_t filter_ratio;
int offset;
spx_word32_t rl, rh;
@@ -607,6 +607,13 @@
res=st->res+offset;
target=st->target+offset;
sw=st->sw+offset;
+ /* Pointer for saving innovation */
+ if (st->innov_save)
+ {
+ innov_save = st->innov_save+2*offset;
+ for (i=0;i<2*st->subframeSize;i++)
+ innov_save[i]=0;
+ }
/* LSP interpolation (quantized and unquantized) */
lsp_interpolate(st->old_lsp, st->lsp, st->interp_lsp, st->lpcSize, sub, st->nbSubframes);
@@ -647,7 +654,7 @@
if (!SUBMODE(innovation_quant)) {/* 1 for spectral folding excitation, 0 for stochastic */
float g;
spx_word16_t el;
- el = compute_rms(low_innov+offset, st->subframeSize);
+ el = compute_rms(st->low_innov+offset, st->subframeSize);
/* Gain to use if we want to use the low-band excitation for high-band */
g=eh/(.01+el);
@@ -660,7 +667,7 @@
ALLOC(tmp_sig, st->subframeSize, spx_sig_t);
for (i=0;i<st->lpcSize;i++)
mem[i]=st->mem_sp[i];
- iir_mem2(low_innov+offset, st->interp_qlpc, tmp_sig, st->subframeSize, st->lpcSize, mem);
+ iir_mem2(st->low_innov+offset, st->interp_qlpc, tmp_sig, st->subframeSize, st->lpcSize, mem);
g2 = compute_rms(sp, st->subframeSize)/(.01+compute_rms(tmp_sig, st->subframeSize));
/*fprintf (stderr, "gains: %f %f\n", g, g2);*/
g = g2;
@@ -764,6 +771,12 @@
for (i=0;i<st->subframeSize;i++)
exc[i] = ADD32(exc[i], innov[i]);
+ if (st->innov_save)
+ {
+ for (i=0;i<st->subframeSize;i++)
+ innov_save[2*i]=innov[i];
+ }
+
if (SUBMODE(double_codebook)) {
char *tmp_stack=stack;
VARDECL(spx_sig_t *innov2);
@@ -871,6 +884,11 @@
st->pi_gain = speex_alloc((st->nbSubframes)*sizeof(spx_word32_t));
st->mem_sp = speex_alloc((2*st->lpcSize)*sizeof(spx_mem_t));
+ st->low_innov = speex_alloc((st->frame_size)*sizeof(spx_word32_t));
+ speex_decoder_ctl(st->st_low, SPEEX_SET_INNOVATION_SAVE, st->low_innov);
+ st->innov_save = NULL;
+
+
st->lpc_enh_enabled=0;
st->seed = 1000;
@@ -1000,7 +1018,6 @@
char *stack;
VARDECL(spx_word32_t *low_pi_gain);
VARDECL(spx_sig_t *low_exc);
- VARDECL(spx_sig_t *low_innov);
VARDECL(spx_coef_t *awk1);
VARDECL(spx_coef_t *awk2);
VARDECL(spx_coef_t *awk3);
@@ -1093,10 +1110,8 @@
ALLOC(low_pi_gain, st->nbSubframes, spx_word32_t);
ALLOC(low_exc, st->frame_size, spx_sig_t);
- ALLOC(low_innov, st->frame_size, spx_sig_t);
speex_decoder_ctl(st->st_low, SPEEX_GET_PI_GAIN, low_pi_gain);
speex_decoder_ctl(st->st_low, SPEEX_GET_EXC, low_exc);
- speex_decoder_ctl(st->st_low, SPEEX_GET_INNOV, low_innov);
SUBMODE(lsp_unquant)(st->qlsp, st->lpcSize, bits);
@@ -1112,7 +1127,7 @@
for (sub=0;sub<st->nbSubframes;sub++)
{
- spx_sig_t *exc, *sp;
+ spx_sig_t *exc, *sp, *innov_save=NULL;
spx_word16_t filter_ratio;
spx_word16_t el=0;
int offset;
@@ -1121,6 +1136,13 @@
offset = st->subframeSize*sub;
sp=st->high+offset;
exc=st->exc+offset;
+ /* Pointer for saving innovation */
+ if (st->innov_save)
+ {
+ innov_save = st->innov_save+2*offset;
+ for (i=0;i<2*st->subframeSize;i++)
+ innov_save[i]=0;
+ }
/* LSP interpolation */
lsp_interpolate(st->old_qlsp, st->qlsp, st->interp_qlsp, st->lpcSize, sub, st->nbSubframes);
@@ -1181,7 +1203,7 @@
#if 0
for (i=0;i<st->subframeSize;i++)
- exc[i]=mode->folding_gain*g*low_innov[offset+i];
+ exc[i]=mode->folding_gain*g*st->low_innov[offset+i];
#else
{
float tmp=1;
@@ -1190,7 +1212,7 @@
el = compute_rms(low_innov+offset, st->subframeSize);*/
for (i=0;i<st->subframeSize;i++)
{
- float e=tmp*g*mode->folding_gain*low_innov[offset+i];
+ float e=tmp*g*mode->folding_gain*st->low_innov[offset+i];
tmp *= -1;
exc[i] = e;
/*float r = speex_rand(g*el,&seed);
@@ -1242,7 +1264,13 @@
}
}
-
+
+ if (st->innov_save)
+ {
+ for (i=0;i<st->subframeSize;i++)
+ innov_save[2*i]=exc[i];
+ }
+
for (i=0;i<st->subframeSize;i++)
sp[i]=exc[i];
if (st->lpc_enh_enabled)
@@ -1476,6 +1504,9 @@
case SPEEX_GET_RELATIVE_QUALITY:
(*(float*)ptr)=st->relative_quality;
break;
+ case SPEEX_SET_INNOVATION_SAVE:
+ st->innov_save = ptr;
+ break;
default:
speex_warning_int("Unknown nb_ctl request: ", request);
return -1;
@@ -1593,6 +1624,9 @@
case SPEEX_GET_DTX_STATUS:
speex_decoder_ctl(st->st_low, SPEEX_GET_DTX_STATUS, ptr);
break;
+ case SPEEX_SET_INNOVATION_SAVE:
+ st->innov_save = ptr;
+ break;
default:
speex_warning_int("Unknown nb_ctl request: ", request);
return -1;
Modified: trunk/speex/libspeex/sb_celp.h
===================================================================
--- trunk/speex/libspeex/sb_celp.h 2006-04-10 00:35:38 UTC (rev 11114)
+++ trunk/speex/libspeex/sb_celp.h 2006-04-10 14:30:54 UTC (rev 11115)
@@ -88,6 +88,8 @@
spx_mem_t *mem_sp2;
spx_mem_t *mem_sw; /**< Perceptual signal memory */
spx_word32_t *pi_gain;
+ spx_sig_t *innov_save; /** If non-NULL, innovation is copied here */
+ spx_sig_t *low_innov; /** Lower-band innovation is copied here magically */
float vbr_quality; /**< Quality setting for VBR encoding */
int vbr_enabled; /**< 1 for enabling VBR, 0 otherwise */
@@ -135,6 +137,9 @@
spx_mem_t *mem_sp;
spx_word32_t *pi_gain;
+ spx_sig_t *innov_save; /** If non-NULL, innovation is copied here */
+ spx_sig_t *low_innov; /** Lower-band innovation is copied here magically */
+
spx_int32_t seed;
int encode_submode;
More information about the commits
mailing list