Skip to content

Commit

Permalink
prepare dsp code to c++ migration
Browse files Browse the repository at this point in the history
  • Loading branch information
derselbst committed Dec 8, 2024
1 parent e604d9e commit 544a383
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 8 deletions.
2 changes: 1 addition & 1 deletion 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
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

6 changes: 6 additions & 0 deletions src/rvoice/fluid_iir_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#define LOG_FILTER(...)
#endif

#ifdef __cplusplus
extern "C" {
#endif
typedef struct _fluid_iir_filter_t fluid_iir_filter_t;

DECLARE_FLUID_RVOICE_FUNCTION(fluid_iir_filter_init);
Expand Down Expand Up @@ -78,5 +81,8 @@ struct _fluid_iir_filter_t
#endif
};

#ifdef __cplusplus
}
#endif
#endif

6 changes: 6 additions & 0 deletions src/rvoice/fluid_lfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

#include "fluid_sys.h"

#ifdef __cplusplus
extern "C" {
#endif
typedef struct _fluid_lfo_t fluid_lfo_t;

struct _fluid_lfo_t
Expand Down Expand Up @@ -71,5 +74,8 @@ fluid_lfo_calc(fluid_lfo_t *lfo, unsigned int cur_delay)

}

#ifdef __cplusplus
}
#endif
#endif

6 changes: 6 additions & 0 deletions src/rvoice/fluid_phase.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#ifndef _FLUID_PHASE_H
#define _FLUID_PHASE_H

#ifdef __cplusplus
extern "C" {
#endif
/*
* phase
*/
Expand Down Expand Up @@ -110,4 +113,7 @@ typedef uint64_t fluid_phase_t;
* Creates the expression a.index++. */
#define fluid_phase_index_plusplus(a) (((a) += 0x100000000LL)

#ifdef __cplusplus
}
#endif
#endif /* _FLUID_PHASE_H */
6 changes: 6 additions & 0 deletions src/rvoice/fluid_rvoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#include "fluid_phase.h"
#include "fluid_sfont.h"

#ifdef __cplusplus
extern "C" {
#endif
typedef struct _fluid_rvoice_envlfo_t fluid_rvoice_envlfo_t;
typedef struct _fluid_rvoice_dsp_t fluid_rvoice_dsp_t;
typedef struct _fluid_rvoice_buffers_t fluid_rvoice_buffers_t;
Expand Down Expand Up @@ -228,4 +231,7 @@ fluid_rvoice_get_sample(const short int *dsp_msb, const char *dsp_lsb, unsigned
return (int32_t)((msb << 8) | lsb);
}

#ifdef __cplusplus
}
#endif
#endif
File renamed without changes.
6 changes: 6 additions & 0 deletions src/sfloader/fluid_sfont.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

#include "fluidsynth.h"

#ifdef __cplusplus
extern "C" {
#endif
int fluid_sample_validate(fluid_sample_t *sample, unsigned int max_end);
int fluid_sample_sanitize_loop(fluid_sample_t *sample, unsigned int max_end);

Expand Down Expand Up @@ -186,4 +189,7 @@ struct _fluid_sample_t
};


#ifdef __cplusplus
}
#endif
#endif /* _PRIV_FLUID_SFONT_H */
6 changes: 6 additions & 0 deletions src/utils/fluid_conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include "fluidsynth_priv.h"
#include "utils/fluid_conv_tables.h"

#ifdef __cplusplus
extern "C" {
#endif
fluid_real_t fluid_ct2hz_real(fluid_real_t cents);
fluid_real_t fluid_ct2hz(fluid_real_t cents);
fluid_real_t fluid_cb2amp(fluid_real_t cb);
Expand All @@ -39,4 +42,7 @@ fluid_real_t fluid_balance(fluid_real_t balance, int left);
fluid_real_t fluid_concave(fluid_real_t val);
fluid_real_t fluid_convex(fluid_real_t val);

#ifdef __cplusplus
}
#endif
#endif /* _FLUID_CONV_H */
7 changes: 7 additions & 0 deletions src/utils/fluid_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ typedef gintptr intptr_t;

#include <glib/gstdio.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* Macro used for safely accessing a message from a GError and using a default
* message if it is NULL.
Expand Down Expand Up @@ -786,4 +790,7 @@ static FLUID_INLINE void *fluid_align_ptr(const void *ptr, unsigned int alignmen

#define FLUID_DEFAULT_ALIGNMENT (64U)

#ifdef __cplusplus
}
#endif
#endif /* _FLUID_SYS_H */

0 comments on commit 544a383

Please sign in to comment.