Class UltrasoundAnalyzer

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

public class UltrasoundAnalyzer
extends java.lang.Thread
implements Constants

The UltrasoundAnalyzer thread class takes an array of bytes, concatenates them into 16-bit values in little endian format, then creates an UltrasoundDetector object to decide whether or not the samples contain the desired frequency. The boolean decision as to whether or not ultrasound was present in the block of samples is sent back to the UltrasoundListener object that instantiated this thread.

UltrasoundAnalyzer is a continuously running thread. As long as the available() method indicates that the thread is ready to receive data, analysis begins by calling the analyze() method with the array of bytes to be analyzed. Once the analysis is complete, this thread signals the UltrasoundListener object and becomes available for another set of data.


Field Summary
protected  boolean analyzing
           
protected  byte[] byteSamples
           
protected  int CHANNELS
           
protected  UltrasoundDetector usd
           
protected  UltrasoundListener usl
           
 
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
UltrasoundAnalyzer(UltrasoundListener usListener, boolean inDebug, int channels)
          The main UltrasoundAnalyzer constructor takes a reference to an UltrasoundListener and a byte array containing the samples to be analyzed.
 
Method Summary
 boolean analyze(byte[] samples)
          Begin DSP analysis of data in order to determine whether or not ultrasound is present in the set of audio samples.
 boolean available()
          Returns a boolean indicating whether or not this thread object is available to begin analysis of a new data set.
protected  double[] littleEndConcat()
          Helper method for concatenating all the values in a byte array into 16-bit double values using the little endian format.
 void run()
          The UltrasoundAnalyzer thread first concatenates the array of bytes into 16-bit little endian samples, then uses the UltrasoundDetector to determine whether or not the samples contain ultrasound and notifies the UltrasoundListener accordingly.
 
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

usl

protected UltrasoundListener usl

usd

protected UltrasoundDetector usd

byteSamples

protected byte[] byteSamples

analyzing

protected volatile boolean analyzing

CHANNELS

protected int CHANNELS
Constructor Detail

UltrasoundAnalyzer

public UltrasoundAnalyzer(UltrasoundListener usListener,
                          boolean inDebug,
                          int channels)
The main UltrasoundAnalyzer constructor takes a reference to an UltrasoundListener and a byte array containing the samples to be analyzed. If ultrasound is detected in the byte array, the UltrasoundListener is notified.

Parameters:
usListener - The object that will be notified of ultrasound detections.
inDebug - Whether or not to print debugging information.
channels - The number of channels on which the audio was recorded.
Method Detail

run

public void run()
The UltrasoundAnalyzer thread first concatenates the array of bytes into 16-bit little endian samples, then uses the UltrasoundDetector to determine whether or not the samples contain ultrasound and notifies the UltrasoundListener accordingly.

Specified by:
run in interface java.lang.Runnable

available

public boolean available()
Returns a boolean indicating whether or not this thread object is available to begin analysis of a new data set. If this thread object is currently analyzing a stream of samples, it cannot allow another thread to begin a new analysis, overwriting the array of byte samples, so this method returns false. This method will return true when this thread object is currently not analyzing a set of samples.

Returns:
Boolean indicating whether or not this thread is available for analyzing a new set of data.

analyze

public boolean analyze(byte[] samples)
Begin DSP analysis of data in order to determine whether or not ultrasound is present in the set of audio samples. This method notifies the thread waiting on this UltrasoundAnalyzer object to wake up and begin processing the bytes passed in to this method. If this UltrasoundAnalyzer is not available to analyze a new set of data, this method simply returns false and does nothing. This method must be synchronized to ensure that the thread calling it owns the UltrasoundAnalyzer object's monitor.

Parameters:
samples - The byte array of audio data to be analyzed for ultrasound
Returns:
Whether or not this UltrasoundAnalyzer object was able to service the request to analyze data.

littleEndConcat

protected double[] littleEndConcat()
Helper method for concatenating all the values in a byte array into 16-bit double values using the little endian format.

Returns:
Array of double values containing the concatenated bytes.