Skip to content

Commit

Permalink
Reduced unnecessary buffers (reduced memory usage)
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.xiph.org/trunk/speex@8997 0101bb08-14d6-0310-b084-bc0e0c8e3800
  • Loading branch information
jmvalin committed Mar 1, 2005
1 parent 82f5eb2 commit cedfccc
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 48 deletions.
1 change: 0 additions & 1 deletion libspeex/modes.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ static const SpeexNBMode nb_mode = {
160, /*frameSize*/
40, /*subframeSize*/
10, /*lpcSize*/
640, /*bufSize*/
17, /*pitchStart*/
144, /*pitchEnd*/
#ifdef FIXED_POINT
Expand Down
1 change: 0 additions & 1 deletion libspeex/modes.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ typedef struct SpeexNBMode {
int frameSize; /**< Size of frames used for encoding */
int subframeSize; /**< Size of sub-frames used for encoding */
int lpcSize; /**< Order of LPC filter */
int bufSize; /**< Size of signal buffer to use in encoder */
int pitchStart; /**< Smallest pitch value allowed */
int pitchEnd; /**< Largest pitch value allowed */

Expand Down
84 changes: 42 additions & 42 deletions libspeex/nb_celp.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ void *nb_encoder_init(const SpeexMode *m)
st->nbSubframes=mode->frameSize/mode->subframeSize;
st->subframeSize=mode->subframeSize;
st->lpcSize = mode->lpcSize;
st->bufSize = mode->bufSize;
st->gamma1=mode->gamma1;
st->gamma2=mode->gamma2;
st->min_pitch=mode->pitchStart;
Expand All @@ -128,16 +127,16 @@ void *nb_encoder_init(const SpeexMode *m)
#endif

/* Allocating input buffer */
st->inBuf = PUSH(st->stack, st->bufSize, spx_sig_t);
st->frame = st->inBuf + st->bufSize - st->windowSize;
st->inBuf = PUSH(st->stack, st->windowSize, spx_sig_t);
st->frame = st->inBuf;
/* Allocating excitation buffer */
st->excBuf = PUSH(st->stack, st->bufSize, spx_sig_t);
st->exc = st->excBuf + st->bufSize - st->windowSize;
st->swBuf = PUSH(st->stack, st->bufSize, spx_sig_t);
st->sw = st->swBuf + st->bufSize - st->windowSize;
st->excBuf = PUSH(st->stack, mode->frameSize+mode->pitchEnd+1, spx_sig_t);
st->exc = st->excBuf + mode->pitchEnd + 1;
st->swBuf = PUSH(st->stack, mode->frameSize+mode->pitchEnd+1, spx_sig_t);
st->sw = st->swBuf + mode->pitchEnd + 1;

st->exc2Buf = PUSH(st->stack, st->bufSize, spx_sig_t);
st->exc2 = st->exc2Buf + st->bufSize - st->windowSize;
/*st->exc2Buf = PUSH(st->stack, st->bufSize, spx_sig_t);
st->exc2 = st->exc2Buf + st->bufSize - st->windowSize;*/

st->innov = PUSH(st->stack, st->frameSize, spx_sig_t);

Expand All @@ -159,8 +158,6 @@ void *nb_encoder_init(const SpeexMode *m)

st->autocorr = PUSH(st->stack, st->lpcSize+1, spx_word16_t);

st->buf2 = PUSH(st->stack, st->windowSize, spx_sig_t);

st->lpc = PUSH(st->stack, st->lpcSize+1, spx_coef_t);
st->interp_lpc = PUSH(st->stack, st->lpcSize+1, spx_coef_t);
st->interp_qlpc = PUSH(st->stack, st->lpcSize+1, spx_coef_t);
Expand Down Expand Up @@ -241,14 +238,15 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
stack=st->stack;

/* Copy new data in input buffer */
speex_move(st->inBuf, st->inBuf+st->frameSize, (st->bufSize-st->frameSize)*sizeof(spx_sig_t));
speex_move(st->inBuf, st->inBuf+st->frameSize, (st->windowSize-st->frameSize)*sizeof(spx_sig_t));
for (i=0;i<st->frameSize;i++)
st->inBuf[st->bufSize-st->frameSize+i] = SHL((int)in[i], SIG_SHIFT);
st->inBuf[st->windowSize-st->frameSize+i] = SHL((int)in[i], SIG_SHIFT);

/* Move signals 1 frame towards the past */
speex_move(st->exc2Buf, st->exc2Buf+st->frameSize, (st->bufSize-st->frameSize)*sizeof(spx_sig_t));
speex_move(st->excBuf, st->excBuf+st->frameSize, (st->bufSize-st->frameSize)*sizeof(spx_sig_t));
speex_move(st->swBuf, st->swBuf+st->frameSize, (st->bufSize-st->frameSize)*sizeof(spx_sig_t));
/*speex_move(st->exc2Buf, st->exc2Buf+st->frameSize, (st->bufSize-st->frameSize)*sizeof(spx_sig_t));*/
//mode->frameSize+mode->pitchEnd+1;
speex_move(st->excBuf, st->excBuf+st->frameSize, (st->max_pitch+1)*sizeof(spx_sig_t));
speex_move(st->swBuf, st->swBuf+st->frameSize, (st->max_pitch+1)*sizeof(spx_sig_t));


{
Expand Down Expand Up @@ -510,7 +508,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
if (st->submodes[st->submodeID] == NULL)
{
for (i=0;i<st->frameSize;i++)
st->exc[i]=st->exc2[i]=st->sw[i]=VERY_SMALL;
st->exc[i]/*=st->exc2[i]*/=st->sw[i]=VERY_SMALL;

for (i=0;i<st->lpcSize;i++)
st->mem_sw[i]=0;
Expand Down Expand Up @@ -636,7 +634,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
for (sub=0;sub<st->nbSubframes;sub++)
{
int offset;
spx_sig_t *sp, *sw, *exc, *exc2;
spx_sig_t *sp, *sw, *exc/*, *exc2*/;
int pitch;
int response_bound = st->subframeSize;
#ifdef EPIC_48K
Expand All @@ -658,7 +656,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
/* Weighted signal */
sw=st->sw+offset;

exc2=st->exc2+offset;
/*exc2=st->exc2+offset;*/


/* LSP interpolation (quantized and unquantized) */
Expand Down Expand Up @@ -713,8 +711,8 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
/* Reset excitation */
for (i=0;i<st->subframeSize;i++)
exc[i]=VERY_SMALL;
for (i=0;i<st->subframeSize;i++)
exc2[i]=VERY_SMALL;
/*for (i=0;i<st->subframeSize;i++)
exc2[i]=VERY_SMALL;*/

/* Compute zero response of A(z/g1) / ( A(z/g2) * A(z) ) */
for (i=0;i<st->lpcSize;i++)
Expand Down Expand Up @@ -747,7 +745,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
target[i]=sw[i]-res[i];

for (i=0;i<st->subframeSize;i++)
exc[i]=exc2[i]=0;
exc[i]=/*exc2[i]=*/0;

/* If we have a long-term predictor (otherwise, something's wrong) */
if (SUBMODE(ltp_quant))
Expand Down Expand Up @@ -785,15 +783,15 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
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, stack,
exc2, syn_resp, st->complexity, ol_pitch_id);
exc, syn_resp, st->complexity, ol_pitch_id);
} else {
#endif

/* Perform pitch search */
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, stack,
exc2, syn_resp, st->complexity, 0);
exc, syn_resp, st->complexity, 0);
#ifdef EPIC_48K
}
#endif
Expand Down Expand Up @@ -909,8 +907,8 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
if (st->complexity!=0)
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];
/*for (i=0;i<st->subframeSize;i++)
exc2[i]=exc[i];*/
}

/* Store the LSPs for interpolation in the next frame */
Expand Down Expand Up @@ -973,11 +971,9 @@ void *nb_decoder_init(const SpeexMode *m)
st->first=1;
/* Codec parameters, should eventually have several "modes"*/
st->frameSize = mode->frameSize;
st->windowSize = st->frameSize*3/2;
st->nbSubframes=mode->frameSize/mode->subframeSize;
st->subframeSize=mode->subframeSize;
st->lpcSize = mode->lpcSize;
st->bufSize = mode->bufSize;
st->min_pitch=mode->pitchStart;
st->max_pitch=mode->pitchEnd;

Expand All @@ -987,13 +983,13 @@ void *nb_decoder_init(const SpeexMode *m)
st->lpc_enh_enabled=0;


st->inBuf = PUSH(st->stack, st->bufSize, spx_sig_t);
st->frame = st->inBuf + st->bufSize - st->windowSize;
st->excBuf = PUSH(st->stack, st->bufSize, spx_sig_t);
st->exc = st->excBuf + st->bufSize - st->windowSize;
for (i=0;i<st->bufSize;i++)
st->inBuf = PUSH(st->stack, st->frameSize, spx_sig_t);
st->frame = st->inBuf;
st->excBuf = PUSH(st->stack, st->frameSize + st->max_pitch + 1, spx_sig_t);
st->exc = st->excBuf + st->max_pitch + 1;
for (i=0;i<st->frameSize;i++)
st->inBuf[i]=0;
for (i=0;i<st->bufSize;i++)
for (i=0;i<st->frameSize + st->max_pitch + 1;i++)
st->excBuf[i]=0;
st->innov = PUSH(st->stack, st->frameSize, spx_sig_t);

Expand Down Expand Up @@ -1057,8 +1053,8 @@ static void nb_decode_lost(DecState *st, spx_word16_t *out, char *stack)
pitch_gain *= fact;

/* Shift all buffers by one frame */
speex_move(st->inBuf, st->inBuf+st->frameSize, (st->bufSize-st->frameSize)*sizeof(spx_sig_t));
speex_move(st->excBuf, st->excBuf+st->frameSize, (st->bufSize-st->frameSize)*sizeof(spx_sig_t));
/*speex_move(st->inBuf, st->inBuf+st->frameSize, (st->bufSize-st->frameSize)*sizeof(spx_sig_t));*/
speex_move(st->excBuf, st->excBuf+st->frameSize, (st->max_pitch + 1)*sizeof(spx_sig_t));

awk1=PUSH(stack, (st->lpcSize+1), spx_coef_t);
awk2=PUSH(stack, (st->lpcSize+1), spx_coef_t);
Expand Down Expand Up @@ -1270,8 +1266,8 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
}

/* Shift all buffers by one frame */
speex_move(st->inBuf, st->inBuf+st->frameSize, (st->bufSize-st->frameSize)*sizeof(spx_sig_t));
speex_move(st->excBuf, st->excBuf+st->frameSize, (st->bufSize-st->frameSize)*sizeof(spx_sig_t));
/*speex_move(st->inBuf, st->inBuf+st->frameSize, (st->bufSize-st->frameSize)*sizeof(spx_sig_t));*/
speex_move(st->excBuf, st->excBuf+st->frameSize, (st->max_pitch + 1)*sizeof(spx_sig_t));

/* If null mode (no transmission), just set a couple things to zero*/
if (st->submodes[st->submodeID] == NULL)
Expand Down Expand Up @@ -1794,8 +1790,10 @@ int nb_encoder_ctl(void *state, int request, void *ptr)
st->lsp[i]=(M_PI*((float)(i+1)))/(st->lpcSize+1);
for (i=0;i<st->lpcSize;i++)
st->mem_sw[i]=st->mem_sw_whole[i]=st->mem_sp[i]=st->mem_exc[i]=0;
for (i=0;i<st->bufSize;i++)
st->excBuf[i]=st->swBuf[i]=st->inBuf[i]=st->exc2Buf[i]=0;
for (i=0;i<st->frameSize+st->max_pitch+1;i++)
st->excBuf[i]=st->swBuf[i]=0;
for (i=0;i<st->windowSize;i++)
st->inBuf[i]=0;
}
break;
case SPEEX_SET_SUBMODE_ENCODING:
Expand Down Expand Up @@ -1897,8 +1895,10 @@ int nb_decoder_ctl(void *state, int request, void *ptr)
int i;
for (i=0;i<2*st->lpcSize;i++)
st->mem_sp[i]=0;
for (i=0;i<st->bufSize;i++)
st->excBuf[i]=st->inBuf[i]=0;
for (i=0;i<st->frameSize + st->max_pitch + 1;i++)
st->excBuf[i]=0;
for (i=0;i<st->frameSize;i++)
st->inBuf[i] = 0;
}
break;
case SPEEX_SET_SUBMODE_ENCODING:
Expand Down
4 changes: 0 additions & 4 deletions libspeex/nb_celp.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ typedef struct EncState {
int nbSubframes; /**< Number of sub-frames */
int windowSize; /**< Analysis (LPC) window length */
int lpcSize; /**< LPC order */
int bufSize; /**< Buffer size */
int min_pitch; /**< Minimum pitch value allowed */
int max_pitch; /**< Maximum pitch value allowed */

Expand Down Expand Up @@ -80,7 +79,6 @@ typedef struct EncState {
spx_sig_t *sw; /**< Start of weighted signal frame */
spx_sig_t *innov; /**< Innovation for the frame */
spx_word16_t *window; /**< Temporary (Hanning) window */
spx_sig_t *buf2; /**< 2nd temporary buffer */
spx_word16_t *autocorr; /**< auto-correlation */
spx_word16_t *lagWindow; /**< Window applied to auto-correlation */
spx_coef_t *lpc; /**< LPCs for current frame */
Expand Down Expand Up @@ -128,9 +126,7 @@ typedef struct DecState {
int frameSize; /**< Size of frames */
int subframeSize; /**< Size of sub-frames */
int nbSubframes; /**< Number of sub-frames */
int windowSize; /**< Analysis (LPC) window length */
int lpcSize; /**< LPC order */
int bufSize; /**< Buffer size */
int min_pitch; /**< Minimum pitch value allowed */
int max_pitch; /**< Maximum pitch value allowed */
int sampling_rate;
Expand Down

0 comments on commit cedfccc

Please sign in to comment.