PageRenderTime 62ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/FluidSynthWrapper/fluidsynth-1.0.8/doc/api/html/fluid__synth_8c-source.html

#
HTML | 3138 lines | 3137 code | 0 blank | 1 comment | 0 complexity | 852e724c5ee1c951e40c9f8660cfb603 MD5 | raw file
Possible License(s): LGPL-2.0, MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
  3. <title>libfluidsynth: src/fluid_synth.c Source File</title>
  4. <link href="doxygen.css" rel="stylesheet" type="text/css">
  5. <link href="tabs.css" rel="stylesheet" type="text/css">
  6. </head><body>
  7. <!-- Generated by Doxygen 1.5.3 -->
  8. <div class="tabs">
  9. <ul>
  10. <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
  11. <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
  12. <li class="current"><a href="files.html"><span>Files</span></a></li>
  13. </ul>
  14. </div>
  15. <h1>src/fluid_synth.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* FluidSynth - A Software Synthesizer</span>
  16. <a name="l00002"></a>00002 <span class="comment"> *</span>
  17. <a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2003 Peter Hanappe and others.</span>
  18. <a name="l00004"></a>00004 <span class="comment"> *</span>
  19. <a name="l00005"></a>00005 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
  20. <a name="l00006"></a>00006 <span class="comment"> * modify it under the terms of the GNU Library General Public License</span>
  21. <a name="l00007"></a>00007 <span class="comment"> * as published by the Free Software Foundation; either version 2 of</span>
  22. <a name="l00008"></a>00008 <span class="comment"> * the License, or (at your option) any later version.</span>
  23. <a name="l00009"></a>00009 <span class="comment"> *</span>
  24. <a name="l00010"></a>00010 <span class="comment"> * This library is distributed in the hope that it will be useful, but</span>
  25. <a name="l00011"></a>00011 <span class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</span>
  26. <a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span>
  27. <a name="l00013"></a>00013 <span class="comment"> * Library General Public License for more details.</span>
  28. <a name="l00014"></a>00014 <span class="comment"> *</span>
  29. <a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU Library General Public</span>
  30. <a name="l00016"></a>00016 <span class="comment"> * License along with this library; if not, write to the Free</span>
  31. <a name="l00017"></a>00017 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA</span>
  32. <a name="l00018"></a>00018 <span class="comment"> * 02111-1307, USA</span>
  33. <a name="l00019"></a>00019 <span class="comment"> */</span>
  34. <a name="l00020"></a>00020
  35. <a name="l00021"></a>00021 <span class="preprocessor">#include &lt;math.h&gt;</span>
  36. <a name="l00022"></a>00022
  37. <a name="l00023"></a>00023 <span class="preprocessor">#include "fluid_synth.h"</span>
  38. <a name="l00024"></a>00024 <span class="preprocessor">#include "fluid_sys.h"</span>
  39. <a name="l00025"></a>00025 <span class="preprocessor">#include "fluid_chan.h"</span>
  40. <a name="l00026"></a>00026 <span class="preprocessor">#include "fluid_tuning.h"</span>
  41. <a name="l00027"></a>00027 <span class="preprocessor">#include "fluid_settings.h"</span>
  42. <a name="l00028"></a>00028 <span class="preprocessor">#include "fluid_sfont.h"</span>
  43. <a name="l00029"></a>00029
  44. <a name="l00030"></a>00030 <span class="preprocessor">#ifdef TRAP_ON_FPE</span>
  45. <a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#define _GNU_SOURCE</span>
  46. <a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#include &lt;fenv.h&gt;</span>
  47. <a name="l00033"></a>00033
  48. <a name="l00034"></a>00034 <span class="comment">/* seems to not be declared in fenv.h */</span>
  49. <a name="l00035"></a>00035 <span class="keyword">extern</span> <span class="keywordtype">int</span> feenableexcept (<span class="keywordtype">int</span> excepts);
  50. <a name="l00036"></a>00036 <span class="preprocessor">#endif</span>
  51. <a name="l00037"></a>00037 <span class="preprocessor"></span>
  52. <a name="l00038"></a>00038
  53. <a name="l00039"></a>00039 <a class="code" href="struct__fluid__sfloader__t.html">fluid_sfloader_t</a>* new_fluid_defsfloader(<span class="keywordtype">void</span>);
  54. <a name="l00040"></a>00040
  55. <a name="l00041"></a>00041 <span class="comment">/************************************************************************</span>
  56. <a name="l00042"></a>00042 <span class="comment"> *</span>
  57. <a name="l00043"></a>00043 <span class="comment"> * These functions were added after the v1.0 API freeze. They are not</span>
  58. <a name="l00044"></a>00044 <span class="comment"> * in synth.h. They should be added as soon as a new development</span>
  59. <a name="l00045"></a>00045 <span class="comment"> * version is started.</span>
  60. <a name="l00046"></a>00046 <span class="comment"> *</span>
  61. <a name="l00047"></a>00047 <span class="comment"> ************************************************************************/</span>
  62. <a name="l00048"></a>00048
  63. <a name="l00049"></a>00049 <span class="keywordtype">int</span> fluid_synth_program_select2(fluid_synth_t* synth,
  64. <a name="l00050"></a>00050 <span class="keywordtype">int</span> chan,
  65. <a name="l00051"></a>00051 <span class="keywordtype">char</span>* sfont_name,
  66. <a name="l00052"></a>00052 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> bank_num,
  67. <a name="l00053"></a>00053 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> preset_num);
  68. <a name="l00054"></a>00054
  69. <a name="l00055"></a>00055 <a class="code" href="struct__fluid__sfont__t.html">fluid_sfont_t</a>* fluid_synth_get_sfont_by_name(fluid_synth_t* synth, <span class="keywordtype">char</span> *name);
  70. <a name="l00056"></a>00056
  71. <a name="l00057"></a>00057 <span class="keywordtype">int</span> fluid_synth_set_gen2(fluid_synth_t* synth, <span class="keywordtype">int</span> chan,
  72. <a name="l00058"></a>00058 <span class="keywordtype">int</span> param, <span class="keywordtype">float</span> value,
  73. <a name="l00059"></a>00059 <span class="keywordtype">int</span> absolute, <span class="keywordtype">int</span> normalized);
  74. <a name="l00060"></a>00060
  75. <a name="l00061"></a>00061
  76. <a name="l00062"></a>00062 <span class="comment">/***************************************************************</span>
  77. <a name="l00063"></a>00063 <span class="comment"> *</span>
  78. <a name="l00064"></a>00064 <span class="comment"> * GLOBAL</span>
  79. <a name="l00065"></a>00065 <span class="comment"> */</span>
  80. <a name="l00066"></a>00066
  81. <a name="l00067"></a>00067 <span class="comment">/* has the synth module been initialized? */</span>
  82. <a name="l00068"></a>00068 <span class="keyword">static</span> <span class="keywordtype">int</span> fluid_synth_initialized = 0;
  83. <a name="l00069"></a>00069 <span class="keyword">static</span> <span class="keywordtype">void</span> fluid_synth_init(<span class="keywordtype">void</span>);
  84. <a name="l00070"></a>00070 <span class="keyword">static</span> <span class="keywordtype">void</span> init_dither(<span class="keywordtype">void</span>);
  85. <a name="l00071"></a>00071
  86. <a name="l00072"></a>00072 <span class="comment">/* default modulators</span>
  87. <a name="l00073"></a>00073 <span class="comment"> * SF2.01 page 52 ff:</span>
  88. <a name="l00074"></a>00074 <span class="comment"> *</span>
  89. <a name="l00075"></a>00075 <span class="comment"> * There is a set of predefined default modulators. They have to be</span>
  90. <a name="l00076"></a>00076 <span class="comment"> * explicitly overridden by the sound font in order to turn them off.</span>
  91. <a name="l00077"></a>00077 <span class="comment"> */</span>
  92. <a name="l00078"></a>00078
  93. <a name="l00079"></a>00079 <a class="code" href="struct__fluid__mod__t.html">fluid_mod_t</a> default_vel2att_mod; <span class="comment">/* SF2.01 section 8.4.1 */</span>
  94. <a name="l00080"></a>00080 <a class="code" href="struct__fluid__mod__t.html">fluid_mod_t</a> default_vel2filter_mod; <span class="comment">/* SF2.01 section 8.4.2 */</span>
  95. <a name="l00081"></a>00081 <a class="code" href="struct__fluid__mod__t.html">fluid_mod_t</a> default_at2viblfo_mod; <span class="comment">/* SF2.01 section 8.4.3 */</span>
  96. <a name="l00082"></a>00082 <a class="code" href="struct__fluid__mod__t.html">fluid_mod_t</a> default_mod2viblfo_mod; <span class="comment">/* SF2.01 section 8.4.4 */</span>
  97. <a name="l00083"></a>00083 <a class="code" href="struct__fluid__mod__t.html">fluid_mod_t</a> default_att_mod; <span class="comment">/* SF2.01 section 8.4.5 */</span>
  98. <a name="l00084"></a>00084 <a class="code" href="struct__fluid__mod__t.html">fluid_mod_t</a> default_pan_mod; <span class="comment">/* SF2.01 section 8.4.6 */</span>
  99. <a name="l00085"></a>00085 <a class="code" href="struct__fluid__mod__t.html">fluid_mod_t</a> default_expr_mod; <span class="comment">/* SF2.01 section 8.4.7 */</span>
  100. <a name="l00086"></a>00086 <a class="code" href="struct__fluid__mod__t.html">fluid_mod_t</a> default_reverb_mod; <span class="comment">/* SF2.01 section 8.4.8 */</span>
  101. <a name="l00087"></a>00087 <a class="code" href="struct__fluid__mod__t.html">fluid_mod_t</a> default_chorus_mod; <span class="comment">/* SF2.01 section 8.4.9 */</span>
  102. <a name="l00088"></a>00088 <a class="code" href="struct__fluid__mod__t.html">fluid_mod_t</a> default_pitch_bend_mod; <span class="comment">/* SF2.01 section 8.4.10 */</span>
  103. <a name="l00089"></a>00089
  104. <a name="l00090"></a>00090 <span class="comment">/* reverb presets */</span>
  105. <a name="l00091"></a>00091 <span class="keyword">static</span> fluid_revmodel_presets_t revmodel_preset[] = {
  106. <a name="l00092"></a>00092 <span class="comment">/* name */</span> <span class="comment">/* roomsize */</span> <span class="comment">/* damp */</span> <span class="comment">/* width */</span> <span class="comment">/* level */</span>
  107. <a name="l00093"></a>00093 { <span class="stringliteral">"Test 1"</span>, 0.2f, 0.0f, 0.5f, 0.9f },
  108. <a name="l00094"></a>00094 { <span class="stringliteral">"Test 2"</span>, 0.4f, 0.2f, 0.5f, 0.8f },
  109. <a name="l00095"></a>00095 { <span class="stringliteral">"Test 3"</span>, 0.6f, 0.4f, 0.5f, 0.7f },
  110. <a name="l00096"></a>00096 { <span class="stringliteral">"Test 4"</span>, 0.8f, 0.7f, 0.5f, 0.6f },
  111. <a name="l00097"></a>00097 { <span class="stringliteral">"Test 5"</span>, 0.8f, 1.0f, 0.5f, 0.5f },
  112. <a name="l00098"></a>00098 { NULL, 0.0f, 0.0f, 0.0f, 0.0f }
  113. <a name="l00099"></a>00099 };
  114. <a name="l00100"></a>00100
  115. <a name="l00101"></a>00101
  116. <a name="l00102"></a>00102 <span class="comment">/***************************************************************</span>
  117. <a name="l00103"></a>00103 <span class="comment"> *</span>
  118. <a name="l00104"></a>00104 <span class="comment"> * INITIALIZATION &amp; UTILITIES</span>
  119. <a name="l00105"></a>00105 <span class="comment"> */</span>
  120. <a name="l00106"></a>00106
  121. <a name="l00107"></a>00107
  122. <a name="l00108"></a>00108 <span class="keywordtype">void</span> fluid_synth_settings(fluid_settings_t* settings)
  123. <a name="l00109"></a>00109 {
  124. <a name="l00110"></a>00110 fluid_settings_register_str(settings, <span class="stringliteral">"synth.verbose"</span>, <span class="stringliteral">"no"</span>, 0, NULL, NULL);
  125. <a name="l00111"></a>00111 fluid_settings_register_str(settings, <span class="stringliteral">"synth.dump"</span>, <span class="stringliteral">"no"</span>, 0, NULL, NULL);
  126. <a name="l00112"></a>00112 fluid_settings_register_str(settings, <span class="stringliteral">"synth.reverb.active"</span>, <span class="stringliteral">"yes"</span>, 0, NULL, NULL);
  127. <a name="l00113"></a>00113 fluid_settings_register_str(settings, <span class="stringliteral">"synth.chorus.active"</span>, <span class="stringliteral">"yes"</span>, 0, NULL, NULL);
  128. <a name="l00114"></a>00114 fluid_settings_register_str(settings, <span class="stringliteral">"synth.ladspa.active"</span>, <span class="stringliteral">"no"</span>, 0, NULL, NULL);
  129. <a name="l00115"></a>00115
  130. <a name="l00116"></a>00116 fluid_settings_register_int(settings, <span class="stringliteral">"synth.polyphony"</span>,
  131. <a name="l00117"></a>00117 256, 16, 4096, 0, NULL, NULL);
  132. <a name="l00118"></a>00118 fluid_settings_register_int(settings, <span class="stringliteral">"synth.midi-channels"</span>,
  133. <a name="l00119"></a>00119 16, 16, 256, 0, NULL, NULL);
  134. <a name="l00120"></a>00120 fluid_settings_register_num(settings, <span class="stringliteral">"synth.gain"</span>,
  135. <a name="l00121"></a>00121 0.2f, 0.0f, 10.0f,
  136. <a name="l00122"></a>00122 0, NULL, NULL);
  137. <a name="l00123"></a>00123 fluid_settings_register_int(settings, <span class="stringliteral">"synth.audio-channels"</span>,
  138. <a name="l00124"></a>00124 1, 1, 256, 0, NULL, NULL);
  139. <a name="l00125"></a>00125 fluid_settings_register_int(settings, <span class="stringliteral">"synth.audio-groups"</span>,
  140. <a name="l00126"></a>00126 1, 1, 256, 0, NULL, NULL);
  141. <a name="l00127"></a>00127 fluid_settings_register_int(settings, <span class="stringliteral">"synth.effects-channels"</span>,
  142. <a name="l00128"></a>00128 2, 2, 2, 0, NULL, NULL);
  143. <a name="l00129"></a>00129 fluid_settings_register_num(settings, <span class="stringliteral">"synth.sample-rate"</span>,
  144. <a name="l00130"></a>00130 44100.0f, 22050.0f, 96000.0f,
  145. <a name="l00131"></a>00131 0, NULL, NULL);
  146. <a name="l00132"></a>00132 }
  147. <a name="l00133"></a>00133
  148. <a name="l00134"></a>00134 <span class="comment">/*</span>
  149. <a name="l00135"></a>00135 <span class="comment"> * fluid_version</span>
  150. <a name="l00136"></a>00136 <span class="comment"> */</span>
  151. <a name="l00137"></a>00137 <span class="keywordtype">void</span> fluid_version(<span class="keywordtype">int</span> *major, <span class="keywordtype">int</span> *minor, <span class="keywordtype">int</span> *micro)
  152. <a name="l00138"></a>00138 {
  153. <a name="l00139"></a>00139 *major = FLUIDSYNTH_VERSION_MAJOR;
  154. <a name="l00140"></a>00140 *minor = FLUIDSYNTH_VERSION_MINOR;
  155. <a name="l00141"></a>00141 *micro = FLUIDSYNTH_VERSION_MICRO;
  156. <a name="l00142"></a>00142 }
  157. <a name="l00143"></a>00143
  158. <a name="l00144"></a>00144 <span class="comment">/*</span>
  159. <a name="l00145"></a>00145 <span class="comment"> * fluid_version_str</span>
  160. <a name="l00146"></a>00146 <span class="comment"> */</span>
  161. <a name="l00147"></a>00147 <span class="keywordtype">char</span>* fluid_version_str(<span class="keywordtype">void</span>)
  162. <a name="l00148"></a>00148 {
  163. <a name="l00149"></a>00149 <span class="keywordflow">return</span> FLUIDSYNTH_VERSION;
  164. <a name="l00150"></a>00150 }
  165. <a name="l00151"></a>00151
  166. <a name="l00152"></a>00152
  167. <a name="l00153"></a>00153 <span class="comment">/*</span>
  168. <a name="l00154"></a>00154 <span class="comment"> * void fluid_synth_init</span>
  169. <a name="l00155"></a>00155 <span class="comment"> *</span>
  170. <a name="l00156"></a>00156 <span class="comment"> * Does all the initialization for this module.</span>
  171. <a name="l00157"></a>00157 <span class="comment"> */</span>
  172. <a name="l00158"></a>00158 <span class="keyword">static</span> <span class="keywordtype">void</span>
  173. <a name="l00159"></a>00159 fluid_synth_init()
  174. <a name="l00160"></a>00160 {
  175. <a name="l00161"></a>00161 fluid_synth_initialized++;
  176. <a name="l00162"></a>00162
  177. <a name="l00163"></a>00163 <span class="preprocessor">#ifdef TRAP_ON_FPE</span>
  178. <a name="l00164"></a>00164 <span class="preprocessor"></span> <span class="comment">/* Turn on floating point exception traps */</span>
  179. <a name="l00165"></a>00165 feenableexcept (FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID);
  180. <a name="l00166"></a>00166 <span class="preprocessor">#endif</span>
  181. <a name="l00167"></a>00167 <span class="preprocessor"></span>
  182. <a name="l00168"></a>00168 fluid_conversion_config();
  183. <a name="l00169"></a>00169
  184. <a name="l00170"></a>00170 fluid_dsp_float_config();
  185. <a name="l00171"></a>00171
  186. <a name="l00172"></a>00172 fluid_sys_config();
  187. <a name="l00173"></a>00173
  188. <a name="l00174"></a>00174 init_dither();
  189. <a name="l00175"></a>00175
  190. <a name="l00176"></a>00176
  191. <a name="l00177"></a>00177 <span class="comment">/* SF2.01 page 53 section 8.4.1: MIDI Note-On Velocity to Initial Attenuation */</span>
  192. <a name="l00178"></a>00178 fluid_mod_set_source1(&amp;default_vel2att_mod, <span class="comment">/* The modulator we are programming here */</span>
  193. <a name="l00179"></a>00179 FLUID_MOD_VELOCITY, <span class="comment">/* Source. VELOCITY corresponds to 'index=2'. */</span>
  194. <a name="l00180"></a>00180 FLUID_MOD_GC <span class="comment">/* Not a MIDI continuous controller */</span>
  195. <a name="l00181"></a>00181 | FLUID_MOD_CONCAVE <span class="comment">/* Curve shape. Corresponds to 'type=1' */</span>
  196. <a name="l00182"></a>00182 | FLUID_MOD_UNIPOLAR <span class="comment">/* Polarity. Corresponds to 'P=0' */</span>
  197. <a name="l00183"></a>00183 | FLUID_MOD_NEGATIVE <span class="comment">/* Direction. Corresponds to 'D=1' */</span>
  198. <a name="l00184"></a>00184 );
  199. <a name="l00185"></a>00185 fluid_mod_set_source2(&amp;default_vel2att_mod, 0, 0); <span class="comment">/* No 2nd source */</span>
  200. <a name="l00186"></a>00186 fluid_mod_set_dest(&amp;default_vel2att_mod, <a class="code" href="gen_8h.html#d17a24ae3b25f3b8cc5762f818eef9b42db65ad593aeff4e814f9a7b7324c0df" title="Initial volume attenuation.">GEN_ATTENUATION</a>); <span class="comment">/* Target: Initial attenuation */</span>
  201. <a name="l00187"></a>00187 fluid_mod_set_amount(&amp;default_vel2att_mod, 960.0); <span class="comment">/* Modulation amount: 960 */</span>
  202. <a name="l00188"></a>00188
  203. <a name="l00189"></a>00189
  204. <a name="l00190"></a>00190
  205. <a name="l00191"></a>00191 <span class="comment">/* SF2.01 page 53 section 8.4.2: MIDI Note-On Velocity to Filter Cutoff</span>
  206. <a name="l00192"></a>00192 <span class="comment"> * Have to make a design decision here. The specs don't make any sense this way or another.</span>
  207. <a name="l00193"></a>00193 <span class="comment"> * One sound font, 'Kingston Piano', which has been praised for its quality, tries to</span>
  208. <a name="l00194"></a>00194 <span class="comment"> * override this modulator with an amount of 0 and positive polarity (instead of what</span>
  209. <a name="l00195"></a>00195 <span class="comment"> * the specs say, D=1) for the secondary source.</span>
  210. <a name="l00196"></a>00196 <span class="comment"> * So if we change the polarity to 'positive', one of the best free sound fonts works...</span>
  211. <a name="l00197"></a>00197 <span class="comment"> */</span>
  212. <a name="l00198"></a>00198 fluid_mod_set_source1(&amp;default_vel2filter_mod, FLUID_MOD_VELOCITY, <span class="comment">/* Index=2 */</span>
  213. <a name="l00199"></a>00199 FLUID_MOD_GC <span class="comment">/* CC=0 */</span>
  214. <a name="l00200"></a>00200 | FLUID_MOD_LINEAR <span class="comment">/* type=0 */</span>
  215. <a name="l00201"></a>00201 | FLUID_MOD_UNIPOLAR <span class="comment">/* P=0 */</span>
  216. <a name="l00202"></a>00202 | FLUID_MOD_NEGATIVE <span class="comment">/* D=1 */</span>
  217. <a name="l00203"></a>00203 );
  218. <a name="l00204"></a>00204 fluid_mod_set_source2(&amp;default_vel2filter_mod, FLUID_MOD_VELOCITY, <span class="comment">/* Index=2 */</span>
  219. <a name="l00205"></a>00205 FLUID_MOD_GC <span class="comment">/* CC=0 */</span>
  220. <a name="l00206"></a>00206 | FLUID_MOD_SWITCH <span class="comment">/* type=3 */</span>
  221. <a name="l00207"></a>00207 | FLUID_MOD_UNIPOLAR <span class="comment">/* P=0 */</span>
  222. <a name="l00208"></a>00208 <span class="comment">// do not remove | FLUID_MOD_NEGATIVE /* D=1 */</span>
  223. <a name="l00209"></a>00209 | FLUID_MOD_POSITIVE <span class="comment">/* D=0 */</span>
  224. <a name="l00210"></a>00210 );
  225. <a name="l00211"></a>00211 fluid_mod_set_dest(&amp;default_vel2filter_mod, <a class="code" href="gen_8h.html#d17a24ae3b25f3b8cc5762f818eef9b4e43e689b0b6349a676d26ea3096ed8d2" title="Filter cutoff.">GEN_FILTERFC</a>); <span class="comment">/* Target: Initial filter cutoff */</span>
  226. <a name="l00212"></a>00212 fluid_mod_set_amount(&amp;default_vel2filter_mod, -2400);
  227. <a name="l00213"></a>00213
  228. <a name="l00214"></a>00214
  229. <a name="l00215"></a>00215
  230. <a name="l00216"></a>00216 <span class="comment">/* SF2.01 page 53 section 8.4.3: MIDI Channel pressure to Vibrato LFO pitch depth */</span>
  231. <a name="l00217"></a>00217 fluid_mod_set_source1(&amp;default_at2viblfo_mod, FLUID_MOD_CHANNELPRESSURE, <span class="comment">/* Index=13 */</span>
  232. <a name="l00218"></a>00218 FLUID_MOD_GC <span class="comment">/* CC=0 */</span>
  233. <a name="l00219"></a>00219 | FLUID_MOD_LINEAR <span class="comment">/* type=0 */</span>
  234. <a name="l00220"></a>00220 | FLUID_MOD_UNIPOLAR <span class="comment">/* P=0 */</span>
  235. <a name="l00221"></a>00221 | FLUID_MOD_POSITIVE <span class="comment">/* D=0 */</span>
  236. <a name="l00222"></a>00222 );
  237. <a name="l00223"></a>00223 fluid_mod_set_source2(&amp;default_at2viblfo_mod, 0,0); <span class="comment">/* no second source */</span>
  238. <a name="l00224"></a>00224 fluid_mod_set_dest(&amp;default_at2viblfo_mod, <a class="code" href="gen_8h.html#d17a24ae3b25f3b8cc5762f818eef9b499387606556a9024de640b4519f7e559" title="Vibrato LFO to pitch.">GEN_VIBLFOTOPITCH</a>); <span class="comment">/* Target: Vib. LFO =&gt; pitch */</span>
  239. <a name="l00225"></a>00225 fluid_mod_set_amount(&amp;default_at2viblfo_mod, 50);
  240. <a name="l00226"></a>00226
  241. <a name="l00227"></a>00227
  242. <a name="l00228"></a>00228
  243. <a name="l00229"></a>00229 <span class="comment">/* SF2.01 page 53 section 8.4.4: Mod wheel (Controller 1) to Vibrato LFO pitch depth */</span>
  244. <a name="l00230"></a>00230 fluid_mod_set_source1(&amp;default_mod2viblfo_mod, 1, <span class="comment">/* Index=1 */</span>
  245. <a name="l00231"></a>00231 FLUID_MOD_CC <span class="comment">/* CC=1 */</span>
  246. <a name="l00232"></a>00232 | FLUID_MOD_LINEAR <span class="comment">/* type=0 */</span>
  247. <a name="l00233"></a>00233 | FLUID_MOD_UNIPOLAR <span class="comment">/* P=0 */</span>
  248. <a name="l00234"></a>00234 | FLUID_MOD_POSITIVE <span class="comment">/* D=0 */</span>
  249. <a name="l00235"></a>00235 );
  250. <a name="l00236"></a>00236 fluid_mod_set_source2(&amp;default_mod2viblfo_mod, 0,0); <span class="comment">/* no second source */</span>
  251. <a name="l00237"></a>00237 fluid_mod_set_dest(&amp;default_mod2viblfo_mod, <a class="code" href="gen_8h.html#d17a24ae3b25f3b8cc5762f818eef9b499387606556a9024de640b4519f7e559" title="Vibrato LFO to pitch.">GEN_VIBLFOTOPITCH</a>); <span class="comment">/* Target: Vib. LFO =&gt; pitch */</span>
  252. <a name="l00238"></a>00238 fluid_mod_set_amount(&amp;default_mod2viblfo_mod, 50);
  253. <a name="l00239"></a>00239
  254. <a name="l00240"></a>00240
  255. <a name="l00241"></a>00241
  256. <a name="l00242"></a>00242 <span class="comment">/* SF2.01 page 55 section 8.4.5: MIDI continuous controller 7 to initial attenuation*/</span>
  257. <a name="l00243"></a>00243 fluid_mod_set_source1(&amp;default_att_mod, 7, <span class="comment">/* index=7 */</span>
  258. <a name="l00244"></a>00244 FLUID_MOD_CC <span class="comment">/* CC=1 */</span>
  259. <a name="l00245"></a>00245 | FLUID_MOD_CONCAVE <span class="comment">/* type=1 */</span>
  260. <a name="l00246"></a>00246 | FLUID_MOD_UNIPOLAR <span class="comment">/* P=0 */</span>
  261. <a name="l00247"></a>00247 | FLUID_MOD_NEGATIVE <span class="comment">/* D=1 */</span>
  262. <a name="l00248"></a>00248 );
  263. <a name="l00249"></a>00249 fluid_mod_set_source2(&amp;default_att_mod, 0, 0); <span class="comment">/* No second source */</span>
  264. <a name="l00250"></a>00250 fluid_mod_set_dest(&amp;default_att_mod, <a class="code" href="gen_8h.html#d17a24ae3b25f3b8cc5762f818eef9b42db65ad593aeff4e814f9a7b7324c0df" title="Initial volume attenuation.">GEN_ATTENUATION</a>); <span class="comment">/* Target: Initial attenuation */</span>
  265. <a name="l00251"></a>00251 fluid_mod_set_amount(&amp;default_att_mod, 960.0); <span class="comment">/* Amount: 960 */</span>
  266. <a name="l00252"></a>00252
  267. <a name="l00253"></a>00253
  268. <a name="l00254"></a>00254
  269. <a name="l00255"></a>00255 <span class="comment">/* SF2.01 page 55 section 8.4.6 MIDI continuous controller 10 to Pan Position */</span>
  270. <a name="l00256"></a>00256 fluid_mod_set_source1(&amp;default_pan_mod, 10, <span class="comment">/* index=10 */</span>
  271. <a name="l00257"></a>00257 FLUID_MOD_CC <span class="comment">/* CC=1 */</span>
  272. <a name="l00258"></a>00258 | FLUID_MOD_LINEAR <span class="comment">/* type=0 */</span>
  273. <a name="l00259"></a>00259 | FLUID_MOD_BIPOLAR <span class="comment">/* P=1 */</span>
  274. <a name="l00260"></a>00260 | FLUID_MOD_POSITIVE <span class="comment">/* D=0 */</span>
  275. <a name="l00261"></a>00261 );
  276. <a name="l00262"></a>00262 fluid_mod_set_source2(&amp;default_pan_mod, 0, 0); <span class="comment">/* No second source */</span>
  277. <a name="l00263"></a>00263 fluid_mod_set_dest(&amp;default_pan_mod, <a class="code" href="gen_8h.html#d17a24ae3b25f3b8cc5762f818eef9b45b713ab8c931017d98f11b5ed5a81fb1" title="Stereo panning.">GEN_PAN</a>); <span class="comment">/* Target: pan */</span>
  278. <a name="l00264"></a>00264 <span class="comment">/* Amount: 500. The SF specs $8.4.6, p. 55 syas: "Amount = 1000</span>
  279. <a name="l00265"></a>00265 <span class="comment"> tenths of a percent". The center value (64) corresponds to 50%,</span>
  280. <a name="l00266"></a>00266 <span class="comment"> so it follows that amount = 50% x 1000/% = 500. */</span>
  281. <a name="l00267"></a>00267 fluid_mod_set_amount(&amp;default_pan_mod, 500.0);
  282. <a name="l00268"></a>00268
  283. <a name="l00269"></a>00269
  284. <a name="l00270"></a>00270 <span class="comment">/* SF2.01 page 55 section 8.4.7: MIDI continuous controller 11 to initial attenuation*/</span>
  285. <a name="l00271"></a>00271 fluid_mod_set_source1(&amp;default_expr_mod, 11, <span class="comment">/* index=11 */</span>
  286. <a name="l00272"></a>00272 FLUID_MOD_CC <span class="comment">/* CC=1 */</span>
  287. <a name="l00273"></a>00273 | FLUID_MOD_CONCAVE <span class="comment">/* type=1 */</span>
  288. <a name="l00274"></a>00274 | FLUID_MOD_UNIPOLAR <span class="comment">/* P=0 */</span>
  289. <a name="l00275"></a>00275 | FLUID_MOD_NEGATIVE <span class="comment">/* D=1 */</span>
  290. <a name="l00276"></a>00276 );
  291. <a name="l00277"></a>00277 fluid_mod_set_source2(&amp;default_expr_mod, 0, 0); <span class="comment">/* No second source */</span>
  292. <a name="l00278"></a>00278 fluid_mod_set_dest(&amp;default_expr_mod, <a class="code" href="gen_8h.html#d17a24ae3b25f3b8cc5762f818eef9b42db65ad593aeff4e814f9a7b7324c0df" title="Initial volume attenuation.">GEN_ATTENUATION</a>); <span class="comment">/* Target: Initial attenuation */</span>
  293. <a name="l00279"></a>00279 fluid_mod_set_amount(&amp;default_expr_mod, 960.0); <span class="comment">/* Amount: 960 */</span>
  294. <a name="l00280"></a>00280
  295. <a name="l00281"></a>00281
  296. <a name="l00282"></a>00282
  297. <a name="l00283"></a>00283 <span class="comment">/* SF2.01 page 55 section 8.4.8: MIDI continuous controller 91 to Reverb send */</span>
  298. <a name="l00284"></a>00284 fluid_mod_set_source1(&amp;default_reverb_mod, 91, <span class="comment">/* index=91 */</span>
  299. <a name="l00285"></a>00285 FLUID_MOD_CC <span class="comment">/* CC=1 */</span>
  300. <a name="l00286"></a>00286 | FLUID_MOD_LINEAR <span class="comment">/* type=0 */</span>
  301. <a name="l00287"></a>00287 | FLUID_MOD_UNIPOLAR <span class="comment">/* P=0 */</span>
  302. <a name="l00288"></a>00288 | FLUID_MOD_POSITIVE <span class="comment">/* D=0 */</span>
  303. <a name="l00289"></a>00289 );
  304. <a name="l00290"></a>00290 fluid_mod_set_source2(&amp;default_reverb_mod, 0, 0); <span class="comment">/* No second source */</span>
  305. <a name="l00291"></a>00291 fluid_mod_set_dest(&amp;default_reverb_mod, <a class="code" href="gen_8h.html#d17a24ae3b25f3b8cc5762f818eef9b48de830acd064933f55e0c1615d1e7f78" title="Reverb send amount.">GEN_REVERBSEND</a>); <span class="comment">/* Target: Reverb send */</span>
  306. <a name="l00292"></a>00292 fluid_mod_set_amount(&amp;default_reverb_mod, 200); <span class="comment">/* Amount: 200 ('tenths of a percent') */</span>
  307. <a name="l00293"></a>00293
  308. <a name="l00294"></a>00294
  309. <a name="l00295"></a>00295
  310. <a name="l00296"></a>00296 <span class="comment">/* SF2.01 page 55 section 8.4.9: MIDI continuous controller 93 to Reverb send */</span>
  311. <a name="l00297"></a>00297 fluid_mod_set_source1(&amp;default_chorus_mod, 93, <span class="comment">/* index=93 */</span>
  312. <a name="l00298"></a>00298 FLUID_MOD_CC <span class="comment">/* CC=1 */</span>
  313. <a name="l00299"></a>00299 | FLUID_MOD_LINEAR <span class="comment">/* type=0 */</span>
  314. <a name="l00300"></a>00300 | FLUID_MOD_UNIPOLAR <span class="comment">/* P=0 */</span>
  315. <a name="l00301"></a>00301 | FLUID_MOD_POSITIVE <span class="comment">/* D=0 */</span>
  316. <a name="l00302"></a>00302 );
  317. <a name="l00303"></a>00303 fluid_mod_set_source2(&amp;default_chorus_mod, 0, 0); <span class="comment">/* No second source */</span>
  318. <a name="l00304"></a>00304 fluid_mod_set_dest(&amp;default_chorus_mod, <a class="code" href="gen_8h.html#d17a24ae3b25f3b8cc5762f818eef9b420dc580d6c53d30eb97efe3e910793b6" title="Chorus send amount.">GEN_CHORUSSEND</a>); <span class="comment">/* Target: Chorus */</span>
  319. <a name="l00305"></a>00305 fluid_mod_set_amount(&amp;default_chorus_mod, 200); <span class="comment">/* Amount: 200 ('tenths of a percent') */</span>
  320. <a name="l00306"></a>00306
  321. <a name="l00307"></a>00307
  322. <a name="l00308"></a>00308
  323. <a name="l00309"></a>00309 <span class="comment">/* SF2.01 page 57 section 8.4.10 MIDI Pitch Wheel to Initial Pitch ... */</span>
  324. <a name="l00310"></a>00310 fluid_mod_set_source1(&amp;default_pitch_bend_mod, FLUID_MOD_PITCHWHEEL, <span class="comment">/* Index=14 */</span>
  325. <a name="l00311"></a>00311 FLUID_MOD_GC <span class="comment">/* CC =0 */</span>
  326. <a name="l00312"></a>00312 | FLUID_MOD_LINEAR <span class="comment">/* type=0 */</span>
  327. <a name="l00313"></a>00313 | FLUID_MOD_BIPOLAR <span class="comment">/* P=1 */</span>
  328. <a name="l00314"></a>00314 | FLUID_MOD_POSITIVE <span class="comment">/* D=0 */</span>
  329. <a name="l00315"></a>00315 );
  330. <a name="l00316"></a>00316 fluid_mod_set_source2(&amp;default_pitch_bend_mod, FLUID_MOD_PITCHWHEELSENS, <span class="comment">/* Index = 16 */</span>
  331. <a name="l00317"></a>00317 FLUID_MOD_GC <span class="comment">/* CC=0 */</span>
  332. <a name="l00318"></a>00318 | FLUID_MOD_LINEAR <span class="comment">/* type=0 */</span>
  333. <a name="l00319"></a>00319 | FLUID_MOD_UNIPOLAR <span class="comment">/* P=0 */</span>
  334. <a name="l00320"></a>00320 | FLUID_MOD_POSITIVE <span class="comment">/* D=0 */</span>
  335. <a name="l00321"></a>00321 );
  336. <a name="l00322"></a>00322 fluid_mod_set_dest(&amp;default_pitch_bend_mod, <a class="code" href="gen_8h.html#d17a24ae3b25f3b8cc5762f818eef9b4b9a5716b5af1baf131a6225da6687ff0" title="Pitch (NOTE: Not a real SoundFont generator).">GEN_PITCH</a>); <span class="comment">/* Destination: Initial pitch */</span>
  337. <a name="l00323"></a>00323 fluid_mod_set_amount(&amp;default_pitch_bend_mod, 12700.0); <span class="comment">/* Amount: 12700 cents */</span>
  338. <a name="l00324"></a>00324 }
  339. <a name="l00325"></a>00325
  340. <a name="l00326"></a>00326
  341. <a name="l00327"></a>00327 <span class="keywordtype">int</span> fluid_synth_verify_settings(fluid_settings_t *settings)
  342. <a name="l00328"></a>00328 {
  343. <a name="l00329"></a>00329 <span class="keywordflow">return</span> 0;
  344. <a name="l00330"></a>00330 }
  345. <a name="l00331"></a>00331
  346. <a name="l00332"></a>00332 <span class="comment">/***************************************************************</span>
  347. <a name="l00333"></a>00333 <span class="comment"> *</span>
  348. <a name="l00334"></a>00334 <span class="comment"> * FLUID SYNTH</span>
  349. <a name="l00335"></a>00335 <span class="comment"> */</span>
  350. <a name="l00336"></a>00336
  351. <a name="l00337"></a>00337 <span class="comment">/*</span>
  352. <a name="l00338"></a>00338 <span class="comment"> * new_fluid_synth</span>
  353. <a name="l00339"></a>00339 <span class="comment"> */</span>
  354. <a name="l00340"></a>00340 fluid_synth_t*
  355. <a name="l00341"></a>00341 new_fluid_synth(fluid_settings_t *settings)
  356. <a name="l00342"></a>00342 {
  357. <a name="l00343"></a>00343 <span class="keywordtype">int</span> i;
  358. <a name="l00344"></a>00344 fluid_synth_t* synth;
  359. <a name="l00345"></a>00345 <a class="code" href="struct__fluid__sfloader__t.html">fluid_sfloader_t</a>* loader;
  360. <a name="l00346"></a>00346
  361. <a name="l00347"></a>00347 <span class="comment">/* initialize all the conversion tables and other stuff */</span>
  362. <a name="l00348"></a>00348 <span class="keywordflow">if</span> (fluid_synth_initialized == 0) {
  363. <a name="l00349"></a>00349 fluid_synth_init();
  364. <a name="l00350"></a>00350 }
  365. <a name="l00351"></a>00351
  366. <a name="l00352"></a>00352 fluid_synth_verify_settings(settings);
  367. <a name="l00353"></a>00353
  368. <a name="l00354"></a>00354 <span class="comment">/* allocate a new synthesizer object */</span>
  369. <a name="l00355"></a>00355 synth = FLUID_NEW(fluid_synth_t);
  370. <a name="l00356"></a>00356 <span class="keywordflow">if</span> (synth == NULL) {
  371. <a name="l00357"></a>00357 FLUID_LOG(<a class="code" href="log_8h.html#a341232c15addd9c336131984840ed9ebc0ff48d192b3b0fc721946ccf095d25" title="Serious error occurred.">FLUID_ERR</a>, <span class="stringliteral">"Out of memory"</span>);
  372. <a name="l00358"></a>00358 <span class="keywordflow">return</span> NULL;
  373. <a name="l00359"></a>00359 }
  374. <a name="l00360"></a>00360 FLUID_MEMSET(synth, 0, <span class="keyword">sizeof</span>(fluid_synth_t));
  375. <a name="l00361"></a>00361
  376. <a name="l00362"></a>00362 fluid_mutex_init(synth-&gt;busy);
  377. <a name="l00363"></a>00363
  378. <a name="l00364"></a>00364 synth-&gt;settings = settings;
  379. <a name="l00365"></a>00365
  380. <a name="l00366"></a>00366 synth-&gt;with_reverb = fluid_settings_str_equal(settings, <span class="stringliteral">"synth.reverb.active"</span>, <span class="stringliteral">"yes"</span>);
  381. <a name="l00367"></a>00367 synth-&gt;with_chorus = fluid_settings_str_equal(settings, <span class="stringliteral">"synth.chorus.active"</span>, <span class="stringliteral">"yes"</span>);
  382. <a name="l00368"></a>00368 synth-&gt;verbose = fluid_settings_str_equal(settings, <span class="stringliteral">"synth.verbose"</span>, <span class="stringliteral">"yes"</span>);
  383. <a name="l00369"></a>00369 synth-&gt;dump = fluid_settings_str_equal(settings, <span class="stringliteral">"synth.dump"</span>, <span class="stringliteral">"yes"</span>);
  384. <a name="l00370"></a>00370
  385. <a name="l00371"></a>00371 fluid_settings_getint(settings, <span class="stringliteral">"synth.polyphony"</span>, &amp;synth-&gt;polyphony);
  386. <a name="l00372"></a>00372 fluid_settings_getnum(settings, <span class="stringliteral">"synth.sample-rate"</span>, &amp;synth-&gt;sample_rate);
  387. <a name="l00373"></a>00373 fluid_settings_getint(settings, <span class="stringliteral">"synth.midi-channels"</span>, &amp;synth-&gt;midi_channels);
  388. <a name="l00374"></a>00374 fluid_settings_getint(settings, <span class="stringliteral">"synth.audio-channels"</span>, &amp;synth-&gt;audio_channels);
  389. <a name="l00375"></a>00375 fluid_settings_getint(settings, <span class="stringliteral">"synth.audio-groups"</span>, &amp;synth-&gt;audio_groups);
  390. <a name="l00376"></a>00376 fluid_settings_getint(settings, <span class="stringliteral">"synth.effects-channels"</span>, &amp;synth-&gt;effects_channels);
  391. <a name="l00377"></a>00377 fluid_settings_getnum(settings, <span class="stringliteral">"synth.gain"</span>, &amp;synth-&gt;gain);
  392. <a name="l00378"></a>00378
  393. <a name="l00379"></a>00379 <span class="comment">/* register the callbacks */</span>
  394. <a name="l00380"></a>00380 fluid_settings_register_num(settings, <span class="stringliteral">"synth.gain"</span>,
  395. <a name="l00381"></a>00381 0.2f, 0.0f, 10.0f, 0,
  396. <a name="l00382"></a>00382 (fluid_num_update_t) fluid_synth_update_gain, synth);
  397. <a name="l00383"></a>00383 fluid_settings_register_int(settings, <span class="stringliteral">"synth.polyphony"</span>,
  398. <a name="l00384"></a>00384 synth-&gt;polyphony, 16, 4096, 0,
  399. <a name="l00385"></a>00385 (fluid_int_update_t) fluid_synth_update_polyphony,
  400. <a name="l00386"></a>00386 synth);
  401. <a name="l00387"></a>00387
  402. <a name="l00388"></a>00388 <span class="comment">/* do some basic sanity checking on the settings */</span>
  403. <a name="l00389"></a>00389
  404. <a name="l00390"></a>00390 <span class="keywordflow">if</span> (synth-&gt;midi_channels % 16 != 0) {
  405. <a name="l00391"></a>00391 <span class="keywordtype">int</span> n = synth-&gt;midi_channels / 16;
  406. <a name="l00392"></a>00392 synth-&gt;midi_channels = (n + 1) * 16;
  407. <a name="l00393"></a>00393 fluid_settings_setint(settings, <span class="stringliteral">"synth.midi-channels"</span>, synth-&gt;midi_channels);
  408. <a name="l00394"></a>00394 FLUID_LOG(<a class="code" href="log_8h.html#a341232c15addd9c336131984840ed9e394460be1ec74fce15e1ff683606df0f" title="Warning.">FLUID_WARN</a>, <span class="stringliteral">"Requested number of MIDI channels is not a multiple of 16. "</span>
  409. <a name="l00395"></a>00395 <span class="stringliteral">"I'll increase the number of channels to the next multiple."</span>);
  410. <a name="l00396"></a>00396 }
  411. <a name="l00397"></a>00397
  412. <a name="l00398"></a>00398 <span class="keywordflow">if</span> (synth-&gt;audio_channels &lt; 1) {
  413. <a name="l00399"></a>00399 FLUID_LOG(<a class="code" href="log_8h.html#a341232c15addd9c336131984840ed9e394460be1ec74fce15e1ff683606df0f" title="Warning.">FLUID_WARN</a>, <span class="stringliteral">"Requested number of audio channels is smaller than 1. "</span>
  414. <a name="l00400"></a>00400 <span class="stringliteral">"Changing this setting to 1."</span>);
  415. <a name="l00401"></a>00401 synth-&gt;audio_channels = 1;
  416. <a name="l00402"></a>00402 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (synth-&gt;audio_channels &gt; 128) {
  417. <a name="l00403"></a>00403 FLUID_LOG(<a class="code" href="log_8h.html#a341232c15addd9c336131984840ed9e394460be1ec74fce15e1ff683606df0f" title="Warning.">FLUID_WARN</a>, <span class="stringliteral">"Requested number of audio channels is too big (%d). "</span>
  418. <a name="l00404"></a>00404 <span class="stringliteral">"Limiting this setting to 128."</span>, synth-&gt;audio_channels);
  419. <a name="l00405"></a>00405 synth-&gt;audio_channels = 128;
  420. <a name="l00406"></a>00406 }
  421. <a name="l00407"></a>00407
  422. <a name="l00408"></a>00408 <span class="keywordflow">if</span> (synth-&gt;audio_groups &lt; 1) {
  423. <a name="l00409"></a>00409 FLUID_LOG(<a class="code" href="log_8h.html#a341232c15addd9c336131984840ed9e394460be1ec74fce15e1ff683606df0f" title="Warning.">FLUID_WARN</a>, <span class="stringliteral">"Requested number of audio groups is smaller than 1. "</span>
  424. <a name="l00410"></a>00410 <span class="stringliteral">"Changing this setting to 1."</span>);
  425. <a name="l00411"></a>00411 synth-&gt;audio_groups = 1;
  426. <a name="l00412"></a>00412 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (synth-&gt;audio_groups &gt; 128) {
  427. <a name="l00413"></a>00413 FLUID_LOG(<a class="code" href="log_8h.html#a341232c15addd9c336131984840ed9e394460be1ec74fce15e1ff683606df0f" title="Warning.">FLUID_WARN</a>, <span class="stringliteral">"Requested number of audio groups is too big (%d). "</span>
  428. <a name="l00414"></a>00414 <span class="stringliteral">"Limiting this setting to 128."</span>, synth-&gt;audio_groups);
  429. <a name="l00415"></a>00415 synth-&gt;audio_groups = 128;
  430. <a name="l00416"></a>00416 }
  431. <a name="l00417"></a>00417
  432. <a name="l00418"></a>00418 <span class="keywordflow">if</span> (synth-&gt;effects_channels != 2) {
  433. <a name="l00419"></a>00419 FLUID_LOG(<a class="code" href="log_8h.html#a341232c15addd9c336131984840ed9e394460be1ec74fce15e1ff683606df0f" title="Warning.">FLUID_WARN</a>, <span class="stringliteral">"Invalid number of effects channels (%d)."</span>
  434. <a name="l00420"></a>00420 <span class="stringliteral">"Setting effects channels to 2."</span>, synth-&gt;effects_channels);
  435. <a name="l00421"></a>00421 synth-&gt;effects_channels = 2;
  436. <a name="l00422"></a>00422 }
  437. <a name="l00423"></a>00423
  438. <a name="l00424"></a>00424
  439. <a name="l00425"></a>00425 <span class="comment">/* The number of buffers is determined by the higher number of nr</span>
  440. <a name="l00426"></a>00426 <span class="comment"> * groups / nr audio channels. If LADSPA is unused, they should be</span>
  441. <a name="l00427"></a>00427 <span class="comment"> * the same. */</span>
  442. <a name="l00428"></a>00428 synth-&gt;nbuf = synth-&gt;audio_channels;
  443. <a name="l00429"></a>00429 <span class="keywordflow">if</span> (synth-&gt;audio_groups &gt; synth-&gt;nbuf) {
  444. <a name="l00430"></a>00430 synth-&gt;nbuf = synth-&gt;audio_groups;
  445. <a name="l00431"></a>00431 }
  446. <a name="l00432"></a>00432
  447. <a name="l00433"></a>00433 <span class="preprocessor">#ifdef LADSPA</span>
  448. <a name="l00434"></a>00434 <span class="preprocessor"></span> <span class="comment">/* Create and initialize the Fx unit.*/</span>
  449. <a name="l00435"></a>00435 synth-&gt;LADSPA_FxUnit = new_fluid_LADSPA_FxUnit(synth);
  450. <a name="l00436"></a>00436 <span class="preprocessor">#endif</span>
  451. <a name="l00437"></a>00437 <span class="preprocessor"></span>
  452. <a name="l00438"></a>00438 <span class="comment">/* as soon as the synth is created it starts playing. */</span>
  453. <a name="l00439"></a>00439 synth-&gt;state = FLUID_SYNTH_PLAYING;
  454. <a name="l00440"></a>00440 synth-&gt;sfont = NULL;
  455. <a name="l00441"></a>00441 synth-&gt;noteid = 0;
  456. <a name="l00442"></a>00442 synth-&gt;ticks = 0;
  457. <a name="l00443"></a>00443 synth-&gt;tuning = NULL;
  458. <a name="l00444"></a>00444
  459. <a name="l00445"></a>00445 <span class="comment">/* allocate and add the default sfont loader */</span>
  460. <a name="l00446"></a>00446 loader = new_fluid_defsfloader();
  461. <a name="l00447"></a>00447
  462. <a name="l00448"></a>00448 <span class="keywordflow">if</span> (loader == NULL) {
  463. <a name="l00449"></a>00449 FLUID_LOG(<a class="code" href="log_8h.html#a341232c15addd9c336131984840ed9e394460be1ec74fce15e1ff683606df0f" title="Warning.">FLUID_WARN</a>, <span class="stringliteral">"Failed to create the default SoundFont loader"</span>);
  464. <a name="l00450"></a>00450 } <span class="keywordflow">else</span> {
  465. <a name="l00451"></a>00451 fluid_synth_add_sfloader(synth, loader);
  466. <a name="l00452"></a>00452 }
  467. <a name="l00453"></a>00453
  468. <a name="l00454"></a>00454 <span class="comment">/* allocate all channel objects */</span>
  469. <a name="l00455"></a>00455 synth-&gt;channel = FLUID_ARRAY(fluid_channel_t*, synth-&gt;midi_channels);
  470. <a name="l00456"></a>00456 <span class="keywordflow">if</span> (synth-&gt;channel == NULL) {
  471. <a name="l00457"></a>00457 FLUID_LOG(<a class="code" href="log_8h.html#a341232c15addd9c336131984840ed9ebc0ff48d192b3b0fc721946ccf095d25" title="Serious error occurred.">FLUID_ERR</a>, <span class="stringliteral">"Out of memory"</span>);
  472. <a name="l00458"></a>00458 <span class="keywordflow">goto</span> error_recovery;
  473. <a name="l00459"></a>00459 }
  474. <a name="l00460"></a>00460 <span class="keywordflow">for</span> (i = 0; i &lt; synth-&gt;midi_channels; i++) {
  475. <a name="l00461"></a>00461 synth-&gt;channel[i] = new_fluid_channel(synth, i);
  476. <a name="l00462"></a>00462 <span class="keywordflow">if</span> (synth-&gt;channel[i] == NULL) {
  477. <a name="l00463"></a>00463 <span class="keywordflow">goto</span> error_recovery;
  478. <a name="l00464"></a>00464 }
  479. <a name="l00465"></a>00465 }
  480. <a name="l00466"></a>00466
  481. <a name="l00467"></a>00467 <span class="comment">/* allocate all synthesis processes */</span>
  482. <a name="l00468"></a>00468 synth-&gt;nvoice = synth-&gt;polyphony;
  483. <a name="l00469"></a>00469 synth-&gt;voice = FLUID_ARRAY(fluid_voice_t*, synth-&gt;nvoice);
  484. <a name="l00470"></a>00470 <span class="keywordflow">if</span> (synth-&gt;voice == NULL) {
  485. <a name="l00471"></a>00471 <span class="keywordflow">goto</span> error_recovery;
  486. <a name="l00472"></a>00472 }
  487. <a name="l00473"></a>00473 <span class="keywordflow">for</span> (i = 0; i &lt; synth-&gt;nvoice; i++) {
  488. <a name="l00474"></a>00474 synth-&gt;voice[i] = new_fluid_voice(synth-&gt;sample_rate);
  489. <a name="l00475"></a>00475 <span class="keywordflow">if</span> (synth-&gt;voice[i] == NULL) {
  490. <a name="l00476"></a>00476 <span class="keywordflow">goto</span> error_recovery;
  491. <a name="l00477"></a>00477 }
  492. <a name="l00478"></a>00478 }
  493. <a name="l00479"></a>00479
  494. <a name="l00480"></a>00480 <span class="comment">/* Allocate the sample buffers */</span>
  495. <a name="l00481"></a>00481 synth-&gt;left_buf = NULL;
  496. <a name="l00482"></a>00482 synth-&gt;right_buf = NULL;
  497. <a name="l00483"></a>00483 synth-&gt;fx_left_buf = NULL;
  498. <a name="l00484"></a>00484 synth-&gt;fx_right_buf = NULL;
  499. <a name="l00485"></a>00485
  500. <a name="l00486"></a>00486 <span class="comment">/* Left and right audio buffers */</span>
  501. <a name="l00487"></a>00487
  502. <a name="l00488"></a>00488 synth-&gt;left_buf = FLUID_ARRAY(fluid_real_t*, synth-&gt;nbuf);
  503. <a name="l00489"></a>00489 synth-&gt;right_buf = FLUID_ARRAY(fluid_real_t*, synth-&gt;nbuf);
  504. <a name="l00490"></a>00490
  505. <a name="l00491"></a>00491 <span class="keywordflow">if</span> ((synth-&gt;left_buf == NULL) || (synth-&gt;right_buf == NULL)) {
  506. <a name="l00492"></a>00492 FLUID_LOG(<a class="code" href="log_8h.html#a341232c15addd9c336131984840ed9ebc0ff48d192b3b0fc721946ccf095d25" title="Serious error occurred.">FLUID_ERR</a>, <span class="stringliteral">"Out of memory"</span>);
  507. <a name="l00493"></a>00493 <span class="keywordflow">goto</span> error_recovery;
  508. <a name="l00494"></a>00494 }
  509. <a name="l00495"></a>00495
  510. <a name="l00496"></a>00496 FLUID_MEMSET(synth-&gt;left_buf, 0, synth-&gt;nbuf * <span class="keyword">sizeof</span>(fluid_real_t*));
  511. <a name="l00497"></a>00497 FLUID_MEMSET(synth-&gt;right_buf, 0, synth-&gt;nbuf * <span class="keyword">sizeof</span>(fluid_real_t*));
  512. <a name="l00498"></a>00498
  513. <a name="l00499"></a>00499 <span class="keywordflow">for</span> (i = 0; i &lt; synth-&gt;nbuf; i++) {
  514. <a name="l00500"></a>00500
  515. <a name="l00501"></a>00501 synth-&gt;left_buf[i] = FLUID_ARRAY(fluid_real_t, FLUID_BUFSIZE);
  516. <a name="l00502"></a>00502 synth-&gt;right_buf[i] = FLUID_ARRAY(fluid_real_t, FLUID_BUFSIZE);
  517. <a name="l00503"></a>00503
  518. <a name="l00504"></a>00504 <span class="keywordflow">if</span> ((synth-&gt;left_buf[i] == NULL) || (synth-&gt;right_buf[i] == NULL)) {
  519. <a name="l00505"></a>00505 FLUID_LOG(<a class="code" href="log_8h.html#a341232c15addd9c336131984840ed9ebc0ff48d192b3b0fc721946ccf095d25" title="Serious error occurred.">FLUID_ERR</a>, <span class="stringli…

Large files files are truncated, but you can click here to view the full file