-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfluidsynth_process_8c-example.html
More file actions
216 lines (214 loc) · 15.9 KB
/
fluidsynth_process_8c-example.html
File metadata and controls
216 lines (214 loc) · 15.9 KB
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>libfluidsynth: fluidsynth_process.c</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="custom.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">libfluidsynth
 <span id="projectnumber">2.5.4</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('fluidsynth_process_8c-example.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="headertitle">
<div class="title">fluidsynth_process.c</div> </div>
</div><!--header-->
<div class="contents">
<p>Usage examples of how to render audio using <a class="el" href="group__audio__rendering.html#gaf41e26b153a095dbc4248e9df4f3ad46" title="Synthesize floating point audio to stereo audio channels (implements the default interface fluid_audi...">fluid_synth_process()</a> (advanced users only)</p>
<div class="fragment"><div class="line"><span class="comment">/*</span></div>
<div class="line"><span class="comment"> * This is a C99 program that outlines different usage examples for fluid_synth_process()</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include <stdio.h></span></div>
<div class="line"><span class="preprocessor">#include <string.h></span></div>
<div class="line"><span class="preprocessor">#include <fluidsynth.h></span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main()</div>
<div class="line">{</div>
<div class="line"> <span class="comment">// any arbitrary number of audio samples to render during on call of fluid_synth_process()</span></div>
<div class="line"> <span class="keyword">enum</span> { SAMPLES = 512 };</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// ...creation of synth omitted...</span></div>
<div class="line"> </div>
<div class="line"> <span class="comment">// USECASE1: render all dry audio channels + reverb and chorus to one stereo channel</span></div>
<div class="line"> {</div>
<div class="line"> <span class="comment">// planar sample buffers that received synthesized (monophonic) audio</span></div>
<div class="line"> <span class="keywordtype">float</span> left[SAMPLES], right[SAMPLES];</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// array of buffers used to setup channel mapping</span></div>
<div class="line"> <span class="keywordtype">float</span> *dry[1 * 2], *fx[1 * 2];</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// first make sure to zero out the sample buffers every time before calling fluid_synth_process()</span></div>
<div class="line"> memset(left, 0, <span class="keyword">sizeof</span>(left));</div>
<div class="line"> memset(right, 0, <span class="keyword">sizeof</span>(right));</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// setup channel mapping for a single stereo channel to which to render all dry audio to</span></div>
<div class="line"> dry[0] = left;</div>
<div class="line"> dry[1] = right;</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Setup channel mapping for a single stereo channel to which to render effects to.</span></div>
<div class="line"> <span class="comment">// Just using the same sample buffers as for dry audio is fine here, as it will cause the effects to be mixed with dry output.</span></div>
<div class="line"> <span class="comment">// Note: reverb and chorus together make up two stereo channels. Setting up only one stereo channel is sufficient</span></div>
<div class="line"> <span class="comment">// as the channels wraps around (i.e. chorus will be mixed with reverb channel).</span></div>
<div class="line"> fx[0] = left;</div>
<div class="line"> fx[1] = right;</div>
<div class="line"> </div>
<div class="line"> <span class="keywordtype">int</span> err = <a name="a0"></a><a class="code" href="group__audio__rendering.html#gaf41e26b153a095dbc4248e9df4f3ad46">fluid_synth_process</a>(synth, SAMPLES, 2, fx, 2, dry);</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">if</span>(err == <a name="a1"></a><a class="code" href="group__misc.html#ga90e8bdbc5a507bbfa5c45bac85a63a61">FLUID_FAILED</a>)</div>
<div class="line"> {</div>
<div class="line"> puts(<span class="stringliteral">"oops"</span>);</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"> <span class="comment">// USECASE2: only render dry audio and discard effects</span></div>
<div class="line"> <span class="comment">// same as above, but call fluid_synth_process() like:</span></div>
<div class="line"> <span class="keywordtype">int</span> err = <a class="code" href="group__audio__rendering.html#gaf41e26b153a095dbc4248e9df4f3ad46">fluid_synth_process</a>(synth, SAMPLES, 0, NULL, 2, dry);</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">if</span>(err == <a class="code" href="group__misc.html#ga90e8bdbc5a507bbfa5c45bac85a63a61">FLUID_FAILED</a>)</div>
<div class="line"> {</div>
<div class="line"> puts(<span class="stringliteral">"oops"</span>);</div>
<div class="line"> }</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"> <span class="comment">// USECASE3: render audio and discard all samples</span></div>
<div class="line"> {</div>
<div class="line"> <span class="keywordtype">int</span> err = <a class="code" href="group__audio__rendering.html#gaf41e26b153a095dbc4248e9df4f3ad46">fluid_synth_process</a>(synth, SAMPLES, 0, NULL, 0, NULL);</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">if</span>(err == <a class="code" href="group__misc.html#ga90e8bdbc5a507bbfa5c45bac85a63a61">FLUID_FAILED</a>)</div>
<div class="line"> {</div>
<div class="line"> puts(<span class="stringliteral">"oops"</span>);</div>
<div class="line"> }</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"> <span class="comment">// USECASE4: multi-channel rendering, i.e. render all audio and effects channels to dedicated audio buffers</span></div>
<div class="line"> <span class="comment">// ofc it‘s not a good idea to allocate all the arrays on the stack</span></div>
<div class="line"> {</div>
<div class="line"> <span class="comment">// lookup number of audio and effect (stereo-)channels of the synth</span></div>
<div class="line"> <span class="comment">// see "synth.audio-channels", "synth.effects-channels" and "synth.effects-groups" settings respectively</span></div>
<div class="line"> <span class="keywordtype">int</span> n_aud_chan = <a name="a2"></a><a class="code" href="group__synthesis__params.html#gafd0280f9f3e9d9aae14a7a9dc02edea7">fluid_synth_count_audio_channels</a>(synth);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// by default there are two effects stereo channels (reverb and chorus) ...</span></div>
<div class="line"> <span class="keywordtype">int</span> n_fx_chan = <a name="a3"></a><a class="code" href="group__synthesis__params.html#gabacb45dc50c05b7a0bb7229df3081b1b">fluid_synth_count_effects_channels</a>(synth);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// ... for each effects unit. Each unit takes care of the effects of one MIDI channel.</span></div>
<div class="line"> <span class="comment">// If there are less units than channels, it wraps around and one unit may render effects of multiple</span></div>
<div class="line"> <span class="comment">// MIDI channels.</span></div>
<div class="line"> n_fx_chan *= <a name="a4"></a><a class="code" href="group__synthesis__params.html#ga2b4731bf062b674937f11db9395360be">fluid_synth_count_effects_groups</a>();</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// for simplicity, allocate one single sample pool</span></div>
<div class="line"> <span class="keywordtype">float</span> samp_buf[SAMPLES * (n_aud_chan + n_fx_chan) * 2];</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// array of buffers used to setup channel mapping</span></div>
<div class="line"> <span class="keywordtype">float</span> *dry[n_aud_chan * 2], *fx[n_fx_chan * 2];</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// setup buffers to mix dry stereo audio to</span></div>
<div class="line"> <span class="comment">// buffers are alternating left and right for each n_aud_chan,</span></div>
<div class="line"> <span class="comment">// please review documentation of fluid_synth_process()</span></div>
<div class="line"> <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0; i < n_aud_chan * 2; i++)</div>
<div class="line"> {</div>
<div class="line"> dry[i] = &samp_buf[i * SAMPLES];</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// setup buffers to mix effects stereo audio to</span></div>
<div class="line"> <span class="comment">// similar channel layout as above, revie fluid_synth_process()</span></div>
<div class="line"> <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0; i < n_fx_chan * 2; i++)</div>
<div class="line"> {</div>
<div class="line"> fx[i] = &samp_buf[n_aud_chan * 2 * SAMPLES + i * SAMPLES];</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// dont forget to zero sample buffer(s) before each rendering</span></div>
<div class="line"> memset(samp_buf, 0, <span class="keyword">sizeof</span>(samp_buf));</div>
<div class="line"> </div>
<div class="line"> <span class="keywordtype">int</span> err = <a class="code" href="group__audio__rendering.html#gaf41e26b153a095dbc4248e9df4f3ad46">fluid_synth_process</a>(synth, SAMPLES, n_fx_chan * 2, fx, n_aud_chan * 2, dry);</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">if</span>(err == <a class="code" href="group__misc.html#ga90e8bdbc5a507bbfa5c45bac85a63a61">FLUID_FAILED</a>)</div>
<div class="line"> {</div>
<div class="line"> puts(<span class="stringliteral">"oops"</span>);</div>
<div class="line"> }</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
<div class="ttc" id="agroup__audio__rendering_html_gaf41e26b153a095dbc4248e9df4f3ad46"><div class="ttname"><a href="group__audio__rendering.html#gaf41e26b153a095dbc4248e9df4f3ad46">fluid_synth_process</a></div><div class="ttdeci">int fluid_synth_process(fluid_synth_t *synth, int len, int nfx, float *fx[], int nout, float *out[])</div><div class="ttdoc">Synthesize floating point audio to stereo audio channels (implements the default interface fluid_audi...</div><div class="ttdef"><b>Definition:</b> fluid_synth.c:4423</div></div>
<div class="ttc" id="agroup__misc_html_ga90e8bdbc5a507bbfa5c45bac85a63a61"><div class="ttname"><a href="group__misc.html#ga90e8bdbc5a507bbfa5c45bac85a63a61">FLUID_FAILED</a></div><div class="ttdeci">#define FLUID_FAILED</div><div class="ttdoc">Value that indicates failure, used by most libfluidsynth functions.</div><div class="ttdef"><b>Definition:</b> misc.h:64</div></div>
<div class="ttc" id="agroup__synthesis__params_html_ga2b4731bf062b674937f11db9395360be"><div class="ttname"><a href="group__synthesis__params.html#ga2b4731bf062b674937f11db9395360be">fluid_synth_count_effects_groups</a></div><div class="ttdeci">int fluid_synth_count_effects_groups(fluid_synth_t *synth)</div><div class="ttdoc">Get the total number of allocated effects units.</div><div class="ttdef"><b>Definition:</b> fluid_synth.c:7204</div></div>
<div class="ttc" id="agroup__synthesis__params_html_gabacb45dc50c05b7a0bb7229df3081b1b"><div class="ttname"><a href="group__synthesis__params.html#gabacb45dc50c05b7a0bb7229df3081b1b">fluid_synth_count_effects_channels</a></div><div class="ttdeci">int fluid_synth_count_effects_channels(fluid_synth_t *synth)</div><div class="ttdoc">Get the total number of allocated effects channels.</div><div class="ttdef"><b>Definition:</b> fluid_synth.c:7186</div></div>
<div class="ttc" id="agroup__synthesis__params_html_gafd0280f9f3e9d9aae14a7a9dc02edea7"><div class="ttname"><a href="group__synthesis__params.html#gafd0280f9f3e9d9aae14a7a9dc02edea7">fluid_synth_count_audio_channels</a></div><div class="ttdeci">int fluid_synth_count_audio_channels(fluid_synth_t *synth)</div><div class="ttdoc">Get the total count of audio channels.</div><div class="ttdef"><b>Definition:</b> fluid_synth.c:7152</div></div>
</div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
</body>
</html>