Added fluid_synth_get_active_voice_count().

This commit is contained in:
Josh Green 2009-11-01 22:56:26 +00:00
parent b46061bfe7
commit 8b231faab7
6 changed files with 44 additions and 3 deletions

View file

@ -102,7 +102,8 @@ API additions:
- Additional synthesizer API: fluid_synth_get_sfont_by_name() to get a SoundFont by name,
fluid_synth_program_select_by_sfont_name() to select an instrument by SoundFont name/bank/program,
fluid_synth_set_gen2() for specifying additional parameters when assigning a generator value,
and fluid_synth_sysex() for sending SYSEX messages to the synth.
fluid_synth_sysex() for sending SYSEX messages to the synth and fluid_synth_get_active_voice_count() to
get the current number of active synthesis voices.
- Miscellaneous additions: fluid_player_set_loop() to set playlist loop count and fluid_player_get_status() to get current player state.

View file

@ -162,6 +162,7 @@ FLUIDSYNTH_API void fluid_synth_set_gain(fluid_synth_t* synth, float gain);
FLUIDSYNTH_API float fluid_synth_get_gain(fluid_synth_t* synth);
FLUIDSYNTH_API int fluid_synth_set_polyphony(fluid_synth_t* synth, int polyphony);
FLUIDSYNTH_API int fluid_synth_get_polyphony(fluid_synth_t* synth);
FLUIDSYNTH_API int fluid_synth_get_active_voice_count(fluid_synth_t* synth);
FLUIDSYNTH_API int fluid_synth_get_internal_bufsize(fluid_synth_t* synth);
FLUIDSYNTH_API

View file

@ -48,6 +48,8 @@ static int fluid_shell_run(fluid_shell_t* shell);
static void fluid_shell_init(fluid_shell_t* shell,
fluid_settings_t* settings, fluid_cmd_handler_t* handler,
fluid_istream_t in, fluid_ostream_t out);
static int fluid_handle_voice_count (fluid_synth_t *synth, int ac, char **av,
fluid_ostream_t out);
void fluid_shell_settings(fluid_settings_t* settings)
{
@ -113,6 +115,8 @@ fluid_cmd_t fluid_commands[] = {
"chorus [0|1|on|off] Turn the chorus on or off" },
{ "gain", "general", (fluid_cmd_func_t) fluid_handle_gain, NULL,
"gain value Set the master gain (0 < gain < 5)" },
{ "voice_count", "general", (fluid_cmd_func_t) fluid_handle_voice_count, NULL,
"voice_count Get number of active synthesis voices" },
{ "tuning", "tuning", (fluid_cmd_func_t) fluid_handle_tuning, NULL,
"tuning name bank prog Create a tuning with name, bank number, \n"
" and program number (0 <= bank,prog <= 127)" },
@ -946,6 +950,16 @@ fluid_handle_gain(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out)
return 0;
}
/* Response to voice_count command */
static int
fluid_handle_voice_count (fluid_synth_t *synth, int ac, char **av,
fluid_ostream_t out)
{
fluid_ostream_printf (out, "voice_count: %d\n",
fluid_synth_get_active_voice_count (synth));
return FLUID_OK;
}
/* Purpose:
* Response to 'interp' command. */
int

View file

@ -2618,6 +2618,23 @@ fluid_synth_get_polyphony(fluid_synth_t* synth)
return fluid_atomic_int_get (&synth->polyphony);
}
/**
* Get current number of active voices.
* @param synth FluidSynth instance
* @return Number of currently active voices.
* @since 1.1.0
*
* Note: To generate accurate continuous statistics of the voice count, caller
* should ensure this function is called synchronously with the audio synthesis
* process. This can be done in the new_fluid_audio_driver2() audio callback
* function for example.
*/
int
fluid_synth_get_active_voice_count(fluid_synth_t* synth)
{
return fluid_atomic_int_get (&synth->active_voice_count);
}
/**
* Get the internal synthesis buffer size value.
* @param synth FluidSynth instance

View file

@ -138,15 +138,16 @@ typedef struct _fluid_sfont_info_t {
* outbuf
* sample_timers
*
* Only synth thread changes
* Only synth thread changes (atomic operations for non-synth thread reads)
* -------------------------
* ticks
* reverb{}
* chorus{}
* cur
* dither_index
* polyphony (atomic int get for non-synth threads)
* polyphony
* st_gain
* active_voice_count
*/
struct _fluid_synth_t
@ -187,6 +188,7 @@ struct _fluid_synth_t
fluid_channel_t** channel; /**< the channels */
int nvoice; /**< the length of the synthesis process array (max polyphony allowed) */
fluid_voice_t** voice; /**< the synthesis voices */
int active_voice_count; /**< count of active voices */
unsigned int noteid; /**< the id is incremented for every new note. it's used for noteoff's */
unsigned int storeid;
int nbuf; /**< How many audio buffers are used? (depends on nr of audio channels / groups)*/

View file

@ -829,6 +829,9 @@ void fluid_voice_start(fluid_voice_t* voice)
voice->ref = fluid_profile_ref();
voice->status = FLUID_VOICE_ON;
/* Increment voice count atomically, for non-synth thread read access */
fluid_atomic_int_add (&voice->channel->synth->active_voice_count, 1);
}
void
@ -1690,6 +1693,9 @@ fluid_voice_off(fluid_voice_t* voice)
voice->sample = NULL;
}
/* Decrement voice count atomically, for non-synth thread read access */
fluid_atomic_int_add (&voice->channel->synth->active_voice_count, -1);
return FLUID_OK;
}