Class: WSK::Actions::FFT
- Inherits:
-
Object
- Object
- WSK::Actions::FFT
- Defined in:
- lib/WSK/Actions/FFT.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
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/WSK/Actions/FFT.rb', line 34 def execute(iInputData, oOutputData) # 1. Create the whole FFT profile log_info 'Creating FFT profile ...' # Object that will create the FFT lFFTComputing = FFTComputing.new(false, iInputData.Header) # Parse the data lIdxSample = 0 iInputData.each_raw_buffer do |iInputRawBuffer, iNbrSamples, iNbrChannels| lFFTComputing.completeFFT(iInputRawBuffer, iNbrSamples) lIdxSample += iNbrSamples $stdout.write("#{(lIdxSample*100)/iInputData.NbrSamples} %\015") $stdout.flush end # Compute the result require 'WSK/FFTUtils/FFTUtils' lFFTUtils = FFTUtils::FFTUtils.new lFFTProfile = lFFTComputing.getFFTProfile lFFTReferenceProfile = lFFTUtils.createCFFTProfile(lFFTProfile) # 2. Compute the distance obtained by comparing this profile with a normal file pass log_info 'Computing average distance ...' lFFTComputing2 = FFTComputing.new(true, iInputData.Header) lIdxSample = 0 lNbrTimes = 0 lSumDist = 0 while (lIdxSample < iInputData.NbrSamples) # Compute the number of samples needed to have a valid FFT. # Modify this number if it exceeds the range we have lNbrSamplesFFTMax = iInputData.Header.SampleRate/FFTSAMPLE_FREQ lIdxBeginFFTSample = lIdxSample lIdxEndFFTSample = lIdxSample+lNbrSamplesFFTMax-1 if (lIdxEndFFTSample >= iInputData.NbrSamples) lIdxEndFFTSample = iInputData.NbrSamples-1 end lNbrSamplesFFT = lIdxEndFFTSample-lIdxBeginFFTSample+1 # Load an FFT buffer of this lFFTBuffer = '' iInputData.each_raw_buffer(lIdxBeginFFTSample, lIdxEndFFTSample, :nbr_samples_prefetch => iInputData.NbrSamples-lIdxBeginFFTSample) do |iInputRawBuffer, iNbrSamples, iNbrChannels| lFFTBuffer.concat(iInputRawBuffer) end # Compute its FFT profile lFFTComputing2.resetData lFFTComputing2.completeFFT(lFFTBuffer, lNbrSamplesFFT) lSumDist += lFFTUtils.distFFTProfiles(lFFTReferenceProfile, lFFTUtils.createCFFTProfile(lFFTComputing2.getFFTProfile), FFTDIST_MAX).abs lNbrTimes += 1 lIdxSample = lIdxEndFFTSample+1 $stdout.write("#{(lIdxSample*100)/iInputData.NbrSamples} %\015") $stdout.flush end lAverageDist = lSumDist/lNbrTimes log_debug "Average distance with silence: #{lAverageDist}" # Display results (FREQINDEX_FIRST..FREQINDEX_LAST).each_with_index do |iIdx, iIdxFreq| log_debug "[#{(440*(2**(iIdx/12.0))).round} Hz]: #{lFFTProfile[2][iIdxFreq].join(', ')}" end # Write the result in a file File.open('fft.result', 'wb') do |oFile| oFile.write(Marshal.dump([lAverageDist, lFFTProfile])) 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 |
# File 'lib/WSK/Actions/FFT.rb', line 23 def get_nbr_samples(iInputData) return 0 end |