1 /* FluidSynth - A Software Synthesizer
3 * Copyright (C) 2003 Peter Hanappe and others.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * as published by the Free Software Foundation; either version 2.1 of
8 * the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 #ifndef _FLUID_SYNTH_H
23 #define _FLUID_SYNTH_H
26 /***************************************************************
31 #include "fluid_sys.h"
32 #include "fluid_list.h"
33 #include "fluid_rev.h"
34 #include "fluid_voice.h"
35 #include "fluid_chorus.h"
36 #include "fluid_rvoice_event.h"
38 /***************************************************************
42 #define FLUID_NUM_PROGRAMS 128
43 #define DRUM_INST_BANK 128
45 #define FLUID_UNSET_PROGRAM 128 /* Program number used to unset a preset */
47 #define FLUID_REVERB_DEFAULT_ROOMSIZE 0.2f /**< Default reverb room size */
48 #define FLUID_REVERB_DEFAULT_DAMP 0.0f /**< Default reverb damping */
49 #define FLUID_REVERB_DEFAULT_WIDTH 0.5f /**< Default reverb width */
50 #define FLUID_REVERB_DEFAULT_LEVEL 0.9f /**< Default reverb level */
52 #define FLUID_CHORUS_DEFAULT_N 3 /**< Default chorus voice count */
53 #define FLUID_CHORUS_DEFAULT_LEVEL 2.0f /**< Default chorus level */
54 #define FLUID_CHORUS_DEFAULT_SPEED 0.3f /**< Default chorus speed */
55 #define FLUID_CHORUS_DEFAULT_DEPTH 8.0f /**< Default chorus depth */
56 #define FLUID_CHORUS_DEFAULT_TYPE FLUID_CHORUS_MOD_SINE /**< Default chorus waveform type */
58 /***************************************************************
64 * Bank Select MIDI message styles. Default style is GS.
66 enum fluid_midi_bank_select
68 FLUID_BANK_STYLE_GM, /**< GM style, bank = 0 always (CC0/MSB and CC32/LSB ignored) */
69 FLUID_BANK_STYLE_GS, /**< GS style, bank = CC0/MSB (CC32/LSB ignored) */
70 FLUID_BANK_STYLE_XG, /**< XG style, bank = CC32/LSB (CC0/MSB ignored) */
71 FLUID_BANK_STYLE_MMA /**< MMA style bank = 128*MSB+LSB */
74 enum fluid_synth_status
82 #define SYNTH_REVERB_CHANNEL 0
83 #define SYNTH_CHORUS_CHANNEL 1
88 * Mutual exclusion notes (as of 1.1.2):
90 * All variables are considered belongning to the "public API" thread,
91 * which processes all MIDI, except for:
93 * ticks_since_start - atomic, set by rendering thread only
94 * cpu_load - atomic, set by rendering thread only
95 * cur, curmax, dither_index - used by rendering thread only
96 * ladspa_fx - same instance copied in rendering thread. Synchronising handled internally.
100 struct _fluid_synth_t
102 fluid_rec_mutex_t mutex; /**< Lock for public API */
103 int use_mutex; /**< Use mutex for all public API functions? */
104 int public_api_count; /**< How many times the mutex is currently locked */
106 fluid_settings_t *settings; /**< the synthesizer settings */
107 int device_id; /**< Device ID used for SYSEX messages */
108 int polyphony; /**< Maximum polyphony */
109 int with_reverb; /**< Should the synth use the built-in reverb unit? */
110 int with_chorus; /**< Should the synth use the built-in chorus unit? */
111 int verbose; /**< Turn verbose mode on? */
112 double sample_rate; /**< The sample rate */
113 int midi_channels; /**< the number of MIDI channels (>= 16) */
114 int bank_select; /**< the style of Bank Select MIDI messages */
115 int audio_channels; /**< the number of audio channels (1 channel=left+right) */
116 int audio_groups; /**< the number of (stereo) 'sub'groups from the synth.
117 Typically equal to audio_channels. */
118 int effects_channels; /**< the number of effects channels (>= 2) */
119 int effects_groups; /**< the number of effects units (>= 1) */
120 int state; /**< the synthesizer state */
121 fluid_atomic_uint_t ticks_since_start; /**< the number of audio samples since the start */
122 unsigned int start; /**< the start in msec, as returned by system clock */
123 fluid_overflow_prio_t overflow; /**< parameters for overflow priority (aka voice-stealing) */
125 fluid_list_t *loaders; /**< the SoundFont loaders */
126 fluid_list_t *sfont; /**< List of fluid_sfont_info_t for each loaded SoundFont (remains until SoundFont is unloaded) */
127 int sfont_id; /**< Incrementing ID assigned to each loaded SoundFont */
129 float gain; /**< master gain */
130 fluid_channel_t **channel; /**< the channels */
131 int nvoice; /**< the length of the synthesis process array (max polyphony allowed) */
132 fluid_voice_t **voice; /**< the synthesis voices */
133 int active_voice_count; /**< count of active voices */
134 unsigned int noteid; /**< the id is incremented for every new note. it's used for noteoff's */
135 unsigned int storeid;
136 int fromkey_portamento; /**< fromkey portamento */
137 fluid_rvoice_eventhandler_t *eventhandler;
139 double reverb_roomsize; /**< Shadow of reverb roomsize */
140 double reverb_damping; /**< Shadow of reverb damping */
141 double reverb_width; /**< Shadow of reverb width */
142 double reverb_level; /**< Shadow of reverb level */
144 int chorus_nr; /**< Shadow of chorus number */
145 double chorus_level; /**< Shadow of chorus level */
146 double chorus_speed; /**< Shadow of chorus speed */
147 double chorus_depth; /**< Shadow of chorus depth */
148 int chorus_type; /**< Shadow of chorus type */
150 int cur; /**< the current sample in the audio buffers to be output */
151 int curmax; /**< current amount of samples present in the audio buffers */
152 int dither_index; /**< current index in random dither value buffer: fluid_synth_(write_s16|dither_s16) */
154 fluid_atomic_float_t cpu_load; /**< CPU load in percent (CPU time required / audio synthesized time * 100) */
156 fluid_tuning_t ***tuning; /**< 128 banks of 128 programs for the tunings */
157 fluid_private_t tuning_iter; /**< Tuning iterators per each thread */
159 fluid_sample_timer_t *sample_timers; /**< List of timers triggered before a block is processed */
160 unsigned int min_note_length_ticks; /**< If note-offs are triggered just after a note-on, they will be delayed */
162 int cores; /**< Number of CPU cores (1 by default) */
164 fluid_mod_t *default_mod; /**< the (dynamic) list of default modulators */
167 fluid_ladspa_fx_t *ladspa_fx; /**< Effects unit for LADSPA support */
169 enum fluid_iir_filter_type custom_filter_type; /**< filter type of the user-defined filter currently used for all voices */
170 enum fluid_iir_filter_flags custom_filter_flags; /**< filter type of the user-defined filter currently used for all voices */
174 * Type definition of the synthesizer's audio callback function.
175 * @param synth FluidSynth instance
176 * @param len Count of audio frames to synthesize
177 * @param out1 Array to store left channel of audio to
178 * @param loff Offset index in 'out1' for first sample
179 * @param lincr Increment between samples stored to 'out1'
180 * @param out2 Array to store right channel of audio to
181 * @param roff Offset index in 'out2' for first sample
182 * @param rincr Increment between samples stored to 'out2'
184 typedef int (*fluid_audio_callback_t)(fluid_synth_t *synth, int len,
185 void *out1, int loff, int lincr,
186 void *out2, int roff, int rincr);
188 fluid_preset_t *fluid_synth_find_preset(fluid_synth_t *synth,
191 void fluid_synth_sfont_unref(fluid_synth_t *synth, fluid_sfont_t *sfont);
193 void fluid_synth_dither_s16(int *dither_index, int len, float *lin, float *rin,
194 void *lout, int loff, int lincr,
195 void *rout, int roff, int rincr);
197 int fluid_synth_reset_reverb(fluid_synth_t *synth);
198 int fluid_synth_set_reverb_preset(fluid_synth_t *synth, unsigned int num);
199 int fluid_synth_set_reverb_full(fluid_synth_t *synth, int set, double roomsize,
200 double damping, double width, double level);
202 int fluid_synth_reset_chorus(fluid_synth_t *synth);
203 int fluid_synth_set_chorus_full(fluid_synth_t *synth, int set, int nr, double level,
204 double speed, double depth_ms, int type);
206 fluid_sample_timer_t *new_fluid_sample_timer(fluid_synth_t *synth, fluid_timer_callback_t callback, void *data);
207 void delete_fluid_sample_timer(fluid_synth_t *synth, fluid_sample_timer_t *timer);
210 void fluid_synth_process_event_queue(fluid_synth_t *synth);
212 int fluid_synth_set_gen2(fluid_synth_t *synth, int chan,
213 int param, float value,
214 int absolute, int normalized);
218 void fluid_synth_settings(fluid_settings_t *settings);
221 /* extern declared in fluid_synth_monopoly.c */
223 int fluid_synth_noteon_mono_staccato(fluid_synth_t *synth, int chan, int key, int vel);
224 int fluid_synth_noteon_mono_LOCAL(fluid_synth_t *synth, int chan, int key, int vel);
225 int fluid_synth_noteoff_mono_LOCAL(fluid_synth_t *synth, int chan, int key);
226 int fluid_synth_noteon_monopoly_legato(fluid_synth_t *synth, int chan, int fromkey, int tokey, int vel);
227 int fluid_synth_noteoff_monopoly(fluid_synth_t *synth, int chan, int key, char Mono);
230 fluid_synth_alloc_voice_LOCAL(fluid_synth_t *synth, fluid_sample_t *sample, int chan, int key, int vel, fluid_zone_range_t *zone_range);
232 void fluid_synth_release_voice_on_same_note_LOCAL(fluid_synth_t *synth, int chan, int key);
233 #endif /* _FLUID_SYNTH_H */