libfluidsynth  2.3.5
Voice Manipulation

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

void fluid_voice_add_mod (fluid_voice_t *voice, fluid_mod_t *mod, int mode)
 Adds a modulator to the voice if the modulator has valid sources. More...
 
float fluid_voice_gen_get (fluid_voice_t *voice, int gen)
 Get the value of a generator. More...
 
void fluid_voice_gen_incr (fluid_voice_t *voice, int gen, float val)
 Offset the value of a generator. More...
 
void fluid_voice_gen_set (fluid_voice_t *voice, int gen, float val)
 Set the value of a generator. More...
 
int fluid_voice_get_actual_key (const fluid_voice_t *voice)
 Return the effective MIDI key of the playing voice. More...
 
int fluid_voice_get_actual_velocity (const fluid_voice_t *voice)
 Return the effective MIDI velocity of the playing voice. More...
 
int fluid_voice_get_channel (const fluid_voice_t *voice)
 Return the MIDI channel the voice is playing on. More...
 
unsigned int fluid_voice_get_id (const fluid_voice_t *voice)
 Get the unique ID of the noteon-event. More...
 
int fluid_voice_get_key (const fluid_voice_t *voice)
 Return the MIDI key from the starting noteon event. More...
 
int fluid_voice_get_velocity (const fluid_voice_t *voice)
 Return the MIDI velocity from the starting noteon event. More...
 
int fluid_voice_is_on (const fluid_voice_t *voice)
 Check if a voice is ON. More...
 
int fluid_voice_is_playing (const fluid_voice_t *voice)
 Check if a voice is producing sound. More...
 
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...
 
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...
 
int fluid_voice_optimize_sample (fluid_sample_t *s)
 Calculate the peak volume of a sample for voice off optimization. More...
 
void fluid_voice_update_param (fluid_voice_t *voice, int gen)
 Update all the synthesis parameters which depend on generator gen. More...
 

Detailed Description

Synthesis voice manipulation functions.

The interface to the synthesizer's voices. Examples on using them can be found in the source code of the default SoundFont loader (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_add_mod()

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

Adds a modulator to the voice if the modulator has valid sources.

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.

◆ fluid_voice_gen_get()

float fluid_voice_gen_get ( fluid_voice_t voice,
int  gen 
)

Get the value of a generator.

Parameters
voiceVoice instance
genGenerator ID (fluid_gen_type)
Returns
Current generator value

◆ fluid_voice_gen_incr()

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

◆ fluid_voice_gen_set()

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

◆ fluid_voice_get_actual_key()

int fluid_voice_get_actual_key ( const fluid_voice_t voice)

Return the effective MIDI key of the playing voice.

Parameters
voiceVoice instance
Returns
The MIDI key this voice is playing at

If the voice was started from an instrument which uses a fixed key generator, it returns that. Otherwise returns the same value as fluid_voice_get_key.

Note
The result of this function is only valid if the voice is playing.
Since
1.1.7

◆ fluid_voice_get_actual_velocity()

int fluid_voice_get_actual_velocity ( const fluid_voice_t voice)

Return the effective MIDI velocity of the playing voice.

Parameters
voiceVoice instance
Returns
The MIDI velocity this voice is playing at

If the voice was started from an instrument which uses a fixed velocity generator, it returns that. Otherwise it returns the same value as fluid_voice_get_velocity.

Note
The result of this function is only valid if the voice is playing.
Since
1.1.7

◆ fluid_voice_get_channel()

int fluid_voice_get_channel ( const fluid_voice_t voice)

Return the MIDI channel the voice is playing on.

Parameters
voiceVoice instance
Returns
The channel assigned to this voice
Note
The result of this function is only valid if the voice is playing.
Since
1.1.7

◆ fluid_voice_get_id()

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 pointers to voices 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 internally which are 'recycled' and never deallocated.

However, 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.

◆ fluid_voice_get_key()

int fluid_voice_get_key ( const fluid_voice_t voice)

Return the MIDI key from the starting noteon event.

Parameters
voiceVoice instance
Returns
The MIDI key of the noteon event that originally turned on this voice
Note
The result of this function is only valid if the voice is playing.
Since
1.1.7

◆ fluid_voice_get_velocity()

int fluid_voice_get_velocity ( const fluid_voice_t voice)

Return the MIDI velocity from the starting noteon event.

Parameters
voiceVoice instance
Returns
The MIDI velocity which originally turned on this voice
Note
The result of this function is only valid if the voice is playing.
Since
1.1.7

◆ fluid_voice_is_on()

int fluid_voice_is_on ( const fluid_voice_t voice)

Check if a voice is ON.

A voice is in ON state as soon as a call to fluid_synth_start_voice() has been made (which is typically done in a fluid_preset_t's noteon function). A voice stays ON as long as it has not received a noteoff event.

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

◆ fluid_voice_is_playing()

int fluid_voice_is_playing ( const fluid_voice_t voice)

Check if a voice is producing sound.

Like fluid_voice_is_on() this will return TRUE once a call to fluid_synth_start_voice() has been made. Contrary to fluid_voice_is_on(), this might also return TRUE after the voice received a noteoff event, as it may still be playing in release phase, or because it has been sustained or sostenuto'ed.

Parameters
voiceVoice instance
Returns
TRUE if playing, FALSE otherwise

◆ fluid_voice_is_sostenuto()

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

◆ fluid_voice_is_sustained()

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

◆ fluid_voice_optimize_sample()

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.

◆ fluid_voice_update_param()

void fluid_voice_update_param ( fluid_voice_t voice,
int  gen 
)

Update all the synthesis parameters which depend on generator gen.

Parameters
voiceVoice instance
genGenerator id (fluid_gen_type)

Calling this function is only necessary after changing a generator of an already playing voice.