Class: WSK::Actions::CutFirstSignal

Inherits:
Object
  • Object
show all
Includes:
Common, FFT
Defined in:
lib/WSK/Actions/CutFirstSignal.rb

Constant Summary

Constants included from FFT

FFT::FFTDISTANCE_AVERAGE_HISTORY_TOLERANCE_PC, FFT::FFTDISTANCE_MAX_HISTORY_TOLERANCE_PC, FFT::FFTDIST_MAX, FFT::FFTNBRSAMPLES_HISTORY, FFT::FFTSAMPLE_FREQ, FFT::FFT_SAMPLES_PREFETCH, FFT::FREQINDEX_FIRST, FFT::FREQINDEX_LAST

Instance Method Summary collapse

Methods included from FFT

#getNextFFTSample, #getNextNonSilentSample, #getNextSilentSample, #getSampleBeyondThresholds

Methods included from Common

#accessInputWaveFile, #accessOutputWaveFile, #getWaveFileAccesses, #parsePlugins, #readDuration, #readFFTProfile, #readThresholds, #val2db

Instance Method Details

#execute(iInputData, oOutputData) ⇒ Object

Execute

Parameters
  • iInputData (WSK::Model::InputData): The input data

  • oOutputData (Object): The output data to fill

Return
  • Exception: An error, or nil if success



60
61
62
63
64
65
66
# File 'lib/WSK/Actions/CutFirstSignal.rb', line 60

def execute(iInputData, oOutputData)
  iInputData.each_raw_buffer(@IdxStartSample) do |iInputRawBuffer, iNbrSamples, iNbrChannels|
    oOutputData.pushRawBuffer(iInputRawBuffer)
  end

  return nil
end

#get_nbr_samples(iInputData) ⇒ Object

Get the number of samples that will be written. This is called before execute, as it is needed to write the output file. It is possible to give a majoration: it will be padded with silence.

Parameters
  • iInputData (WSK::Model::InputData): The input data

Return
  • Integer: The number of samples to be written



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/WSK/Actions/CutFirstSignal.rb', line 23

def get_nbr_samples(iInputData)
  @IdxStartSample = 0
  lSilenceThresholds = readThresholds(@SilenceThreshold, iInputData.Header.NbrChannels)
  # Find the first signal
  lIdxSignalSample, lIdxNextAboveThresholds = getNextNonSilentSample(iInputData, 0, lSilenceThresholds, nil, nil, false)
  if (lIdxSignalSample == nil)
    log_warn 'No signal found. Keeping the whole file.'
  else
    lNoiseFFTMaxDistance, lNoiseFFTProfile = readFFTProfile(@NoiseFFTFileName)
    lSilenceDuration = readDuration(@SilenceMin, iInputData.Header.SampleRate)
    lIdxSilenceSample, lSilenceLength, lIdxNextAboveThresholds = getNextSilentSample(iInputData, lIdxSignalSample, lSilenceThresholds, lSilenceDuration, lNoiseFFTProfile, lNoiseFFTMaxDistance, false)
    if (lIdxSilenceSample == nil)
      log_warn "No silence found after the signal beginning at #{lIdxSignalSample}. Keeping the whole file."
    elsif (lSilenceLength == nil)
      # Find the silence length by parsing following data
      lIdxNonSilentSample, lIdxNextAboveThresholds = getNextNonSilentSample(iInputData, lIdxSilenceSample+1, lSilenceThresholds, lNoiseFFTProfile, lNoiseFFTMaxDistance, false)
      if (lIdxNonSilentSample == nil)
        # The file should be empty
        @IdxStartSample = iInputData.NbrSamples-1
      else
        @IdxStartSample = lIdxNonSilentSample
      end
    else
      @IdxStartSample = lIdxSilenceSample + lSilenceLength
    end
  end

  return iInputData.NbrSamples-@IdxStartSample
end