asiojni
Class ASIOSoundSystem

java.lang.Object
  extended by Acquisition.DaqSystem
      extended by asiojni.ASIOSoundSystem
All Implemented Interfaces:
PamSettings

public class ASIOSoundSystem
extends DaqSystem
implements PamSettings

Everything and everything to do with controlling and reading ASIO sound cards.

Author:
Doug Gillespie
See Also:
DaqSystem, AcquisitionProcess

Nested Class Summary
(package private)  class ASIOSoundSystem.CaptureThreadAsio
           
 
Field Summary
private  AcquisitionControl acquisitionControl
           
private  AsioJniInterface asioJniInterface
           
private  ASIOPlaybackSystem asioPlaybackSystem
           
(package private)  javax.swing.JComboBox audioDevices
           
private  javax.sound.sampled.AudioFormat audioFormat
           
private  int[] channelList
          locally held channel list i.e.
private  int daqChannels
           
(package private)  javax.swing.JPanel daqDialog
           
private  int dataUnitSamples
           
(package private)  int expectedChannel
           
(package private)  java.util.List<RawDataUnit> newDataUnits
           
private  int rawBufferSizeInBytes
           
private  int[] reverseChannelList
          locally held convert hardware channels to software chans
private  int sampleSizeInBytes
           
(package private)  SoundCardParameters soundCardParameters
           
private  boolean stopCapture
           
(package private)  long[] totalSamples
           
private static boolean ZeroIndexChannels
          collect data using zero channel indexes rather than the annoying hardware channel numbers.
 
Fields inherited from class Acquisition.DaqSystem
PARAMETER_FIXED, PARAMETER_UNKNOWN, STREAM_CLOSED, STREAM_ENDED, STREAM_OPEN, STREAM_PAUSED, STREAM_RUNNING
 
Constructor Summary
ASIOSoundSystem(AcquisitionControl acquisitionControl)
           
 
Method Summary
 boolean areSampleSettingsOk(int numInputsRequested, float sampleRateRequested)
           
 boolean canPlayBack(float sampleRate)
           
private  javax.swing.JPanel createDaqDialogPanel()
           
 void daqHasEnded()
          Called after DAQ has stopped - for whatever reason.
 boolean dialogGetParams()
          Called by AcquisitionDialog.GetParams so that parameters can be extracted from the dialog component.
 void dialogSetParams()
          Called by AcquisitionDialog.SetParams so that the dialog componenet can update it's fields
 int getChannels()
           
 javax.swing.JPanel getDaqSpecificDialogComponent(AcquisitionDialog acquisitionDialog)
          The AcquisitionDialog has been designed to that each data source type can plug in it's own panel of device specific controls.
 int getDataUnitSamples()
           
 java.lang.String getDeviceName()
          Gets a name for the acquisition device (may just be a number but need to generalise).
 java.util.ArrayList<AsioDriverInfo> getDevicesList()
           
 int getMaxChannels()
           
 int getMaxSampleRate()
           
 double getPeak2PeakVoltage(int swChannel)
           
 PlaybackSystem getPlaybackSystem()
          Gets a playback system for playing sound back out through headphones / speakers, etc.
static short getSample(byte[] buffer, int position)
           
 java.io.Serializable getSettingsReference()
           
 long getSettingsVersion()
           
 java.lang.String getSystemName()
           
 java.lang.String getSystemType()
           
 java.lang.String getUnitName()
           
 java.lang.String getUnitType()
           
 boolean isRealTime()
           
 boolean newASIOData(double[] data, int channel)
           
protected  boolean playData(int outputChannel, RawDataUnit rawDataUnit)
           
 boolean preparePlayback(int channels, float sampleRate)
           
 boolean prepareSystem(AcquisitionControl daqControl)
          Prepare the DaqSystem.
 boolean restoreSettings(PamControlledUnitSettings pamControlledUnitSettings)
           
 void showSampleSettingsDialog(AcquisitionDialog acquisitionDialog)
           
 boolean startSystem(AcquisitionControl daqControl)
          Start the DaqSystem.
 void stopSystem(AcquisitionControl daqControl)
          Stop the DaqSystem.
 boolean supportsChannelLists()
           
 
Methods inherited from class Acquisition.DaqSystem
getDaqSpecificChannelListPanel, getInputChannelMap, getStatusBarComponent, getStreamStatus, setSelected, setStreamStatus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

daqDialog

javax.swing.JPanel daqDialog

audioDevices

javax.swing.JComboBox audioDevices

soundCardParameters

SoundCardParameters soundCardParameters

audioFormat

private javax.sound.sampled.AudioFormat audioFormat

newDataUnits

java.util.List<RawDataUnit> newDataUnits

stopCapture

private volatile boolean stopCapture

acquisitionControl

private AcquisitionControl acquisitionControl

rawBufferSizeInBytes

private int rawBufferSizeInBytes

sampleSizeInBytes

private final int sampleSizeInBytes
See Also:
Constant Field Values

daqChannels

private int daqChannels

ZeroIndexChannels

private static final boolean ZeroIndexChannels
collect data using zero channel indexes rather than the annoying hardware channel numbers.

See Also:
Constant Field Values

channelList

private int[] channelList
locally held channel list i.e. hardware channels for software channels.


reverseChannelList

private int[] reverseChannelList
locally held convert hardware channels to software chans


asioJniInterface

private AsioJniInterface asioJniInterface

asioPlaybackSystem

private ASIOPlaybackSystem asioPlaybackSystem

dataUnitSamples

private int dataUnitSamples

totalSamples

long[] totalSamples

expectedChannel

int expectedChannel
Constructor Detail

ASIOSoundSystem

public ASIOSoundSystem(AcquisitionControl acquisitionControl)
Method Detail

prepareSystem

public boolean prepareSystem(AcquisitionControl daqControl)
Description copied from class: DaqSystem
Prepare the DaqSystem.

Usually this is the time for opening files, preparing data buffers, etc.

Specified by:
prepareSystem in class DaqSystem
Parameters:
daqControl - AcquisitionControl unit.
Returns:
true if OK, false otherwise.

getDataUnitSamples

public int getDataUnitSamples()
Specified by:
getDataUnitSamples in class DaqSystem
Returns:
the number of samples expected in each data unit.

preparePlayback

public boolean preparePlayback(int channels,
                               float sampleRate)

areSampleSettingsOk

public boolean areSampleSettingsOk(int numInputsRequested,
                                   float sampleRateRequested)
Overrides:
areSampleSettingsOk in class DaqSystem

showSampleSettingsDialog

public void showSampleSettingsDialog(AcquisitionDialog acquisitionDialog)
Overrides:
showSampleSettingsDialog in class DaqSystem

startSystem

public boolean startSystem(AcquisitionControl daqControl)
Description copied from class: DaqSystem
Start the DaqSystem. This is called immediately after PrepareSystem

Most things should be ready from the call to PrepareSystem. In StartSystem you will generally need to start a thread which will read in the data and place PamDataUnits in a buffer from where they are read by the main thred and passed on to other Pam modules for processing (see SoundCardSystem for an example)

Specified by:
startSystem in class DaqSystem
Parameters:
daqControl - AcquisitionControl unit.
Returns:
true if OK, false otherwise

stopSystem

public void stopSystem(AcquisitionControl daqControl)
Description copied from class: DaqSystem
Stop the DaqSystem.

Specified by:
stopSystem in class DaqSystem

getDaqSpecificDialogComponent

public javax.swing.JPanel getDaqSpecificDialogComponent(AcquisitionDialog acquisitionDialog)
Description copied from class: DaqSystem
The AcquisitionDialog has been designed to that each data source type can plug in it's own panel of device specific controls. These could be things like a file name, gain settings, channel lists, whatever is available for the specific device

The AcquisitionDialog will handle placing this component on the dialog when a particular DaqSystem is selected. The component will be placed between a drop down list of available DaqSystem's and a section of the dialog showing the sample rate and number of channels.

Specified by:
getDaqSpecificDialogComponent in class DaqSystem
Parameters:
acquisitionDialog - the AcquisitionDialog this component will be added to
Returns:
dialog component specific to this DAQ device

createDaqDialogPanel

private javax.swing.JPanel createDaqDialogPanel()

getDevicesList

public java.util.ArrayList<AsioDriverInfo> getDevicesList()

dialogSetParams

public void dialogSetParams()
Description copied from class: DaqSystem
Called by AcquisitionDialog.SetParams so that the dialog componenet can update it's fields

Specified by:
dialogSetParams in class DaqSystem

dialogGetParams

public boolean dialogGetParams()
Description copied from class: DaqSystem
Called by AcquisitionDialog.GetParams so that parameters can be extracted from the dialog component. The DaqSystem should also implement PamSettings and handle storage of parameters between runs.

Specified by:
dialogGetParams in class DaqSystem
Returns:
true if the parameters and selections are OK. If false is returned the Acquisition dialog will not respond to its Ok button.

getSystemType

public java.lang.String getSystemType()
Specified by:
getSystemType in class DaqSystem
Returns:
The 'type' of data source for display in the Data Source dialog

Calling functions should be able to handle 'null'


getSystemName

public java.lang.String getSystemName()
Specified by:
getSystemName in class DaqSystem
Returns:
A string describing the data source, e.g. the sound card name, file name, udp port, etc.

getMaxChannels

public int getMaxChannels()
Specified by:
getMaxChannels in class DaqSystem
Returns:
the maximum number of channels supporrted by the selected device, or PARAMETER_UNKNOWN

getMaxSampleRate

public int getMaxSampleRate()
Specified by:
getMaxSampleRate in class DaqSystem
Returns:
the maximum sample rate supporrted by the selected device, or PARAMETER_UNKNOWN

getPeak2PeakVoltage

public double getPeak2PeakVoltage(int swChannel)
Specified by:
getPeak2PeakVoltage in class DaqSystem
Returns:
peak to peak voltage for the device or PARAMETER_UNKNOWN

isRealTime

public boolean isRealTime()
Specified by:
isRealTime in class DaqSystem
Returns:
true for real time systems (e.g. sound cards, NI cards, wav files which are being played back over speakers. false for reading files which are to be processed as fast as possible with no playback.

canPlayBack

public boolean canPlayBack(float sampleRate)
Specified by:
canPlayBack in class DaqSystem
Returns:
true if the system can also play back sound - likely to be true for sound cards and ASIO, and some NI cards, false for wav files. Simulator ?

getPlaybackSystem

public PlaybackSystem getPlaybackSystem()
Description copied from class: DaqSystem
Gets a playback system for playing sound back out through headphones / speakers, etc.

Generally, anything acquiring data in real time should play the sound back through itself so that clocks are correctly synchronised. i.e. A sound card input will go to the same sound card output, etc. At a later date, we may try to support output through different devices at different speeds - but this will be problematic !

If data are being read from a file, then playback is through a sound card which sits in a standalone implementation of PlaybackSystem

Overrides:
getPlaybackSystem in class DaqSystem
Returns:
null if no playback available or a PlaybackSystem object.
See Also:
PlaybackSystem, FilePlayback

getChannels

public int getChannels()

getSettingsReference

public java.io.Serializable getSettingsReference()
Specified by:
getSettingsReference in interface PamSettings
Returns:
The serialisable object that will be stored

getSettingsVersion

public long getSettingsVersion()
Specified by:
getSettingsVersion in interface PamSettings
Returns:
An integer version number for the settings

getUnitName

public java.lang.String getUnitName()
Specified by:
getUnitName in interface PamSettings
Returns:
A Name specific to this instance of the particular class, e.g. Sperm whale detector, Beaked whale detector, etc.

getUnitType

public java.lang.String getUnitType()
Specified by:
getUnitType in interface PamSettings
Returns:
A Name specific to the type, e.g. Glick detector

restoreSettings

public boolean restoreSettings(PamControlledUnitSettings pamControlledUnitSettings)
Specified by:
restoreSettings in interface PamSettings
Returns:
true if successful The object performs final checks (if needed) and then casts the settings data pamcontrolledunitSettings.settings into the correct type and uses as required

newASIOData

public boolean newASIOData(double[] data,
                           int channel)

getSample

public static short getSample(byte[] buffer,
                              int position)

daqHasEnded

public void daqHasEnded()
Description copied from class: DaqSystem
Called after DAQ has stopped - for whatever reason. Nost DAQ systems will not need to do anything here, but they could potentially clean up memory The motivation for putting this here now is for the folder analysis system so that it can start analysing the next file.

Specified by:
daqHasEnded in class DaqSystem

supportsChannelLists

public boolean supportsChannelLists()
Overrides:
supportsChannelLists in class DaqSystem

playData

protected boolean playData(int outputChannel,
                           RawDataUnit rawDataUnit)

getDeviceName

public java.lang.String getDeviceName()
Description copied from class: DaqSystem
Gets a name for the acquisition device (may just be a number but need to generalise).

Specified by:
getDeviceName in class DaqSystem
Returns: