-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample_8c-example.html
More file actions
75 lines (73 loc) · 8.19 KB
/
example_8c-example.html
File metadata and controls
75 lines (73 loc) · 8.19 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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://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.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>libfluidsynth: example.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="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" />
</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">1.1.11</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- 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">example.c</div> </div>
</div><!--header-->
<div class="contents">
<p>Example producing short random music with FluidSynth</p>
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment"> An example of how to use FluidSynth.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment"> To compile it on Linux:</span></div><div class="line"><span class="comment"> $ gcc -o example example.c `pkg-config fluidsynth --libs`</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment"> To compile it on Windows:</span></div><div class="line"><span class="comment"> ... </span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment"> Author: Peter Hanappe.</span></div><div class="line"><span class="comment"> This code is in the public domain. Use it as you like.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">*/</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include <fluidsynth.h></span></div><div class="line"></div><div class="line"><span class="preprocessor">#if defined(WIN32)</span></div><div class="line"><span class="preprocessor">#include <windows.h></span></div><div class="line"><span class="preprocessor">#define sleep(_t) Sleep(_t * 1000)</span></div><div class="line"><span class="preprocessor">#else</span></div><div class="line"><span class="preprocessor">#include <stdlib.h></span></div><div class="line"><span class="preprocessor">#endif</span></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv)</div><div class="line">{</div><div class="line"> <a class="code" href="types_8h.html#aa363402d3c77333b0f070ba531d034ba">fluid_settings_t</a>* settings;</div><div class="line"> <a class="code" href="types_8h.html#ae265f10ae174a13afe010de50d87e1a4">fluid_synth_t</a>* synth;</div><div class="line"> <a class="code" href="types_8h.html#ac3706330ce49cac5b7dd079e90d376d8">fluid_audio_driver_t</a>* adriver;</div><div class="line"> <span class="keywordtype">int</span> sfont_id;</div><div class="line"> <span class="keywordtype">int</span> i, key;</div><div class="line"></div><div class="line"> <span class="comment">/* Create the settings. */</span></div><div class="line"> settings = <a name="a0"></a><a class="code" href="settings_8h.html#ad7ab9269a28c2b5852d512ffe3546949">new_fluid_settings</a>();</div><div class="line"></div><div class="line"> <span class="comment">/* Change the settings if necessary*/</span></div><div class="line"></div><div class="line"> <span class="comment">/* Create the synthesizer. */</span></div><div class="line"> synth = <a name="a1"></a><a class="code" href="synth_8h.html#a344f7369c0f57d30f72702d0c88e6178">new_fluid_synth</a>(settings);</div><div class="line"></div><div class="line"> <span class="comment">/* Create the audio driver. The synthesizer starts playing as soon</span></div><div class="line"><span class="comment"> as the driver is created. */</span></div><div class="line"> adriver = <a name="a2"></a><a class="code" href="audio_8h.html#a4ad51317b10b89bfe94ade5db345864b">new_fluid_audio_driver</a>(settings, synth);</div><div class="line"></div><div class="line"> <span class="comment">/* Load a SoundFont and reset presets (so that new instruments</span></div><div class="line"><span class="comment"> * get used from the SoundFont) */</span></div><div class="line"> sfont_id = <a name="a3"></a><a class="code" href="synth_8h.html#aaf9376cf7189f9c64da5ffdeed85c9c4">fluid_synth_sfload</a>(synth, <span class="stringliteral">"example.sf2"</span>, 1);</div><div class="line"></div><div class="line"> <span class="comment">/* Initialize the random number generator */</span></div><div class="line"> srand(getpid());</div><div class="line"></div><div class="line"> <span class="keywordflow">for</span> (i = 0; i < 12; i++) {</div><div class="line"></div><div class="line"> <span class="comment">/* Generate a random key */</span></div><div class="line"> key = 60 + (int) (12.0f * rand() / (float) RAND_MAX);</div><div class="line"></div><div class="line"> <span class="comment">/* Play a note */</span></div><div class="line"> <a name="a4"></a><a class="code" href="synth_8h.html#a4a98222fe1c36bfd598dc4cd89f4b75c">fluid_synth_noteon</a>(synth, 0, key, 80);</div><div class="line"></div><div class="line"> <span class="comment">/* Sleep for 1 second */</span></div><div class="line"> sleep(1);</div><div class="line"></div><div class="line"> <span class="comment">/* Stop the note */</span></div><div class="line"> <a name="a5"></a><a class="code" href="synth_8h.html#a5e8f96cacbc6460f7677a6191cbd4472">fluid_synth_noteoff</a>(synth, 0, key);</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">/* Clean up */</span></div><div class="line"> <a name="a6"></a><a class="code" href="audio_8h.html#a05678e633d37da0f93000045393e9442">delete_fluid_audio_driver</a>(adriver);</div><div class="line"> <a name="a7"></a><a class="code" href="synth_8h.html#a585a63f3a25b9df17b82ae87f2d38cfc">delete_fluid_synth</a>(synth);</div><div class="line"> <a name="a8"></a><a class="code" href="settings_8h.html#a550270f09e4f3c645cbe9e6d3c514ca4">delete_fluid_settings</a>(settings);</div><div class="line"></div><div class="line"> <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by  <a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>