com.groovemanager.sampled.fx
Class FXUnit

java.lang.Object
  extended by com.groovemanager.sampled.fx.FXUnit
All Implemented Interfaces:
javax.sound.sampled.Line, javax.sound.sampled.Mixer

public class FXUnit
extends java.lang.Object
implements javax.sound.sampled.Mixer

This implementation of Mixer is a questionable effort to think of an effect unit as a Mixer. An FXUnit can handle the processing of audio data with an Effect instance. A SourceDataLine for analysis and a SourceDataLine for processing as well as a TargetDataLine for the resulting audio data are provided by this Mixer and the effect´s Controls can also be accessed through the FXUnit.

Author:
Manu Robledo

Nested Class Summary
(package private)  class FXUnit.FXAnalysisLine
          A FXAnalysisLine is used for streaming audio data for analysis into the FXUnit
(package private)  class FXUnit.FXSourceDataLine
          A FXSourceDataLine is used for streaming audio data into the FXUnit
(package private)  class FXUnit.FXTargetDataLine
          A FXTargetDataLine is used for reading processed audio data out of the FXUnit
(package private)  class FXUnit.Info
          Subclass of Mixer.Info to be able to create a new instance
 
Field Summary
private  FXUnit.FXAnalysisLine analysisLine
          The SourceDataLine for sending the audio data to be analyzed
private  RingBuffer buffer
          The RingBuffer into which the FXSourceLine writes its data and from which the FXTargetLine reads its data
private  javax.sound.sampled.AudioFormat currentFormat
          The current used AudioFormat
private static int DEFAULT_BUFFER_SIZE
          The default buffer size for effect processing
static javax.sound.sampled.AudioFormat DEFAULT_FORMAT
          A Float encoded 2 channel AudioFormat with NOT_SPECIFIED sample rate for use with DataLine.Info.getFormats()
private  Effect effect
          The Effect represented by this FXUnit
static javax.sound.sampled.AudioFormat FORMAT
          A Float encoded 2 channel AudioFormat with NOT_SPECIFIED sample rate for use with DataLine.Info.getFormats()
private  java.nio.FloatBuffer[] inBuffers
          Array of two FloatBuffers used for processing
private  java.util.ArrayList lineListeners
          List of LineListeners
private  boolean lineOpen
          Indicates whether the FXSourceLine and/or the FXTargetLine are open or not
private  FXUnit.Info mixerInfo
          The Mixer.Info object for this FXUnit
private  java.nio.FloatBuffer[] outBuffers
          Array of two FloatBuffers used for processing
private  FXUnit.FXSourceDataLine sourceLine
          The SourceDataLine for sending the audio data to be processed
private  FXUnit.FXTargetDataLine targetLine
          The TargetDataLine for receiving the processed audio data
 
Constructor Summary
FXUnit(Effect effect)
          Create a new FXUnit for the given Effect
 
Method Summary
 void addLineListener(javax.sound.sampled.LineListener listener)
           
 void close()
           
private  void createBuffers(int bufferSize)
          Create the RingBuffer and the needed temporary Buffers for the specified buffer size in bytes
protected  javax.sound.sampled.AudioFormat createFormat(float sampleRate)
          Create an AudioFormat object with the given sample rate
protected  FXUnit.Info createInfo()
          Create the Mixer.Info object for this Unit
 javax.sound.sampled.SourceDataLine getAnalysisLine()
          Get the SourceDataLine that is used for analysis input
 javax.sound.sampled.Control getControl(javax.sound.sampled.Control.Type type)
           
 javax.sound.sampled.Control[] getControls()
           
 javax.sound.sampled.SourceDataLine getEffectSourceLine()
          Get the SourceDataLine used for effect input
 javax.sound.sampled.TargetDataLine getEffectTargetLine()
          Get the TargetDataLine from which the Effect´s result can be read
 javax.sound.sampled.Line getLine(javax.sound.sampled.Line.Info info)
           
 javax.sound.sampled.Line.Info getLineInfo()
           
 int getMaxLines(javax.sound.sampled.Line.Info info)
           
 javax.sound.sampled.Mixer.Info getMixerInfo()
           
 javax.sound.sampled.Line.Info[] getSourceLineInfo()
           
 javax.sound.sampled.Line.Info[] getSourceLineInfo(javax.sound.sampled.Line.Info info)
           
 javax.sound.sampled.Line[] getSourceLines()
           
 javax.sound.sampled.Line.Info[] getTargetLineInfo()
           
 javax.sound.sampled.Line.Info[] getTargetLineInfo(javax.sound.sampled.Line.Info info)
           
 javax.sound.sampled.Line[] getTargetLines()
           
 boolean isControlSupported(javax.sound.sampled.Control.Type type)
           
 boolean isLineSupported(javax.sound.sampled.Line.Info info)
           
 boolean isOpen()
           
 boolean isSynchronizationSupported(javax.sound.sampled.Line[] lines, boolean maintainSync)
           
private  void notifyListeners(javax.sound.sampled.LineEvent.Type type)
          Notify all registered LineListeners about a LineEvent
 void open()
           
 void removeLineListener(javax.sound.sampled.LineListener listener)
           
 void synchronize(javax.sound.sampled.Line[] lines, boolean maintainSync)
           
 void unsynchronize(javax.sound.sampled.Line[] lines)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

analysisLine

private final FXUnit.FXAnalysisLine analysisLine
The SourceDataLine for sending the audio data to be analyzed


buffer

private RingBuffer buffer
The RingBuffer into which the FXSourceLine writes its data and from which the FXTargetLine reads its data


currentFormat

private javax.sound.sampled.AudioFormat currentFormat
The current used AudioFormat


DEFAULT_BUFFER_SIZE

private static final int DEFAULT_BUFFER_SIZE
The default buffer size for effect processing

See Also:
Constant Field Values

DEFAULT_FORMAT

public static final javax.sound.sampled.AudioFormat DEFAULT_FORMAT
A Float encoded 2 channel AudioFormat with NOT_SPECIFIED sample rate for use with DataLine.Info.getFormats()


effect

private final Effect effect
The Effect represented by this FXUnit


FORMAT

public static final javax.sound.sampled.AudioFormat FORMAT
A Float encoded 2 channel AudioFormat with NOT_SPECIFIED sample rate for use with DataLine.Info.getFormats()


inBuffers

private java.nio.FloatBuffer[] inBuffers
Array of two FloatBuffers used for processing


lineListeners

private java.util.ArrayList lineListeners
List of LineListeners


lineOpen

private boolean lineOpen
Indicates whether the FXSourceLine and/or the FXTargetLine are open or not


mixerInfo

private final FXUnit.Info mixerInfo
The Mixer.Info object for this FXUnit


outBuffers

private java.nio.FloatBuffer[] outBuffers
Array of two FloatBuffers used for processing


sourceLine

private final FXUnit.FXSourceDataLine sourceLine
The SourceDataLine for sending the audio data to be processed


targetLine

private final FXUnit.FXTargetDataLine targetLine
The TargetDataLine for receiving the processed audio data

Constructor Detail

FXUnit

public FXUnit(Effect effect)
Create a new FXUnit for the given Effect

Parameters:
effect - The Effect to wrap with an FXUnit
Method Detail

addLineListener

public void addLineListener(javax.sound.sampled.LineListener listener)
Specified by:
addLineListener in interface javax.sound.sampled.Line
See Also:
Line.addLineListener(javax.sound.sampled.LineListener)

close

public void close()
Specified by:
close in interface javax.sound.sampled.Line
See Also:
Line.close()

createBuffers

private void createBuffers(int bufferSize)
Create the RingBuffer and the needed temporary Buffers for the specified buffer size in bytes

Parameters:
bufferSize - The buffer size in bytes

createFormat

protected javax.sound.sampled.AudioFormat createFormat(float sampleRate)
Create an AudioFormat object with the given sample rate

Parameters:
sampleRate -
Returns:
The new AudioFormat object

createInfo

protected FXUnit.Info createInfo()
Create the Mixer.Info object for this Unit

Returns:
The Mixer.Info object to be used for this unit

getAnalysisLine

public javax.sound.sampled.SourceDataLine getAnalysisLine()
Get the SourceDataLine that is used for analysis input

Returns:
A SourceDataLine into which the audio data for analyzation should be fed.

getControl

public javax.sound.sampled.Control getControl(javax.sound.sampled.Control.Type type)
Specified by:
getControl in interface javax.sound.sampled.Line
See Also:
Line.getControl(javax.sound.sampled.Control.Type)

getControls

public javax.sound.sampled.Control[] getControls()
Specified by:
getControls in interface javax.sound.sampled.Line
See Also:
Line.getControls()

getEffectSourceLine

public javax.sound.sampled.SourceDataLine getEffectSourceLine()
Get the SourceDataLine used for effect input

Returns:
A SourceDataLine into which the audio data for processing should be fed.

getEffectTargetLine

public javax.sound.sampled.TargetDataLine getEffectTargetLine()
Get the TargetDataLine from which the Effect´s result can be read

Returns:
A TargetDataLine from which the processed audio data can be read

getLine

public javax.sound.sampled.Line getLine(javax.sound.sampled.Line.Info info)
                                 throws javax.sound.sampled.LineUnavailableException
Specified by:
getLine in interface javax.sound.sampled.Mixer
Throws:
javax.sound.sampled.LineUnavailableException
See Also:
Mixer.getLine(javax.sound.sampled.Line.Info)

getLineInfo

public javax.sound.sampled.Line.Info getLineInfo()
Specified by:
getLineInfo in interface javax.sound.sampled.Line
See Also:
Line.getLineInfo()

getMaxLines

public int getMaxLines(javax.sound.sampled.Line.Info info)
Specified by:
getMaxLines in interface javax.sound.sampled.Mixer
See Also:
Mixer.getMaxLines(javax.sound.sampled.Line.Info)

getMixerInfo

public javax.sound.sampled.Mixer.Info getMixerInfo()
Specified by:
getMixerInfo in interface javax.sound.sampled.Mixer
See Also:
Mixer.getMixerInfo()

getSourceLineInfo

public javax.sound.sampled.Line.Info[] getSourceLineInfo()
Specified by:
getSourceLineInfo in interface javax.sound.sampled.Mixer
See Also:
Mixer.getSourceLineInfo()

getSourceLineInfo

public javax.sound.sampled.Line.Info[] getSourceLineInfo(javax.sound.sampled.Line.Info info)
Specified by:
getSourceLineInfo in interface javax.sound.sampled.Mixer
See Also:
Mixer.getSourceLineInfo(javax.sound.sampled.Line.Info)

getSourceLines

public javax.sound.sampled.Line[] getSourceLines()
Specified by:
getSourceLines in interface javax.sound.sampled.Mixer
See Also:
Mixer.getSourceLines()

getTargetLineInfo

public javax.sound.sampled.Line.Info[] getTargetLineInfo()
Specified by:
getTargetLineInfo in interface javax.sound.sampled.Mixer
See Also:
Mixer.getTargetLineInfo()

getTargetLineInfo

public javax.sound.sampled.Line.Info[] getTargetLineInfo(javax.sound.sampled.Line.Info info)
Specified by:
getTargetLineInfo in interface javax.sound.sampled.Mixer
See Also:
Mixer.getTargetLineInfo(javax.sound.sampled.Line.Info)

getTargetLines

public javax.sound.sampled.Line[] getTargetLines()
Specified by:
getTargetLines in interface javax.sound.sampled.Mixer
See Also:
Mixer.getTargetLines()

isControlSupported

public boolean isControlSupported(javax.sound.sampled.Control.Type type)
Specified by:
isControlSupported in interface javax.sound.sampled.Line
See Also:
Line.isControlSupported(javax.sound.sampled.Control.Type)

isLineSupported

public boolean isLineSupported(javax.sound.sampled.Line.Info info)
Specified by:
isLineSupported in interface javax.sound.sampled.Mixer
See Also:
Mixer.isLineSupported(javax.sound.sampled.Line.Info)

isOpen

public boolean isOpen()
Specified by:
isOpen in interface javax.sound.sampled.Line
See Also:
Line.isOpen()

isSynchronizationSupported

public boolean isSynchronizationSupported(javax.sound.sampled.Line[] lines,
                                          boolean maintainSync)
Specified by:
isSynchronizationSupported in interface javax.sound.sampled.Mixer
See Also:
Mixer.isSynchronizationSupported(javax.sound.sampled.Line[], boolean)

notifyListeners

private void notifyListeners(javax.sound.sampled.LineEvent.Type type)
Notify all registered LineListeners about a LineEvent

Parameters:
type - The type of the LineEvent

open

public void open()
          throws javax.sound.sampled.LineUnavailableException
Specified by:
open in interface javax.sound.sampled.Line
Throws:
javax.sound.sampled.LineUnavailableException
See Also:
Line.open()

removeLineListener

public void removeLineListener(javax.sound.sampled.LineListener listener)
Specified by:
removeLineListener in interface javax.sound.sampled.Line
See Also:
Line.removeLineListener(javax.sound.sampled.LineListener)

synchronize

public void synchronize(javax.sound.sampled.Line[] lines,
                        boolean maintainSync)
Specified by:
synchronize in interface javax.sound.sampled.Mixer
See Also:
Mixer.synchronize(javax.sound.sampled.Line[], boolean)

unsynchronize

public void unsynchronize(javax.sound.sampled.Line[] lines)
Specified by:
unsynchronize in interface javax.sound.sampled.Mixer
See Also:
Mixer.unsynchronize(javax.sound.sampled.Line[])