summaryrefslogtreecommitdiffstats
path: root/www/devmaster/lesson1.html
diff options
context:
space:
mode:
Diffstat (limited to 'www/devmaster/lesson1.html')
-rw-r--r--www/devmaster/lesson1.html44
1 files changed, 23 insertions, 21 deletions
diff --git a/www/devmaster/lesson1.html b/www/devmaster/lesson1.html
index 7960c7d..12c7c7f 100644
--- a/www/devmaster/lesson1.html
+++ b/www/devmaster/lesson1.html
@@ -68,8 +68,8 @@ tutorial from <a href="http://devmaster.net/">DevMaster.net</a> to JOAL.
before we do that we have to learn the basics.</p>
<p>So let's get coding!</p>
-<pre class=code><font color="#0000FF">import</font> net.java.games.joal.*;
-<font color="#0000FF">import</font> net.java.games.joal.util.*;
+<pre class=code><font color="#0000FF">import</font> com.jogamp.openal.*;
+<font color="#0000FF">import</font> com.jogamp.openal.util.*;
<font color="#0000FF">import</font> java.io.*;
<font color="#0000FF">import</font> java.nio.ByteBuffer;</pre>
<pre class=code><font color="#0000FF">public</font> <font color="#0000FF">class</font> SingleStaticSource {
@@ -120,20 +120,21 @@ tutorial from <a href="http://devmaster.net/">DevMaster.net</a> to JOAL.
I used arrays for simplicity.</p>
<p>Here we will create a function that loads all of our sound data from a file.
</p>
-<pre class=code><span class=codeComment><font color="#006600"> </font></span><font color="#0000FF">static int</font> LoadALData() {
+<pre class=code><span class=codeComment><font color="#006600"> </font></span><font color="#0000FF">static int</font> loadALData() {
<span class=codeComment><font color="#006600"> </font><font color="#006600"> </font><font color="#006600">// variables to load into</font>
<font color="#006600"> </font><font color="#006600"> </font><font color="#0000FF">int</font>[] format = <font color="#0000FF">new int</font>[1];<br><font color="#006600"> </font><font color="#006600"> </font><font color="#0000FF">int</font>[] size = <font color="#0000FF">new int</font>[1];<br><font color="#006600"> </font><font color="#006600"> </font>ByteBuffer[] data = <font color="#0000FF">new</font> ByteBuffer[1];<br><font color="#006600"> </font><font color="#006600"> </font><font color="#0000FF">int</font>[] freq = new <font color="#0000FF">int</font>[1];
<font color="#006600"> </font><font color="#006600"> </font><font color="#0000FF">int</font>[] loop = new <font color="#0000FF">int</font>[1];<br></span>
<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><font color="#006600">// Load wav data into a buffer.</font>
-<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>al.alGenBuffers(1, buffer);
+<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>al.alGenBuffers(1, buffer, 0);
<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeKeyword>if</span> (al.alGetError() != AL.AL_NO_ERROR)
<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeKeyword>return</span> AL.AL_FALSE;
<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>ALut.alutLoadWAVFile(&quot;wavdata/FancyPants.wav&quot;, format, data, size, freq, loop);
<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>al.alBufferData(buffer[0], format[0], data[0], size[0], freq[0]);
-<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>ALut.alutUnloadWAV(format[0],data[0],size[0],freq[0]);
+<!-- JOAL never implemented alutUnloadWAV because JOAL implements ALut in Java and Java uses GC hence it was un-needed to implement for this binding. -->
+<!-- <span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>ALut.alutUnloadWAV(format[0],data[0],size[0],freq[0]); -->
</pre>
<p align="justify">The function 'alGenBuffers' will create the buffer objects
and store them in the variable we passed it. It's important to do an error check
@@ -141,13 +142,13 @@ tutorial from <a href="http://devmaster.net/">DevMaster.net</a> to JOAL.
not generate a buffer object due to a lack of memory. In this case it would
set the error bit.</p>
<p align="justify">The ALut is very helpful here. It opens up the file for us
- and gives us all the information we need to create the buffer. And after we
- have attached all this data to the buffer it will help use dispose of the data.
+ and gives us all the information we need to create the buffer.<!-- And after we
+ have attached all this data to the buffer it will help use dispose of the data. -->
It all works in a clean and efficient manner.</p>
<pre>
<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><font color="#006600">// Bind buffer with a source.</font>
-<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>al.alGenSources(1, source);
+<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>al.alGenSources(1, source, 0);
<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeKeyword>if</span> (al.alGetError() != AL.AL_NO_ERROR)
<span class=codeComment><font color="#006600"> </font></span><span class=codeKeyword>return</span> AL.AL_FALSE;
@@ -155,8 +156,8 @@ tutorial from <a href="http://devmaster.net/">DevMaster.net</a> to JOAL.
<span class=codeComment><font color="#006600"> </font></span>al.alSourcei (source[0], AL.AL_BUFFER, buffer[0] );
<span class=codeComment><font color="#006600"> </font></span> al.alSourcef (source[0], AL.AL_PITCH, 1.0f );
<span class=codeComment><font color="#006600"> </font></span> al.alSourcef (source[0], AL.AL_GAIN, 1.0f );
-<span class=codeComment><font color="#006600"> </font></span> al.alSourcefv(source[0], AL.AL_POSITION, sourcePos);
-<span class=codeComment><font color="#006600"> </font></span> al.alSourcefv(source[0], AL.AL_VELOCITY, sourceVel);
+<span class=codeComment><font color="#006600"> </font></span> al.alSourcefv(source[0], AL.AL_POSITION, sourcePos, 0);
+<span class=codeComment><font color="#006600"> </font></span> al.alSourcefv(source[0], AL.AL_VELOCITY, sourceVel, 0);
<span class=codeComment><font color="#006600"> </font></span> al.alSourcei (source[0], AL.AL_LOOPING, loop[0] );</pre>
<p align="justify">We generate a source object in the same manner we generated
the buffer object. Then we define the source properties that it will use when
@@ -182,16 +183,16 @@ tutorial from <a href="http://devmaster.net/">DevMaster.net</a> to JOAL.
<p>To end the function we just do one more check to make sure all is well, then
we return success.</p>
<pre class=code><font color="#0000FF"><span class=codeComment><font color="#006600"> </font></span>static <span class=codeKeyword>void</span> </font>setListenerValues() {
-<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>al.alListenerfv(AL.AL_POSITION, listenerPos);
-<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>al.alListenerfv(AL.AL_VELOCITY, listenerVel);
-<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>al.alListenerfv(AL.AL_ORIENTATION, listenerOri);
+<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>al.alListenerfv(AL.AL_POSITION, listenerPos, 0);
+<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>al.alListenerfv(AL.AL_VELOCITY, listenerVel, 0);
+<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>al.alListenerfv(AL.AL_ORIENTATION, listenerOri, 0);
<span class=codeComment><font color="#006600"> </font></span>}
</pre>
<p>We created this function to update the listener properties.</p>
<pre class=code><font color="#0000FF"><span class=codeComment><font color="#006600"> </font></span>static <span class=codeKeyword>void</span> </font>killALData() {
-<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>al.alDeleteBuffers(1, buffer);
-<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>al.alDeleteSources(1, source);
-<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>Alut.alutExit();
+<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>al.alDeleteBuffers(1, buffer, 0);
+<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>al.alDeleteSources(1, source, 0);
+<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>ALut.alutExit();
<span class=codeComment><font color="#006600"> </font></span>}
</pre>
<p>This will be our shutdown procedure. It is necessary to call this to release
@@ -204,7 +205,7 @@ all the memory and audio devices that our program may be using.</p>
</pre>
<p align="justify">The function 'alutInit' will setup everything that the Alc
- needs to do for us. Basically Alut creates a single OpenAL context through Alc
+ needs to do for us. Basically ALut creates a single OpenAL context through Alc
and sets it to current. On the Windows platform it initializes DirectSound.
We also do an initial call to the error function to clear it. Every time we
call 'glGetError' it will reset itself to 'AL_NO_ERROR'.</p>
@@ -212,7 +213,7 @@ all the memory and audio devices that our program may be using.</p>
<span class=codeComment><font color="#006600"> </font><font color="#006600"> </font><font color="#006600">// Load the wav data.</font></span>
<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeKeyword><font color="#0000FF">if</font></span> (loadALData() == AL.AL_FALSE)
-<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeKeyword><font color="#0000FF">return</font></span> -1;
+<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>System.exit(-1);
<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>setListenerValues();
@@ -223,7 +224,7 @@ all the memory and audio devices that our program may be using.</p>
<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><font color="#0000FF">new</font> Thread(
<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><font color="#0000FF">new</font> Runnable() {
<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><font color="#0000FF">public void</font> run() {
-<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>killAllData();
+<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>killALData();
<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>}
<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>}
<span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span><span class=codeComment><font color="#006600"> </font></span>)
@@ -246,11 +247,11 @@ and finally we set our exit procedure.</p>
<font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF">break</font>;
<font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF">case</font> 's':
<font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#006600">// Pressing 's' will stop the sample from playing.</font>
-<font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font>alSourceStop(source[0]);
+<font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font>al.alSourceStop(source[0]);
<font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF">break</font>;
<font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF">case</font> 'h':
<font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#006600">// Pressing 'n' will pause (hold) the sample.</font>
-<font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font>alSourcePause(source[0]);
+<font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font>al.alSourcePause(source[0]);
<font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF">break</font>;
<font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font><font color="#0000FF"> </font>}
<font color="#0000FF"> </font><font color="#0000FF"> </font>} <font color="#0000FF">catch</font> (IOException e) {
@@ -259,6 +260,7 @@ and finally we set our exit procedure.</p>
<font color="#0000FF"> </font>}
}
+} // class SingleStaticSource
</pre>
<p align="justify">This is the interesting part of the tutorial. It's a very basic
loop that lets us control the playback of the audio sample. Pressing 'p' will