Class: WSK::Actions::VolumeProfile

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/WSK/Actions/VolumeProfile.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



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/WSK/Actions/VolumeProfile.rb', line 33

def execute(iInputData, oOutputData)
  rError = nil

  lIdxBegin = readDuration(@Begin, iInputData.Header.SampleRate)
  lIdxEnd = readDuration(@End, iInputData.Header.SampleRate)
  lInterval = readDuration(@Interval, iInputData.Header.SampleRate)
  if (lIdxEnd == -1)
    lIdxEnd = iInputData.NbrSamples - 1
  end
  if (lIdxEnd >= iInputData.NbrSamples)
    rError = RuntimeError.new("Profile ends at #{lIdxEnd}, superceeding last sample (#{iInputData.NbrSamples-1})")
  else
    lFunction = WSK::Functions::Function.new
    lFunction.read_from_input_volume(iInputData, lIdxBegin, lIdxEnd, lInterval, @RMSRatio)
    # Normalize the volume function on a [-1..1] scale
    lFunction.divide_by(Rational(2)**(iInputData.Header.NbrBitsPerSample-1))
    _, lMinY, _, lMaxY = lFunction.get_bounds
    lDBMinY = lFunction.value_val_2_db(lMinY, Rational(1))
    lDBMaxY = lFunction.value_val_2_db(lMaxY, Rational(1))
    log_info "Dynamic range: [#{sprintf('%.2f',lMinY)} - #{sprintf('%.2f',lMaxY)}] ([#{sprintf('%.2f',lDBMinY)}db - #{sprintf('%.2f',lDBMaxY)}db] = #{sprintf('%.2f',lDBMaxY-lDBMinY)}db)"
    lFunction.write_to_file(@FctFileName)
  end

  return rError
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
# File 'lib/WSK/Actions/VolumeProfile.rb', line 22

def get_nbr_samples(iInputData)
  return 0
end