Class: WSK::Actions::GenSine
- Inherits:
-
Object
- Object
- WSK::Actions::GenSine
- Defined in:
- lib/WSK/Actions/GenSine.rb
Instance Method Summary collapse
-
#execute(iInputData, oOutputData) ⇒ Object
Execute.
-
#get_nbr_samples(iInputData) ⇒ Object
Get the number of samples that will be written.
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
31 32 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 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/WSK/Actions/GenSine.rb', line 31 def execute(iInputData, oOutputData) # Compute values used to create sawtooth lMaxValue = 2**(iInputData.Header.NbrBitsPerSample-1)-1 # Compute the number of complete periods to put in the samples we want lNbrSamplesPeriod = iInputData.Header.SampleRate/@Frequency lNbrPeriods = @NbrSamples/lNbrSamplesPeriod lBuffer = nil if (lNbrPeriods > 0) # Generate a buffer with a omplete period in it lBuffer = [] lNbrSamplesPeriod.times do |iIdx| lBuffer.concat( [(Math.sin((2*Math::PI*iIdx)/lNbrSamplesPeriod)*lMaxValue).round] * iInputData.Header.NbrChannels ) end # Write them lNbrPeriods.times do |iIdx| oOutputData.pushBuffer(lBuffer) end end lRemainingSamples = @NbrSamples % lNbrSamplesPeriod if (lRemainingSamples > 0) # Add the remaining part of the buffer if (lBuffer == nil) # Generate a part of the buffer lBuffer = [] lRemainingSamples.times do |iIdx| lBuffer.concat( [(Math.sin((2*Math::PI*iIdx)/lNbrSamplesPeriod)*lMaxValue).round] * iInputData.Header.NbrChannels ) end # Write it oOutputData.pushBuffer(lBuffer) else # Write a part of the already generated buffer oOutputData.pushBuffer(lBuffer[0..iInputData.Header.NbrChannels*lRemainingSamples-1]) end 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
20 21 22 |
# File 'lib/WSK/Actions/GenSine.rb', line 20 def get_nbr_samples(iInputData) return @NbrSamples end |