From 06a3aaa5fd38097a4644921a269d6ca282fb31eb Mon Sep 17 00:00:00 2001 From: Xerxes Rånby Date: Tue, 9 Jul 2013 17:13:32 +0200 Subject: www/devmaster/lesson*.html: net.java.games.joal.* -> com.jogamp.openal.* MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Java OpenAL JOAL HTML tutorials are now usefull. This change made is possible to copy and paste the many code sections of the JOAL tutorial into working applications. Signed-off-by: Xerxes Rånby --- www/devmaster/lesson1.html | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'www/devmaster/lesson1.html') 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 DevMaster.net to JOAL. before we do that we have to learn the basics.

So let's get coding!

-
import net.java.games.joal.*;
-import net.java.games.joal.util.*;
+
import com.jogamp.openal.*;
+import com.jogamp.openal.util.*;
 import java.io.*;
 import java.nio.ByteBuffer;
public class SingleStaticSource {
@@ -120,20 +120,21 @@ tutorial from DevMaster.net to JOAL.
   I used arrays for simplicity.

Here we will create a function that loads all of our sound data from a file.

-
    static int LoadALData() {
+
    static int loadALData() {
 
         // variables to load into
    
         int[] format = new int[1];
int[] size = new int[1];
ByteBuffer[] data = new ByteBuffer[1];
int[] freq = new int[1]; int[] loop = new int[1];
// Load wav data into a buffer. - al.alGenBuffers(1, buffer); + al.alGenBuffers(1, buffer, 0); if (al.alGetError() != AL.AL_NO_ERROR) return AL.AL_FALSE; ALut.alutLoadWAVFile("wavdata/FancyPants.wav", format, data, size, freq, loop); al.alBufferData(buffer[0], format[0], data[0], size[0], freq[0]); - ALut.alutUnloadWAV(format[0],data[0],size[0],freq[0]); + +

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 DevMaster.net to JOAL. not generate a buffer object due to a lack of memory. In this case it would set the error bit.

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. It all works in a clean and efficient manner.

 
         // Bind buffer with a source.
-        al.alGenSources(1, source);
+        al.alGenSources(1, source, 0);
 
         if (al.alGetError() != AL.AL_NO_ERROR)
             return AL.AL_FALSE;
@@ -155,8 +156,8 @@ tutorial from DevMaster.net to JOAL.
         al.alSourcei (source[0], AL.AL_BUFFER,   buffer[0]   );
         al.alSourcef (source[0], AL.AL_PITCH,    1.0f     );
         al.alSourcef (source[0], AL.AL_GAIN,     1.0f     );
-        al.alSourcefv(source[0], AL.AL_POSITION, sourcePos);
-        al.alSourcefv(source[0], AL.AL_VELOCITY, sourceVel);
+        al.alSourcefv(source[0], AL.AL_POSITION, sourcePos, 0);
+        al.alSourcefv(source[0], AL.AL_VELOCITY, sourceVel, 0);
         al.alSourcei (source[0], AL.AL_LOOPING,  loop[0]     );

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 DevMaster.net to JOAL.

To end the function we just do one more check to make sure all is well, then we return success.

    static void setListenerValues() {
-        al.alListenerfv(AL.AL_POSITION,	listenerPos);
-        al.alListenerfv(AL.AL_VELOCITY,    listenerVel);
-        al.alListenerfv(AL.AL_ORIENTATION, listenerOri);
+        al.alListenerfv(AL.AL_POSITION,	listenerPos, 0);
+        al.alListenerfv(AL.AL_VELOCITY,    listenerVel, 0);
+        al.alListenerfv(AL.AL_ORIENTATION, listenerOri, 0);
     }
 

We created this function to update the listener properties.

    static void killALData() {
-        al.alDeleteBuffers(1, buffer);
-        al.alDeleteSources(1, source);
-        Alut.alutExit();
+        al.alDeleteBuffers(1, buffer, 0);
+        al.alDeleteSources(1, source, 0);
+        ALut.alutExit();
     }
 

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.

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'.

@@ -212,7 +213,7 @@ all the memory and audio devices that our program may be using.

// Load the wav data. if (loadALData() == AL.AL_FALSE) - return -1; + System.exit(-1); setListenerValues(); @@ -223,7 +224,7 @@ all the memory and audio devices that our program may be using.

new Thread( new Runnable() { public void run() { - killAllData(); + killALData(); } } ) @@ -246,11 +247,11 @@ and finally we set our exit procedure.

break; case 's': // Pressing 's' will stop the sample from playing. - alSourceStop(source[0]); + al.alSourceStop(source[0]); break; case 'h': // Pressing 'n' will pause (hold) the sample. - alSourcePause(source[0]); + al.alSourcePause(source[0]); break; } } catch (IOException e) { @@ -259,6 +260,7 @@ and finally we set our exit procedure.

} } +} // class SingleStaticSource

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 -- cgit v1.2.3