class_docstr: This class resamples an audio signal using sinc-based interpolation.
  
  It is a modification of the `resample` function from torchaudio
  (https://pytorch.org/audio/stable/tutorials/audio_resampling_tutorial.html)
  
  Arguments
  ---------
  orig_freq : int
      the sampling frequency of the input signal.
  new_freq : int
      the new sampling frequency after this operation is performed.
  lowpass_filter_width : int
      Controls the sharpness of the filter, larger numbers result in a
      sharper filter, but they are less efficient. Values from 4 to 10 are
      allowed.
  
  Example
  -------
  >>> from speechbrain.dataio.dataio import read_audio
  >>> signal = read_audio('tests/samples/single-mic/example1.wav')
  >>> signal = signal.unsqueeze(0) # [batch, time, channels]
  >>> resampler = Resample(orig_freq=16000, new_freq=8000)
  >>> resampled = resampler(signal)
  >>> signal.shape
  torch.Size([1, 52173])
  >>> resampled.shape
  torch.Size([1, 26087])
class_docstr_tok: ["This","class","resamples","an","audio","signal","using","sinc-based","interpolation",".","It","is","a","modification","of","the","`","resample","`","function","from","torchaudio","(","https",":","\/\/pytorch.org\/audio\/stable\/tutorials\/audio_resampling_tutorial.html",")","Arguments","--","--","--","--","-","orig_freq",":","int","the","sampling","frequency","of","the","input","signal",".","new_freq",":","int","the","new","sampling","frequency","after","this","operation","is","performed",".","lowpass_filter_width",":","int","Controls","the","sharpness","of","the","filter",",","larger","numbers","result","in","a","sharper","filter",",","but","they","are","less","efficient",".","Values","from","4","to","10","are","allowed",".","Example","--","--","--","-",">",">",">","from","speechbrain.dataio.dataio","import","read_audio",">",">",">","signal","=","read_audio","(","'tests\/samples\/single-mic\/example1.wav","'",")",">",">",">","signal","=","signal.unsqueeze","(","0",")","#","[","batch",",","time",",","channels","]",">",">",">","resampler","=","Resample","(","orig_freq=16000",",","new_freq=8000",")",">",">",">","resampled","=","resampler","(","signal",")",">",">",">","signal.shape","torch.Size","(","[","1",",","52173","]",")",">",">",">","resampled.shape","torch.Size","(","[","1",",","26087","]",")"]
docstr: Resamples the waveform at the new frequency.
  
  This matches Kaldi's OfflineFeatureTpl ResampleWaveform which uses a
  LinearResample (resample a signal at linearly spaced intervals to
  up/downsample a signal). LinearResample (LR) means that the output
  signal is at linearly spaced intervals (i.e the output signal has a
  frequency of `new_freq`). It uses sinc/bandlimited interpolation to
  upsample/downsample the signal.
  
  (almost directly from torchaudio.compliance.kaldi)
  
  https://ccrma.stanford.edu/~jos/resample/
  Theory_Ideal_Bandlimited_Interpolation.html
  
  https://github.com/kaldi-asr/kaldi/blob/master/src/feat/resample.h#L56
  
  Arguments
  ---------
  waveforms : tensor
      The batch of audio signals to resample.
  
  Returns
  -------
  The waveforms at the new frequency.
docstr_tok: ["Resamples","the","waveform","at","the","new","frequency",".","This","matches","Kaldi","'s","OfflineFeatureTpl","ResampleWaveform","which","uses","a","LinearResample","(","resample","a","signal","at","linearly","spaced","intervals","to","up\/downsample","a","signal",")",".","LinearResample","(","LR",")","means","that","the","output","signal","is","at","linearly","spaced","intervals","(","i.e","the","output","signal","has","a","frequency","of","`","new_freq","`",")",".","It","uses","sinc\/bandlimited","interpolation","to","upsample\/downsample","the","signal",".","(","almost","directly","from","torchaudio.compliance.kaldi",")","https",":","\/\/ccrma.stanford.edu\/~jos\/resample\/","Theory_Ideal_Bandlimited_Interpolation.html","https",":","\/\/github.com\/kaldi-asr\/kaldi\/blob\/master\/src\/feat\/resample.h","#","L56","Arguments","--","--","--","--","-","waveforms",":","tensor","The","batch","of","audio","signals","to","resample",".","Returns","--","--","--","-","The","waveforms","at","the","new","frequency","."]
code: def _perform_resample(self, waveforms):
      """Resamples the waveform at the new frequency.
  
      This matches Kaldi's OfflineFeatureTpl ResampleWaveform which uses a
      LinearResample (resample a signal at linearly spaced intervals to
      up/downsample a signal). LinearResample (LR) means that the output
      signal is at linearly spaced intervals (i.e the output signal has a
      frequency of `new_freq`). It uses sinc/bandlimited interpolation to
      upsample/downsample the signal.
  
      (almost directly from torchaudio.compliance.kaldi)
  
      https://ccrma.stanford.edu/~jos/resample/
      Theory_Ideal_Bandlimited_Interpolation.html
  
      https://github.com/kaldi-asr/kaldi/blob/master/src/feat/resample.h#L56
  
      Arguments
      ---------
      waveforms : tensor
          The batch of audio signals to resample.
  
      Returns
      -------
      The waveforms at the new frequency.
      """
  
      # Compute output size and initialize
      batch_size, num_channels, wave_len = waveforms.size()
      window_size = self.weights.size(1)
      tot_output_samp = self._output_samples(wave_len)
      resampled_waveform = torch.zeros(
          (batch_size, num_channels, tot_output_samp),
          device=waveforms.device,
      )
      self.weights = self.weights.to(waveforms.device)
  
      # Check weights are on correct device
      if waveforms.device != self.weights.device:
          self.weights = self.weights.to(waveforms.device)
  
      # eye size: (num_channels, num_channels, 1)
      eye = torch.eye(num_channels, device=waveforms.device).unsqueeze(
          2
      )
  
      # Iterate over the phases in the polyphase filter
      for i in range(self.first_indices.size(0)):
          wave_to_conv = waveforms
          first_index = int(self.first_indices[i].item())
          if first_index >= 0:
              # trim the signal as the filter will not be applied
              # before the first_index
              wave_to_conv = wave_to_conv[..., first_index:]
  
          # pad the right of the signal to allow partial convolutions
          # meaning compute values for partial windows (e.g. end of the
          # window is outside the signal length)
          max_index = (tot_output_samp - 1) // self.output_samples
          end_index = max_index * self.conv_stride + window_size
          current_wave_len = wave_len - first_index
          right_padding = max(0, end_index + 1 - current_wave_len)
          left_padding = max(0, -first_index)
          wave_to_conv = torch.nn.functional.pad(
              wave_to_conv, (left_padding, right_padding)
          )
          conv_wave = torch.nn.functional.conv1d(
              input=wave_to_conv,
              weight=self.weights[i].repeat(num_channels, 1, 1),
              stride=self.conv_stride,
              groups=num_channels,
          )
  
          # we want conv_wave[:, i] to be at
          # output[:, i + n*conv_transpose_stride]
          dilated_conv_wave = torch.nn.functional.conv_transpose1d(
              conv_wave, eye, stride=self.conv_transpose_stride
          )
  
          # pad dilated_conv_wave so it reaches the output length if needed.
          left_padding = i
          previous_padding = left_padding + dilated_conv_wave.size(-1)
          right_padding = max(0, tot_output_samp - previous_padding)
          dilated_conv_wave = torch.nn.functional.pad(
              dilated_conv_wave, (left_padding, right_padding)
          )
          dilated_conv_wave = dilated_conv_wave[..., :tot_output_samp]
  
          resampled_waveform += dilated_conv_wave
  
      return resampled_waveform
  
imports: import math
  import random
  import torch
  import torch.nn.functional
  from speechbrain.dataio.legacy import ExtendedCSVDataset
  from speechbrain.dataio.dataloader import make_dataloader
  from speechbrain.processing.signal_processing import compute_amplitude, dB_to_amplitude, convolve1d, notch_filter, reverberate
label_desc: Use image node_id 4 for calling the Resample obj's underlying member method code with example usage: obj._perform_resample(waveforms) and returns: resampled_waveform