Class: TorchAudio::Transforms::Vol
- Inherits:
-
Torch::NN::Module
- Object
- Torch::NN::Module
- TorchAudio::Transforms::Vol
- Defined in:
- lib/torchaudio/transforms/vol.rb
Instance Method Summary collapse
- #forward(waveform) ⇒ Object
-
#initialize(gain, gain_type: "amplitude") ⇒ Vol
constructor
A new instance of Vol.
Constructor Details
#initialize(gain, gain_type: "amplitude") ⇒ Vol
Returns a new instance of Vol.
4 5 6 7 8 9 10 11 12 |
# File 'lib/torchaudio/transforms/vol.rb', line 4 def initialize(gain, gain_type: "amplitude") super() @gain = gain @gain_type = gain_type if ["amplitude", "power"].include?(gain_type) && gain < 0 raise ArgumentError, "If gain_type = amplitude or power, gain must be positive." end end |
Instance Method Details
#forward(waveform) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/torchaudio/transforms/vol.rb', line 14 def forward(waveform) if @gain_type == "amplitude" waveform = waveform * @gain end if @gain_type == "db" waveform = F.gain(waveform, @gain) end if @gain_type == "power" waveform = F.gain(waveform, 10 * Math.log10(@gain)) end Torch.clamp(waveform, -1, 1) end |