up to date version

This commit is contained in:
Brian Matzon 2002-12-21 12:10:05 +00:00
parent 00edb7fcb2
commit 96a0f9beb3
1 changed files with 10 additions and 15 deletions

View File

@ -36,7 +36,7 @@ org.lwjgl.openal.AL;<br>
import org.lwjgl.openal.ALC;<br> import org.lwjgl.openal.ALC;<br>
import org.lwjgl.openal.ALCcontext;<br> import org.lwjgl.openal.ALCcontext;<br>
import org.lwjgl.openal.ALCdevice;<br> import org.lwjgl.openal.ALCdevice;<br>
import org.lwjgl.openal.ALUT;<code></code><br> <br>
<br> <br>
public class PlayTest {<br> public class PlayTest {<br>
    <br>     <br>
@ -46,9 +46,6 @@ public class PlayTest {<br>
  /** OpenAL Context instance */<br>   /** OpenAL Context instance */<br>
  protected ALC alc;<br>   protected ALC alc;<br>
    <br>     <br>
  /** OpenAL Util library instance */<br>
  protected ALUT alut;<br>
    <br>
  /** OpenAL context */<br>   /** OpenAL context */<br>
  protected ALCcontext context;<br>   protected ALCcontext context;<br>
    <br>     <br>
@ -60,13 +57,12 @@ public class PlayTest {<br>
   */<br>    */<br>
  public PlayTest() {<br>   public PlayTest() {<br>
    try {<br>     try {<br>
</tt>          <tt> al      = new AL();<br> </tt>         
<tt> al      = new AL();<br>
      alc     = new ALC();<br>       alc     = new ALC();<br>
      alut    = new ALUT();<br>
<br> <br>
      al.create();<br>       al.create();<br>
      alc.create();<br>       alc.create();<br>
      alut.create();<br>
   } catch (Exception e) {<br>    } catch (Exception e) {<br>
      e.printStackTrace();<br>       e.printStackTrace();<br>
    }</tt><tt><br>     }</tt><tt><br>
@ -76,7 +72,6 @@ We need instances of the following classes:<br>
<ul> <ul>
<li><tt>AL  </tt>- basic source, buffer and listener interaction</li> <li><tt>AL  </tt>- basic source, buffer and listener interaction</li>
<li><tt>ALC </tt>- context and device creatiuon</li> <li><tt>ALC </tt>- context and device creatiuon</li>
<li><tt>ALUT </tt>- OpenAL utility class</li>
</ul> </ul>
<b>1.3 OpenAL initialization</b><br> <b>1.3 OpenAL initialization</b><br>
Now that we have created a basic class containing instances of the relevant Now that we have created a basic class containing instances of the relevant
@ -129,21 +124,21 @@ Lets start of by creating one source, and one buffer:</p>
<b>1.5 Loading sounddata and setting up a buffer</b><br> <b>1.5 Loading sounddata and setting up a buffer</b><br>
Now that we have a buffer, we need to load some sound data into this buffer. Now that we have a buffer, we need to load some sound data into this buffer.
This is done using the <tt>al.bufferData</tt> method. In our example we will This is done using the <tt>al.bufferData</tt> method. In our example we will
cheat a bit, by using the <tt>ALUT </tt>method <tt>loadWAVFile</tt> to load "cheat" a bit, by using the <tt>WaveData</tt> class to load
a wave file, and copy this into the buffer:<br> a wave file, and copy this into the buffer:<br>
<p <p
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>  style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt> 
//load wave data<br> //load wave data<br>
  ALUTLoadWAVData file = alut.loadWAVFile("myfile.wav");<br>   WaveData wavefile = WaveData.create("mywavefile.wav");<br>
        <br>         <br>
  //copy to buffer<br>   //copy to buffer<br>
  al.bufferData(buffers.get(0), file.format, file.data, file.size, file.freq);<br>   al.bufferData(buffers.get(0), wavefile.format, Sys.getDirectBufferAddress(wavefile.data), wavefile.data.capacity(), wavefile.samplerate);<br>
        <br>         <br>
  //unload file again<br>   //unload file again<br>
  alut.unloadWAV(file.format, file.data, file.size, file.freq);        <br>   wavefile.dispose();        <br>
</tt></p> </tt></p>
Having loaded the data, we pass it to <tt>bufferData</tt>. Once the buffer Having loaded the data, we pass it to <tt>bufferData</tt>. Once the buffer
has been filled with sounddata, we unload it from the system using <tt>alut.unloadWAV</tt>. has been filled with sounddata, we unload it from the system using <tt>wavefile.dispose()</tt>.
Don't worry about deleting it this soon - the sounddata has been <b>copied</b> Don't worry about deleting it this soon - the sounddata has been <b>copied</b>
to the buffer.<br> to the buffer.<br>
<br> <br>
@ -202,7 +197,7 @@ as is shown here:<b><br>
  alc.closeDevice(device);</tt></p>   alc.closeDevice(device);</tt></p>
There, all set. Now you should be able to play some basic sound!<br> There, all set. Now you should be able to play some basic sound!<br>
This tutorial is rather short, and the above examples feature no error checking. This tutorial is rather short, and the above examples feature no error checking.
For the complete source code, look at:<br> For the complete source code, look at the classes in the <br>
<tt>org.lwjgl.openal.BasicTest</tt> in the repository.<br> <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/java/org/lwjgl/test/openal/" target="_blank"><tt>org.lwjgl.test.openal</tt></a> package.<br>
</body> </body>
</html> </html>