-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfluidsynth_simple_8c-example.html
More file actions
75 lines (73 loc) · 9.21 KB
/
fluidsynth_simple_8c-example.html
File metadata and controls
75 lines (73 loc) · 9.21 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: fluidsynth_simple.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">fluidsynth_simple.c</div> </div>
</div><!--header-->
<div class="contents">
<p>A basic example of using fluidsynth to play a single note</p>
<div class="fragment"><div class="line"><span class="comment">/* FluidSynth Simple - An example of using fluidsynth</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * This code is in the public domain.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * To compile:</span></div><div class="line"><span class="comment"> * gcc -g -O -o fluidsynth_simple fluidsynth_simple.c -lfluidsynth</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * To run</span></div><div class="line"><span class="comment"> * fluidsynth_simple soundfont</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * [Peter Hanappe]</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="preprocessor">#include <stdio.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(<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 = NULL;</div><div class="line"> <a class="code" href="types_8h.html#ac3706330ce49cac5b7dd079e90d376d8">fluid_audio_driver_t</a>* adriver = NULL;</div><div class="line"> <span class="keywordtype">int</span> err = 0;</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (argc != 2) {</div><div class="line"> fprintf(stderr, <span class="stringliteral">"Usage: fluidsynth_simple [soundfont]\n"</span>);</div><div class="line"> <span class="keywordflow">return</span> 1;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">/* Create the settings object. This example uses the default</span></div><div class="line"><span class="comment"> * values for 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"> <span class="keywordflow">if</span> (settings == NULL) {</div><div class="line"> fprintf(stderr, <span class="stringliteral">"Failed to create the settings\n"</span>);</div><div class="line"> err = 2;</div><div class="line"> <span class="keywordflow">goto</span> cleanup;</div><div class="line"> }</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"> <span class="keywordflow">if</span> (synth == NULL) {</div><div class="line"> fprintf(stderr, <span class="stringliteral">"Failed to create the synthesizer\n"</span>);</div><div class="line"> err = 3;</div><div class="line"> <span class="keywordflow">goto</span> cleanup;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">/* Load the soundfont */</span></div><div class="line"> <span class="keywordflow">if</span> (<a name="a2"></a><a class="code" href="synth_8h.html#aaf9376cf7189f9c64da5ffdeed85c9c4">fluid_synth_sfload</a>(synth, argv[1], 1) == -1) {</div><div class="line"> fprintf(stderr, <span class="stringliteral">"Failed to load the SoundFont\n"</span>);</div><div class="line"> err = 4;</div><div class="line"> <span class="keywordflow">goto</span> cleanup;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">/* Create the audio driver. As soon as the audio driver is</span></div><div class="line"><span class="comment"> * created, the synthesizer can be played. */</span></div><div class="line"> adriver = <a name="a3"></a><a class="code" href="audio_8h.html#a4ad51317b10b89bfe94ade5db345864b">new_fluid_audio_driver</a>(settings, synth);</div><div class="line"> <span class="keywordflow">if</span> (adriver == NULL) {</div><div class="line"> fprintf(stderr, <span class="stringliteral">"Failed to create the audio driver\n"</span>);</div><div class="line"> err = 5;</div><div class="line"> <span class="keywordflow">goto</span> cleanup;</div><div class="line"> }</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, 60, 100);</div><div class="line"></div><div class="line"> printf(<span class="stringliteral">"Press \"Enter\" to stop: "</span>);</div><div class="line"> fgetc(stdin);</div><div class="line"> printf(<span class="stringliteral">"done\n"</span>);</div><div class="line"></div><div class="line"> </div><div class="line"> cleanup:</div><div class="line"> </div><div class="line"> <span class="keywordflow">if</span> (adriver) {</div><div class="line"> <a name="a5"></a><a class="code" href="audio_8h.html#a05678e633d37da0f93000045393e9442">delete_fluid_audio_driver</a>(adriver);</div><div class="line"> }</div><div class="line"> <span class="keywordflow">if</span> (synth) {</div><div class="line"> <a name="a6"></a><a class="code" href="synth_8h.html#a585a63f3a25b9df17b82ae87f2d38cfc">delete_fluid_synth</a>(synth);</div><div class="line"> }</div><div class="line"> <span class="keywordflow">if</span> (settings) {</div><div class="line"> <a name="a7"></a><a class="code" href="settings_8h.html#a550270f09e4f3c645cbe9e6d3c514ca4">delete_fluid_settings</a>(settings);</div><div class="line"> }</div><div class="line"> </div><div class="line"> <span class="keywordflow">return</span> err;</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>