Skip to content

Commit 03945c5

Browse files
committed
Fix issues with C++ and add an option to compile without opus
1 parent eb45832 commit 03945c5

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

CMakeLists.txt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,36 @@
11
cmake_minimum_required(VERSION 3.1)
22
project(rnnoise)
33

4+
option(RNNOISE_COMPILE_OPUS ON)
5+
6+
if(RNNOISE_COMPILE_OPUS)
7+
add_definitions(-DCOMPILE_OPUS)
8+
endif()
9+
10+
# Ignore CRT warnings
11+
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
12+
413
# Get source files
514
file(GLOB SOURCES "src/*.c" "src/*.h" "include/*.h")
615

16+
# Build rnnoise
17+
add_definitions(-DRNNOISE_BUILD)
18+
719
# Compile the library
8-
add_library(rnnoise STATIC ${SOURCES})
20+
add_library(rnnoise ${SOURCES})
21+
22+
# Build DLL if needed
23+
if(BUILD_SHARED_LIBS)
24+
if(WIN32)
25+
target_compile_definitions(rnnoise PRIVATE DLL_EXPORT)
26+
else()
27+
include(CheckCCompilerFlag)
28+
check_c_compiler_flag(-fvisibility=hidden COMPILER_HAS_HIDDEN_VISIBILITY)
29+
if(COMPILER_HAS_HIDDEN_VISIBILITY)
30+
set_target_properties(rnnoise PROPERTIES C_VISIBILITY_PRESET hidden)
31+
endif()
32+
endif()
33+
endif()
934

1035
# Include dirs
1136
target_include_directories(rnnoise PUBLIC

include/rnnoise.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
#include <stdio.h>
3232

33-
3433
#ifndef RNNOISE_EXPORT
3534
# if defined(WIN32)
3635
# if defined(RNNOISE_BUILD) && defined(DLL_EXPORT)
@@ -45,6 +44,10 @@
4544
# endif
4645
#endif
4746

47+
#ifdef __cplusplus
48+
extern "C" {
49+
#endif
50+
4851
typedef struct DenoiseState DenoiseState;
4952
typedef struct RNNModel RNNModel;
5053

@@ -62,4 +65,7 @@ RNNOISE_EXPORT RNNModel *rnnoise_model_from_file(FILE *f);
6265

6366
RNNOISE_EXPORT void rnnoise_model_free(RNNModel *model);
6467

68+
#ifdef __cplusplus
69+
}
70+
#endif
6571
#endif

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/rnn.c

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

79+
#ifdef COMPILE_OPUS
7980
void compute_dense(const DenseLayer *layer, float *output, const float *input)
8081
{
8182
int i, j;
@@ -154,6 +155,7 @@ void compute_gru(const GRULayer *gru, float *state, const float *input)
154155
for (i=0;i<N;i++)
155156
state[i] = h[i];
156157
}
158+
#endif
157159

158160
#define INPUT_SIZE 42
159161

0 commit comments

Comments
 (0)