Acquisition
Class FileInputSystem

java.lang.Object
  extended by Acquisition.DaqSystem
      extended by Acquisition.FileInputSystem
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener, PamSettings
Direct Known Subclasses:
FolderInputSystem

public class FileInputSystem
extends DaqSystem
implements java.awt.event.ActionListener, PamSettings

Implementation of DaqSystem for reading data from audio files.

Author:
Doug Gillespie
See Also:
DaqSystem, AcquisitionProcess, FolderInputSystem

Nested Class Summary
 class FileInputSystem.CollectorThread
           
 
Field Summary
protected  AcquisitionControl acquisitionControl
           
protected  AcquisitionDialog acquisitionDialog
           
protected  javax.sound.sampled.AudioFormat audioFormat
           
protected  javax.sound.sampled.AudioInputStream audioStream
           
private  int blockSamples
           
private  ByteConverter byteConverter
           
protected  FileInputSystem.CollectorThread collectorThread
           
private  javax.swing.JPanel daqDialog
           
private  boolean dontStop
           
private  javax.swing.JLabel etaLabel
           
private  double[] fileData
           
(package private)  FileDate fileDate
           
(package private)  long fileDateMillis
           
protected  javax.swing.JTextField fileDateText
           
protected  FileInputParameters fileInputParameters
           
(package private)  long fileLength
           
protected  javax.swing.JComboBox fileName
           
private  javax.swing.JProgressBar fileProgress
           
(package private)  long fileSamples
           
protected  javax.swing.JButton fileSelect
           
protected  long fileStartTime
          using a system.currentTimeMS not PamCalander time to predict eta.
(package private)  int nChannels
           
protected  java.util.List<RawDataUnit> newDataUnits
           
(package private)  long readFileSamples
           
protected  javax.swing.JCheckBox repeat
           
(package private)  float sampleRate
           
(package private)  long startTimeMS
           
(package private)  javax.swing.JPanel statusPanel
           
protected  java.lang.Thread theThread
           
 
Fields inherited from class Acquisition.DaqSystem
PARAMETER_FIXED, PARAMETER_UNKNOWN, STREAM_CLOSED, STREAM_ENDED, STREAM_OPEN, STREAM_PAUSED, STREAM_RUNNING
 
Constructor Summary
FileInputSystem()
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
           
(package private)  void addComponent(javax.swing.JPanel panel, java.awt.Component p, java.awt.GridBagConstraints constraints)
           
static double[] bytesToSamples(byte[] byteArray, long nBytes, int channel, javax.sound.sampled.AudioFormat audioFormat)
          Format one channel of the data in a byte array into a sample array.
 boolean canPlayBack(float sampleRate)
           
protected  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
private  void fillFileList()
           
 int getChannels()
           
 java.io.File getCurrentFile()
           
 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).
 long getEta()
           
 int getMaxChannels()
           
 int getMaxSampleRate()
           
 double getPeak2PeakVoltage(int swChannel)
           
static double getSample(byte[] buffer, int position, int bytesPerSample, boolean isBigEndian)
          Convenience method for getting samples from a byte array.
 float getSampleRate()
           
 java.io.Serializable getSettingsReference()
           
 long getSettingsVersion()
           
 java.awt.Component getStatusBarComponent()
           
 java.lang.String getSystemName()
           
 java.lang.String getSystemType()
           
 java.lang.String getUnitName()
           
 java.lang.String getUnitType()
           
 void interpretNewFile(java.lang.String newFile)
           
 boolean isRealTime()
           
private  boolean loadByteConverter(javax.sound.sampled.AudioFormat audioFormat)
           
protected  boolean openNextFile()
           
 boolean prepareInputFile()
           
 boolean prepareSystem(AcquisitionControl daqControl)
          Prepare the DaqSystem.
 boolean restoreSettings(PamControlledUnitSettings pamControlledUnitSettings)
           
 boolean runFileAnalysis()
           
 void sayEta()
           
 void sayEta(long timeMs)
           
protected  void selectFile()
           
 void setNewFile(java.lang.String newFile)
           
 void setStreamStatus(int streamStatus)
           
 boolean startSystem(AcquisitionControl daqControl)
          Start the DaqSystem.
 void stopSystem(AcquisitionControl daqControl)
          Stop the DaqSystem.
 void systemHasStopped(boolean wasRunning)
           
 
Methods inherited from class Acquisition.DaqSystem
areSampleSettingsOk, getDaqSpecificChannelListPanel, getInputChannelMap, getPlaybackSystem, getStreamStatus, setSelected, showSampleSettingsDialog, supportsChannelLists
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

daqDialog

private javax.swing.JPanel daqDialog

fileName

protected javax.swing.JComboBox fileName

fileSelect

protected javax.swing.JButton fileSelect

fileDateText

protected javax.swing.JTextField fileDateText

acquisitionDialog

protected AcquisitionDialog acquisitionDialog

fileInputParameters

protected FileInputParameters fileInputParameters

acquisitionControl

protected AcquisitionControl acquisitionControl

blockSamples

private int blockSamples

fileProgress

private javax.swing.JProgressBar fileProgress

etaLabel

private javax.swing.JLabel etaLabel

fileStartTime

protected long fileStartTime
using a system.currentTimeMS not PamCalander time to predict eta.


dontStop

private volatile boolean dontStop

fileData

private double[] fileData

audioFormat

protected javax.sound.sampled.AudioFormat audioFormat

audioStream

protected javax.sound.sampled.AudioInputStream audioStream

collectorThread

protected FileInputSystem.CollectorThread collectorThread

theThread

protected java.lang.Thread theThread

newDataUnits

protected java.util.List<RawDataUnit> newDataUnits

startTimeMS

long startTimeMS

nChannels

int nChannels

sampleRate

float sampleRate

fileDate

FileDate fileDate

fileDateMillis

long fileDateMillis

fileLength

long fileLength

fileSamples

long fileSamples

readFileSamples

long readFileSamples

repeat

protected javax.swing.JCheckBox repeat

byteConverter

private ByteConverter byteConverter

statusPanel

javax.swing.JPanel statusPanel
Constructor Detail

FileInputSystem

public FileInputSystem()
Method Detail

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

protected javax.swing.JPanel createDaqDialogPanel()

addComponent

void addComponent(javax.swing.JPanel panel,
                  java.awt.Component p,
                  java.awt.GridBagConstraints constraints)

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

fillFileList

private void fillFileList()

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.

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Specified by:
actionPerformed in interface java.awt.event.ActionListener

selectFile

protected void selectFile()

setNewFile

public void setNewFile(java.lang.String newFile)

interpretNewFile

public void interpretNewFile(java.lang.String newFile)

loadByteConverter

private boolean loadByteConverter(javax.sound.sampled.AudioFormat audioFormat)

setStreamStatus

public void setStreamStatus(int streamStatus)
Overrides:
setStreamStatus in class DaqSystem

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 ?

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

getChannels

public int getChannels()

getSampleRate

public float getSampleRate()

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.

getCurrentFile

public java.io.File getCurrentFile()

getDataUnitSamples

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

prepareInputFile

public boolean prepareInputFile()

runFileAnalysis

public boolean runFileAnalysis()

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

systemHasStopped

public void systemHasStopped(boolean wasRunning)

openNextFile

protected boolean openNextFile()

bytesToSamples

public static double[] bytesToSamples(byte[] byteArray,
                                      long nBytes,
                                      int channel,
                                      javax.sound.sampled.AudioFormat audioFormat)
Format one channel of the data in a byte array into a sample array.


getSample

public static double getSample(byte[] buffer,
                               int position,
                               int bytesPerSample,
                               boolean isBigEndian)
Convenience method for getting samples from a byte array. Samples should be signed, integer, of either endian-ness, and 8, 16, 24, or 32 bits long. Result is scaled to the range of [-1,1). Note that .wav files are little-endian and .aif files are big-endian.


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

getStatusBarComponent

public java.awt.Component getStatusBarComponent()
Overrides:
getStatusBarComponent in class DaqSystem

sayEta

public void sayEta()

getEta

public long getEta()

sayEta

public void sayEta(long timeMs)

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: