www/devmaster/lesson*.html: Fix links to original articles.
[joal-demos.git] / www / devmaster / lesson4.html
Content-type: text/html Git - joal-demos.git/blame - www/devmaster/lesson4.html

500 - Internal Server Error

Malformed UTF-8 character (fatal) at (eval 5) line 1, <$fd> line 336.
10be763d 1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
aaf9d0a3 4 <title>JOAL OpenAL Tutorials from Lesson 4: A Closer Look at ALC</title>
10be763d 5</head>
aaf9d0a3 7<a href="../index.html"><img src="../../../images/jogamp_symbols/website_final_blue_joal_346x70pel.png" alt="JOAL Symbol"></a><a href=""><img src="../openal_c.gif"></a>
10be763d 8<br>
9OpenAL Tutorials from Reprinted with Permission.<br>
12<table border="0" cellspacing="0" style="border-collapse: collapse" width="100%" cellpadding="0" id="AutoNumber1" height="12" bgcolor="#666699">
13 <tr>
14 <td width="47%" height="12" valign="middle"><p><b><font color="#FFFFFF">OpenAL
15 Tutorials</font></b></p></td>
16 <td width="53%" height="12" align="right" valign="middle"><p align="right"><a href=""><font color="#66FF99"></font></a></p></td>
17 </tr>
18 </table>
20<p class="ArticleTitle"><font size="5">A Closer Look at ALC</font></p>
21<p class="ArticleTitle"><font size="4"><strong>Lesson 4</strong></font></p>
22<p align="right" class="ArticleAuthor">Author: <a href="">Jesse
23 Maurais<br>
24 </a>Adapted for Java by: <a href="">Athomas
25 Goldberg </a></p>
26<p align="justify">This is a translation of <a href="">
27OpenAL Lesson 4: The ALC</a>
28tutorial from <a href=""></a> to JOAL.
10be763d 31<p align="justify">Up until now we have been letting Alut do all the real tricky
32 stuff for us. For example handling the audio devices. It's really nice that
33 the Alut library is there to provide this functionality, but any smart coder
34 will want to know exactly what their doing. We may want to, at some point, use
35 the Alc directly. In this tutorial we will expose the Alc layer and take a look
36 at how to handle the devices on our own.</p>
37<pre class=code>
39ALC alc = ALFactory.getALC();
42String deviceName = "DirectSound3D";
44ALC.Device device = alc.alcOpenDevice(deviceName);
46<p align="justify">So what is an Alc device? Try to think of it in terms of a
47 resource. OpenAL grabs a handle to the hardware being used, which must in turn
48 be shared with the entire system. A device can be of a specific implementation
49 as well, as in this case where we are using DirectSound as the audio device.
50 This code grabs a handle to the hardware device and readies it to be used by
51 the application. Eventually we should see more devices made for specific soundcards.</p>
52<p>Passing <font color="#0000FF" face="Courier New, Courier, mono">null</font>
53 to 'alcOpenDevice' is a perfectly valid argument. It forces the Alc to use a
54 default device.</p>
56ALC.Context context = alc.alcCreateContext(device, <font color="#0000FF">null</font>);
59<p align="justify">What is an Alc context? OpenGL coders will recall that there
60 was rendering contexts used by OpenGL that controlled the state management across
61 different windows. An 'HGLRC' as they are called could be created several times
62 to enable multiple rendering windows. And different rendering states for each
63 context could be achieved. An Alc context works on the same principal. First
64 we tell it which device to use (which we have already created), then we make
65 that context current. In theory you could create multiple rendering contexts
66 for different windows, and set the state variables differently and have it work
67 just fine. Although the term &quot;rendering context&quot; usually applies to
68 a visual rendering, this is the term preferred in the sdk docs and should be
69 the term used.</p>
70<p align="justify">You may notice too that the second parameter in 'alcCreateContext'
71 has been set to <font face="Courier New, Courier, mono">null</font>. The OpenAL
72 sdk from Creative Labs defines the following variables which are optional flags
73 to that parameter.</p>
75 <li>ALC_FREQUENCY</li>
76 <li>ALC_REFRESH</li>
77 <li>ALC_SYNC</li>
79<p align="justify">If you were to create multiple contexts you could make them
80 interchangeable by making a call to 'alcMakeContextCurrent'. Sending NULL to
81 'alcMakeContextCurrent' is also a perfectly valid argument. It will prevent
82 processing of any audio data. Be aware that even if you have multiple rendering
83 contexts, you can only have one current at a time, and when your application
84 needs to use two contexts interchangeably you must be the one to make sure the
85 appropriate context is current. And if you do decide to do this, then there
86 may be times when you want to know exactly which context is current without
87 going through a big check.</p>
88<pre class=code>ALC.Context curContext = alc.alcGetCurrentContext();
90<p>Once you have your context you can also obtain the device in use by that context.</p>
91<pre class=code>ALC.Device curDevice = alc.alcGetContextsDevice(curContext);
93<p align="justify">Above we used the context we retrieved to find out which device
94 it was using. There is also one other cool feature that was built into Alc for
95 handling contexts.</p>
96<pre class=code>alc.alcSuspendContext(context);
97<span class=codeComment><font color="#006600">// Processing has been suspended to context.</font></span>
100<span class=codeComment><font color="#006600">// Processing has been re-enabled to context.</font></span>
102<p align="justify">What we have done above was stop, and then resume processing
103 of audio data to the context. When processing has been suspended, no sound will
104 be generated from data sent through that context. A further note on the rendering
105 context: the OpenAL 1.0 spec does imply, but does not explicitly say, that sources
106 and buffers may be used across contexts. The &quot;lifetime&quot; of a source
107 or buffer during the application, is said to be valid as long as the source
108 and buffer id is valid (i.e. they have not been deleted).</p>
109<pre class=code>alc.alcMakeContextCurrent(<font color="#0000FF">null</font>);
113<p align="justify">And that is how we clean up. The current context is defaulted
114 to <font face="Courier New, Courier, mono">null</font>, the context we created
115 is released, and the handle to the device is given back to the system resources.
116 There is but a few more Alc functions we have not yet covered.</p>
117<pre class=code><font color="#0000FF">public int</font> alcGetError();
119<font color="#0000FF">public</font> <font color="#0000FF">boolean</font> alcIsExtensionPresent(ALC.Device device, String extName);
121<font color="#0000FF">public</font> <font color="#0000FF">int</font> alcGetEnumValue(ALC.Device device, String enumName);
123<font color="#0000FF">public </font>String alcGetString(ALC.Device device, <font color="#0000FF">int</font> token);
125<font color="#0000FF">public</font> <font color="#0000FF">void</font> alcGetIntegerv(ALC.Device device, <font color="#0000FF">int</font> token, <font color="#0000FF">int</font> size, <font color="#0000FF">int</font>[] dest);
127<p align="justify">It may be pretty obvious to you what these do, but lets humour
128 ourselves and have a closer look. First we have 'alcGetError' which is just
129 like 'alGetError' but will return Alc errors. The next two functions are for
130 querying Alc extensions. This was just the creators planning ahead, as there
131 are no Alc extensions either. The last function, 'alcGetInteger', will return
132 the Alc version when passed 'ALC_MAJOR_VERSION' or 'ALC_MINOR_VERSION'.</p>
133<p>The function 'alcGetString' is pretty cool. It can take any of the following
134 three parameters to 'token':</p>
138 <li>ALC_EXTENSIONS</li>
140<p align="justify">The first will return the device string which your OpenAL implementation
141 will prefer you to use. In current OpenAL this should be &quot;DirectSound3D&quot;,
142 like we used above. The second token will return a list of specifiers, but in
143 current OpenAL will only return &quot;DirectSound&quot; (without the &quot;3D&quot;
144 for some reason). The last will return a list of Alc extensions, of which none
145 exist yet.</p>
146<p align="justify">Well that's most of Alc for you. I hope it gave you a better
147 understanding of how OpenAL interacts with the operation system. You might try
148 writing your own initialization routines so you can cast off Alut altogether.
149 Either way have fun with it.</p>
150<table border="0" cellspacing="1" style="border-collapse: collapse" width="100%" id="AutoNumber2" bgcolor="#666699">
151 <tr>
152 git info: FAQ, tutorial and man pages.