Class Channel

java.lang.Object
com.ardor3d.audio.Channel
Direct Known Subclasses:
ChannelJOAL

public class Channel extends Object
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
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    Whatever 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).
    protected Class<? extends Library>
    The library class associated with this type of channel.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Channel(int type)
    Constructor: Takes channelType identifier as a paramater.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the number of queued byte[] buffers that have finished playing.
    void
    Shuts the channel down and removes references to all instantiated objects.
    void
    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
    Prints an error message.
    int
    feedRawAudioData(byte[] buffer)
    Feeds raw data to the stream.
    void
    Dequeues all previously queued data.
    Returns the name of the class.
    protected void
    Prints an important message.
    protected void
    message(String message)
    Prints a message.
    float
    Calculates the number of milliseconds since the channel began playing.
    void
    Temporarily stops playback for this channel.
    void
    Plays the currently attached normal source, opens this channel up for streaming, or resumes playback if this channel was paused.
    boolean
    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
    Rewinds the attached source to the beginning.
    void
    Sets the channel up to receive the specified audio format.
    void
    Stops playback for this channel and rewinds the attached source to the beginning.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • libraryType

      protected Class<? extends Library> libraryType
      The library class associated with this type of channel.
    • channelType

      public int channelType
      Global identifier for the type of channel (normal or streaming). Possible values for this varriable can be found in the SoundSystemConfig class.
    • attachedSource

      public Source attachedSource
      Whatever source is attached to this channel.
    • buffersUnqueued

      public int buffersUnqueued
      Cumulative 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 the SoundSystemConfig 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

      public boolean preLoadBuffers(LinkedList<byte[]> bufferList)
      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 seperate StreamThread.
      Returns:
      False when no more buffers are left to process.
    • setAudioFormat

      public void setAudioFormat(AudioFormat audioFormat)
      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

      public String getClassName()
      Returns the name of the class.
      Returns:
      "Channel" + library title.
    • message

      protected void message(String message)
      Prints a message.
      Parameters:
      message - Message to print.
    • importantMessage

      protected void importantMessage(String message)
      Prints an important message.
      Parameters:
      message - Message to print.
    • errorCheck

      protected boolean errorCheck(boolean error, String message)
      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

      protected void errorMessage(String message)
      Prints an error message.
      Parameters:
      message - Message to print.
    • printStackTrace

      protected void printStackTrace(Exception e)
      Prints an exception's error message followed by the stack trace.
      Parameters:
      e - Exception containing the information to print.