com.groovemanager.spi.asio
Class ASIODataLine

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

public class ASIODataLine
extends Object
implements SourceDataLine, 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/interfaces inherited from interface javax.sound.sampled.DataLine
DataLine.Info
 
Field Summary
(package private)  ByteBuffer[][] asioBuffers
          The real asioBuffers.
(package private)  int channels
          Number of channels associated with this line right now
private  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  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  ArrayList<LineListener> 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(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
 Control getControl(Control.Type control)
          Will return a Clock Source Control for Selection of the Clock Source
 Control[] getControls()
          Will return a Clock Source Control for Selection of the Clock Source
 AudioFormat getFormat()
           
 int getFramePosition()
           
 float getLevel()
          ASIO doesn't support this.
 ASIOLineInfo getLineInfo()
           
 long getLongFramePosition()
           
 long getMicrosecondPosition()
           
(package private)  ASIOMixer getMixer()
          Get the ASIOMixer to which this Line belongs
 boolean isActive()
           
 boolean isControlSupported(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(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(AudioFormat format)
           
 void open(AudioFormat format, int buffersize)
           
(package private)  void opened(long seq, ByteBuffer[][] buffers)
          called from the Mixer to indicate that this line has been opened
 int read(byte[] b, int off, int len)
           
 void removeLineListener(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

ringBuffers

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


asioBuffers

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


listeners

private ArrayList<LineListener> listeners
List of the registered LineListeners


mixer

private ASIOMixer mixer
The ASIOMixer instance which created this line


info

private ASIOLineInfo info
THE ASIOLineInfo object corresponding to this line


desiredBufferSize

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


open

private boolean open
Indicates if this line is open


format

private AudioFormat format
The format of this line when its running


channels

int channels
Number of channels associated with this line right now


openSeq

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


frameSize

private int frameSize
frameSize of the current format


sampleSize

private int sampleSize
sample size of the current format


started

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


flushed

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


controls

private Control[] controls
the Controls for this line


emptyArray

private byte[] emptyArray
an empty array for flushing

Constructor Detail

ASIODataLine

ASIODataLine(ASIOMixer mixer,
             ASIOLineInfo info)
Method Detail

getMixer

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

Returns:
The ASIOMixer to which this Line belongs

drain

public void drain()
Specified by:
drain in interface DataLine

flush

public void flush()
Specified by:
flush in interface DataLine

start

public void start()
Specified by:
start in interface DataLine

stop

public void stop()
Specified by:
stop in interface DataLine

isRunning

public boolean isRunning()
Specified by:
isRunning in interface DataLine

isActive

public boolean isActive()
Specified by:
isActive in interface DataLine

getFormat

public AudioFormat getFormat()
Specified by:
getFormat in interface DataLine

getBufferSize

public int getBufferSize()
Specified by:
getBufferSize in interface DataLine

available

public int available()
Specified by:
available in interface DataLine

getFramePosition

public int getFramePosition()
Specified by:
getFramePosition in interface DataLine

getMicrosecondPosition

public long getMicrosecondPosition()
Specified by:
getMicrosecondPosition in interface DataLine

getLevel

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

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

getLineInfo

public ASIOLineInfo getLineInfo()
Specified by:
getLineInfo in interface Line

open

public void open()
          throws 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 Line
Throws:
LineUnavailableException
See Also:
Line.open()

close

public void close()
Specified by:
close in interface Line

isOpen

public boolean isOpen()
Specified by:
isOpen in interface Line

getControls

public Control[] getControls()
Will return a Clock Source Control for Selection of the Clock Source

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

isControlSupported

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

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

getControl

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

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

addLineListener

public void addLineListener(LineListener listener)
Specified by:
addLineListener in interface Line

removeLineListener

public void removeLineListener(LineListener listener)
Specified by:
removeLineListener in interface Line

open

public void open(AudioFormat format,
                 int buffersize)
          throws LineUnavailableException
Specified by:
open in interface SourceDataLine
Specified by:
open in interface TargetDataLine
Throws:
LineUnavailableException

open

public void open(AudioFormat format)
          throws LineUnavailableException
Specified by:
open in interface SourceDataLine
Specified by:
open in interface TargetDataLine
Throws:
LineUnavailableException

read

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

write

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

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

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

opened

void opened(long seq,
            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

started

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


notifyListeners

private void notifyListeners(LineEvent e)
Notify the line listeners

Parameters:
e - The LineEvent

stopped

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


closed

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


finalize

public void finalize()
Overrides:
finalize in class Object

getLongFramePosition

public long getLongFramePosition()
Specified by:
getLongFramePosition in interface DataLine