The Physiologist's Friend Simulation API

ch.unizh.ini.friend.record
Class MicrophoneReporter

java.lang.Object
  extended by java.lang.Thread
      extended by ch.unizh.ini.friend.record.MicrophoneReporter
All Implemented Interfaces:
SpikeEventSource, SpikeReporter, Updateable, Runnable

public class MicrophoneReporter
extends Thread
implements SpikeReporter, Updateable

Uses the microphone input to detect and generate SpikeEvent's. This object is a thread that reads the microphone input and generates spikes from it. To use this class, make a new instance, register SpikeListener's, and startReporting() the thread. To stop reporting, use stopReporting().

An instance of this class is constructed by FriendGUI when microphone recording is activated; listeners are added there.

A spike is positive edge triggered by the microphone input going above the setThreshold(byte); a new spike is not generated until the input falls below the threshold-hystersis level.

Version:
$Revision: 1.3 $
Author:
$Author: tobi $

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
MicrophoneReporter()
          Creates a new instance of SpikeTest.
MicrophoneReporter(SimulationSetup setup)
           
 
Method Summary
 void addSpikeListener(SpikeListener listener)
          add a listener for all spikes.
 void clearSpikeListeners()
          remove all listeners
 void compute(float dt)
          Computes the new state of this component of the simulation.
protected  void finalize()
          Release the line on finialization.
 byte getHystersis()
           
 Collection getSpikeListeners()
           
 byte getThreshold()
           
 boolean isReporting()
           
static void main(String[] args)
          test class by just printing . when it gets spikes
 void removeSpikeListener(SpikeListener listener)
          removes a listener
 void run()
          grabs samples from microphone input and generates SpikeEvent's whenver spikes are detected.
 void setHystersis(byte h)
          sets the hystersis for spike detection.
 void setThreshold(byte t)
          sets the threshold for detecting spikes.
 void startReporting()
          starts acquisition from microphone port and generation of SpikeEvent's.
 void stopReporting()
          removes all spike event listeners, ends thread after first stopping microphone acquisition.
 void update()
          Updates the actual state to the newly computed - aka double-buffering.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MicrophoneReporter

public MicrophoneReporter(SimulationSetup setup)
                   throws LineUnavailableException
Parameters:
setup - we are added to the setup as an updateable, but our update method does nothing
Throws:
LineUnavailableException - if microphone input not available
See Also:
MicrophoneReporter()

MicrophoneReporter

public MicrophoneReporter()
                   throws LineUnavailableException
Creates a new instance of SpikeTest. Opens the microphone input as the target line. To start the reporting, Thread.start() the thread.

Throws:
LineUnavailableException - if microphone input is not available
Method Detail

setThreshold

public void setThreshold(byte t)
sets the threshold for detecting spikes.

Parameters:
t - the threshold.

getThreshold

public byte getThreshold()
Returns:
the threshold
See Also:
setThreshold(byte)

setHystersis

public void setHystersis(byte h)
sets the hystersis for spike detection. Set this to avoid triggering multiple spikes on a noisy signal. A new SpikeEvent can be not generated until the input drops below the threshold-hystersis.


getHystersis

public byte getHystersis()
Returns:
hysteresis
See Also:
setHystersis(byte)

startReporting

public void startReporting()
starts acquisition from microphone port and generation of SpikeEvent's. If line is not available it does nothing.

Specified by:
startReporting in interface SpikeReporter

stopReporting

public void stopReporting()
removes all spike event listeners, ends thread after first stopping microphone acquisition. This ends generation of SpikeEvent's

Specified by:
stopReporting in interface SpikeReporter

run

public void run()
grabs samples from microphone input and generates SpikeEvent's whenver spikes are detected. Stopped by stopReporting()

Specified by:
run in interface Runnable
Overrides:
run in class Thread

finalize

protected void finalize()
                 throws Throwable
Release the line on finialization.

Overrides:
finalize in class Object
Throws:
Throwable

addSpikeListener

public void addSpikeListener(SpikeListener listener)
add a listener for all spikes. Listeners are called when a spike occurs and are passed a SpikeEvent.

Specified by:
addSpikeListener in interface SpikeEventSource
Parameters:
listener - the listener

removeSpikeListener

public void removeSpikeListener(SpikeListener listener)
removes a listener

Specified by:
removeSpikeListener in interface SpikeEventSource
Parameters:
listener - to remove

clearSpikeListeners

public void clearSpikeListeners()
remove all listeners

Specified by:
clearSpikeListeners in interface SpikeEventSource

main

public static void main(String[] args)
test class by just printing . when it gets spikes


getSpikeListeners

public Collection getSpikeListeners()
Specified by:
getSpikeListeners in interface SpikeEventSource
Returns:
the Collection of listeners

isReporting

public boolean isReporting()
Specified by:
isReporting in interface SpikeReporter
Returns:
whether reporting is enabled (Thread.isAlive())

compute

public void compute(float dt)
Computes the new state of this component of the simulation.

Specified by:
compute in interface Updateable
Parameters:
dt - The time that has passed since the last invocation.

update

public void update()
Updates the actual state to the newly computed - aka double-buffering.

Specified by:
update in interface Updateable

http://www.ini.unizh.ch/~tobi/friend