com.groovemanager.spi.asio
Class ASIOMixerProvider

java.lang.Object
  extended by javax.sound.sampled.spi.MixerProvider
      extended by com.groovemanager.spi.asio.ASIOMixerProvider

public class ASIOMixerProvider
extends javax.sound.sampled.spi.MixerProvider

This class serves as ServiceProvider for accessing ASIODrivers from Java Sound

Author:
Manu Robledo

Nested Class Summary
static class ASIOMixerProvider.ASIOMixerInfo
          Info-class for ASIOMixer instances
 
Field Summary
private static ASIOMixer activeMixer
          The currently loaded ASIO driver if any
private static ASIODriverInfo asioDriverInfo
          ASIODriverInfo of the currently loaded Mixer if any
private static AsioDrivers asioDrivers
          AsioDrivers object for accessing driver infos
private static java.util.ArrayList asioListeners
          List of all registered ASIOListeners
private static ASIOBufferInfo[] bufferInfos
          The last used ASIOBufferInfos
private static java.lang.String[] drivers
          The available ASIO drivers
private static java.lang.String errorMessage
          Last error message if any
private static javax.sound.sampled.Mixer.Info[] infos
          The Info objects for the available ASIO drivers
private static long initSeq
          The sequence number that was actually used for the last real ASIOInit() call
(package private) static java.lang.String LIB_NAME
          The name of the jsasio library
(package private) static java.lang.String LIB_VERSION
          The version of the jsasio library version
private static java.util.HashMap mixerPool
          The pool of Mixers.
private static long sequence
          Sequence number that will be incremented and returned for each ASIOInit() call
 
Constructor Summary
ASIOMixerProvider()
          Constructs a new ASIOMixerProvider
 
Method Summary
 void addASIOListener(ASIOListener listener)
          Register an ASIOListener that will be notified of callbacks from any ASIOMixer
(package private) static void ASIOExit(ASIOMixer mixer, long seq)
          Exit this driver
(package private) static long ASIOInit(ASIOMixer mixer)
          Initialize and load an ASIO driver if needed
private static boolean ASIOLoad(ASIOMixer mixer)
          Try to load an ASIO driver if needed
private  int asioMessage(int selector, int value)
           
(package private) static long ASIOPrepare(ASIOMixer mixer, ASIOBufferInfo[] infos, int buffersize)
          Prepare, initialize and load an ASIO driver if needed
(package private) static long ASIOStart(ASIOMixer mixer, ASIOBufferInfo[] infos, int buffersize)
          Start, prepare, init and load an ASIO driver if needed
(package private) static boolean ASIOStop(ASIOMixer mixer)
          Stop an ASIO driver if needed
private static void ASIOUnLoad(ASIOMixer mixer)
          Unload an ASIO driver
(package private) static boolean ASIOUnPrepare(ASIOMixer mixer)
          Dispose buffers and Stop the driver if needed
private  boolean bufferSizeChanged(int newSize)
           
private  boolean bufferSizeChangedSupported()
           
static void freeAll()
          This method tries to free all ASIO-related ressources.
(package private) static ASIOMixer getActiveMixer()
          Get the currently loaded ASIOMixer if any
(package private) static ASIOBufferInfo[] getBufferInfo()
          Get the last used ASIOBufferInfos
(package private) static ASIODriverInfo getDriverInfo()
          Get the ASIODriverInfo of the currently loaded driver if any.
(package private) static java.lang.String getErrorMessage()
          Get the last error message.
(package private) static java.lang.String getLibName()
          Get the full library name to be loaded
 javax.sound.sampled.Mixer getMixer(javax.sound.sampled.Mixer.Info info)
           
 javax.sound.sampled.Mixer.Info[] getMixerInfo()
           
 boolean isMixerSupported(javax.sound.sampled.Mixer.Info i)
           
private  void jSampleRateDidChange(long pointer)
           
private  boolean latenciesChanged()
           
private  boolean latenciesChangedSupported()
           
private static long nextSeq()
          Get the next sequence number
 void removeASIOListener(ASIOListener listener)
          Removes a registered ASIOListener
private  void resetRequest(ASIOMixer mixer)
           
private  boolean resyncRequest()
           
private  boolean resyncRequestSupported()
           
private  void sampleRateDidChange(ASIOSampleRate newRate)
           
private  boolean selectorSupported(int selector)
          Called from the ASIO callback asioMessage()
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

activeMixer

private static ASIOMixer activeMixer
The currently loaded ASIO driver if any


asioDriverInfo

private static ASIODriverInfo asioDriverInfo
ASIODriverInfo of the currently loaded Mixer if any


asioDrivers

private static AsioDrivers asioDrivers
AsioDrivers object for accessing driver infos


asioListeners

private static java.util.ArrayList asioListeners
List of all registered ASIOListeners


bufferInfos

private static ASIOBufferInfo[] bufferInfos
The last used ASIOBufferInfos


drivers

private static java.lang.String[] drivers
The available ASIO drivers


errorMessage

private static java.lang.String errorMessage
Last error message if any


infos

private static javax.sound.sampled.Mixer.Info[] infos
The Info objects for the available ASIO drivers


initSeq

private static long initSeq
The sequence number that was actually used for the last real ASIOInit() call


LIB_NAME

static final java.lang.String LIB_NAME
The name of the jsasio library

See Also:
Constant Field Values

LIB_VERSION

static final java.lang.String LIB_VERSION
The version of the jsasio library version

See Also:
Constant Field Values

mixerPool

private static java.util.HashMap mixerPool
The pool of Mixers. Should guarantee that for each ASIO driver there exists only one ASIOMixer instance


sequence

private static long sequence
Sequence number that will be incremented and returned for each ASIOInit() call

Constructor Detail

ASIOMixerProvider

public ASIOMixerProvider()
Constructs a new ASIOMixerProvider

Method Detail

addASIOListener

public void addASIOListener(ASIOListener listener)
Register an ASIOListener that will be notified of callbacks from any ASIOMixer

Parameters:
listener - The ASIOListener to be added

ASIOExit

static void ASIOExit(ASIOMixer mixer,
                     long seq)
Exit this driver

Parameters:
mixer - The ASIO driver
seq - The sequence number from the call to ASIOInit(). If this sequence number is the one provided from the real ASIOinit() call, ASIOExit() will really be called, otherwise not

ASIOInit

static long ASIOInit(ASIOMixer mixer)
              throws ASIOError
Initialize and load an ASIO driver if needed

Parameters:
mixer - The ASIO driver to initialize
Returns:
true if the driver could be initialized or had already been initialized, false otherwise
Throws:
ASIOError - If ASIOInit() fails

ASIOLoad

private static boolean ASIOLoad(ASIOMixer mixer)
Try to load an ASIO driver if needed

Parameters:
mixer - The ASIOMixer to load
Returns:
true if the driver could be loaded or had already been loaded, false otherwise

asioMessage

private int asioMessage(int selector,
                        int value)

ASIOPrepare

static long ASIOPrepare(ASIOMixer mixer,
                        ASIOBufferInfo[] infos,
                        int buffersize)
                 throws ASIOError
Prepare, initialize and load an ASIO driver if needed

Parameters:
mixer - The ASIO driver to prepare
infos - The ASIOBufferInfo objects that should be filled
buffersize - The buffer size in sample frames
Returns:
A sequence number for the use with ASIOExit()
Throws:
ASIOError - If ASIOCreateBuffers() fails

ASIOStart

static long ASIOStart(ASIOMixer mixer,
                      ASIOBufferInfo[] infos,
                      int buffersize)
               throws ASIOError
Start, prepare, init and load an ASIO driver if needed

Parameters:
mixer - The ASIO driver to start
infos - The ASIOBufferInfos to be filled
buffersize - The buffersize
Returns:
A sequence number to be used with ASIOExit()
Throws:
ASIOError - If ASIOStart() fails

ASIOStop

static boolean ASIOStop(ASIOMixer mixer)
                 throws ASIOError
Stop an ASIO driver if needed

Parameters:
mixer - The ASIO driver that should be stopped
Returns:
true If the Mixer was already stopped before or if the Mixer could be stopped
Throws:
ASIOError - If ASIOStop() failed

ASIOUnLoad

private static void ASIOUnLoad(ASIOMixer mixer)
Unload an ASIO driver

Parameters:
mixer - The ASIO driver

ASIOUnPrepare

static boolean ASIOUnPrepare(ASIOMixer mixer)
                      throws ASIOError
Dispose buffers and Stop the driver if needed

Parameters:
mixer - The ASIO driver to be stopped
Returns:
true if this Mixer´s buffers had already been disposed or if the dispose succeeded
Throws:
ASIOError - If ASIODisposeBuffers failed

bufferSizeChanged

private boolean bufferSizeChanged(int newSize)

bufferSizeChangedSupported

private boolean bufferSizeChangedSupported()

freeAll

public static void freeAll()
This method tries to free all ASIO-related ressources. Should only be needed in special cases.


getActiveMixer

static ASIOMixer getActiveMixer()
Get the currently loaded ASIOMixer if any

Returns:
The currently loaded ASIOMixer or null if none is loaded

getBufferInfo

static ASIOBufferInfo[] getBufferInfo()
Get the last used ASIOBufferInfos

Returns:
Array of the last used ASIOBufferInfos or null if none are used

getDriverInfo

static ASIODriverInfo getDriverInfo()
Get the ASIODriverInfo of the currently loaded driver if any.

Returns:
The ASIODriverInfo of the currently loaded driver or null if no driver is loaded

getErrorMessage

static java.lang.String getErrorMessage()
Get the last error message.

Returns:
The last error message or an empty String if no error occured.

getLibName

static java.lang.String getLibName()
Get the full library name to be loaded

Returns:
The library name consisting of LIB_NAME + "_" + LIB_VERSION

getMixer

public javax.sound.sampled.Mixer getMixer(javax.sound.sampled.Mixer.Info info)
Specified by:
getMixer in class javax.sound.sampled.spi.MixerProvider
See Also:
MixerProvider.getMixer(javax.sound.sampled.Mixer.Info)

getMixerInfo

public javax.sound.sampled.Mixer.Info[] getMixerInfo()
Specified by:
getMixerInfo in class javax.sound.sampled.spi.MixerProvider
See Also:
MixerProvider.getMixerInfo()

isMixerSupported

public boolean isMixerSupported(javax.sound.sampled.Mixer.Info i)
Overrides:
isMixerSupported in class javax.sound.sampled.spi.MixerProvider
See Also:
MixerProvider.isMixerSupported(javax.sound.sampled.Mixer.Info)

jSampleRateDidChange

private void jSampleRateDidChange(long pointer)

latenciesChanged

private boolean latenciesChanged()

latenciesChangedSupported

private boolean latenciesChangedSupported()

nextSeq

private static long nextSeq()
Get the next sequence number

Returns:
The next sequence number

removeASIOListener

public void removeASIOListener(ASIOListener listener)
Removes a registered ASIOListener

Parameters:
listener - The ASIOListener to be removed

resetRequest

private void resetRequest(ASIOMixer mixer)

resyncRequest

private boolean resyncRequest()

resyncRequestSupported

private boolean resyncRequestSupported()

sampleRateDidChange

private void sampleRateDidChange(ASIOSampleRate newRate)

selectorSupported

private boolean selectorSupported(int selector)
Called from the ASIO callback asioMessage()

Parameters:
selector - The selector to be supported
Returns:
true if this selector is supported, false otherwise