Skip to content

Commit ed6283d

Browse files
committed
Port DSP code to C++ to address performance penalty (#1469)
1 parent 30de0fc commit ed6283d

13 files changed

+618
-382
lines changed

CMakeLists.txt

+11-11
Original file line numberDiff line numberDiff line change
@@ -439,23 +439,23 @@ if ( enable-profiling )
439439
set ( WITH_PROFILING 1 )
440440
if ( CMAKE_C_COMPILER_ID STREQUAL "Clang" )
441441
set ( OPT_FLAGS "-Rpass=loop-vectorize" ) # -Rpass-analysis=loop-vectorize" )
442+
find_program( CLANG_TIDY
443+
NAMES "clang-tidy"
444+
DOC "Path to clang-tidy executable" )
445+
446+
if ( CLANG_TIDY )
447+
message ( STATUS "Found clang-tidy at ${CLANG_TIDY}" )
448+
execute_process ( COMMAND ${CLANG_TIDY} "--version" )
449+
set ( CMAKE_C_CLANG_TIDY ${CLANG_TIDY} )
450+
endif ( CLANG_TIDY )
442451
elseif ( CMAKE_C_COMPILER_ID STREQUAL "Intel" )
443452
set ( OPT_FLAGS "-qopt-report=3" )
444453
elseif ( CMAKE_C_COMPILER_ID STREQUAL "GNU" )
445-
set ( OPT_FLAGS "" )
454+
set ( OPT_FLAGS "-fopt-info -fopt-info-vec-missed" )
446455
endif ( )
447456

448457
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPT_FLAGS}" )
449-
450-
find_program( CLANG_TIDY
451-
NAMES "clang-tidy"
452-
DOC "Path to clang-tidy executable" )
453-
454-
if ( CLANG_TIDY )
455-
message ( STATUS "Found clang-tidy at ${CLANG_TIDY}" )
456-
execute_process ( COMMAND ${CLANG_TIDY} "--version" )
457-
set ( CMAKE_C_CLANG_TIDY ${CLANG_TIDY} )
458-
endif ( CLANG_TIDY )
458+
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPT_FLAGS}" )
459459

460460
endif ( enable-profiling )
461461

src/CMakeLists.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ set ( libfluidsynth_SOURCES
139139
rvoice/fluid_lfo.h
140140
rvoice/fluid_rvoice.h
141141
rvoice/fluid_rvoice.c
142-
rvoice/fluid_rvoice_dsp.c
142+
rvoice/fluid_rvoice_dsp.cpp
143143
rvoice/fluid_rvoice_event.h
144144
rvoice/fluid_rvoice_event.c
145145
rvoice/fluid_rvoice_mixer.h
@@ -311,8 +311,6 @@ elseif ( WIN32 )
311311
set_target_properties ( libfluidsynth
312312
PROPERTIES
313313
PUBLIC_HEADER "${public_HEADERS}"
314-
ARCHIVE_OUTPUT_NAME "fluidsynth"
315-
PREFIX "lib"
316314
OUTPUT_NAME "fluidsynth-${LIB_VERSION_CURRENT}"
317315
VERSION ${LIB_VERSION_INFO}
318316
SOVERSION ${LIB_VERSION_CURRENT}

src/gentables/make_tables.c

+18-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,22 @@ static void open_table(FILE**fp, const char* dir, const char* file)
6161
}
6262

6363
/* Emit warning header */
64-
fprintf(*fp, "/* THIS FILE HAS BEEN AUTOMATICALLY GENERATED. DO NOT EDIT. */\n\n");
64+
fprintf(*fp,
65+
"/* THIS FILE HAS BEEN AUTOMATICALLY GENERATED. DO NOT EDIT. */\n\n"
66+
"#ifdef __cplusplus\n"
67+
"extern \"C\" {\n"
68+
"#endif\n\n"
69+
);
70+
}
71+
72+
static void close_table(FILE**fp)
73+
{
74+
fprintf(*fp,
75+
"#ifdef __cplusplus\n"
76+
"}\n"
77+
"#endif\n"
78+
);
79+
fclose(*fp);
6580
}
6681

6782
int main (int argc, char *argv[])
@@ -74,11 +89,11 @@ int main (int argc, char *argv[])
7489

7590
open_table(&fp, argv[1], "fluid_conv_tables.inc.h");
7691
gen_conv_table(fp);
77-
fclose(fp);
92+
close_table(&fp);
7893

7994
open_table(&fp, argv[1], "fluid_rvoice_dsp_tables.inc.h");
8095
gen_rvoice_table_dsp(fp);
81-
fclose(fp);
96+
close_table(&fp);
8297

8398
return 0;
8499
}

src/rvoice/fluid_adsr_env.h

+10-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#include "fluidsynth_priv.h"
2525
#include "fluid_sys.h"
2626

27+
#ifdef __cplusplus
28+
extern "C" {
29+
#endif
2730
/*
2831
* envelope data
2932
*/
@@ -39,7 +42,7 @@ struct _fluid_env_data_t
3942
/* Indices for envelope tables */
4043
enum fluid_voice_envelope_index
4144
{
42-
FLUID_VOICE_ENVDELAY,
45+
FLUID_VOICE_ENVDELAY=0,
4346
FLUID_VOICE_ENVATTACK,
4447
FLUID_VOICE_ENVHOLD,
4548
FLUID_VOICE_ENVDECAY,
@@ -56,9 +59,9 @@ typedef struct _fluid_adsr_env_t fluid_adsr_env_t;
5659
struct _fluid_adsr_env_t
5760
{
5861
fluid_env_data_t data[FLUID_VOICE_ENVLAST];
62+
unsigned int section; // type fluid_adsr_env_section_t, but declare it unsigned to make C++ happy
5963
unsigned int count;
6064
fluid_real_t val; /* the current value of the envelope */
61-
fluid_adsr_env_section_t section;
6265
};
6366

6467
/* For performance, all functions are inlined */
@@ -136,14 +139,14 @@ fluid_adsr_env_set_val(fluid_adsr_env_t *env, fluid_real_t val)
136139
static FLUID_INLINE fluid_adsr_env_section_t
137140
fluid_adsr_env_get_section(fluid_adsr_env_t *env)
138141
{
139-
return env->section;
142+
return (fluid_adsr_env_section_t)env->section;
140143
}
141144

142145
static FLUID_INLINE void
143146
fluid_adsr_env_set_section(fluid_adsr_env_t *env,
144147
fluid_adsr_env_section_t section)
145148
{
146-
env->section = section;
149+
env->section = (unsigned int)section;
147150
env->count = 0;
148151
}
149152

@@ -163,5 +166,8 @@ fluid_adsr_env_get_max_val(fluid_adsr_env_t *env)
163166
}
164167
}
165168

169+
#ifdef __cplusplus
170+
}
171+
#endif
166172
#endif
167173

0 commit comments

Comments
 (0)