Package com.ardor3d.audio
Class Channel
java.lang.Object
com.ardor3d.audio.Channel
- Direct Known Subclasses:
ChannelJOAL
The Channel class is the base class which can be extended for
library-specific channels. It is also used in the "no-sound" library.
A channel is a reserved sound-card voice through which sources are played
back. Channels can be either streaming channels or normal (non-streaming)
ones. For consistant naming conventions, each sub-class should have the
name prefix "Channel".
SoundSystem 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 may not falsely claim to be the author of this library or any unmodified portion of it.
2) You may not copyright this library or a modified version of it and then sue me for copyright infringement.
3) 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.
4) 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
5) 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.
6) 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
SoundSystem 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 may not falsely claim to be the author of this library or any unmodified portion of it.
2) You may not copyright this library or a modified version of it and then sue me for copyright infringement.
3) 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.
4) 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
5) 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.
6) 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
Modifier and TypeFieldDescriptionWhatever source is attached to this channel.int
Cumulative counter of the buffers played then unqued.int
Global identifier for the type of channel (normal or streaming).The library class associated with this type of channel. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
Returns the number of queued byte[] buffers that have finished playing.void
cleanup()
Shuts the channel down and removes references to all instantiated objects.void
close()
Stops the channel, dequeues any queued data, and closes the channel.protected boolean
errorCheck
(boolean error, String message) Prints the specified message if error is true.protected void
errorMessage
(String message) Prints an error message.int
feedRawAudioData
(byte[] buffer) Feeds raw data to the stream.void
flush()
Dequeues all previously queued data.Returns the name of the class.protected void
importantMessage
(String message) Prints an important message.protected void
Prints a message.float
Calculates the number of milliseconds since the channel began playing.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
(LinkedList<byte[]> bufferList) Queues up the initial byte[] buffers of data to be streamed.protected void
Prints an exception's error message followed by the stack trace.boolean
Plays the next queued byte[] buffer.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
(AudioFormat audioFormat) Sets the channel up to receive the specified audio format.void
stop()
Stops playback for this channel and rewinds the attached source to the beginning.
-
Field Details
-
libraryType
The library class associated with this type of channel. -
channelType
public int channelTypeGlobal identifier for the type of channel (normal or streaming). Possible values for this varriable can be found in theSoundSystemConfig
class. -
attachedSource
Whatever source is attached to this channel. -
buffersUnqueued
public int buffersUnqueuedCumulative counter of the buffers played then unqued.
-
-
Constructor Details
-
Channel
public Channel(int type) Constructor: Takes channelType identifier as a paramater. Possible values for channel type can be found in theSoundSystemConfig
class.- Parameters:
type
- Type of channel (normal or streaming).
-
-
Method Details
-
cleanup
public void cleanup()Shuts the channel down and removes references to all instantiated objects. -
preLoadBuffers
Queues up the initial byte[] buffers of data to be streamed.- Parameters:
bufferList
- List of the first buffers to be played for a streaming source.- Returns:
- False if an error occurred or if end of stream was reached.
-
queueBuffer
public boolean queueBuffer(byte[] buffer) Queues up a byte[] buffer of data to be streamed.- 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.- Parameters:
buffer
- Buffer containing raw audio data to stream.- Returns:
- Number of prior buffers that have been processed.
-
buffersProcessed
public int buffersProcessed()Returns the number of queued byte[] buffers that have finished playing.- Returns:
- Number of buffers processed.
-
millisecondsPlayed
public float millisecondsPlayed()Calculates the number of milliseconds since the channel began playing.- Returns:
- Milliseconds, or -1 if unable to calculate.
-
processBuffer
public boolean processBuffer()Plays the next queued byte[] buffer. This method is run from the seperateStreamThread
.- Returns:
- False when no more buffers are left to process.
-
setAudioFormat
Sets the channel up to receive the specified audio format. -
flush
public void flush()Dequeues all previously queued data. -
close
public void close()Stops the channel, dequeues any queued data, and closes the 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. -
pause
public void pause()Temporarily stops playback for this channel. -
stop
public void stop()Stops playback for this channel and rewinds the attached source to the beginning. -
rewind
public void rewind()Rewinds the attached source to the beginning. Stops the source if it was paused. -
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.- Returns:
- True if this channel is playing a source.
-
getClassName
Returns the name of the class.- Returns:
- "Channel" + library title.
-
message
Prints a message.- Parameters:
message
- Message to print.
-
importantMessage
Prints an important message.- Parameters:
message
- Message to print.
-
errorCheck
Prints the specified message if error is true.- Parameters:
error
- True or False.message
- Message to print if error is true.- Returns:
- True if error is true.
-
errorMessage
Prints an error message.- Parameters:
message
- Message to print.
-
printStackTrace
Prints an exception's error message followed by the stack trace.- Parameters:
e
- Exception containing the information to print.
-