Path: blob/master/libs/fluidsynth/src/synth/fluid_synth.h
4396 views
/* FluidSynth - A Software Synthesizer1*2* Copyright (C) 2003 Peter Hanappe and others.3*4* This library is free software; you can redistribute it and/or5* modify it under the terms of the GNU Lesser General Public License6* as published by the Free Software Foundation; either version 2.1 of7* the License, or (at your option) any later version.8*9* This library is distributed in the hope that it will be useful, but10* WITHOUT ANY WARRANTY; without even the implied warranty of11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU12* Lesser General Public License for more details.13*14* You should have received a copy of the GNU Lesser General Public15* License along with this library; if not, write to the Free16* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA17* 02110-1301, USA18*/192021#ifndef _FLUID_SYNTH_H22#define _FLUID_SYNTH_H232425/***************************************************************26*27* INCLUDES28*/2930#include "fluid_sys.h"31#include "fluid_list.h"32#include "fluid_rev.h"33#include "fluid_voice.h"34#include "fluid_chorus.h"35#include "fluid_ladspa.h"36#include "fluid_midi_router.h"37#include "fluid_rvoice_event.h"3839/***************************************************************40*41* DEFINES42*/43#define FLUID_NUM_PROGRAMS 12844#define DRUM_INST_BANK 1284546#define FLUID_UNSET_PROGRAM 128 /* Program number used to unset a preset */4748#define FLUID_REVERB_DEFAULT_DAMP 0.3f /**< Default reverb damping */49#define FLUID_REVERB_DEFAULT_LEVEL 0.7f /**< Default reverb level */50#define FLUID_REVERB_DEFAULT_ROOMSIZE 0.5f /**< Default reverb room size */51#define FLUID_REVERB_DEFAULT_WIDTH 0.8f /**< Default reverb width */5253#define FLUID_CHORUS_DEFAULT_DEPTH 4.25f /**< Default chorus depth */54#define FLUID_CHORUS_DEFAULT_LEVEL 0.6f /**< Default chorus level */55#define FLUID_CHORUS_DEFAULT_N 3 /**< Default chorus voice count */56#define FLUID_CHORUS_DEFAULT_SPEED 0.2f /**< Default chorus speed */57#define FLUID_CHORUS_DEFAULT_TYPE FLUID_CHORUS_MOD_SINE /**< Default chorus waveform type */5859/***************************************************************60*61* ENUM62*/6364/**65* Bank Select MIDI message styles. Default style is GS.66*/67enum fluid_midi_bank_select68{69FLUID_BANK_STYLE_GM, /**< GM style, bank = 0 always (CC0/MSB and CC32/LSB ignored) */70FLUID_BANK_STYLE_GS, /**< GS style, bank = CC0/MSB (CC32/LSB ignored) */71FLUID_BANK_STYLE_XG, /**< XG style, bank = CC32/LSB (CC0/MSB ignored) */72FLUID_BANK_STYLE_MMA /**< MMA style bank = 128*MSB+LSB */73};7475enum fluid_synth_status76{77FLUID_SYNTH_CLEAN,78FLUID_SYNTH_PLAYING,79FLUID_SYNTH_QUIET,80FLUID_SYNTH_STOPPED81};8283#define SYNTH_REVERB_CHANNEL 084#define SYNTH_CHORUS_CHANNEL 18586/*87* fluid_synth_t88*89* Mutual exclusion notes (as of 1.1.2):90*91* All variables are considered belongning to the "public API" thread,92* which processes all MIDI, except for:93*94* ticks_since_start - atomic, set by rendering thread only95* cpu_load - atomic, set by rendering thread only96* cur, curmax, dither_index - used by rendering thread only97* ladspa_fx - same instance copied in rendering thread. Synchronising handled internally.98*99*/100101struct _fluid_synth_t102{103fluid_rec_mutex_t mutex; /**< Lock for public API */104int use_mutex; /**< Use mutex for all public API functions? */105int public_api_count; /**< How many times the mutex is currently locked */106107fluid_settings_t *settings; /**< the synthesizer settings */108int device_id; /**< Device ID used for SYSEX messages */109int polyphony; /**< Maximum polyphony */110int with_reverb; /**< Should the synth use the built-in reverb unit? */111int with_chorus; /**< Should the synth use the built-in chorus unit? */112int verbose; /**< Turn verbose mode on? */113double sample_rate; /**< The sample rate */114int midi_channels; /**< the number of MIDI channels (>= 16) */115int bank_select; /**< the style of Bank Select MIDI messages */116int audio_channels; /**< the number of audio channels (1 channel=left+right) */117int audio_groups; /**< the number of (stereo) 'sub'groups from the synth.118Typically equal to audio_channels. */119int effects_channels; /**< the number of effects channels (>= 2) */120int effects_groups; /**< the number of effects units (>= 1) */121int state; /**< the synthesizer state */122fluid_atomic_int_t ticks_since_start; /**< the number of audio samples since the start */123unsigned int start; /**< the start in msec, as returned by system clock */124fluid_overflow_prio_t overflow; /**< parameters for overflow priority (aka voice-stealing) */125126fluid_list_t *loaders; /**< the SoundFont loaders */127fluid_list_t *sfont; /**< List of fluid_sfont_info_t for each loaded SoundFont (remains until SoundFont is unloaded) */128int sfont_id; /**< Incrementing ID assigned to each loaded SoundFont */129fluid_list_t *fonts_to_be_unloaded; /**< list of timers that try to unload a soundfont */130131float gain; /**< master gain */132fluid_channel_t **channel; /**< the channels */133int nvoice; /**< the length of the synthesis process array (max polyphony allowed) */134fluid_voice_t **voice; /**< the synthesis voices */135int active_voice_count; /**< count of active voices */136unsigned int noteid; /**< the id is incremented for every new note. it's used for noteoff's */137unsigned int storeid;138int fromkey_portamento; /**< fromkey portamento */139fluid_rvoice_eventhandler_t *eventhandler;140141/**< Shadow of reverb parameter: roomsize, damping, width, level */142double reverb_param[FLUID_REVERB_PARAM_LAST];143144/**< Shadow of chorus parameter: chorus number, level, speed, depth, type */145double chorus_param[FLUID_CHORUS_PARAM_LAST];146147int cur; /**< the current sample in the audio buffers to be output */148int curmax; /**< current amount of samples present in the audio buffers */149int dither_index; /**< current index in random dither value buffer: fluid_synth_(write_s16|dither_s16) */150151fluid_atomic_float_t cpu_load; /**< CPU load in percent (CPU time required / audio synthesized time * 100) */152153fluid_tuning_t ***tuning; /**< 128 banks of 128 programs for the tunings */154fluid_private_t tuning_iter; /**< Tuning iterators per each thread */155156fluid_sample_timer_t *sample_timers; /**< List of timers triggered before a block is processed */157unsigned int min_note_length_ticks; /**< If note-offs are triggered just after a note-on, they will be delayed */158159int cores; /**< Number of CPU cores (1 by default) */160161fluid_mod_t *default_mod; /**< the (dynamic) list of default modulators */162163fluid_ladspa_fx_t *ladspa_fx; /**< Effects unit for LADSPA support */164enum fluid_iir_filter_type custom_filter_type; /**< filter type of the user-defined filter currently used for all voices */165enum fluid_iir_filter_flags custom_filter_flags; /**< filter type of the user-defined filter currently used for all voices */166};167168/**169* Type definition of the synthesizer's audio callback function.170* @param synth FluidSynth instance171* @param len Count of audio frames to synthesize172* @param out1 Array to store left channel of audio to173* @param loff Offset index in 'out1' for first sample174* @param lincr Increment between samples stored to 'out1'175* @param out2 Array to store right channel of audio to176* @param roff Offset index in 'out2' for first sample177* @param rincr Increment between samples stored to 'out2'178*/179typedef int (*fluid_audio_callback_t)(fluid_synth_t *synth, int len,180void *out1, int loff, int lincr,181void *out2, int roff, int rincr);182183typedef int (*fluid_audio_channels_callback_t)(fluid_synth_t *synth, int len,184int channels_count,185void *channels_out[], int channels_off[],186int channels_incr[]);187188int189fluid_synth_write_float_channels_LOCAL(fluid_synth_t *synth, int len,190int channels_count,191void *channels_out[], int channels_off[],192int channels_incr[],193int (*block_render_func)(fluid_synth_t *, int));194195int196fluid_synth_write_s16_channels(fluid_synth_t *synth, int len,197int channels_count,198void *channels_out[], int channels_off[],199int channels_incr[]);200int201fluid_synth_write_float_channels(fluid_synth_t *synth, int len,202int channels_count,203void *channels_out[], int channels_off[],204int channels_incr[]);205206fluid_preset_t *fluid_synth_find_preset(fluid_synth_t *synth,207int banknum,208int prognum);209void fluid_synth_sfont_unref(fluid_synth_t *synth, fluid_sfont_t *sfont);210211void fluid_synth_dither_s16(int *dither_index, int len, const float *lin, const float *rin,212void *lout, int loff, int lincr,213void *rout, int roff, int rincr);214215int fluid_synth_reset_reverb(fluid_synth_t *synth);216int fluid_synth_set_reverb_preset(fluid_synth_t *synth, unsigned int num);217int fluid_synth_reverb_set_param(fluid_synth_t *synth, int fx_group,218int param,219double value);220int fluid_synth_set_reverb_full(fluid_synth_t *synth, int fx_group, int set,221const double values[]);222223int fluid_synth_reset_chorus(fluid_synth_t *synth);224int fluid_synth_chorus_set_param(fluid_synth_t *synth, int fx_group,225int param, double value);226int fluid_synth_set_chorus_full(fluid_synth_t *synth, int fx_group, int set,227const double values[]);228229fluid_sample_timer_t *new_fluid_sample_timer(fluid_synth_t *synth, fluid_timer_callback_t callback, void *data);230void delete_fluid_sample_timer(fluid_synth_t *synth, fluid_sample_timer_t *timer);231void fluid_sample_timer_reset(fluid_synth_t *synth, fluid_sample_timer_t *timer);232233void fluid_synth_process_event_queue(fluid_synth_t *synth);234235int236fluid_synth_process_LOCAL(fluid_synth_t *synth, int len, int nfx, float *fx[],237int nout, float *out[], int (*block_render_func)(fluid_synth_t *, int));238int239fluid_synth_write_float_LOCAL(fluid_synth_t *synth, int len,240void *lout, int loff, int lincr,241void *rout, int roff, int rincr,242int (*block_render_func)(fluid_synth_t *, int));243/*244* misc245*/246void fluid_synth_settings(fluid_settings_t *settings);247void fluid_synth_set_sample_rate_immediately(fluid_synth_t *synth, float sample_rate);248249250/* extern declared in fluid_synth_monopoly.c */251252int fluid_synth_noteon_mono_staccato(fluid_synth_t *synth, int chan, int key, int vel);253int fluid_synth_noteon_mono_LOCAL(fluid_synth_t *synth, int chan, int key, int vel);254int fluid_synth_noteoff_mono_LOCAL(fluid_synth_t *synth, int chan, int key);255int fluid_synth_noteon_monopoly_legato(fluid_synth_t *synth, int chan, int fromkey, int tokey, int vel);256int fluid_synth_noteoff_monopoly(fluid_synth_t *synth, int chan, int key, char Mono);257258fluid_voice_t *259fluid_synth_alloc_voice_LOCAL(fluid_synth_t *synth, fluid_sample_t *sample, int chan, int key, int vel, fluid_zone_range_t *zone_range);260261void fluid_synth_release_voice_on_same_note_LOCAL(fluid_synth_t *synth, int chan, int key);262#endif /* _FLUID_SYNTH_H */263264265