paulscode.sound.libraries
Class ChannelLWJGLOpenAL

java.lang.Object
  extended by paulscode.sound.Channel
      extended by paulscode.sound.libraries.ChannelLWJGLOpenAL

public class ChannelLWJGLOpenAL
extends Channel

The ChannelLWJGLOpenAL class is used to reserve a sound-card voice using the lwjgl binding of OpenAL. Channels can be either normal or streaming channels.

This software is based on or using the LWJGL Lightweight Java Gaming Library available from http://www.lwjgl.org/.


LWJGL License:
Copyright (c) 2002-2008 Lightweight Java Game Library Project All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of 'Light Weight Java Game Library' nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


SoundSystem LibraryLWJGLOpenAL License:

You are free to use this library for any purpose, commercial or otherwise. You may modify this library or source code, and distribute it any way you like, provided the following conditions are met:
1) You must abide by the conditions of the aforementioned LWJGL License.
2) You may not falsely claim to be the author of this library or any unmodified portion of it.
3) You may not copyright this library or a modified version of it and then sue me for copyright infringement.
4) If you modify the source code, you must clearly document the changes made before redistributing the modified source code, so other users know it is not the original code.
5) You are not required to give me credit for this library in any derived work, but if you do, you must also mention my website: http://www.paulscode.com
6) I the author will not be responsible for any damages (physical, financial, or otherwise) caused by the use if this library or any part of it.
7) I the author do not guarantee, warrant, or make any representations, either expressed or implied, regarding the use of this library or any part of it.

Author: Paul Lamb
http://www.paulscode.com


Field Summary
 int ALformat
          OpenAL data format to use when playing back the assigned source.
 java.nio.IntBuffer ALSource
          OpenAL's IntBuffer identifier for this channel.
 float millisPreviouslyPlayed
          Miliseconds of buffers previously played (streaming sources).
 int sampleRate
          Sample rate (speed) to use for play-back.
 
Fields inherited from class paulscode.sound.Channel
attachedSource, buffersUnqueued, channelType, libraryType
 
Constructor Summary
ChannelLWJGLOpenAL(int type, java.nio.IntBuffer src)
          Constructor: takes channelType identifier and a handle to the OpenAL IntBuffer identifier to use for this channel.
 
Method Summary
 boolean attachBuffer(java.nio.IntBuffer buf)
          Attaches an OpenAL sound-buffer identifier for the sound data to be played back for a normal source.
 int buffersProcessed()
          Returns the number of queued byte[] buffers that have finished playing.
 void cleanup()
          Empties the streamBuffers list, stops and deletes the ALSource, shuts the channel down, and removes references to all instantiated objects.
 void close()
          Stops the channel, dequeues any queued data, and closes the channel.
 int feedRawAudioData(byte[] buffer)
          Feeds raw data to the stream.
 void flush()
          Dequeues all previously queued data.
 float millisecondsPlayed()
          Calculates the number of milliseconds since the channel began playing.
 float millisInBuffer(int alBufferi)
          Returns the number of milliseconds of audio contained in specified buffer.
 void pause()
          Temporarily stops playback for this channel.
 void play()
          Plays the currently attached normal source, opens this channel up for streaming, or resumes playback if this channel was paused.
 boolean playing()
          Used to determine if a channel is actively playing a source.
 boolean preLoadBuffers(java.util.LinkedList<byte[]> bufferList)
          Queues up the initial byte[] buffers of data to be streamed.
 boolean queueBuffer(byte[] buffer)
          Queues up a byte[] buffer of data to be streamed.
 void rewind()
          Rewinds the attached source to the beginning.
 void setAudioFormat(javax.sound.sampled.AudioFormat audioFormat)
          Sets the channel up to receive the specified audio format.
 void setFormat(int format, int rate)
          Sets the channel up to receive the specified OpenAL audio format and sample rate.
 void stop()
          Stops playback for this channel and rewinds the attached source to the beginning.
 
Methods inherited from class paulscode.sound.Channel
errorCheck, errorMessage, getClassName, importantMessage, message, printStackTrace, processBuffer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALSource

public java.nio.IntBuffer ALSource
OpenAL's IntBuffer identifier for this channel.


ALformat

public int ALformat
OpenAL data format to use when playing back the assigned source.


sampleRate

public int sampleRate
Sample rate (speed) to use for play-back.


millisPreviouslyPlayed

public float millisPreviouslyPlayed
Miliseconds of buffers previously played (streaming sources).

Constructor Detail

ChannelLWJGLOpenAL

public ChannelLWJGLOpenAL(int type,
                          java.nio.IntBuffer src)
Constructor: takes channelType identifier and a handle to the OpenAL IntBuffer identifier to use for this channel. Possible values for channel type can be found in the SoundSystemConfig class.

Parameters:
type - Type of channel (normal or streaming).
src - Handle to the OpenAL source identifier.
Method Detail

cleanup

public void cleanup()
Empties the streamBuffers list, stops and deletes the ALSource, shuts the channel down, and removes references to all instantiated objects.

Overrides:
cleanup in class Channel

attachBuffer

public boolean attachBuffer(java.nio.IntBuffer buf)
Attaches an OpenAL sound-buffer identifier for the sound data to be played back for a normal source.

Parameters:
buf - Intbuffer identifier for the sound data to play.
Returns:
False if an error occurred.

setAudioFormat

public void setAudioFormat(javax.sound.sampled.AudioFormat audioFormat)
Sets the channel up to receive the specified audio format.

Overrides:
setAudioFormat in class Channel
Parameters:
audioFormat - Format to use when playing the stream data.

setFormat

public void setFormat(int format,
                      int rate)
Sets the channel up to receive the specified OpenAL audio format and sample rate.

Parameters:
format - Format to use.
rate - Sample rate (speed) to use.

preLoadBuffers

public boolean preLoadBuffers(java.util.LinkedList<byte[]> bufferList)
Queues up the initial byte[] buffers of data to be streamed.

Overrides:
preLoadBuffers in class Channel
Parameters:
bufferList - List of the first buffers to be played for a streaming source.
Returns:
False if problem occurred or if end of stream was reached.

queueBuffer

public boolean queueBuffer(byte[] buffer)
Queues up a byte[] buffer of data to be streamed.

Overrides:
queueBuffer in class Channel
Parameters:
buffer - The next buffer to be played for a streaming source.
Returns:
False if an error occurred or if the channel is shutting down.

feedRawAudioData

public int feedRawAudioData(byte[] buffer)
Feeds raw data to the stream.

Overrides:
feedRawAudioData in class Channel
Parameters:
buffer - Buffer containing raw audio data to stream.
Returns:
Number of prior buffers that have been processed., or -1 if error.

millisInBuffer

public float millisInBuffer(int alBufferi)
Returns the number of milliseconds of audio contained in specified buffer.

Returns:
milliseconds, or 0 if unable to calculate.

millisecondsPlayed

public float millisecondsPlayed()
Calculates the number of milliseconds since the channel began playing.

Overrides:
millisecondsPlayed in class Channel
Returns:
Milliseconds, or -1 if unable to calculate.

buffersProcessed

public int buffersProcessed()
Returns the number of queued byte[] buffers that have finished playing.

Overrides:
buffersProcessed in class Channel
Returns:
Number of buffers processed.

flush

public void flush()
Dequeues all previously queued data.

Overrides:
flush in class Channel

close

public void close()
Stops the channel, dequeues any queued data, and closes the channel.

Overrides:
close in class Channel

play

public void play()
Plays the currently attached normal source, opens this channel up for streaming, or resumes playback if this channel was paused.

Overrides:
play in class Channel

pause

public void pause()
Temporarily stops playback for this channel.

Overrides:
pause in class Channel

stop

public void stop()
Stops playback for this channel and rewinds the attached source to the beginning.

Overrides:
stop in class Channel

rewind

public void rewind()
Rewinds the attached source to the beginning. Stops the source if it was paused.

Overrides:
rewind in class Channel

playing

public boolean playing()
Used to determine if a channel is actively playing a source. This method will return false if the channel is paused or stopped and when no data is queued to be streamed.

Overrides:
playing in class Channel
Returns:
True if this channel is playing a source.