Package clipgenerator

Class ClipProcess

All Implemented Interfaces:
PamObserver, ProcessAnnotator, SpectrogramMarkObserver

public class ClipProcess extends SpectrogramMarkProcess
Process for making short clips of audio data.
separate subscriber processes for each triggering data block, but these all send clip requests back into the main observer of the actual raw data - so that all clips are made from the same central thread.
Let the request queue trigger off the main clock signal.
Author:
Doug Gillespie
  • Constructor Details

    • ClipProcess

      public ClipProcess(ClipControl clipControl)
  • Method Details

    • newData

      public void newData(PamObservable o, PamDataUnit arg)
      Overrides:
      newData in class PamProcess
    • masterClockUpdate

      public void masterClockUpdate(long timeMilliseconds, long sampleNumber)
      Specified by:
      masterClockUpdate in interface PamObserver
      Overrides:
      masterClockUpdate in class PamProcess
    • prepareProcess

      public void prepareProcess()
      Description copied from class: PamProcess
      Called for each process before any of them receive the PamStart command
      Overrides:
      prepareProcess in class PamProcess
    • 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).
      Overrides:
      pamStart in class SpectrogramMarkProcess
    • findClipFile

      public File findClipFile(ClipDataUnit clipDataUnit)
      Find the wav file to go with a particular clip
      Parameters:
      clipDataUnit - data unit to find the file for.
      Returns:
      file, or null if not found.
    • flushDataBlockBuffers

      public boolean flushDataBlockBuffers(long maxWait)
      Description copied from class: PamProcess
      Work through all the output datablocks and wait for their internal buffers to flush through.

      This is used when stopping PAMGUARD to ensure that all data complete processing before anything else happens.

      Overrides:
      flushDataBlockBuffers in class PamProcess
      Parameters:
      maxWait - maxWait time in milliseconds.
      Returns:
      true if successful, or false if there was a timeout.
    • getRequiredDataHistory

      public long getRequiredDataHistory(PamObservable o, Object arg)
      Specified by:
      getRequiredDataHistory in interface PamObserver
      Overrides:
      getRequiredDataHistory in class PamProcess
      Parameters:
      arg - optional argument from PamObservable
      Returns:
      time in milliseconds required by data held in PamObservable
    • spectrogramNotification

      public boolean spectrogramNotification(SpectrogramDisplay display, MouseEvent mouseEvent, int downUp, int channel, long startMilliseconds, long duration, double f1, double f2, TDGraphFX tdDisplay)
      Description copied from class: SpectrogramMarkProcess
      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 invalid input: '<' 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
      Overrides:
      spectrogramNotification in class SpectrogramMarkProcess
      Parameters:
      display - spectrogram display
      downUp - 0 = mouse down, 1 = mouse up, 2 = drag + button number in upper 16 bits.
      channel - channel or sequence number, depending on the source
      startMilliseconds - start time in milliseconds.
      duration - duration in milliseconds.
      f1 - min frequency in Hz
      f2 - max frequency in Hz
      Returns:
      true if the user has popped up a menu or done something that should stop the sending display from carrying out any further actions on this mouse action (put in place to prevent the spectrogram menu popping up when editing marks in viewer mode).
    • canMark

      public boolean canMark()
      Returns:
      whether or not it's possible to use this marker. Generally false when in viewer mode, but maynot always be.
    • subscribeDataBlocks

      public void subscribeDataBlocks()
      Called at end of setup of after settings dialog to subscribe data blocks.
    • getClipControl

      public ClipControl getClipControl()
      Returns:
      the clipControl
    • getClipDataBlock

      public ClipDataBlock getClipDataBlock()
      Returns:
      the clipDataBlock
    • getClipSpectrogramMarkDataBlock

      public ClipSpectrogramMarkDataBlock getClipSpectrogramMarkDataBlock()
      Returns:
      the clipSpectrogramMarkDataBlock
    • processNewBuoyData

      public void processNewBuoyData(BuoyStatusDataUnit buoyStatusDataUnit, PamDataUnit pamDataUnit)
      Overrides:
      processNewBuoyData in class PamProcess
    • getMarkName

      public String getMarkName()
      Description copied from interface: SpectrogramMarkObserver
      Name of the mark. Observers may have several mark types and might want to change the name to indicate what action will be taken when a mark is made
      Returns:
    • playClip

      public void playClip(ClipDataUnit clipDataUnit)
    • getManualAnnotaionHandler

      public ManualAnnotationHandler getManualAnnotaionHandler()
      Returns:
      the manualAnnotaionHandler