-
Notifications
You must be signed in to change notification settings - Fork 243
/
fluidsynth-v11-devdoc.txt
1768 lines (1560 loc) · 56.2 KB
/
fluidsynth-v11-devdoc.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
\mainpage FluidSynth 1.1 Developer Documentation
\author Peter Hanappe
\author Conrad Berhörster
\author Antoine Schmitt
\author Pedro López-Cabanillas
\author Josh Green
\author David Henningsson
\author Copyright © 2003-2011 Peter Hanappe, Conrad Berhörster, Antoine Schmitt, Pedro López-Cabanillas, Josh Green, David Henningsson
\version Revision 1.1.4
\date 2011-07-22
All the source code examples in this document are in the public domain; you can use them as you please. This document is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ . The FluidSynth library is distributed under the GNU Library General Public License. A copy of the GNU Library General Public License is contained in the FluidSynth package; if not, visit http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt or write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\section Abstract
<a href="http://www.fluidsynth.org">FluidSynth</a> is a software synthesizer based on the <a href="http://en.wikipedia.org/wiki/SoundFont">SoundFont 2</a> specifications. The synthesizer is available as a shared object that can easily be reused in any application that wants to use wave-table synthesis. This document explains the basic usage of FluidSynth. Some of the more advanced features are not yet discussed but will be added in future versions.
\section Contents Table of Contents
- \ref Disclaimer
- \ref Introduction
- \ref NewIn1_1_5
- \ref NewIn1_1_4
- \ref NewIn1_1_3
- \ref NewIn1_1_2
- \ref NewIn1_1_1
- \ref NewIn1_1_0
- \ref CreatingSettings
- \ref CreatingSynth
- \ref CreatingAudioDriver
- \ref UsingSynth
- \ref LoadingSoundfonts
- \ref SendingMIDI
- \ref RealtimeMIDI
- \ref MIDIPlayer
- \ref MIDIPlayerMem
- \ref MIDIRouter
- \ref Sequencer
- \ref Shell
- \ref Advanced
\section Disclaimer
This documentation, in its current version, is incomplete. As always, the source code is the final reference.
SoundFont(R) is a registered trademark of E-mu Systems, Inc.
\section Introduction
What is FluidSynth?
- FluidSynth is a software synthesizer based on the SoundFont 2 specifications. The synthesizer is available as a shared object (a concept also named Dynamic Linking Library, or DLL) that can be easily reused in any application for wave-table synthesis. This document explains the basic usage of FluidSynth.
- FluidSynth provides a Command Line Interface program ready to be used from the console terminal, offering most of the library functionalities to end users, among them the ability of render and play Standard MIDI Files, receive real-time MIDI events from external hardware ports and other applications, perform advanced routing of such events, enabling at the same time a local shell as well as a remote server commands interface.
- FluidSynth is an API (Application Programming Interface) relieving programmers from a lot of details of reading SoundFont and MIDI events and files, and sending the digital audio output to a Sound Card. These tasks can be accomplished using a small set of functions. This document explains most of the API functions and gives short examples about them.
- FluidSynth uses instrument samples contained in standard SF2 (SoundFont 2) files, having a file structure based on the RIFF format. The specification can be obtained here: http://connect.creativelabs.com/developer/SoundFont/Forms/AllItems.aspx but most users don't need to know any details of the format.
- FluidSynth can easily be embedded in an application. It has a main header file, fluidsynth.h, and one dynamically linkable library. FluidSynth runs on Linux, Mac OS X, and the Windows platforms, and support for OS/2 and OpenSolaris is experimental. It has audio and midi drivers for all mentioned platforms but you can use it with your own drivers if your application already handles MIDI and audio input/output. This document explains the basic usage of FluidSynth and provides examples that you can reuse.
- FluidSynth is open source, in active development. For more details, take a look at http://www.fluidsynth.org
\section NewIn1_1_5 Whats new in 1.1.5?
Changes in FluidSynth 1.1.5 concerning developers:
- A change in the Jack driver might require a newer Jack version compared to 1.1.4.
- For a full list of bug fixes, see
http://sourceforge.net/apps/trac/fluidsynth/wiki/ChangeLog1_1_5
\section NewIn1_1_4 Whats new in 1.1.4?
Changes in FluidSynth 1.1.4 concerning developers:
- You can now play MIDI files that reside in memory (instead of specifying a filename). See \ref MIDIPlayerMem for an example.
- A hook can be inserted for MIDI file playback, at playback time. This is done through the new fluid_player_set_playback_callback API function. You can use this to both inspect and modify MIDI events as they are being played (or add a MIDI router), just as you can for MIDI input drivers.
- Channel 10 used to be the one and only drum channel, this can now be changed using the fluid_synth_set_channel_type.
- fluid_synth_all_sounds_off and fluid_synth_all_notes_off are new public API functions. You can use them to turn notes off (i e releasing all keys, voices advance to release phase) or sounds off (more like pressing the mute button), for one channel or all channels.
- For Mac OS X users: The CoreAudio driver has been adapted to use AuHAL, and the default build style has changed to "FluidSynth.framework".
- For a full list of other enhancements and bug fixes, see
http://sourceforge.net/apps/trac/fluidsynth/wiki/ChangeLog1_1_4
\section NewIn1_1_3 Whats new in 1.1.3?
Changes in FluidSynth 1.1.3 concerning developers:
- There are no new API additions in 1.1.3, this is a pure bug-fix release.
For a list of bugs fixed, see
https://sourceforge.net/apps/trac/fluidsynth/wiki/ChangeLog1_1_3
\section NewIn1_1_2 Whats new in 1.1.2?
Changes in FluidSynth 1.1.2 concerning developers:
- Build system has switched from autotools to CMake. For more information, see
README.cmake. The autotools build system is still working, but it is
deprecated. The "winbuild" and "macbuild" directories have been dropped in
favor of CMake's ability to create project files on demand.
- Thread safety has been reworked to overcome the limitations and bugs in
version 1.1.0 and 1.1.1. There are two new settings controlling the thread
safety, synth.threadsafe-api and synth.parallel-render. More information
about these settings is in the \ref CreatingSettings section. Please look
them through and set them appropriately according to your use case.
- Voice overflow, i e what voice to kill when polyphony is exceeded, is now
configurable.
- Possibility to update polyphony and sample rate real-time. Note that
updating polyphony is not hard real-time safe, and updating sample rate will
kill all currently sounding voices.
- MIDI Bank Select handling is now configurable. See the synth.midi-bank-select
setting in the \ref CreatingSettings section for more information.
- Can use RealTimeKit (on Linux) to get real-time priority, if the original
attempt fails. Note that you'll need development headers for DBus to enable
this functionality.
- Shell commands for pitch bend and pitch bend range.
- PulseAudio driver: two new settings allows you to specify media role,
and control whether pulseaudio can adjust latency.
\section NewIn1_1_1 Whats new in 1.1.1?
Changes in FluidSynth 1.1.1 concerning developers:
- fluid_synth_get_channel_preset() marked as deprecated. New function
fluid_synth_get_channel_info() added which is thread safe and should replace
most uses of the older function.
- Added fluid_synth_unset_program() to unset the active preset on a channel.
\section NewIn1_1_0 Whats new in 1.1.0?
Overview of changes in FluidSynth 1.1.0 concerning developers:
- Extensive work to make FluidSynth thread safe. Previous versions had many multi-thread
issues which could lead to crashes or synthesis glitches. Some of the API additions,
deprecations and function recommended conditions of use are related to this work.
- File renderer object for rendering audio to files.
- Sequencer objects can now use the system timer or the sample clock. When using the sample
clock, events are triggered based on the current output audio sample position. This means
that MIDI is synchronized with the audio and identical output will be achieved for the same
MIDI event input.
- libsndfile support for rendering audio to different formats and file types.
- API for using the MIDI router subsystem.
- MIDI Tuning Standard functions were added for specifying whether to activate tuning changes
in realtime or not.
- SYSEX support (MIDI Tuning Standard only at the moment).
- Changed all yes/no boolean string settings to integer #FLUID_HINT_TOGGLED settings with
backwards compatibility (assignment and query of boolean values as strings).
- Many other improvements and bug fixes.
API additions:
- A file renderer can be created with new_fluid_file_renderer(), deleted with
delete_fluid_file_renderer() and a block of audio processed with fluid_file_renderer_process_block().
- Additional functions were added for using the MIDI router subsystem.
To clear all rules from a router use fluid_midi_router_clear_rules() and to set a router to default rules
use fluid_midi_router_set_default_rules().
To create a router rule use new_fluid_midi_router_rule() and to delete a rule use
delete_fluid_midi_router_rule() (seldom used). Set values of a router rule with
fluid_midi_router_rule_set_chan(), fluid_midi_router_rule_set_param1() and fluid_midi_router_rule_set_param2().
fluid_midi_router_add_rule() can be used to add a rule to a router.
- New MIDI event functions were added, including fluid_event_channel_pressure(), fluid_event_system_reset(),
and fluid_event_unregistering().
- Additional sequencer functions include fluid_sequencer_add_midi_event_to_buffer(),
fluid_sequencer_get_use_system_timer() and fluid_sequencer_process(). new_fluid_sequencer2() was added to
allow for the timer type to be specified (system or sample clock).
- The settings subsystem has some new functions for thread safety: fluid_settings_copystr() and fluid_settings_dupstr().
Also there are new convenience functions to count the number of string options for a setting: fluid_settings_option_count()
and for concatenating setting options with a separator: fluid_settings_option_concat().
- MIDI Tuning Standard functions added include: fluid_synth_activate_key_tuning(), fluid_synth_activate_octave_tuning(),
fluid_synth_activate_tuning() and fluid_synth_deactivate_tuning(). All of which provide a parameter for specifying if
tuning changes should occur in realtime (affect existing voices) or not.
- Additional synthesizer API: fluid_synth_get_sfont_by_name() to get a SoundFont by name,
fluid_synth_program_select_by_sfont_name() to select an instrument by SoundFont name/bank/program,
fluid_synth_set_gen2() for specifying additional parameters when assigning a generator value,
fluid_synth_sysex() for sending SYSEX messages to the synth and fluid_synth_get_active_voice_count() to
get the current number of active synthesis voices.
- Miscellaneous additions: fluid_player_set_loop() to set playlist loop count and fluid_player_get_status() to get current player state.
\section CreatingSettings Creating and changing the settings
Before you can use the synthesizer, you have to create a settings object. The settings objects is used by many components of the FluidSynth library. It gives a unified API to set the parameters of the audio drivers, the midi drivers, the synthesizer, and so forth. A number of default settings are defined by the current implementation.
All settings have a name that follows the "dotted-name" notation. For example, "synth.polyphony" refers to the number of voices (polyphony) preallocated by the synthesizer. The settings also have a type. There are currently three types: strings, numbers (double floats), and integers. You can change the values of a setting using the fluid_settings_setstr(), fluid_settings_setnum(), and fluid_settings_setint() functions. For example:
\code
#include <fluidsynth.h>
int main(int argc, char** argv)
{
fluid_settings_t* settings = new_fluid_settings();
fluid_synth_setint(settings, "synth.polyphony", 128);
/* ... */
delete_fluid_settings(settings);
return 0;
}
\endcode
The API contains the functions to query the type, the current value, the default value, the range and the "hints" of a setting. The range is the minimum and maximum value of the setting. The hints gives additional information about a setting. For example, whether a string represents a filename. Or whether a number should be interpreted on on a logarithmic scale. Check the settings.h API documentation for a description of all functions.
\section CreatingSynth Creating the synthesizer
To create the synthesizer, you pass it the settings object, as in the following example:
\code
#include <fluidsynth.h>
int main(int argc, char** argv)
{
fluid_settings_t* settings;
fluid_synth_t* synth;
settings = new_fluid_settings();
synth = new_fluid_synth(settings);
/* Do useful things here */
delete_fluid_synth(synth);
delete_fluid_settings(settings);
return 0;
}
\endcode
The following table provides details on all the settings used by the synthesizer.
<table border="1" cellspacing="0">
<caption>Table 1. Synthesizer settings</caption>
<tr>
<td>synth.audio-channels</td>
<td>Type</td>
<td>integer</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>1</td>
</tr>
<tr>
<td></td>
<td>Min-Max</td>
<td>1-128</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>By default, the synthesizer outputs a single stereo signal.
Using this option, the synthesizer can output multichannel
audio. Sets the number of stereo channel pairs. So 1 is actually
2 channels (a stereo pair).</td>
</tr>
<tr>
<td>synth.audio-groups</td>
<td>Type</td>
<td>integer</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>1</td>
</tr>
<tr>
<td></td>
<td>Min-Max</td>
<td>1-128</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>Normally the same value as synth.audio-channels. LADSPA
effects subsystem can use this value though, in which case it may
differ.</td>
</tr>
<tr>
<td>synth.chorus.active</td>
<td>Type</td>
<td>boolean</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>1 (TRUE)</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>When set to 1 (TRUE) the chorus effects module is activated.
Otherwise, no chorus will be added to the output signal. Note
that the amount of signal sent to the chorus module depends on the
"chorus send" generator defined in the SoundFont.</td>
</tr>
<tr>
<td>synth.cpu-cores</td>
<td>Type</td>
<td>integer</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>1</td>
</tr>
<tr>
<td></td>
<td>Min-Max</td>
<td>1-256</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>(Experimental) Sets the number of synthesis CPU cores. If set to a value
greater than 1, then additional synthesis threads will be created to take
advantage of a multi CPU or CPU core system. This has the affect of
utilizing more of the total CPU for voices or decreasing render times
when synthesizing audio to a file.</td>
</tr>
<tr>
<td>synth.device-id</td>
<td>Type</td>
<td>integer</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>0</td>
</tr>
<tr>
<td></td>
<td>Min-Max</td>
<td>0-126</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>Device identifier used for SYSEX commands, such as MIDI
Tuning Standard commands. Only those SYSEX commands destined
for this ID or to all devices will be acted upon.</td>
</tr>
<tr>
<td>synth.dump</td>
<td>Type</td>
<td>boolean</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>0 (FALSE)</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>Does nothing currently.</td>
</tr>
<tr>
<td>synth.effects-channels</td>
<td>Type</td>
<td>integer</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>2</td>
</tr>
<tr>
<td></td>
<td>Min-Max</td>
<td>2-2</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td></td>
</tr>
<tr>
<td>synth.gain</td>
<td>Type</td>
<td>number</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>0.2</td>
</tr>
<tr>
<td></td>
<td>Min-Max</td>
<td>0.0-10.0</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>The gain is applied to the final or master output of the
synthesizer. It is set to a low value by default to avoid the
saturation of the output when many notes are played.</td>
</tr>
<tr>
<td>synth.ladspa.active</td>
<td>Type</td>
<td>boolean</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>0 (FALSE)</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>When set to "yes" the LADSPA subsystem will be enabled. This
subsystem allows to load and interconnect LADSPA plug-ins. The
output of the synthesizer is processed by the LADSPA subsystem.
Note that the synthesizer has to be compiled with LADSPA
support. More information about the LADSPA subsystem
later.</td>
</tr>
<tr>
<td>synth.midi-channels</td>
<td>Type</td>
<td>integer</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>16</td>
</tr>
<tr>
<td></td>
<td>Min-Max</td>
<td>16-256</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>This setting defines the number of MIDI channels of the
synthesizer. The MIDI standard defines 16 channels, so MIDI
hardware is limited to this number. Internally FluidSynth can use
more channels which can be mapped to different MIDI sources.</td>
</tr>
<tr>
<td>synth.midi-bank-select</td>
<td>Type</td>
<td>string</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>gs</td>
</tr>
<tr>
<td></td>
<td>Options</td>
<td>gm, gs, xg, mma</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>This setting defines how the synthesizer interprets Bank Select messages.
<ul>
<li>gm: ignores CC0 and CC32 messages.</li>
<li>gs: (default) CC0 becomes the bank number, CC32 is ignored.</li>
<li>xg: CC32 becomes the bank number, CC0 is ignored.</li>
<li>mma: bank is calculated as CC0*128+CC32.</li>
</ul>
</td>
</tr>
<tr>
<td>synth.min-note-length</td>
<td>Type</td>
<td>integer</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>10</td>
</tr>
<tr>
<td></td>
<td>Min-Max</td>
<td>0-65535</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>Sets the minimum note duration in milliseconds. This
ensures that really short duration note events, such as
percussion notes, have a better chance of sounding as
intended. Set to 0 to disable this feature.</td>
</tr>
<tr>
<td>synth.parallel-render</td>
<td>Type</td>
<td>boolean</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>1 (TRUE)</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>synth.parallel-render is the low-latency setting. If on, you're allowed
to call fluid_synth_write_s16, fluid_synth_write_float,
fluid_synth_nwrite_float or fluid_synth_process in parallel with the
rest of the calls, and it won't be blocked by time intensive calls to
the synth. Turn it off if throughput is more important than latency, e g
in rendering-to-file scenarios where underruns is not an issue.</td>
</tr>
<tr>
<td>synth.polyphony</td>
<td>Type</td>
<td>integer</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>256</td>
</tr>
<tr>
<td></td>
<td>Min-Max</td>
<td>1-65535</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>The polyphony defines how many voices can be played in
parallel. A note event produces one or more voices.
Its good to set this to a value which the system can handle
and will thus limit FluidSynth's CPU usage. When FluidSynth
runs out of voices it will begin terminating lower priority
voices for new note events.</td>
</tr>
<tr>
<td>synth.reverb.active</td>
<td>Type</td>
<td>boolean</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>1 (TRUE)</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>When set to 1 (TRUE) the reverb effects module is activated.
Otherwise, no reverb will be added to the output signal. Note
that the amount of signal sent to the reverb module depends on the
"reverb send" generator defined in the SoundFont.</td>
</tr>
<tr>
<td>synth.sample-rate</td>
<td>Type</td>
<td>number</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>44100</td>
</tr>
<tr>
<td></td>
<td>Min-Max</td>
<td>22050-96000</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>The sample rate of the audio generated by the
synthesizer.</td>
</tr>
<tr>
<td>synth.threadsafe-api</td>
<td>Type</td>
<td>boolean</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>1 (TRUE)</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>synth.threadsafe-api controls whether the synth's public API is
protected by a mutex or not. Default is on, turn it off for slightly
better performance if you know you're only accessing the synth from one
thread only, this could be the case in many embedded use cases for
example. Note that libfluidsynth can use many threads by itself (shell
is one, midi driver is one, midi player is one etc) so you should usually
leave it on. Also see synth.parallel-render.</td>
</tr>
<tr>
<td>synth.verbose</td>
<td>Type</td>
<td>boolean</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>0 (FALSE)</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>When set to 1 (TRUE) the synthesizer will print out
information about the received MIDI events to the stdout. This
can be helpful for debugging. This setting cannot be changed
after the synthesizer has started.</td>
</tr>
</table>
\section CreatingAudioDriver Creating the Audio Driver
The synthesizer itself does not write any audio to the audio output. This allows application developers to manage the audio output themselves if they wish. The next section describes the use of the synthesizer without an audio driver in more detail.
Creating the audio driver is straightforward: set the appropriate settings and create the driver object. Because the FluidSynth has support for several audio systems, you may want to change which one you want to use. The list below shows the audio systems that are currently supported. It displays the name, as used by the fluidsynth library, and a description.
- jack: JACK Audio Connection Kit (Linux, Mac OS X, Windows)
- alsa: Advanced Linux Sound Architecture (Linux)
- oss: Open Sound System (Linux, Unix)
- pulseaudio: PulseAudio (Linux, Mac OS X, Windows)
- coreaudio: Apple CoreAudio (Mac OS X)
- dsound: Microsoft DirectSound (Windows)
- portaudio: PortAudio Library (Mac OS 9 & X, Windows, Linux)
- sndman: Apple SoundManager (Mac OS Classic)
- dart: DART sound driver (OS/2)
- file: Driver to output audio to a file
The default audio driver depends on the settings with which FluidSynth was compiled. You can get the default driver with fluid_settings_getstr_default(). To get the list of available drivers use the fluid_settings_foreach_option() function. Finally, you can set the driver with fluid_settings_setstr(). In most cases, the default driver should work out of the box.
Additional options that define the audio quality and latency are "audio.sample-format", "audio.period-size", and "audio.periods". The details are described later.
You create the audio driver with the new_fluid_audio_driver() function. This function takes the settings and synthesizer object as arguments. For example:
\code
void init()
{
fluid_settings_t* settings;
fluid_synth_t* synth;
fluid_audio_driver_t* adriver;
settings = new_fluid_settings();
/* Set the synthesizer settings, if necessary */
synth = new_fluid_synth(settings);
fluid_settings_setstr(settings, "audio.driver", "jack");
adriver = new_fluid_audio_driver(settings, synth);
}
\endcode
As soon as the audio driver is created, it will start playing. The audio driver creates a separate thread that uses the synthesizer object to generate the audio.
There are a number of general audio driver settings. The audio.driver settings define the audio subsystem that will be used. The audio.periods and audio.period-size settings define the latency and robustness against scheduling delays. There are additional settings for the audio subsystems used which are documented in another table.
<table border="1" cellspacing="0">
<caption>Table 2. General audio driver settings</caption>
<tr>
<td>audio.driver</td>
<td>Type</td>
<td>string</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>jack (Linux), dsound (Windows), sndman (MacOS9), coreaudio
(Mac OS X), dart (OS/2)</td>
</tr>
<tr>
<td></td>
<td>Options</td>
<td>jack, alsa, oss, pulseaudio, coreaudio, dsound, portaudio, sndman, dart, file</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>The audio system to be used.</td>
</tr>
<tr>
<td>audio.periods</td>
<td>Type</td>
<td>int</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>16 (Linux, Mac OS X), 8 (Windows)</td>
</tr>
<tr>
<td></td>
<td>Min-Max</td>
<td>2-64</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>The number of the audio buffers used by the driver. This
number of buffers, multiplied by the buffer size (see setting
audio.period-size), determines the maximum latency of the audio
driver.</td>
</tr>
<tr>
<td>audio.period-size</td>
<td>Type</td>
<td>integer</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>64 (Linux, Mac OS X), 512 (Windows)</td>
</tr>
<tr>
<td></td>
<td>Min-Max</td>
<td>64-8192</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>The size of the audio buffers (in frames).</td>
</tr>
<tr>
<td>audio.realtime-prio</td>
<td>Type</td>
<td>integer</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>60</td>
</tr>
<tr>
<td></td>
<td>Min-Max</td>
<td>0-99</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>Sets the realtime scheduling priority of the audio synthesis thread
(0 disables high priority scheduling). Linux is the only platform which
currently makes use of different priority levels. Drivers which use this
option: alsa, oss and pulseaudio</td>
</tr>
<tr>
<td>audio.sample-format</td>
<td>Type</td>
<td>string</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>"16bits"</td>
</tr>
<tr>
<td></td>
<td>Options</td>
<td>"16bits", "float"</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>The format of the audio samples. This is currently only an
indication; the audio driver may ignore this setting if it
can't handle the specified format.</td>
</tr>
</table>
The following table describes audio driver specific settings.
<table border="1" cellspacing="0">
<caption>Table 3. Audio driver specific settings</caption>
<tr>
<td>audio.alsa.device</td>
<td>Type</td>
<td>string</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>"default"</td>
</tr>
<tr>
<td></td>
<td>Options</td>
<td>ALSA device string, such as: "hw:0", "plughw:1", etc.</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>Selects the ALSA audio device to use.</td>
</tr>
<tr>
<td>audio.coreaudio.device</td>
<td>Type</td>
<td>string</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>"default"</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>Selects the CoreAudio device to use.</td>
</tr>
<tr>
<td>audio.dart.device</td>
<td>Type</td>
<td>string</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>"default"</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>Selects the Dart (OS/2 driver) device to use.</td>
</tr>
<tr>
<td>audio.dsound.device</td>
<td>Type</td>
<td>string</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>"default"</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>Selects the DirectSound (Windows) device to use.</td>
</tr>
<tr>
<td>audio.file.endian</td>
<td>Type</td>
<td>string</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>'auto' if libsndfile support is built in, 'cpu' otherwise.</td>
</tr>
<tr>
<td></td>
<td>Options</td>
<td>auto, big, cpu, little ('cpu' is all that is supported if libsndfile
support is not built in)</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>Defines the byte order when using the 'file' driver or file renderer to
store audio to a file. 'auto' uses the default for the given file type,
'cpu' uses the CPU byte order, 'big' uses big endian byte order and 'little' uses
little endian byte order.</td>
</tr>
<tr>
<td>audio.file.format</td>
<td>Type</td>
<td>string</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>s16</td>
</tr>
<tr>
<td></td>
<td>Options</td>
<td>double, float, s16, s24, s32, s8, u8 ('s16' is all that is supported if
libsndfile support not built in)</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>Defines the audio format when rendering audio to a file. 'double' is
64 bit floating point, 'float' is 32 bit floating point, 's16' is 16 bit signed
PCM, 's24' is 24 bit signed PCM, 's32' is 32 bit signed PCM, 's8' is 8 bit
signed PCM and 'u8' is 8 bit unsigned PCM.</td>
</tr>
<tr>
<td>audio.file.name</td>
<td>Type</td>
<td>string</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>'fluidsynth.wav' if libsndfile support is built in, 'fluidsynth.raw'
otherwise.</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>Specifies the file name to store the audio to, when rendering audio to
a file.</td>
</tr>
<tr>
<td>audio.file.type</td>
<td>Type</td>
<td>string</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>'auto' if libsndfile support is built in, 'raw' otherwise.</td>
</tr>
<tr>
<td></td>
<td>Options</td>
<td>aiff, au, auto, avr, caf, flac, htk, iff, mat, oga, paf, pvf, raw, sd2, sds,
sf, voc, w64, wav, xi (actual list of types may vary and depends on the
libsndfile library used, 'raw' is the only type available if no libsndfile
support is built in).</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>Sets the file type of the file which the audio will be stored to.
'auto' attempts to determine the file type from the audio.file.name file
extension and falls back to 'wav' if the extension doesn't match any types.</td>
</tr>
<tr>
<td>audio.jack.autoconnect</td>
<td>Type</td>
<td>boolean</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>0 (FALSE)</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>If 1 (TRUE), then FluidSynth output is automatically connected to jack
system audio output.</td>
</tr>
<tr>
<td>audio.jack.id</td>
<td>Type</td>
<td>string</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>fluidsynth</td>
</tr>
<tr>
<td></td>
<td>Description</td>
<td>ID used when creating Jack client connection.</td>
</tr>
<tr>
<td>audio.jack.multi</td>
<td>Type</td>
<td>boolean</td>
</tr>
<tr>
<td></td>
<td>Default</td>
<td>0 (FALSE)</td>
</tr>