paulscode.sound.libraries
Class ChannelJOAL

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

public class ChannelJOAL
extends Channel

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

This software is based on or using the JOAL Library available from http://joal.dev.java.net/


JOAL License:
Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
-Redistribution of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
-Redistribution 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 Sun Microsystems, Inc. or the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.
This software is provided "AS IS," without a warranty of any kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
You acknowledge that this software is not designed or intended for use in the design, construction, operation or maintenance of any nuclear facility.


SoundSystem LibraryJOAL 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 JOAL 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.
 int[] ALSource
          OpenAL's 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
ChannelJOAL(int type, int[] src)
          Constructor: takes channelType identifier and a handle to the OpenAL identifier to use for this channel.
 
Method Summary
 boolean attachBuffer(int[] 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 int[] ALSource
OpenAL's 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

ChannelJOAL

public ChannelJOAL(int type,
                   int[] src)
Constructor: takes channelType identifier and a handle to the OpenAL 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(int[] buf)
Attaches an OpenAL sound-buffer identifier for the sound data to be played back for a normal source.

Parameters:
buf - 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.