Spectrogram
Class SpectrogramMarkProcess

java.lang.Object
  extended by PamguardMVC.PamProcess
      extended by Spectrogram.SpectrogramMarkProcess
All Implemented Interfaces:
Annotator, PamObserver, SpectrogramMarkObserver
Direct Known Subclasses:
ClipProcess

public abstract class SpectrogramMarkProcess
extends PamProcess
implements SpectrogramMarkObserver

Standard process for any PamControlled unit observing marks made manually on spectrogram displays.

These processes receive a notification message from spectrgram displays when the mouse is pressed on the display and again when it is released. The notification contains the time and frequency bounds of the mark, which can then be used to perform some kind of data processing, e.g. calculate the bearing to the sound within the mark, make a waveform clip, etc.

It is important that the necessary data is available in memory for the SpectrogramMarkProcess. This is most likely to be either the spectrgram data itself, or the waveform data used to create the spectrogram FFT blocks. To ensure that these data are available, any SpectrogramDisplay which has one or more active SpectrogramMarkObservers will subscribe to the FFT and Waveform data blocks and ensure that at least one complete screen full of data is always stored. When the mouse is pressed, the SpectrogramDisplay ceases scrolling, but Pamguard data processing continues. During the time that the mouse is pressed, the SpectrogramDisplay will extend the time data are kept for as necessary to ensure that data from the mouse press time are indeed available.

This abstract subclass of PamProcess provides some simple utilities to get at the waveform data and tha FFT data.

Author:
Doug Gillespie
See Also:
SpectrogramDisplay, SpectrogramMarkObserver, PamDataBlock

Field Summary
 
Fields inherited from class PamguardMVC.PamProcess
outputDataBlocks, processName, sampleRate
 
Fields inherited from interface Spectrogram.SpectrogramMarkObserver
MOUSE_DOWN, MOUSE_UP
 
Constructor Summary
SpectrogramMarkProcess(PamControlledUnit pamControlledUnit)
           
 
Method Summary
 java.lang.String getMarkObserverName()
           
 void pamStart()
          Called for each process to tell it to start (may not be necessary for processes which are listening for data anyway.
 void pamStop()
          Stops the process.
 void spectrogramNotification(SpectrogramDisplay display, int downUp, int channel, long startMilliseconds, long duration, double f1, double f2)
          Override this to process data from the marked spectrogram.
 
Methods inherited from class PamguardMVC.PamProcess
absMillisecondsToSamples, absSamplesToMilliseconds, addOutputDataBlock, changedThreading, clearOldData, createAnnotations, destroyProcess, fillXMLElement, fillXMLParameters, getAncestorDataBlock, getAnnotation, getBackendProcess, getChainPosition, getCpuPercent, getNumAnnotations, getNumOutputDataBlocks, getObserverName, getObserverObject, getOfflineData, getOutputDataBlock, getPamControlledUnit, getParentDataBlock, getParentProcess, getProcessName, getRawSourceDataBlock, getRequiredDataHistory, getSampleRate, getSourceDataBlock, getSourceProcess, isCanMultiThread, makePamProcess, masterClockUpdate, newData, noteNewSettings, notifyModelChanged, prepareProcess, relMillisecondsToSamples, relSamplesToMilliseconds, removeObservable, removeOutputDatablock, saveViewerData, setBackendProcess, setCanMultiThread, setParentDataBlock, setParentDataBlock, setProcessName, setSampleRate, setupProcess, toString, update, updateData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SpectrogramMarkProcess

public SpectrogramMarkProcess(PamControlledUnit pamControlledUnit)
Method Detail

spectrogramNotification

public void spectrogramNotification(SpectrogramDisplay display,
                                    int downUp,
                                    int channel,
                                    long startMilliseconds,
                                    long duration,
                                    double f1,
                                    double f2)
Override this to process data from the marked spectrogram.

The spectrogram will have already ensured that Raw waveform data and FFT data that made the SpectrogramDisplay are still in memory and the data blocks can be accessed using

PamRawDataBlock rawDataBlock = (PamRawDataBlock) display.getSourceRawDataBlock();

and

PamDataBlock fftDataBlock = display.getSourceFFTDataBlock();

To obtain raw data, first convert the startMilliseconds and duration to sample numbers using

long startSample = absMillisecondsToSamples(startMilliseconds);

and

int numSamples = (int) relMillisecondsToSamples(duration);

then make a bitmap of the channels you wnat -

int channelMap;

channelMap = PamUtils.SetBit(0, channel, 1); // just the channel that had the mark

channelMap = rawDataBlock.getChannelMap(); // all channels in the raw data block

Then get teh samples from the raw data block ...

double[][] rawData = rawDataBlock.getSamples(startSample, numSamples, channelMap);

To get the FFT data, use PamDataUnit fftDataUnit;

int fftDataUnitIndex = fftDataBlock.getIndexOfFirstUnitAfter(startMilliseconds);

if (fftDataUnitIndex >= 0) while (fftDataUnitIndex < fftDataBlock.getUnitsCount()) {

fftDataUnit = fftDataBlock.getDataUnit(fftDataUnitIndex, PamDataBlock.REFERENCE_CURRENT);

if (fftDataUnit.timeMilliseconds + fftDataUnit.duration > startMilliseconds + duration) {

break;

}

// process that unit in any way you want, then get the next unit

fftDataUnitIndex ++;

}

Remember that the data units will contain one channel of fft data each and multiple channels may be interleaved.

Specified by:
spectrogramNotification in interface SpectrogramMarkObserver

getMarkObserverName

public java.lang.String getMarkObserverName()
Specified by:
getMarkObserverName in interface SpectrogramMarkObserver

pamStart

public void pamStart()
Description copied from class: PamProcess
Called for each process to tell it to start (may not be necessary for processes which are listening for data anyway.

Specified by:
pamStart in class PamProcess

pamStop

public void pamStop()
Description copied from class: PamProcess
Stops the process.

Specified by:
pamStop in class PamProcess