Class: WSK::Actions::Cut

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

Instance Method Summary collapse

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



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/WSK/Actions/Cut.rb', line 36

def execute(iInputData, oOutputData)
  lChannelsSampleSize = (iInputData.Header.NbrChannels*iInputData.Header.NbrBitsPerSample)/8
  lIdxFirstSample = @IdxBeginSample
  iInputData.each_raw_buffer(@IdxBeginSample) do |iInputRawBuffer, iNbrSamples, iNbrChannels|
    # If the end sample is in this buffer, write only up to it
    if (@IdxEndSample < lIdxFirstSample + iNbrSamples - 1)
      oOutputData.pushRawBuffer(iInputRawBuffer[0..(@IdxEndSample-lIdxFirstSample+1)*lChannelsSampleSize-1])
    else
      oOutputData.pushRawBuffer(iInputRawBuffer)
    end
    if (@IdxEndSample < lIdxFirstSample + iNbrSamples)
      # Nothing left to write
      break
    end
    lIdxFirstSample += iNbrSamples
  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



22
23
24
25
26
27
# File 'lib/WSK/Actions/Cut.rb', line 22

def get_nbr_samples(iInputData)
  @IdxBeginSample = readDuration(@BeginSample, iInputData.Header.SampleRate)
  @IdxEndSample = readDuration(@EndSample, iInputData.Header.SampleRate)

  return @IdxEndSample-@IdxBeginSample+1
end