From dffc10ee4bf25e699849f99d33616b456b617a9e Mon Sep 17 00:00:00 2001 From: Davide Beatrici Date: Tue, 16 Feb 2021 14:05:36 +0100 Subject: [PATCH] Add USE_MALLOC define, to toggle the use of malloc() and free() instead of VLA This is required for MSVC. --- src/celt_lpc.c | 25 +++++++++++++++++++++++++ src/pitch.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/src/celt_lpc.c b/src/celt_lpc.c index 521351e9..ae747637 100644 --- a/src/celt_lpc.c +++ b/src/celt_lpc.c @@ -96,7 +96,11 @@ void celt_fir( int ord) { int i,j; +#ifdef USE_MALLOC + opus_val16 *rnum = malloc(sizeof(*rnum) * ord); +#else opus_val16 rnum[ord]; +#endif for(i=0;i0); celt_assert(overlap>=0); if (overlap == 0) @@ -275,5 +296,9 @@ int _celt_autocorr( } #endif +#ifdef USE_MALLOC + free(xx); +#endif + return shift; } diff --git a/src/pitch.c b/src/pitch.c index bd101a6c..9b0271be 100644 --- a/src/pitch.c +++ b/src/pitch.c @@ -43,6 +43,10 @@ #include "celt_lpc.h" #include "math.h" +#ifdef USE_MALLOC +#include +#endif + static void find_best_pitch(opus_val32 *xcorr, opus_val16 *y, int len, int max_pitch, int *best_pitch #ifdef FIXED_POINT @@ -297,9 +301,15 @@ void pitch_search(const opus_val16 *x_lp, opus_val16 *y, celt_assert(max_pitch>0); lag = len+max_pitch; +#ifdef USE_MALLOC + opus_val16 *x_lp4 = malloc(sizeof(*x_lp4) * len>>2); + opus_val16 *y_lp4 = malloc(sizeof(*y_lp4) * lag>>2); + opus_val32 *xcorr = malloc(sizeof(*xcorr) * max_pitch>>1); +#else opus_val16 x_lp4[len>>2]; opus_val16 y_lp4[lag>>2]; opus_val32 xcorr[max_pitch>>1]; +#endif /* Downsample by 2 again */ for (j=0;j>2;j++) @@ -382,6 +392,12 @@ void pitch_search(const opus_val16 *x_lp, opus_val16 *y, offset = 0; } *pitch = 2*best_pitch[0]-offset; + +#ifdef USE_MALLOC + free(x_lp4); + free(y_lp4); + free(xcorr); +#endif } #ifdef FIXED_POINT @@ -427,7 +443,11 @@ opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod, opus_val16 g, g0; opus_val16 pg; opus_val32 xy,xx,yy,xy2; +#ifdef USE_MALLOC + opus_val32 *xcorr = malloc(sizeof(*xcorr) * 3); +#else opus_val32 xcorr[3]; +#endif opus_val32 best_xy, best_yy; int offset; int minperiod0; @@ -443,7 +463,11 @@ opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod, *T0_=maxperiod-1; T = T0 = *T0_; +#ifdef USE_MALLOC + opus_val16 *yy_lookup = malloc(sizeof(*yy_lookup) * (maxperiod+1)); +#else opus_val32 yy_lookup[maxperiod+1]; +#endif dual_inner_prod(x, x, x-T0, N, &xx, &xy); yy_lookup[0] = xx; yy=xx; @@ -522,5 +546,11 @@ opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod, if (*T0_