cnrg.itx.datax
Class MixerChannel

java.lang.Object
  |
  +--cnrg.itx.datax.Channel
        |
        +--cnrg.itx.datax.MixerChannel

public class MixerChannel
extends Channel
implements java.lang.Runnable

MixerChannel acts as a channel with multiple inputs. Destinations can be set (as in a standard Channel) with the addDestination() method. To use multiple inputs, call the getNewInput method. This returns a Channel object that can be assigned a source. Example:

The following creates a MixerChannel and adds a microphone soruce and a mixer source to it.

 
 Channel ch;
 MixerChannel mc = new MixerChannel();
 
 ch = mc.getNewInput();
 ch.setSource(new MicrophoneSource(ch));
 ch = mc.getNewInput();
 ch.setSource(new NetworkSource(...,ch,...));
 


Fields inherited from class cnrg.itx.datax.Channel
INPUT, OTHER, OUTPUT, SAMPLE_SIZE
 
Constructor Summary
MixerChannel()
          Creates an mixerChannel with no sources or destinations.
MixerChannel(int sampleSize)
          Creates a new mixerChannel with the specified sample size.
 
Method Summary
 void addDestination(Destination d)
          Method to add a destination for the Channel.
 void close()
          This method closes the MixerChannel.
 Channel getNewInput()
          Adds an additional source to the mixerChannel.
 Channel getNewSubtractedInput(Destination dest)
          Adds an additional source to the mixerChannel that will be silent to the given destination.
 PropertiesCollection getProperties()
          Gets the properties for this MixerChannel
 Source getSource()
          Returns the channel's source.
 Stats getStatistics()
          Method to get the statistics from the channel.
 void mute(boolean state)
          Method to mute all the sources and destinations
 void open()
          Method to open the Channel.
 void push(byte[] b)
          This method will push data into the MixerChannel's output channel skipping over the mixer.
 void removeAllDestinations()
          Method to remove all destinations.
 boolean removeDestination(Destination d)
          Method to remove a destination from the list.
 void removeInput(Channel c)
          Closes and removes a channel form the mixer.
 void removeInput(Source s)
          Closes and removes from the mixer the channel corresponding to the given source.
 void run()
          Implements the mixer thread.
 void setPeerProperties(PropertiesCollection pc)
          Interface to set the given properties collection into the device.
 void setProperties(PropertiesCollection pc)
          Sets the properties for this MixerChannel
 void setSource(Source s)
          Sets the source of the Mixer channel to a single source.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MixerChannel

public MixerChannel()
Creates an mixerChannel with no sources or destinations.

MixerChannel

public MixerChannel(int sampleSize)
Creates a new mixerChannel with the specified sample size.
Parameters:
sampleSize - the number of bytes to be sent by the channel in each write.
Method Detail

addDestination

public void addDestination(Destination d)
                    throws DuplicateDestinationException
Method to add a destination for the Channel. This will add the destination to the list of destinations.
Parameters:
d - The destination to add to the list of destination for the channel
Throws:
DuplicateDestinationException - thrown when d is already a destination of this channel.
Overrides:
addDestination in class Channel

removeDestination

public boolean removeDestination(Destination d)
Method to remove a destination from the list.
Parameters:
d - The Destination object to remove
Returns:
boolean True if the destination was found and removed
Overrides:
removeDestination in class Channel

removeAllDestinations

public void removeAllDestinations()
Method to remove all destinations.
Overrides:
removeAllDestinations in class Channel

open

public void open()
          throws DataException
Method to open the Channel. This method starts the mixer thread that mixes data from the sources and sends it to all the destinations. It also starts all of the mixer's sources and destinations.
Throws:
DataException - thrown when channel, or components of channel have already been closed.
Overrides:
open in class Channel

mute

public void mute(boolean state)
Method to mute all the sources and destinations
Parameters:
state - The state of the mute. true to mute and false to unmute
Overrides:
mute in class Channel

getProperties

public PropertiesCollection getProperties()
Gets the properties for this MixerChannel
Returns:
the ProertiesCollection
Overrides:
getProperties in class Channel

setProperties

public void setProperties(PropertiesCollection pc)
Sets the properties for this MixerChannel
Parameters:
pc - The new PropertiesCollection for this MixerChannel
Overrides:
setProperties in class Channel

setPeerProperties

public void setPeerProperties(PropertiesCollection pc)
                       throws DataException
Interface to set the given properties collection into the device. Works under the assumption that this is the properties collection of the peer.
Overrides:
setPeerProperties in class Channel

getStatistics

public Stats getStatistics()
Method to get the statistics from the channel. This method gets the statistics from the devices connected to the channel.
Returns:
Stats the statistics for the channel
Overrides:
getStatistics in class Channel

getSource

public Source getSource()
Returns the channel's source. By default, this is a dummy object. This method is included for compatibility. NOTE: This will not return the ultimate source of the audio, since there is no single source.
Returns:
Source the channel's Source
Overrides:
getSource in class Channel

setSource

public void setSource(Source s)
Sets the source of the Mixer channel to a single source. By default, MixerChannels have no real single source. Setting one could produce unpredictable results.
Parameters:
s - the new source for the MixerChannel
Overrides:
setSource in class Channel

getNewInput

public Channel getNewInput()
Adds an additional source to the mixerChannel. If a new input is added after the mixer has been opened, you must open the input's corresponding channel manually by calling its open() method.
Returns:
Channel a channel to which you can assign a new source

getNewSubtractedInput

public Channel getNewSubtractedInput(Destination dest)
Adds an additional source to the mixerChannel that will be silent to the given destination. If the output is not a destination of the mixerChannel, it will be added as one.
Parameters:
dest - the Destination object to be removed from the mix sent to the returned channel
Returns:
Channel the new ChannelBuffer input to the mixer

removeInput

public void removeInput(Channel c)
Closes and removes a channel form the mixer.

Closing this channel also closes its source.

Parameters:
the - channel corresponding to the input to be removed.

removeInput

public void removeInput(Source s)
Closes and removes from the mixer the channel corresponding to the given source.

(closes both channel and source)

NOTE: slower than removeInput(Channel c).

Parameters:
s - the Source corresponding to the input to be removed

run

public void run()
Implements the mixer thread. Reads form all of the inputs, mixes the samples, and writes out the result to the destinations.
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class Channel

close

public void close()
This method closes the MixerChannel. It first closes all of the channels inputs, then brings down the mixer thread. finally, it closes the output buffer (if it exists)
Overrides:
close in class Channel

push

public void push(byte[] b)
This method will push data into the MixerChannel's output channel skipping over the mixer. When sending data through the mixerChannel, data should instead be sent by invoking the push methods of the inChannels. Included for compatibility. May produce unpredictable results.
Parameters:
b - the data to be sent to the output
Overrides:
push in class Channel