diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..eaa0200a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,41 @@ +cmake_minimum_required(VERSION 3.1) +project(rnnoise) + +option(RNNOISE_COMPILE_OPUS ON) + +if(RNNOISE_COMPILE_OPUS) + add_definitions(-DCOMPILE_OPUS) +endif() + +# Ignore CRT warnings on MSVC +if(MSVC) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) +endif() + +# Get source files +file(GLOB SOURCES "src/*.c" "src/*.h" "include/*.h") + +# Build rnnoise +add_definitions(-DRNNOISE_BUILD) + +# Compile the library +add_library(rnnoise ${SOURCES}) + +# Build DLL if needed +if(BUILD_SHARED_LIBS) + if(WIN32) + target_compile_definitions(rnnoise PRIVATE DLL_EXPORT) + else() + include(CheckCCompilerFlag) + check_c_compiler_flag(-fvisibility=hidden COMPILER_HAS_HIDDEN_VISIBILITY) + if(COMPILER_HAS_HIDDEN_VISIBILITY) + set_target_properties(rnnoise PROPERTIES C_VISIBILITY_PRESET hidden) + endif() + endif() +endif() + +# Include dirs +target_include_directories(rnnoise PUBLIC + $ + $ + PRIVATE src) \ No newline at end of file diff --git a/src/celt_lpc.c b/src/celt_lpc.c index 521351e9..f2ede0bc 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]; + opus_val16 *rnum = malloc(sizeof(opus_val16) * ord); for(i=0;i0); celt_assert(overlap>=0); if (overlap == 0) @@ -274,6 +277,6 @@ int _celt_autocorr( shift += shift2; } #endif - + free(xx); return shift; } diff --git a/src/denoise.c b/src/denoise.c index d1c21dc0..53bb8030 100644 --- a/src/denoise.c +++ b/src/denoise.c @@ -29,6 +29,8 @@ #include "config.h" #endif +#define _USE_MATH_DEFINES + #include #include #include diff --git a/src/kiss_fft.c b/src/kiss_fft.c index d6b9f26d..46e4fa07 100644 --- a/src/kiss_fft.c +++ b/src/kiss_fft.c @@ -515,6 +515,7 @@ void opus_fft_free(const kiss_fft_state *cfg, int arch) #endif /* CUSTOM_MODES */ +#ifdef COMPILE_OPUS void opus_fft_impl(const kiss_fft_state *st,kiss_fft_cpx *fout) { int m2, m; @@ -599,3 +600,4 @@ void opus_ifft_c(const kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx * for (i=0;infft;i++) fout[i].i = -fout[i].i; } +#endif \ No newline at end of file diff --git a/src/pitch.c b/src/pitch.c index bd101a6c..fc832d1f 100644 --- a/src/pitch.c +++ b/src/pitch.c @@ -297,9 +297,9 @@ void 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]; + opus_val16 *x_lp4 = malloc(sizeof(opus_val16) * (len >> 2)); + opus_val16 *y_lp4 = malloc(sizeof(opus_val16) * (lag >> 2)); + opus_val32 *xcorr = malloc(sizeof(opus_val32) * (max_pitch >> 1)); /* Downsample by 2 again */ for (j=0;j>2;j++) @@ -382,6 +382,10 @@ void pitch_search(const opus_val16 *x_lp, opus_val16 *y, offset = 0; } *pitch = 2*best_pitch[0]-offset; + + free(x_lp4); + free(y_lp4); + free(xcorr); } #ifdef FIXED_POINT @@ -443,7 +447,7 @@ opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod, *T0_=maxperiod-1; T = T0 = *T0_; - opus_val32 yy_lookup[maxperiod+1]; + opus_val32 *yy_lookup = malloc(sizeof(opus_val32) * (maxperiod + 1)); dual_inner_prod(x, x, x-T0, N, &xx, &xy); yy_lookup[0] = xx; yy=xx; @@ -522,5 +526,7 @@ opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod, if (*T0_