Class UltrasoundListener

java.lang.Object
  extended byjava.lang.Thread
      extended byUltrasoundListener
All Implemented Interfaces:
Constants, java.lang.Runnable

public class UltrasoundListener
extends java.lang.Thread
implements Constants

This class is a thread that continuously listens for ultrasound through the microphone and notifies the UltrasoundUpdateListener it was instantiated with whenever ultrasound is detected. Any class that instantiates an UltrasoundListener must provide it with an object that implements the UltrasoundUpdateListener interface so that the UltrasoundListener class can properly notify the appropriate class of ultrasound updates.


Field Summary
protected  UltrasoundAnalyzer[] analyzerPool
           
protected  int analyzerPoolInd
           
protected  int CHANNELS
           
protected  boolean debug
           
protected  int negCount
           
protected  int posCount
           
protected  javax.sound.sampled.TargetDataLine targetDataLine
           
protected  long[] timesDetected
           
protected  UltrasoundUpdateListener updateListener
           
protected  boolean usDebounced
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Fields inherited from interface Constants
AVG_DETECT_TIME, BIGEND, DEBOUNCE_VAL, GROUPADDR, HISTORY_SIZE, MAX_DETECT_TIME, MAXMSGSIZE, N, NUMTHREADS, PORTNUM, ROOM_MSG_BUF, SAMPLE_SIZE, SAMPLING_RATE, SEQUENCE, SIGN, TARGET_FREQUENCY, WEIGHT
 
Constructor Summary
UltrasoundListener(UltrasoundUpdateListener outsideUpdateListener)
          This default constructor assumes a sampling rate of 44100 Hz, a target frequency of 21000 Hz, an N value of 420, and debugging information turned off.
UltrasoundListener(UltrasoundUpdateListener outsideUpdateListener, boolean inDebug)
           
 
Method Summary
 void analysisDone(boolean usDetected, long timeDone)
          Provides a means by which UltrasoundAnalyzer threads can notify this UltrasoundListener class when a block of samples is done being analyzed.
 void run()
          This is the main processing method of this class, where sound is recorded and the samples obtained are analyzed.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

updateListener

protected UltrasoundUpdateListener updateListener

targetDataLine

protected javax.sound.sampled.TargetDataLine targetDataLine

analyzerPool

protected UltrasoundAnalyzer[] analyzerPool

analyzerPoolInd

protected int analyzerPoolInd

usDebounced

protected boolean usDebounced

posCount

protected int posCount

negCount

protected int negCount

debug

protected boolean debug

timesDetected

protected long[] timesDetected

CHANNELS

protected int CHANNELS
Constructor Detail

UltrasoundListener

public UltrasoundListener(UltrasoundUpdateListener outsideUpdateListener)
This default constructor assumes a sampling rate of 44100 Hz, a target frequency of 21000 Hz, an N value of 420, and debugging information turned off. A reference to an UltrasoundUpdateListener object must be passed to this constructor because the UltrasoundListener class needs some way of notifying outside classes of ultrasound updates.

Parameters:
outsideUpdateListener - Reference to the object that implements the UltrasoundUpdateListener interface.

UltrasoundListener

public UltrasoundListener(UltrasoundUpdateListener outsideUpdateListener,
                          boolean inDebug)
Method Detail

run

public void run()
This is the main processing method of this class, where sound is recorded and the samples obtained are analyzed. Since the UltrasoundDetector object analyzes N samples at a time, each iteration of this method reads N samples from the microphone then starts another thread for analyzing the samples.

Specified by:
run in interface java.lang.Runnable

analysisDone

public void analysisDone(boolean usDetected,
                         long timeDone)
Provides a means by which UltrasoundAnalyzer threads can notify this UltrasoundListener class when a block of samples is done being analyzed.

Parameters:
usDetected - Whether or not ultrasound was detected in the samples.
timeDone - The time at which analysis of the samples was completed.