ddf.minim
Class SignalSplitter

java.lang.Object
  extended by ddf.minim.SignalSplitter
All Implemented Interfaces:
AudioListener, Recordable

public class SignalSplitter
extends java.lang.Object
implements Recordable, AudioListener

A SignalSplitter acts exactly like a headphone splitter. When you pass it audio with the samples method, it echoes that audio out to all of its listeners, giving each their own copy of the audio. In other words, changes that the listeners make to the float arrays they receive from a SignalSplitter will not be reflected in the arrays you pass to samples. SignalSplitter is fully synchronized so that listeners cannot be added and removed while it is in the midst transmitting.

Author:
Damien Di Fede

Constructor Summary
SignalSplitter(javax.sound.sampled.AudioFormat format, int bufferSize)
          Construct a SignalSplitter that will receive audio in the given format and in buffers the size of bufferSize.
 
Method Summary
 void addListener(AudioListener listener)
          Adds a listener who will be notified each time this receives or creates a new buffer of samples.
 int bufferSize()
          Returns the buffer size being used by this.
 javax.sound.sampled.AudioFormat getFormat()
          Returns the format of this recordable audio.
 void removeListener(AudioListener listener)
          Removes the listener from the list of listeners.
 float sampleRate()
          Returns the sample rate of this recordable audio.
 void samples(float[] samp)
          Called by the Recordable object this is attached to when that object has new samples.
 void samples(float[] sampL, float[] sampR)
          Called by the Recordable object this is attached to when that object has new samples.
 int type()
          Returns either Minim.MONO or Minim.STEREO
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SignalSplitter

public SignalSplitter(javax.sound.sampled.AudioFormat format,
                      int bufferSize)
Construct a SignalSplitter that will receive audio in the given format and in buffers the size of bufferSize. Strictly speaking, a SignalSplitter doesn't care about either of these things because it does nothing with the samples it receives other than pass them on. But both things are required to fulfill the Recordable contract.

Parameters:
format - the AudioFormat of samples that this will receive
bufferSize - the size of the float arrays this will receive
Method Detail

bufferSize

public int bufferSize()
Description copied from interface: Recordable
Returns the buffer size being used by this.

Specified by:
bufferSize in interface Recordable
Returns:
the buffer size

getFormat

public javax.sound.sampled.AudioFormat getFormat()
Description copied from interface: Recordable
Returns the format of this recordable audio.

Specified by:
getFormat in interface Recordable
Returns:
the format of the audio

type

public int type()
Description copied from interface: Recordable
Returns either Minim.MONO or Minim.STEREO

Specified by:
type in interface Recordable
Returns:
Minim.MONO if this is mono, Minim.STEREO if this is stereo

addListener

public void addListener(AudioListener listener)
Description copied from interface: Recordable
Adds a listener who will be notified each time this receives or creates a new buffer of samples. If the listener has already been added, it will not be added again.

Specified by:
addListener in interface Recordable
Parameters:
listener - the listener to add

removeListener

public void removeListener(AudioListener listener)
Description copied from interface: Recordable
Removes the listener from the list of listeners.

Specified by:
removeListener in interface Recordable
Parameters:
listener - the listener to remove

samples

public void samples(float[] samp)
Description copied from interface: AudioListener
Called by the Recordable object this is attached to when that object has new samples.

Specified by:
samples in interface AudioListener
Parameters:
samp - a buffer of samples from a MONO sound stream

samples

public void samples(float[] sampL,
                    float[] sampR)
Description copied from interface: AudioListener
Called by the Recordable object this is attached to when that object has new samples.

Specified by:
samples in interface AudioListener
Parameters:
sampL - the left channel of a STEREO sound stream
sampR - the right channel of a STEREO sound stream

sampleRate

public float sampleRate()
Description copied from interface: Recordable
Returns the sample rate of this recordable audio.

Specified by:
sampleRate in interface Recordable
Returns:
the sample rate of this recordable audio