torchaudio.prototype.functional.adsr_envelope¶
- torchaudio.prototype.functional.adsr_envelope(num_frames: int, *, attack: float = 0.0, hold: float = 0.0, decay: float = 0.0, sustain: float = 1.0, release: float = 0.0, n_decay: int = 2, dtype: Optional[dtype] = None, device: Optional[device] = None)[source]¶
Generate ADSR Envelope
- Parameters:
num_frames (int) – The number of output frames.
attack (float, optional) – The relative time it takes to reach the maximum level from the start. (Default:
0.0
)hold (float, optional) – The relative time the maximum level is held before it starts to decay. (Default:
0.0
)decay (float, optional) – The relative time it takes to sustain from the maximum level. (Default:
0.0
)sustain (float, optional) –
The relative level at which the sound should sustain. (Default:
1.0
)Note
The duration of sustain is derived as 1.0 - (The sum of attack, hold, decay and release).
release (float, optional) – The relative time it takes for the sound level to reach zero after the sustain. (Default:
0.0
)n_decay (int, optional) – The degree of polynomial decay. Default:
2
.dtype (torch.dpython:type, optional) – the desired data type of returned tensor. Default: if
None
, uses a global default (seetorch.set_default_tensor_type()
).device (torch.device, optional) – the desired device of returned tensor. Default: if
None
, uses the current device for the default tensor type (seetorch.set_default_tensor_type()
). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.
- Returns:
ADSR Envelope. Shape: (num_frames, )
- Return type:
Tensor
- Example
- Tutorials using
adsr_envelope
: - Additive SynthesisOscillator and ADSR envelope