code: def reverberate(waveforms, rir_waveform, rescale_amp="avg"):
      """
      General function to contaminate a given signal with reverberation given a
      Room Impulse Response (RIR).
      It performs convolution between RIR and signal, but without changing
      the original amplitude of the signal.
  
      Arguments
      ---------
      waveforms : tensor
          The waveforms to normalize.
          Shape should be `[batch, time]` or `[batch, time, channels]`.
      rir_waveform : tensor
          RIR tensor, shape should be [time, channels].
      rescale_amp : str
          Whether reverberated signal is rescaled (None) and with respect either
          to original signal "peak" amplitude or "avg" average amplitude.
          Choose between [None, "avg", "peak"].
  
      Returns
      -------
      waveforms: tensor
          Reverberated signal.
  
      """
  
      orig_shape = waveforms.shape
  
      if len(waveforms.shape) > 3 or len(rir_waveform.shape) > 3:
          raise NotImplementedError
  
      # if inputs are mono tensors we reshape to 1, samples
      if len(waveforms.shape) == 1:
          waveforms = waveforms.unsqueeze(0).unsqueeze(-1)
      elif len(waveforms.shape) == 2:
          waveforms = waveforms.unsqueeze(-1)
  
      if (
          len(rir_waveform.shape) == 1
      ):  # convolve1d expects a 3d tensor !
          rir_waveform = rir_waveform.unsqueeze(0).unsqueeze(-1)
      elif len(rir_waveform.shape) == 2:
          rir_waveform = rir_waveform.unsqueeze(-1)
  
      # Compute the average amplitude of the clean
      orig_amplitude = compute_amplitude(
          waveforms, waveforms.size(1), rescale_amp
      )
  
      # Compute index of the direct signal, so we can preserve alignment
      value_max, direct_index = rir_waveform.abs().max(
          axis=1, keepdim=True
      )
  
      # Making sure the max is always positive (if not, flip)
      # mask = torch.logical_and(rir_waveform == value_max,  rir_waveform < 0)
      # rir_waveform[mask] = -rir_waveform[mask]
  
      # Use FFT to compute convolution, because of long reverberation filter
      waveforms = convolve1d(
          waveform=waveforms,
          kernel=rir_waveform,
          use_fft=True,
          rotation_index=direct_index,
      )
  
      # Rescale to the peak amplitude of the clean waveform
      waveforms = rescale(
          waveforms, waveforms.size(1), orig_amplitude, rescale_amp
      )
  
      if len(orig_shape) == 1:
          waveforms = waveforms.squeeze(0).squeeze(-1)
      if len(orig_shape) == 2:
          waveforms = waveforms.squeeze(-1)
  
      return waveforms
  
file_path: speechbrain/speechbrain/processing/signal_processing.py
imports: import torch
  import math
  from packaging import version
label_desc: Use image node_id 6 for calling a global function with example usage: reverberate(waveforms, rir_waveform, rescale_amp) and returns: waveforms