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: Based on LinearResample::SetIndexesAndWeights
  
  Retrieves the weights for resampling as well as the indices in which
  they are valid. 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.
  
  Returns
  -------
  - the place where each filter should start being applied
  - the filters to be applied to the signal for resampling
docstr_tok: ["Based","on","LinearResample",":",":SetIndexesAndWeights","Retrieves","the","weights","for","resampling","as","well","as","the","indices","in","which","they","are","valid",".","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",".","Returns","--","--","--","-","-","the","place","where","each","filter","should","start","being","applied","-","the","filters","to","be","applied","to","the","signal","for","resampling"]
code: def _indices_and_weights(self, waveforms):
      """Based on LinearResample::SetIndexesAndWeights
  
      Retrieves the weights for resampling as well as the indices in which
      they are valid. 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.
  
      Returns
      -------
      - the place where each filter should start being applied
      - the filters to be applied to the signal for resampling
      """
  
      # Lowpass filter frequency depends on smaller of two frequencies
      min_freq = min(self.orig_freq, self.new_freq)
      lowpass_cutoff = 0.99 * 0.5 * min_freq
  
      assert lowpass_cutoff * 2 <= min_freq
      window_width = self.lowpass_filter_width / (2.0 * lowpass_cutoff)
  
      assert lowpass_cutoff < min(self.orig_freq, self.new_freq) / 2
      output_t = torch.arange(
          start=0.0, end=self.output_samples, device=waveforms.device
      )
      output_t /= self.new_freq
      min_t = output_t - window_width
      max_t = output_t + window_width
  
      min_input_index = torch.ceil(min_t * self.orig_freq)
      max_input_index = torch.floor(max_t * self.orig_freq)
      num_indices = max_input_index - min_input_index + 1
  
      max_weight_width = num_indices.max()
      j = torch.arange(max_weight_width, device=waveforms.device)
      input_index = min_input_index.unsqueeze(1) + j.unsqueeze(0)
      delta_t = (input_index / self.orig_freq) - output_t.unsqueeze(1)
  
      weights = torch.zeros_like(delta_t)
      inside_window_indices = delta_t.abs().lt(window_width)
  
      # raised-cosine (Hanning) window with width `window_width`
      weights[inside_window_indices] = 0.5 * (
          1
          + torch.cos(
              2
              * math.pi
              * lowpass_cutoff
              / self.lowpass_filter_width
              * delta_t[inside_window_indices]
          )
      )
  
      t_eq_zero_indices = delta_t.eq(0.0)
      t_not_eq_zero_indices = ~t_eq_zero_indices
  
      # sinc filter function
      weights[t_not_eq_zero_indices] *= torch.sin(
          2 * math.pi * lowpass_cutoff * delta_t[t_not_eq_zero_indices]
      ) / (math.pi * delta_t[t_not_eq_zero_indices])
  
      # limit of the function at t = 0
      weights[t_eq_zero_indices] *= 2 * lowpass_cutoff
  
      # size (output_samples, max_weight_width)
      weights /= self.orig_freq
  
      self.first_indices = min_input_index
      self.weights = weights
  
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 6 for calling the Resample obj's underlying member method code with example usage: obj._indices_and_weights(waveforms) without return types