Shortcuts

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

This feature supports the following devices: CPU, CUDA
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 (see torch.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 (see torch.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
https://download.pytorch.org/torchaudio/doc-assets/adsr_examples.png
Tutorials using adsr_envelope:
Additive Synthesis

Additive Synthesis

Additive Synthesis
Oscillator and ADSR envelope

Oscillator and ADSR envelope

Oscillator and ADSR envelope

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources