ref: 8d4ac155e64c8cc564314a0e2714b9ad89ea8711
parent: 9b9e98625c89b943c402eacf480f6444905f790a
author: Jean-Marc Valin <[email protected]>
date: Fri Feb 29 12:24:02 EST 2008
Saved on stack usage by changing the order of the allocation
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -261,8 +261,6 @@
C = st->mode->nbChannels;
ALLOC(in, (B+1)*C*N, celt_sig_t);
ALLOC(freq, B*C*N, celt_sig_t); /**< Interleaved signal MDCTs */
- ALLOC(X, B*C*N, celt_norm_t); /**< Interleaved normalised MDCTs */
- ALLOC(P, B*C*N, celt_norm_t); /**< Interleaved normalised pitch MDCTs*/
ALLOC(bandE,st->mode->nbEBands*C, celt_ener_t);
ALLOC(gains,st->mode->nbPBands, celt_pgain_t);
@@ -309,6 +307,10 @@
}
find_spectral_pitch(st->fft, &st->psy, in, st->out_mem, MAX_PERIOD, (B+1)*N, C, &pitch_index);
+ /* Deferred allocation after find_spectral_pitch() to reduce the peak memory usage */
+ ALLOC(X, B*C*N, celt_norm_t); /**< Interleaved normalised MDCTs */
+ ALLOC(P, B*C*N, celt_norm_t); /**< Interleaved normalised pitch MDCTs*/
+
/*printf ("%f %f\n", curr_power, pitch_power);*/
/*int j;
for (j=0;j<B*N;j++)
--- a/libcelt/pitch.c
+++ b/libcelt/pitch.c
@@ -56,7 +56,6 @@
int n2 = lag/2;
ALLOC(xx, lag*C, celt_word32_t);
ALLOC(X, lag*C, celt_word32_t);
- ALLOC(Y, lag*C, celt_word32_t);
ALLOC(curve, n2*C, celt_mask_t);
for (i=0;i<C*lag;i++)
@@ -66,12 +65,16 @@
xx[c*lag+i] = x[C*i+c];
kiss_fftr(fft, xx, X);
+
+ compute_masking(decay, X, curve, lag*C);
+
+ /* Deferred allocation to reduce peak stack usage */
+ ALLOC(Y, lag*C, celt_word32_t);
for (c=0;c<C;c++)
for (i=0;i<lag;i++)
xx[c*lag+i] = y[C*i+c];
kiss_fftr(fft, xx, Y);
- compute_masking(decay, X, curve, lag*C);
for (i=1;i<C*n2;i++)
{