Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/rnnoise.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavide Beatrici <git@davidebeatrici.dev>2021-02-16 16:05:36 +0300
committerDavide Beatrici <git@davidebeatrici.dev>2021-02-16 16:05:36 +0300
commita9afcccb3c4f01e6e76a1ef67ccb58b7799856bf (patch)
treec28fcca289f6086f51bf2899102bc41eaa50392b
parent1cbdbcf1283499bbb2230a6b0f126eb9b236defd (diff)
Add USE_MALLOC define, to toggle the use of malloc() and free() instead of VLAHEADmaster
This is required for MSVC.
-rw-r--r--src/celt_lpc.c25
-rw-r--r--src/pitch.c30
2 files changed, 55 insertions, 0 deletions
diff --git a/src/celt_lpc.c b/src/celt_lpc.c
index 521351e..ae74763 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;i<ord;i++)
rnum[i] = num[ord-i-1];
for (i=0;i<N-3;i+=4)
@@ -119,6 +123,10 @@ void celt_fir(
sum = MAC16_16(sum,rnum[j],x[i+j-ord]);
y[i] = ROUND16(sum, SIG_SHIFT);
}
+
+#ifdef USE_MALLOC
+ free(rnum);
+#endif
}
void celt_iir(const opus_val32 *_x,
@@ -147,8 +155,13 @@ void celt_iir(const opus_val32 *_x,
#else
int i,j;
celt_assert((ord&3)==0);
+#ifdef USE_MALLOC
+ opus_val16 *rden = malloc(sizeof(*rden) * ord);
+ opus_val16 *y = malloc(sizeof(*y) * (N+ord));
+#else
opus_val16 rden[ord];
opus_val16 y[N+ord];
+#endif
for(i=0;i<ord;i++)
rden[i] = den[ord-i-1];
for(i=0;i<ord;i++)
@@ -192,7 +205,11 @@ void celt_iir(const opus_val32 *_x,
}
for(i=0;i<ord;i++)
mem[i] = _y[N-i-1];
+#ifdef USE_MALLOC
+ free(rden);
+ free(y) ;
#endif
+#endif // SMALL_FOOTPRINT
}
int _celt_autocorr(
@@ -208,7 +225,11 @@ int _celt_autocorr(
int fastN=n-lag;
int shift;
const opus_val16 *xptr;
+#ifdef USE_MALLOC
+ opus_val16 *xx = malloc(sizeof(*xx) * n);
+#else
opus_val16 xx[n];
+#endif
celt_assert(n>0);
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 bd101a6..9b0271b 100644
--- a/src/pitch.c
+++ b/src/pitch.c
@@ -43,6 +43,10 @@
#include "celt_lpc.h"
#include "math.h"
+#ifdef USE_MALLOC
+#include <stdlib.h>
+#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<len>>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_<minperiod0)
*T0_=minperiod0;
+
+#ifdef USE_MALLOC
+ free(xcorr);
+ free(yy_lookup);
+#endif
+
return pg;
}