code: def _xfade_and_unfold(y: Tensor, overlap: int) -> Tensor:
      r"""Applies a crossfade and unfolds into a 1d array.
  
      y = [[seq1],
           [seq2],
           [seq3]]
      Apply a gain envelope at both ends of the sequences
      y = [[seq1_in, seq1_timesteps, seq1_out],
           [seq2_in, seq2_timesteps, seq2_out],
           [seq3_in, seq3_timesteps, seq3_out]]
      Stagger and add up the groups of samples:
          [seq1_in, seq1_timesteps, (seq1_out + seq2_in), seq2_timesteps, ...]
  
      Args:
          y (Tensor): Batched sequences of audio samples of size
              (num_folds, channels, timesteps + 2 * overlap).
          overlap (int): Timesteps for both xfade and rnn warmup.
  
      Returns:
          unfolded waveform (Tensor) : waveform in a 1d tensor of size (channels, total_len).
      """
  
      num_folds, channels, length = y.shape
      timesteps = length - 2 * overlap
      total_len = num_folds * (timesteps + overlap) + overlap
  
      # Need some silence for the rnn warmup
      silence_len = overlap // 2
      fade_len = overlap - silence_len
      silence = torch.zeros(
          (silence_len), dtype=y.dtype, device=y.device
      )
      linear = torch.ones((silence_len), dtype=y.dtype, device=y.device)
  
      # Equal power crossfade
      t = torch.linspace(
          -1, 1, fade_len, dtype=y.dtype, device=y.device
      )
      fade_in = torch.sqrt(0.5 * (1 + t))
      fade_out = torch.sqrt(0.5 * (1 - t))
  
      # Concat the silence to the fades
      fade_in = torch.cat([silence, fade_in])
      fade_out = torch.cat([linear, fade_out])
  
      # Apply the gain to the overlap samples
      y[:, :, :overlap] *= fade_in
      y[:, :, -overlap:] *= fade_out
  
      unfolded = torch.zeros(
          (channels, total_len), dtype=y.dtype, device=y.device
      )
  
      # Loop to add up all the samples
      for i in range(num_folds):
          start = i * (timesteps + overlap)
          end = start + timesteps + 2 * overlap
          unfolded[:, start:end] += y[i]
  
      return unfolded
  
file_path: audio/examples/pipeline_wavernn/wavernn_inference_wrapper.py
imports: import torch
  import torchaudio
  from processing import normalized_waveform_to_bits
  from torch import Tensor
  from torchaudio.models.wavernn import WaveRNN
label_desc: Use image node_id 2 for calling a global function with example usage: _xfade_and_unfold(y, overlap) and returns: unfolded