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 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 ArrayList<ASIOListener> asioListeners
          List of all registered ASIOListeners
private static ASIOBufferInfo[] bufferInfos
          The last used ASIOBufferInfos
private static String[] drivers
          The available ASIO drivers
private static String errorMessage
          Last error message if any
private static boolean fullCheck
          speed improvement enables/disables fullCheck useful for realtime use, if all parameters are safe!
private static 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 String LIB_NAME
          The name of the jsasio library
(package private) static String LIB_VERSION
          The version of the jsasio library version
private static HashMap<String,ASIOMixer> 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 static 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 static boolean bufferSizeChanged(int newSize)
           
private static 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.
static String getErrorMessage()
          Get the last error message.
(package private) static String getLibName()
          Get the full library name to be loaded
 ASIOMixer getMixer(Mixer.Info info)
           
 Mixer.Info[] getMixerInfo()
           
static boolean isFullCheck()
           
 boolean isMixerSupported(Mixer.Info i)
           
private  void jSampleRateDidChange(long pointer)
           
private static boolean latenciesChanged()
           
private static boolean latenciesChangedSupported()
           
private static long nextSeq()
          Get the next sequence number
 void removeASIOListener(ASIOListener listener)
          Removes a registered ASIOListener
private static void resetRequest(ASIOMixer mixer)
           
private static boolean resyncRequest()
           
private static boolean resyncRequestSupported()
           
private  void sampleRateDidChange(ASIOSampleRate newRate)
           
private static boolean selectorSupported(int selector)
          Called from the ASIO callback asioMessage()
static void setFullCheck(boolean fullCheck)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fullCheck

private static boolean fullCheck
speed improvement enables/disables fullCheck useful for realtime use, if all parameters are safe! must be enabled on inquiries to get full information!


mixerPool

private static HashMap<String,ASIOMixer> mixerPool
The pool of Mixers. Should guarantee that for each ASIO driver there exists only one ASIOMixer instance


asioDrivers

private static AsioDrivers asioDrivers
AsioDrivers object for accessing driver infos


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


errorMessage

private static String errorMessage
Last error message if any


bufferInfos

private static ASIOBufferInfo[] bufferInfos
The last used ASIOBufferInfos


drivers

private static String[] drivers
The available ASIO drivers


infos

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


sequence

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


initSeq

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


asioListeners

private static ArrayList<ASIOListener> asioListeners
List of all registered ASIOListeners


LIB_VERSION

static final String LIB_VERSION
The version of the jsasio library version

See Also:
Constant Field Values

LIB_NAME

static final String LIB_NAME
The name of the jsasio library

See Also:
Constant Field Values
Constructor Detail

ASIOMixerProvider

public ASIOMixerProvider()
Constructs a new ASIOMixerProvider

Method Detail

setFullCheck

public static void setFullCheck(boolean fullCheck)

isFullCheck

public static boolean isFullCheck()

getLibName

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

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

freeAll

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


isMixerSupported

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

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

nextSeq

private static long nextSeq()
Get the next sequence number

Returns:
The next sequence number

getMixerInfo

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

getMixer

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

getErrorMessage

public static String getErrorMessage()
Get the last error message.

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

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

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

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

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

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

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

ASIOUnLoad

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

Parameters:
mixer - The ASIO driver

selectorSupported

private static 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

bufferSizeChangedSupported

private static boolean bufferSizeChangedSupported()

latenciesChangedSupported

private static boolean latenciesChangedSupported()

resyncRequestSupported

private static boolean resyncRequestSupported()

resetRequest

private static void resetRequest(ASIOMixer mixer)

bufferSizeChanged

private static boolean bufferSizeChanged(int newSize)

resyncRequest

private static boolean resyncRequest()

latenciesChanged

private static boolean latenciesChanged()

asioMessage

private static int asioMessage(int selector,
                               int value)

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

removeASIOListener

public void removeASIOListener(ASIOListener listener)
Removes a registered ASIOListener

Parameters:
listener - The ASIOListener to be removed

jSampleRateDidChange

private void jSampleRateDidChange(long pointer)

sampleRateDidChange

private void sampleRateDidChange(ASIOSampleRate newRate)