Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port DSP code to C++ to address performance penalty #1469

Merged
merged 2 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -439,23 +439,23 @@ if ( enable-profiling )
set ( WITH_PROFILING 1 )
if ( CMAKE_C_COMPILER_ID STREQUAL "Clang" )
set ( OPT_FLAGS "-Rpass=loop-vectorize" ) # -Rpass-analysis=loop-vectorize" )
find_program( CLANG_TIDY
NAMES "clang-tidy"
DOC "Path to clang-tidy executable" )

if ( CLANG_TIDY )
message ( STATUS "Found clang-tidy at ${CLANG_TIDY}" )
execute_process ( COMMAND ${CLANG_TIDY} "--version" )
set ( CMAKE_C_CLANG_TIDY ${CLANG_TIDY} )
endif ( CLANG_TIDY )
elseif ( CMAKE_C_COMPILER_ID STREQUAL "Intel" )
set ( OPT_FLAGS "-qopt-report=3" )
elseif ( CMAKE_C_COMPILER_ID STREQUAL "GNU" )
set ( OPT_FLAGS "" )
set ( OPT_FLAGS "-fopt-info -fopt-info-vec-missed" )
endif ( )

set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPT_FLAGS}" )

find_program( CLANG_TIDY
NAMES "clang-tidy"
DOC "Path to clang-tidy executable" )

if ( CLANG_TIDY )
message ( STATUS "Found clang-tidy at ${CLANG_TIDY}" )
execute_process ( COMMAND ${CLANG_TIDY} "--version" )
set ( CMAKE_C_CLANG_TIDY ${CLANG_TIDY} )
endif ( CLANG_TIDY )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPT_FLAGS}" )

endif ( enable-profiling )

Expand Down
4 changes: 1 addition & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ set ( libfluidsynth_SOURCES
rvoice/fluid_lfo.h
rvoice/fluid_rvoice.h
rvoice/fluid_rvoice.c
rvoice/fluid_rvoice_dsp.c
rvoice/fluid_rvoice_dsp.cpp
rvoice/fluid_rvoice_event.h
rvoice/fluid_rvoice_event.c
rvoice/fluid_rvoice_mixer.h
Expand Down Expand Up @@ -311,8 +311,6 @@ elseif ( WIN32 )
set_target_properties ( libfluidsynth
PROPERTIES
PUBLIC_HEADER "${public_HEADERS}"
ARCHIVE_OUTPUT_NAME "fluidsynth"
PREFIX "lib"
OUTPUT_NAME "fluidsynth-${LIB_VERSION_CURRENT}"
VERSION ${LIB_VERSION_INFO}
SOVERSION ${LIB_VERSION_CURRENT}
Expand Down
21 changes: 18 additions & 3 deletions src/gentables/make_tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,22 @@ static void open_table(FILE**fp, const char* dir, const char* file)
}

/* Emit warning header */
fprintf(*fp, "/* THIS FILE HAS BEEN AUTOMATICALLY GENERATED. DO NOT EDIT. */\n\n");
fprintf(*fp,
"/* THIS FILE HAS BEEN AUTOMATICALLY GENERATED. DO NOT EDIT. */\n\n"
"#ifdef __cplusplus\n"
"extern \"C\" {\n"
"#endif\n\n"
);
}

static void close_table(FILE**fp)
{
fprintf(*fp,
"#ifdef __cplusplus\n"
"}\n"
"#endif\n"
);
fclose(*fp);
}

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

open_table(&fp, argv[1], "fluid_conv_tables.inc.h");
gen_conv_table(fp);
fclose(fp);
close_table(&fp);

open_table(&fp, argv[1], "fluid_rvoice_dsp_tables.inc.h");
gen_rvoice_table_dsp(fp);
fclose(fp);
close_table(&fp);

return 0;
}
14 changes: 10 additions & 4 deletions src/rvoice/fluid_adsr_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include "fluidsynth_priv.h"
#include "fluid_sys.h"

#ifdef __cplusplus
extern "C" {
#endif
/*
* envelope data
*/
Expand All @@ -39,7 +42,7 @@ struct _fluid_env_data_t
/* Indices for envelope tables */
enum fluid_voice_envelope_index
{
FLUID_VOICE_ENVDELAY,
FLUID_VOICE_ENVDELAY=0,
FLUID_VOICE_ENVATTACK,
FLUID_VOICE_ENVHOLD,
FLUID_VOICE_ENVDECAY,
Expand All @@ -56,9 +59,9 @@ typedef struct _fluid_adsr_env_t fluid_adsr_env_t;
struct _fluid_adsr_env_t
{
fluid_env_data_t data[FLUID_VOICE_ENVLAST];
unsigned int section; // type fluid_adsr_env_section_t, but declare it unsigned to make C++ happy
unsigned int count;
fluid_real_t val; /* the current value of the envelope */
fluid_adsr_env_section_t section;
};

/* For performance, all functions are inlined */
Expand Down Expand Up @@ -136,14 +139,14 @@ fluid_adsr_env_set_val(fluid_adsr_env_t *env, fluid_real_t val)
static FLUID_INLINE fluid_adsr_env_section_t
fluid_adsr_env_get_section(fluid_adsr_env_t *env)
{
return env->section;
return (fluid_adsr_env_section_t)env->section;
}

static FLUID_INLINE void
fluid_adsr_env_set_section(fluid_adsr_env_t *env,
fluid_adsr_env_section_t section)
{
env->section = section;
env->section = (unsigned int)section;
env->count = 0;
}

Expand All @@ -163,5 +166,8 @@ fluid_adsr_env_get_max_val(fluid_adsr_env_t *env)
}
}

#ifdef __cplusplus
}
#endif
#endif

Loading
Loading