libfluidsynth  1.1.8
Enumerations | Functions
voice.h File Reference

Synthesis voice manipulation functions. More...

Enumerations

enum  fluid_voice_add_mod { FLUID_VOICE_OVERWRITE, FLUID_VOICE_ADD, FLUID_VOICE_DEFAULT }
 Enum used with fluid_voice_add_mod() to specify how to handle duplicate modulators. More...
 

Functions

FLUIDSYNTH_API void fluid_voice_update_param (fluid_voice_t *voice, int gen)
 Update all the synthesis parameters, which depend on generator gen. More...
 
FLUIDSYNTH_API void fluid_voice_add_mod (fluid_voice_t *voice, fluid_mod_t *mod, int mode)
 Adds a modulator to the voice. More...
 
FLUIDSYNTH_API void fluid_voice_gen_set (fluid_voice_t *voice, int gen, float val)
 Set the value of a generator. More...
 
FLUIDSYNTH_API float fluid_voice_gen_get (fluid_voice_t *voice, int gen)
 Get the value of a generator. More...
 
FLUIDSYNTH_API void fluid_voice_gen_incr (fluid_voice_t *voice, int gen, float val)
 Offset the value of a generator. More...
 
FLUIDSYNTH_API unsigned int fluid_voice_get_id (const fluid_voice_t *voice)
 Get the unique ID of the noteon-event. More...
 
FLUIDSYNTH_API int fluid_voice_is_playing (const fluid_voice_t *voice)
 Check if a voice is producing sound. More...
 
FLUIDSYNTH_API int fluid_voice_is_on (const fluid_voice_t *voice)
 Check if a voice is ON. More...
 
FLUIDSYNTH_API int fluid_voice_is_sustained (const fluid_voice_t *voice)
 Check if a voice keeps playing after it has received a noteoff due to being held by sustain. More...
 
FLUIDSYNTH_API int fluid_voice_is_sostenuto (const fluid_voice_t *voice)
 Check if a voice keeps playing after it has received a noteoff due to being held by sostenuto. More...
 
FLUIDSYNTH_API int fluid_voice_get_channel (const fluid_voice_t *voice)
 If the voice is playing, gets the midi channel the voice is playing on. More...
 
FLUIDSYNTH_API int fluid_voice_get_actual_key (const fluid_voice_t *voice)
 If the voice is playing, gets the midi key the voice is actually playing at. More...
 
FLUIDSYNTH_API int fluid_voice_get_key (const fluid_voice_t *voice)
 If the voice is playing, gets the midi key from the noteon event, by which the voice was initially turned on with. More...
 
FLUIDSYNTH_API int fluid_voice_get_actual_velocity (const fluid_voice_t *voice)
 If the voice is playing, gets the midi velocity the voice is actually playing at. More...
 
FLUIDSYNTH_API int fluid_voice_get_velocity (const fluid_voice_t *voice)
 If the voice is playing, gets the midi velocity from the noteon event, by which the voice was initially turned on with. More...
 
FLUIDSYNTH_API int fluid_voice_optimize_sample (fluid_sample_t *s)
 Calculate the peak volume of a sample for voice off optimization. More...
 

Detailed Description

Synthesis voice manipulation functions.

The interface to the synthesizer's voices. Examples on using them can be found in fluid_defsfont.c. Most of these functions should only be called from within synthesis context, such as the SoundFont loader's noteon method.

Enumeration Type Documentation

◆ fluid_voice_add_mod

Enum used with fluid_voice_add_mod() to specify how to handle duplicate modulators.

Enumerator
FLUID_VOICE_OVERWRITE 

Overwrite any existing matching modulator.

FLUID_VOICE_ADD 

Add (sum) modulator amounts.

FLUID_VOICE_DEFAULT 

For default modulators only, no need to check for duplicates.

Function Documentation

◆ fluid_voice_update_param()

FLUIDSYNTH_API void fluid_voice_update_param ( fluid_voice_t voice,
int  gen 
)

◆ fluid_voice_add_mod()

FLUIDSYNTH_API void fluid_voice_add_mod ( fluid_voice_t voice,
fluid_mod_t mod,
int  mode 
)

Adds a modulator to the voice.

Parameters
voiceVoice instance
modModulator info (copied)
modeDetermines how to handle an existing identical modulator FLUID_VOICE_ADD to add (offset) the modulator amounts, FLUID_VOICE_OVERWRITE to replace the modulator, FLUID_VOICE_DEFAULT when adding a default modulator - no duplicate should exist so don't check.

References _fluid_mod_t::amount, _fluid_mod_t::flags1, FLUID_MOD_CC, FLUID_MOD_CHANNELPRESSURE, FLUID_MOD_KEY, FLUID_MOD_KEYPRESSURE, FLUID_MOD_NONE, FLUID_MOD_PITCHWHEEL, FLUID_MOD_PITCHWHEELSENS, fluid_mod_test_identity(), FLUID_MOD_VELOCITY, FLUID_NUM_MOD, FLUID_VOICE_ADD, FLUID_VOICE_OVERWRITE, FLUID_WARN, and _fluid_mod_t::src1.

◆ fluid_voice_gen_set()

FLUIDSYNTH_API void fluid_voice_gen_set ( fluid_voice_t voice,
int  i,
float  val 
)

Set the value of a generator.

Parameters
voiceVoice instance
iGenerator ID (fluid_gen_type)
valGenerator value

References GEN_SAMPLEMODE, and GEN_SET.

Referenced by fluid_ramsfont_izone_set_loop(), and fluid_voice_update_param().

◆ fluid_voice_gen_get()

FLUIDSYNTH_API float fluid_voice_gen_get ( fluid_voice_t voice,
int  gen 
)

◆ fluid_voice_gen_incr()

FLUIDSYNTH_API void fluid_voice_gen_incr ( fluid_voice_t voice,
int  i,
float  val 
)

Offset the value of a generator.

Parameters
voiceVoice instance
iGenerator ID (fluid_gen_type)
valValue to add to the existing value

References GEN_SET.

Referenced by fluid_ramsfont_izone_set_loop().

◆ fluid_voice_get_id()

FLUIDSYNTH_API unsigned int fluid_voice_get_id ( const fluid_voice_t voice)

Get the unique ID of the noteon-event.

Parameters
voiceVoice instance
Returns
Note on unique ID

A SoundFont loader may store the voice processes it has created for real-time control during the operation of a voice (for example: parameter changes in SoundFont editor). The synth uses a pool of voices, which are 'recycled' and never deallocated.

Before modifying an existing voice, check

  • that its state is still 'playing'
  • that the ID is still the same

Otherwise the voice has finished playing.

Referenced by fluid_ramsfont_izone_set_loop(), fluid_synth_alloc_voice(), fluid_synth_get_chorus_type(), fluid_synth_noteoff(), fluid_synth_stop(), and fluid_synth_write_s16().

◆ fluid_voice_is_playing()

FLUIDSYNTH_API int fluid_voice_is_playing ( const fluid_voice_t voice)

Check if a voice is producing sound.

This is also true after a voice received a noteoff as it may be playing in release phase.

Parameters
voiceVoice instance
Returns
TRUE if playing, FALSE otherwise

References fluid_voice_is_sostenuto(), and fluid_voice_is_sustained().

Referenced by delete_fluid_synth(), fluid_ramsfont_izone_set_loop(), fluid_synth_all_notes_off(), fluid_synth_all_sounds_off(), fluid_synth_alloc_voice(), fluid_synth_get_chorus_type(), fluid_synth_get_voicelist(), fluid_synth_set_gain(), fluid_synth_set_polyphony(), fluid_synth_system_reset(), fluid_voice_gen_get(), and fluid_voice_update_param().

◆ fluid_voice_is_on()

FLUIDSYNTH_API int fluid_voice_is_on ( const fluid_voice_t voice)

Check if a voice is ON.

A voice is ON, if it has not yet received a noteoff event.

Parameters
voiceVoice instance
Returns
TRUE if on, FALSE otherwise
Since
1.1.7

Referenced by fluid_synth_get_cpu_load(), fluid_synth_noteoff(), and fluid_synth_stop().

◆ fluid_voice_is_sustained()

FLUIDSYNTH_API int fluid_voice_is_sustained ( const fluid_voice_t voice)

Check if a voice keeps playing after it has received a noteoff due to being held by sustain.

Parameters
voiceVoice instance
Returns
TRUE if sustained, FALSE otherwise
Since
1.1.7

Referenced by fluid_synth_noteoff(), fluid_voice_is_playing(), and fluid_voice_optimize_sample().

◆ fluid_voice_is_sostenuto()

FLUIDSYNTH_API int fluid_voice_is_sostenuto ( const fluid_voice_t voice)

Check if a voice keeps playing after it has received a noteoff due to being held by sostenuto.

Parameters
voiceVoice instance
Returns
TRUE if sostenuto, FALSE otherwise
Since
1.1.7

Referenced by fluid_synth_get_chorus_type(), fluid_synth_noteoff(), fluid_voice_is_playing(), and fluid_voice_optimize_sample().

◆ fluid_voice_get_channel()

FLUIDSYNTH_API int fluid_voice_get_channel ( const fluid_voice_t voice)

If the voice is playing, gets the midi channel the voice is playing on.

Else the result is undefined.

Parameters
voiceVoice instance
Returns
The channel assigned to this voice
Since
1.1.7

Referenced by fluid_synth_all_notes_off(), fluid_synth_all_sounds_off(), fluid_synth_alloc_voice(), fluid_synth_get_chorus_type(), fluid_synth_noteoff(), fluid_synth_set_gen(), fluid_synth_system_reset(), and fluid_synth_write_s16().

◆ fluid_voice_get_actual_key()

FLUIDSYNTH_API int fluid_voice_get_actual_key ( const fluid_voice_t voice)

If the voice is playing, gets the midi key the voice is actually playing at.

Else the result is undefined. If the voice was started from an instrument which uses a fixed key generator, it returns that. Else returns the same as fluid_voice_get_key.

Parameters
voiceVoice instance
Returns
The midi key this voice is playing at
Since
1.1.7

References fluid_voice_get_key(), and GEN_KEYNUM.

Referenced by fluid_mod_get_amount(), and fluid_voice_gen_get().

◆ fluid_voice_get_key()

FLUIDSYNTH_API int fluid_voice_get_key ( const fluid_voice_t voice)

If the voice is playing, gets the midi key from the noteon event, by which the voice was initially turned on with.

Else the result is undefined.

Parameters
voiceVoice instance
Returns
The midi key of the noteon event that originally turned on this voice
Since
1.1.7

Referenced by fluid_synth_get_chorus_type(), fluid_synth_noteoff(), fluid_synth_write_s16(), and fluid_voice_get_actual_key().

◆ fluid_voice_get_actual_velocity()

FLUIDSYNTH_API int fluid_voice_get_actual_velocity ( const fluid_voice_t voice)

If the voice is playing, gets the midi velocity the voice is actually playing at.

Else the result is undefined. If the voice was started from an instrument which uses a fixed velocity generator, it returns that. Else returns the same as fluid_voice_get_velocity.

Parameters
voiceVoice instance
Returns
The midi velocity this voice is playing at
Since
1.1.7

References fluid_voice_get_velocity(), and GEN_VELOCITY.

Referenced by fluid_mod_get_amount().

◆ fluid_voice_get_velocity()

FLUIDSYNTH_API int fluid_voice_get_velocity ( const fluid_voice_t voice)

If the voice is playing, gets the midi velocity from the noteon event, by which the voice was initially turned on with.

Else the result is undefined.

Parameters
voiceVoice instance
Returns
The midi velocity which originally turned on this voice
Since
1.1.7

References _fluid_mod_t::amount, _fluid_mod_t::dest, _fluid_mod_t::flags1, _fluid_mod_t::flags2, FLUID_MOD_BIPOLAR, FLUID_MOD_CC, FLUID_MOD_PITCHWHEEL, FLUID_OK, fluid_voice_update_param(), GEN_ABS_NRPN, GEN_ATTENUATION, GEN_SET, and _fluid_mod_t::src1.

Referenced by fluid_voice_get_actual_velocity().

◆ fluid_voice_optimize_sample()

FLUIDSYNTH_API int fluid_voice_optimize_sample ( fluid_sample_t s)

Calculate the peak volume of a sample for voice off optimization.

Parameters
sSample to optimize
Returns
FLUID_OK on success, FLUID_FAILED otherwise

If the peak volume during the loop is known, then the voice can be released earlier during the release phase. Otherwise, the voice will operate (inaudibly), until the envelope is at the nominal turnoff point. So it's a good idea to call fluid_voice_optimize_sample() on each sample once.

References _fluid_sample_t::amplitude_that_reaches_noise_floor, _fluid_sample_t::amplitude_that_reaches_noise_floor_is_valid, CHANNEL_TYPE_DRUM, _fluid_sample_t::data, FLUID_OK, fluid_voice_is_sostenuto(), fluid_voice_is_sustained(), _fluid_sample_t::loopend, _fluid_sample_t::loopstart, and _fluid_sample_t::valid.