diff --git a/CMakeLists.txt b/CMakeLists.txt index fa5be32..0e5af83 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,11 @@ set( # Build rnnoise add_definitions(-DRNNOISE_BUILD) +if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + # MSVC requires this to expose definitions like M_PI + add_definitions(-D_USE_MATH_DEFINES) +endif() + # Compile the library add_library(rnnoise ${SOURCES}) diff --git a/src/arch.h b/src/arch.h index 52de623..cfa7df6 100644 --- a/src/arch.h +++ b/src/arch.h @@ -258,4 +258,15 @@ static OPUS_INLINE int celt_isnan(float x) #endif #endif +#if __STDC_VERSION__ < 199901L || (__STDC_VERSION__ > 201000L && __STDC_NO_VLA__ == 1) + #define NO_VLA +#endif + +#ifdef NO_VLA + #include + #define stackalloc(type, id, len) type *id = alloca(len) +#else + #define stackalloc(type, id, len) type id[len] +#endif + #endif /* ARCH_H */ diff --git a/src/celt_lpc.c b/src/celt_lpc.c index e922783..08bd713 100644 --- a/src/celt_lpc.c +++ b/src/celt_lpc.c @@ -96,7 +96,7 @@ void celt_fir( int ord) { int i,j; - opus_val16 rnum[ord]; + stackalloc(opus_val16, rnum, ord); for(i=0;i0); celt_assert(overlap>=0); if (overlap == 0) diff --git a/src/pitch.c b/src/pitch.c index f4a2651..fd29e3b 100644 --- a/src/pitch.c +++ b/src/pitch.c @@ -297,9 +297,9 @@ void tn_pitch_search(const opus_val16 *x_lp, opus_val16 *y, celt_assert(max_pitch>0); lag = len+max_pitch; - opus_val16 x_lp4[len>>2]; - opus_val16 y_lp4[lag>>2]; - opus_val32 xcorr[max_pitch>>1]; + stackalloc(opus_val16, x_lp4, len>>2); + stackalloc(opus_val16, y_lp4, lag>>2); + stackalloc(opus_val32, xcorr, max_pitch>>1); /* Downsample by 2 again */ for (j=0;j>2;j++) @@ -443,7 +443,7 @@ opus_val16 tn_remove_doubling(opus_val16 *x, int maxperiod, int minperiod, *T0_=maxperiod-1; T = T0 = *T0_; - opus_val32 yy_lookup[maxperiod+1]; + stackalloc(opus_val32, yy_lookup, maxperiod+1); dual_inner_prod(x, x, x-T0, N, &xx, &xy); yy_lookup[0] = xx; yy=xx;