Skip to content

Commit 2938bcf

Browse files
committed
Add support for CMake, Windows and compiling without Opus functions
1 parent 125d8a5 commit 2938bcf

File tree

7 files changed

+65
-15
lines changed

7 files changed

+65
-15
lines changed

CMakeLists.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
project(rnnoise)
3+
4+
option(RNNOISE_COMPILE_OPUS ON)
5+
6+
if(RNNOISE_COMPILE_OPUS)
7+
add_definitions(-DCOMPILE_OPUS)
8+
endif()
9+
10+
# Ignore CRT warnings on MSVC
11+
if(MSVC)
12+
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
13+
endif()
14+
15+
# Get source files
16+
file(GLOB SOURCES "src/*.c" "src/*.h" "include/*.h")
17+
18+
# Build rnnoise
19+
add_definitions(-DRNNOISE_BUILD)
20+
21+
# Compile the library
22+
add_library(rnnoise ${SOURCES})
23+
24+
# Build DLL if needed
25+
if(BUILD_SHARED_LIBS)
26+
if(WIN32)
27+
target_compile_definitions(rnnoise PRIVATE DLL_EXPORT)
28+
else()
29+
include(CheckCCompilerFlag)
30+
check_c_compiler_flag(-fvisibility=hidden COMPILER_HAS_HIDDEN_VISIBILITY)
31+
if(COMPILER_HAS_HIDDEN_VISIBILITY)
32+
set_target_properties(rnnoise PROPERTIES C_VISIBILITY_PRESET hidden)
33+
endif()
34+
endif()
35+
endif()
36+
37+
# Include dirs
38+
target_include_directories(rnnoise PUBLIC
39+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
40+
$<INSTALL_INTERFACE:include>
41+
PRIVATE src)

src/celt_lpc.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void celt_fir(
9696
int ord)
9797
{
9898
int i,j;
99-
opus_val16 rnum[ord];
99+
opus_val16 *rnum = malloc(sizeof(opus_val16) * ord);
100100
for(i=0;i<ord;i++)
101101
rnum[i] = num[ord-i-1];
102102
for (i=0;i<N-3;i+=4)
@@ -119,6 +119,7 @@ void celt_fir(
119119
sum = MAC16_16(sum,rnum[j],x[i+j-ord]);
120120
y[i] = ROUND16(sum, SIG_SHIFT);
121121
}
122+
free(rnum);
122123
}
123124

124125
void celt_iir(const opus_val32 *_x,
@@ -147,8 +148,8 @@ void celt_iir(const opus_val32 *_x,
147148
#else
148149
int i,j;
149150
celt_assert((ord&3)==0);
150-
opus_val16 rden[ord];
151-
opus_val16 y[N+ord];
151+
opus_val16 *rden = malloc(sizeof(opus_val16) * ord);
152+
opus_val16 *y = malloc(sizeof(opus_val16) * (N + ord));
152153
for(i=0;i<ord;i++)
153154
rden[i] = den[ord-i-1];
154155
for(i=0;i<ord;i++)
@@ -192,6 +193,8 @@ void celt_iir(const opus_val32 *_x,
192193
}
193194
for(i=0;i<ord;i++)
194195
mem[i] = _y[N-i-1];
196+
free(rden);
197+
free(y);
195198
#endif
196199
}
197200

@@ -208,7 +211,7 @@ int _celt_autocorr(
208211
int fastN=n-lag;
209212
int shift;
210213
const opus_val16 *xptr;
211-
opus_val16 xx[n];
214+
opus_val16 *xx = malloc(sizeof(opus_val16) * n);
212215
celt_assert(n>0);
213216
celt_assert(overlap>=0);
214217
if (overlap == 0)
@@ -274,6 +277,6 @@ int _celt_autocorr(
274277
shift += shift2;
275278
}
276279
#endif
277-
280+
free(xx);
278281
return shift;
279282
}

src/denoise.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include "config.h"
3030
#endif
3131

32+
#define _USE_MATH_DEFINES
33+
3234
#include <stdlib.h>
3335
#include <string.h>
3436
#include <stdio.h>

src/kiss_fft.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ void opus_fft_free(const kiss_fft_state *cfg, int arch)
515515

516516
#endif /* CUSTOM_MODES */
517517

518+
#ifdef COMPILE_OPUS
518519
void opus_fft_impl(const kiss_fft_state *st,kiss_fft_cpx *fout)
519520
{
520521
int m2, m;
@@ -599,3 +600,4 @@ void opus_ifft_c(const kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx *
599600
for (i=0;i<st->nfft;i++)
600601
fout[i].i = -fout[i].i;
601602
}
603+
#endif

src/pitch.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,9 @@ void pitch_search(const opus_val16 *x_lp, opus_val16 *y,
297297
celt_assert(max_pitch>0);
298298
lag = len+max_pitch;
299299

300-
opus_val16 x_lp4[len>>2];
301-
opus_val16 y_lp4[lag>>2];
302-
opus_val32 xcorr[max_pitch>>1];
300+
opus_val16 *x_lp4 = malloc(sizeof(opus_val16) * (len >> 2));
301+
opus_val16 *y_lp4 = malloc(sizeof(opus_val16) * (lag >> 2));
302+
opus_val32 *xcorr = malloc(sizeof(opus_val32) * (max_pitch >> 1));
303303

304304
/* Downsample by 2 again */
305305
for (j=0;j<len>>2;j++)
@@ -382,6 +382,10 @@ void pitch_search(const opus_val16 *x_lp, opus_val16 *y,
382382
offset = 0;
383383
}
384384
*pitch = 2*best_pitch[0]-offset;
385+
386+
free(x_lp4);
387+
free(y_lp4);
388+
free(xcorr);
385389
}
386390

387391
#ifdef FIXED_POINT
@@ -443,7 +447,7 @@ opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod,
443447
*T0_=maxperiod-1;
444448

445449
T = T0 = *T0_;
446-
opus_val32 yy_lookup[maxperiod+1];
450+
opus_val32 *yy_lookup = malloc(sizeof(opus_val32) * (maxperiod + 1));
447451
dual_inner_prod(x, x, x-T0, N, &xx, &xy);
448452
yy_lookup[0] = xx;
449453
yy=xx;
@@ -522,5 +526,7 @@ opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod,
522526

523527
if (*T0_<minperiod0)
524528
*T0_=minperiod0;
529+
530+
free(yy_lookup);
525531
return pg;
526532
}

src/rnn.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static OPUS_INLINE float relu(float x)
7676
return x < 0 ? 0 : x;
7777
}
7878

79-
void compute_dense(const DenseLayer *layer, float *output, const float *input)
79+
static void compute_dense(const DenseLayer *layer, float *output, const float *input)
8080
{
8181
int i, j;
8282
int N, M;
@@ -106,7 +106,7 @@ void compute_dense(const DenseLayer *layer, float *output, const float *input)
106106
}
107107
}
108108

109-
void compute_gru(const GRULayer *gru, float *state, const float *input)
109+
static void compute_gru(const GRULayer *gru, float *state, const float *input)
110110
{
111111
int i, j;
112112
int N, M;

src/rnn.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ typedef struct {
6060

6161
typedef struct RNNState RNNState;
6262

63-
void compute_dense(const DenseLayer *layer, float *output, const float *input);
64-
65-
void compute_gru(const GRULayer *gru, float *state, const float *input);
66-
6763
void compute_rnn(RNNState *rnn, float *gains, float *vad, const float *input);
6864

6965
#endif /* _MLP_H_ */

0 commit comments

Comments
 (0)