com.groovemanager.spi.asio
Class ASIODataLine

java.lang.Object
  extended by com.groovemanager.spi.asio.ASIODataLine
All Implemented Interfaces:
javax.sound.sampled.DataLine, javax.sound.sampled.Line, javax.sound.sampled.SourceDataLine, javax.sound.sampled.TargetDataLine

public class ASIODataLine
extends java.lang.Object
implements javax.sound.sampled.SourceDataLine, javax.sound.sampled.TargetDataLine

This class implements SourceDataLine as well as TargetDataLine because input and output processing is similar in ASIO. All lines provided by the ASIOMixer will be instances of this class.

Author:
Manu Robledo

Nested Class Summary
 
Nested classes inherited from class javax.sound.sampled.DataLine
javax.sound.sampled.DataLine.Info
 
Nested classes inherited from class javax.sound.sampled.DataLine
javax.sound.sampled.DataLine.Info
 
Field Summary
(package private)  java.nio.ByteBuffer[][] asioBuffers
          The real asioBuffers.
(package private)  int channels
          Number of channels associated with this line right now
private  javax.sound.sampled.Control[] controls
          the Controls for this line
private  int desiredBufferSize
          The buffersize in bytes specified to open(AudioFormat, int)
private  byte[] emptyArray
          an empty array for flushing
private  boolean flushed
          indicates whether flus() has been called lately on this line
private  javax.sound.sampled.AudioFormat format
          The format of this line when its running
private  int frameSize
          frameSize of the current format
private  ASIOLineInfo info
          THE ASIOLineInfo object corresponding to this line
private  java.util.ArrayList listeners
          List of the registered LineListeners
private  ASIOMixer mixer
          The ASIOMixer instance which created this line
private  boolean open
          Indicates if this line is open
private  long openSeq
          Sequence number used when opening this line.
(package private)  DoubleHalfRingBuffer[] ringBuffers
          A RingBuffer for each channel wrapped around the two buffer halfs
private  int sampleSize
          sample size of the current format
private  boolean started
          indicates whether this line has been started or not
 
Constructor Summary
ASIODataLine(ASIOMixer mixer, ASIOLineInfo info)
           
 
Method Summary
 void addLineListener(javax.sound.sampled.LineListener listener)
           
 int available()
           
 void close()
           
(package private)  void closed()
          called from the Mixer to indicate that this line has been closed
 void drain()
           
 void finalize()
           
 void flush()
           
 int getBufferSize()
           
(package private)  int getChannel()
          Get the channel index of the first channel that belongs to this line
 javax.sound.sampled.Control getControl(javax.sound.sampled.Control.Type control)
          Will return a Clock Source Control for Selection of the Clock Source
 javax.sound.sampled.Control[] getControls()
          Will return a Clock Source Control for Selection of the Clock Source
 javax.sound.sampled.AudioFormat getFormat()
           
 int getFramePosition()
           
 float getLevel()
          ASIO doesn't support this.
 javax.sound.sampled.Line.Info getLineInfo()
           
 long getMicrosecondPosition()
           
(package private)  ASIOMixer getMixer()
          Get the ASIOMixer to which this Line belongs
 boolean isActive()
           
 boolean isControlSupported(javax.sound.sampled.Control.Type control)
          Only a Clock Source Control for Selection of the Clock Source is supported
 boolean isInput()
          Tells if this Line is used as In- or Output
 boolean isOpen()
           
 boolean isRunning()
           
private  void notifyListeners(javax.sound.sampled.LineEvent e)
          Notify the line listeners
 void open()
          If no arguments are specified to open(), the preferred buffer size will be used and the Format will be Mono with the preferred Sample Rate
 void open(javax.sound.sampled.AudioFormat format)
           
 void open(javax.sound.sampled.AudioFormat format, int buffersize)
           
(package private)  void opened(long seq, java.nio.ByteBuffer[][] buffers)
          called from the Mixer to indicate that this line has been opened
 int read(byte[] b, int off, int len)
           
 void removeLineListener(javax.sound.sampled.LineListener listener)
           
 void start()
           
(package private)  void started()
          called from the Mixer to indicate that this line has been started
 void stop()
           
(package private)  void stopped()
          called from the Mixer to indicate that this line has been stopped
 int write(byte[] b, int off, int len)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

asioBuffers

java.nio.ByteBuffer[][] asioBuffers
The real asioBuffers. They are not used by the line itself, but by the ASIOMixer. It copies the content from/to the internalBuffers when bufferSwitchtimeInfo() is called


channels

int channels
Number of channels associated with this line right now


controls

private javax.sound.sampled.Control[] controls
the Controls for this line


desiredBufferSize

private int desiredBufferSize
The buffersize in bytes specified to open(AudioFormat, int)


emptyArray

private byte[] emptyArray
an empty array for flushing


flushed

private boolean flushed
indicates whether flus() has been called lately on this line


format

private javax.sound.sampled.AudioFormat format
The format of this line when its running


frameSize

private int frameSize
frameSize of the current format


info

private ASIOLineInfo info
THE ASIOLineInfo object corresponding to this line


listeners

private java.util.ArrayList listeners
List of the registered LineListeners


mixer

private ASIOMixer mixer
The ASIOMixer instance which created this line


open

private boolean open
Indicates if this line is open


openSeq

private long openSeq
Sequence number used when opening this line. This number should be used for ASIOMixer.ASIOExit(long seq)


ringBuffers

DoubleHalfRingBuffer[] ringBuffers
A RingBuffer for each channel wrapped around the two buffer halfs


sampleSize

private int sampleSize
sample size of the current format


started

private boolean started
indicates whether this line has been started or not

Constructor Detail

ASIODataLine

ASIODataLine(ASIOMixer mixer,
             ASIOLineInfo info)
Method Detail

addLineListener

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

available

public int available()
Specified by:
available in interface javax.sound.sampled.DataLine

close

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

closed

void closed()
called from the Mixer to indicate that this line has been closed


drain

public void drain()
Specified by:
drain in interface javax.sound.sampled.DataLine

finalize

public void finalize()
Overrides:
finalize in class java.lang.Object

flush

public void flush()
Specified by:
flush in interface javax.sound.sampled.DataLine

getBufferSize

public int getBufferSize()
Specified by:
getBufferSize in interface javax.sound.sampled.DataLine

getChannel

int getChannel()
Get the channel index of the first channel that belongs to this line

Returns:
The zero-based index of the lowest channel that belongs to this line

getControl

public javax.sound.sampled.Control getControl(javax.sound.sampled.Control.Type control)
Will return a Clock Source Control for Selection of the Clock Source

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()
Will return a Clock Source Control for Selection of the Clock Source

Specified by:
getControls in interface javax.sound.sampled.Line
See Also:
Line.getControls()

getFormat

public javax.sound.sampled.AudioFormat getFormat()
Specified by:
getFormat in interface javax.sound.sampled.DataLine

getFramePosition

public int getFramePosition()
Specified by:
getFramePosition in interface javax.sound.sampled.DataLine

getLevel

public float getLevel()
ASIO doesn't support this. AudioSystem.NOT_SPECIFIED will be returned.

Specified by:
getLevel in interface javax.sound.sampled.DataLine
See Also:
DataLine.getLevel()

getLineInfo

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

getMicrosecondPosition

public long getMicrosecondPosition()
Specified by:
getMicrosecondPosition in interface javax.sound.sampled.DataLine

getMixer

ASIOMixer getMixer()
Get the ASIOMixer to which this Line belongs

Returns:
The ASIOMixer to which this Line belongs

isActive

public boolean isActive()
Specified by:
isActive in interface javax.sound.sampled.DataLine

isControlSupported

public boolean isControlSupported(javax.sound.sampled.Control.Type control)
Only a Clock Source Control for Selection of the Clock Source is supported

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

isInput

public boolean isInput()
Tells if this Line is used as In- or Output

Returns:
true if this Line is used as Input false otherwise

isOpen

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

isRunning

public boolean isRunning()
Specified by:
isRunning in interface javax.sound.sampled.DataLine

notifyListeners

private void notifyListeners(javax.sound.sampled.LineEvent e)
Notify the line listeners

Parameters:
e - The LineEvent

open

public void open()
          throws javax.sound.sampled.LineUnavailableException
If no arguments are specified to open(), the preferred buffer size will be used and the Format will be Mono with the preferred Sample Rate

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

open

public void open(javax.sound.sampled.AudioFormat format)
          throws javax.sound.sampled.LineUnavailableException
Specified by:
open in interface javax.sound.sampled.SourceDataLine
Throws:
javax.sound.sampled.LineUnavailableException

open

public void open(javax.sound.sampled.AudioFormat format,
                 int buffersize)
          throws javax.sound.sampled.LineUnavailableException
Specified by:
open in interface javax.sound.sampled.SourceDataLine
Throws:
javax.sound.sampled.LineUnavailableException

opened

void opened(long seq,
            java.nio.ByteBuffer[][] buffers)
called from the Mixer to indicate that this line has been opened

Parameters:
seq - The sequence number that should be used for closing
buffers - The asioBuffers

read

public int read(byte[] b,
                int off,
                int len)
Specified by:
read in interface javax.sound.sampled.TargetDataLine

removeLineListener

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

start

public void start()
Specified by:
start in interface javax.sound.sampled.DataLine

started

void started()
called from the Mixer to indicate that this line has been started


stop

public void stop()
Specified by:
stop in interface javax.sound.sampled.DataLine

stopped

void stopped()
called from the Mixer to indicate that this line has been stopped


write

public int write(byte[] b,
                 int off,
                 int len)
Specified by:
write in interface javax.sound.sampled.SourceDataLine