Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/fluidsynth/src/synth/fluid_synth.h
4396 views
1
/* FluidSynth - A Software Synthesizer
2
*
3
* Copyright (C) 2003 Peter Hanappe and others.
4
*
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.
9
*
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.
14
*
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
18
* 02110-1301, USA
19
*/
20
21
22
#ifndef _FLUID_SYNTH_H
23
#define _FLUID_SYNTH_H
24
25
26
/***************************************************************
27
*
28
* INCLUDES
29
*/
30
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_ladspa.h"
37
#include "fluid_midi_router.h"
38
#include "fluid_rvoice_event.h"
39
40
/***************************************************************
41
*
42
* DEFINES
43
*/
44
#define FLUID_NUM_PROGRAMS 128
45
#define DRUM_INST_BANK 128
46
47
#define FLUID_UNSET_PROGRAM 128 /* Program number used to unset a preset */
48
49
#define FLUID_REVERB_DEFAULT_DAMP 0.3f /**< Default reverb damping */
50
#define FLUID_REVERB_DEFAULT_LEVEL 0.7f /**< Default reverb level */
51
#define FLUID_REVERB_DEFAULT_ROOMSIZE 0.5f /**< Default reverb room size */
52
#define FLUID_REVERB_DEFAULT_WIDTH 0.8f /**< Default reverb width */
53
54
#define FLUID_CHORUS_DEFAULT_DEPTH 4.25f /**< Default chorus depth */
55
#define FLUID_CHORUS_DEFAULT_LEVEL 0.6f /**< Default chorus level */
56
#define FLUID_CHORUS_DEFAULT_N 3 /**< Default chorus voice count */
57
#define FLUID_CHORUS_DEFAULT_SPEED 0.2f /**< Default chorus speed */
58
#define FLUID_CHORUS_DEFAULT_TYPE FLUID_CHORUS_MOD_SINE /**< Default chorus waveform type */
59
60
/***************************************************************
61
*
62
* ENUM
63
*/
64
65
/**
66
* Bank Select MIDI message styles. Default style is GS.
67
*/
68
enum fluid_midi_bank_select
69
{
70
FLUID_BANK_STYLE_GM, /**< GM style, bank = 0 always (CC0/MSB and CC32/LSB ignored) */
71
FLUID_BANK_STYLE_GS, /**< GS style, bank = CC0/MSB (CC32/LSB ignored) */
72
FLUID_BANK_STYLE_XG, /**< XG style, bank = CC32/LSB (CC0/MSB ignored) */
73
FLUID_BANK_STYLE_MMA /**< MMA style bank = 128*MSB+LSB */
74
};
75
76
enum fluid_synth_status
77
{
78
FLUID_SYNTH_CLEAN,
79
FLUID_SYNTH_PLAYING,
80
FLUID_SYNTH_QUIET,
81
FLUID_SYNTH_STOPPED
82
};
83
84
#define SYNTH_REVERB_CHANNEL 0
85
#define SYNTH_CHORUS_CHANNEL 1
86
87
/*
88
* fluid_synth_t
89
*
90
* Mutual exclusion notes (as of 1.1.2):
91
*
92
* All variables are considered belongning to the "public API" thread,
93
* which processes all MIDI, except for:
94
*
95
* ticks_since_start - atomic, set by rendering thread only
96
* cpu_load - atomic, set by rendering thread only
97
* cur, curmax, dither_index - used by rendering thread only
98
* ladspa_fx - same instance copied in rendering thread. Synchronising handled internally.
99
*
100
*/
101
102
struct _fluid_synth_t
103
{
104
fluid_rec_mutex_t mutex; /**< Lock for public API */
105
int use_mutex; /**< Use mutex for all public API functions? */
106
int public_api_count; /**< How many times the mutex is currently locked */
107
108
fluid_settings_t *settings; /**< the synthesizer settings */
109
int device_id; /**< Device ID used for SYSEX messages */
110
int polyphony; /**< Maximum polyphony */
111
int with_reverb; /**< Should the synth use the built-in reverb unit? */
112
int with_chorus; /**< Should the synth use the built-in chorus unit? */
113
int verbose; /**< Turn verbose mode on? */
114
double sample_rate; /**< The sample rate */
115
int midi_channels; /**< the number of MIDI channels (>= 16) */
116
int bank_select; /**< the style of Bank Select MIDI messages */
117
int audio_channels; /**< the number of audio channels (1 channel=left+right) */
118
int audio_groups; /**< the number of (stereo) 'sub'groups from the synth.
119
Typically equal to audio_channels. */
120
int effects_channels; /**< the number of effects channels (>= 2) */
121
int effects_groups; /**< the number of effects units (>= 1) */
122
int state; /**< the synthesizer state */
123
fluid_atomic_int_t ticks_since_start; /**< the number of audio samples since the start */
124
unsigned int start; /**< the start in msec, as returned by system clock */
125
fluid_overflow_prio_t overflow; /**< parameters for overflow priority (aka voice-stealing) */
126
127
fluid_list_t *loaders; /**< the SoundFont loaders */
128
fluid_list_t *sfont; /**< List of fluid_sfont_info_t for each loaded SoundFont (remains until SoundFont is unloaded) */
129
int sfont_id; /**< Incrementing ID assigned to each loaded SoundFont */
130
fluid_list_t *fonts_to_be_unloaded; /**< list of timers that try to unload a soundfont */
131
132
float gain; /**< master gain */
133
fluid_channel_t **channel; /**< the channels */
134
int nvoice; /**< the length of the synthesis process array (max polyphony allowed) */
135
fluid_voice_t **voice; /**< the synthesis voices */
136
int active_voice_count; /**< count of active voices */
137
unsigned int noteid; /**< the id is incremented for every new note. it's used for noteoff's */
138
unsigned int storeid;
139
int fromkey_portamento; /**< fromkey portamento */
140
fluid_rvoice_eventhandler_t *eventhandler;
141
142
/**< Shadow of reverb parameter: roomsize, damping, width, level */
143
double reverb_param[FLUID_REVERB_PARAM_LAST];
144
145
/**< Shadow of chorus parameter: chorus number, level, speed, depth, type */
146
double chorus_param[FLUID_CHORUS_PARAM_LAST];
147
148
int cur; /**< the current sample in the audio buffers to be output */
149
int curmax; /**< current amount of samples present in the audio buffers */
150
int dither_index; /**< current index in random dither value buffer: fluid_synth_(write_s16|dither_s16) */
151
152
fluid_atomic_float_t cpu_load; /**< CPU load in percent (CPU time required / audio synthesized time * 100) */
153
154
fluid_tuning_t ***tuning; /**< 128 banks of 128 programs for the tunings */
155
fluid_private_t tuning_iter; /**< Tuning iterators per each thread */
156
157
fluid_sample_timer_t *sample_timers; /**< List of timers triggered before a block is processed */
158
unsigned int min_note_length_ticks; /**< If note-offs are triggered just after a note-on, they will be delayed */
159
160
int cores; /**< Number of CPU cores (1 by default) */
161
162
fluid_mod_t *default_mod; /**< the (dynamic) list of default modulators */
163
164
fluid_ladspa_fx_t *ladspa_fx; /**< Effects unit for LADSPA support */
165
enum fluid_iir_filter_type custom_filter_type; /**< filter type of the user-defined filter currently used for all voices */
166
enum fluid_iir_filter_flags custom_filter_flags; /**< filter type of the user-defined filter currently used for all voices */
167
};
168
169
/**
170
* Type definition of the synthesizer's audio callback function.
171
* @param synth FluidSynth instance
172
* @param len Count of audio frames to synthesize
173
* @param out1 Array to store left channel of audio to
174
* @param loff Offset index in 'out1' for first sample
175
* @param lincr Increment between samples stored to 'out1'
176
* @param out2 Array to store right channel of audio to
177
* @param roff Offset index in 'out2' for first sample
178
* @param rincr Increment between samples stored to 'out2'
179
*/
180
typedef int (*fluid_audio_callback_t)(fluid_synth_t *synth, int len,
181
void *out1, int loff, int lincr,
182
void *out2, int roff, int rincr);
183
184
typedef int (*fluid_audio_channels_callback_t)(fluid_synth_t *synth, int len,
185
int channels_count,
186
void *channels_out[], int channels_off[],
187
int channels_incr[]);
188
189
int
190
fluid_synth_write_float_channels_LOCAL(fluid_synth_t *synth, int len,
191
int channels_count,
192
void *channels_out[], int channels_off[],
193
int channels_incr[],
194
int (*block_render_func)(fluid_synth_t *, int));
195
196
int
197
fluid_synth_write_s16_channels(fluid_synth_t *synth, int len,
198
int channels_count,
199
void *channels_out[], int channels_off[],
200
int channels_incr[]);
201
int
202
fluid_synth_write_float_channels(fluid_synth_t *synth, int len,
203
int channels_count,
204
void *channels_out[], int channels_off[],
205
int channels_incr[]);
206
207
fluid_preset_t *fluid_synth_find_preset(fluid_synth_t *synth,
208
int banknum,
209
int prognum);
210
void fluid_synth_sfont_unref(fluid_synth_t *synth, fluid_sfont_t *sfont);
211
212
void fluid_synth_dither_s16(int *dither_index, int len, const float *lin, const float *rin,
213
void *lout, int loff, int lincr,
214
void *rout, int roff, int rincr);
215
216
int fluid_synth_reset_reverb(fluid_synth_t *synth);
217
int fluid_synth_set_reverb_preset(fluid_synth_t *synth, unsigned int num);
218
int fluid_synth_reverb_set_param(fluid_synth_t *synth, int fx_group,
219
int param,
220
double value);
221
int fluid_synth_set_reverb_full(fluid_synth_t *synth, int fx_group, int set,
222
const double values[]);
223
224
int fluid_synth_reset_chorus(fluid_synth_t *synth);
225
int fluid_synth_chorus_set_param(fluid_synth_t *synth, int fx_group,
226
int param, double value);
227
int fluid_synth_set_chorus_full(fluid_synth_t *synth, int fx_group, int set,
228
const double values[]);
229
230
fluid_sample_timer_t *new_fluid_sample_timer(fluid_synth_t *synth, fluid_timer_callback_t callback, void *data);
231
void delete_fluid_sample_timer(fluid_synth_t *synth, fluid_sample_timer_t *timer);
232
void fluid_sample_timer_reset(fluid_synth_t *synth, fluid_sample_timer_t *timer);
233
234
void fluid_synth_process_event_queue(fluid_synth_t *synth);
235
236
int
237
fluid_synth_process_LOCAL(fluid_synth_t *synth, int len, int nfx, float *fx[],
238
int nout, float *out[], int (*block_render_func)(fluid_synth_t *, int));
239
int
240
fluid_synth_write_float_LOCAL(fluid_synth_t *synth, int len,
241
void *lout, int loff, int lincr,
242
void *rout, int roff, int rincr,
243
int (*block_render_func)(fluid_synth_t *, int));
244
/*
245
* misc
246
*/
247
void fluid_synth_settings(fluid_settings_t *settings);
248
void fluid_synth_set_sample_rate_immediately(fluid_synth_t *synth, float sample_rate);
249
250
251
/* extern declared in fluid_synth_monopoly.c */
252
253
int fluid_synth_noteon_mono_staccato(fluid_synth_t *synth, int chan, int key, int vel);
254
int fluid_synth_noteon_mono_LOCAL(fluid_synth_t *synth, int chan, int key, int vel);
255
int fluid_synth_noteoff_mono_LOCAL(fluid_synth_t *synth, int chan, int key);
256
int fluid_synth_noteon_monopoly_legato(fluid_synth_t *synth, int chan, int fromkey, int tokey, int vel);
257
int fluid_synth_noteoff_monopoly(fluid_synth_t *synth, int chan, int key, char Mono);
258
259
fluid_voice_t *
260
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);
261
262
void fluid_synth_release_voice_on_same_note_LOCAL(fluid_synth_t *synth, int chan, int key);
263
#endif /* _FLUID_SYNTH_H */
264
265