Class: WSK::Actions::SilenceRemover
- Inherits:
-
Object
- Object
- WSK::Actions::SilenceRemover
- Defined in:
- lib/WSK/Actions/SilenceRemover.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
-
#execute(iInputData, oOutputData) ⇒ Object
Execute.
-
#get_nbr_samples(iInputData) ⇒ Object
Get the number of samples that will be written.
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
62 63 64 65 66 67 68 |
# File 'lib/WSK/Actions/SilenceRemover.rb', line 62 def execute(iInputData, oOutputData) iInputData.each_raw_buffer(@IdxFirstSample, @IdxLastSample) 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 52 53 |
# File 'lib/WSK/Actions/SilenceRemover.rb', line 23 def get_nbr_samples(iInputData) lSilenceThresholds = readThresholds(@SilenceThreshold, iInputData.Header.NbrChannels) @IdxFirstSample, lNextAboveThresholds = getNextNonSilentSample(iInputData, 0, lSilenceThresholds, nil, nil, false) if (@IdxFirstSample == nil) log_info 'The whole file is silent' @IdxFirstSample = 0 @IdxLastSample = 0 else lNoiseFFTMaxDistance, lNoiseFFTProfile = readFFTProfile(@NoiseFFTFileName) @IdxLastSample, lNextAboveThresholds = getNextNonSilentSample(iInputData, iInputData.NbrSamples-1, lSilenceThresholds, lNoiseFFTProfile, lNoiseFFTMaxDistance, true) if (@IdxLastSample == nil) log_err "A beginning sample has been found (#{@IdxFirstSample}), but no ending sample could. This is a bug." raise RuntimeError.new("A beginning sample has been found (#{@IdxFirstSample}), but no ending sample could. This is a bug.") end # Compute the limits of fadein and fadeout lNbrAttack = readDuration(@Attack, iInputData.Header.SampleRate) lNbrRelease = readDuration(@Release, iInputData.Header.SampleRate) @IdxFirstSample -= lNbrAttack if (@IdxFirstSample < 0) log_warn "Attack duration #{lNbrAttack} makes first non silent sample negative. Setting it to 0. Please consider decreasing attack duration." @IdxFirstSample = 0 end @IdxLastSample += lNbrRelease if (@IdxLastSample >= iInputData.NbrSamples) log_warn "Release duration #{lNbrRelease} makes last non silent sample overflow. Setting it to the last sample (#{iInputData.NbrSamples - 1}). Please consider decreasing release duration." @IdxLastSample = iInputData.NbrSamples - 1 end end return @IdxLastSample-@IdxFirstSample+1 end |