class_docstr: This class is to convert spectrograms back to waveforms. It only works for the complex value spectrograms.
  If you have the magnitude spectrograms, please use :func:`~nnAudio.Spectrogram.Griffin_Lim`.
  The parameters (e.g. n_fft, window) need to be the same as the STFT in order to obtain the correct inverse.
  If trainability is not required, it is recommended to use the ``inverse`` method under the ``STFT`` class
  to save GPU/RAM memory.
  
  When ``trainable=True`` and ``freq_scale!='no'``, there is no guarantee that the inverse is perfect, please
  use with extra care.
  
  Parameters
  ----------
  n_fft : int
      The window size. Default value is 2048.
  
  freq_bins : int
      Number of frequency bins. Default is ``None``, which means ``n_fft//2+1`` bins
      Please make sure the value is the same as the forward STFT.
  
  hop_length : int
      The hop (or stride) size. Default value is ``None`` which is equivalent to ``n_fft//4``.
      Please make sure the value is the same as the forward STFT.
  
  window : str
      The windowing function for iSTFT. It uses ``scipy.signal.get_window``, please refer to
      scipy documentation for possible windowing functions. The default value is 'hann'.
      Please make sure the value is the same as the forward STFT.
  
  freq_scale : 'linear', 'log', or 'no'
      Determine the spacing between each frequency bin. When `linear` or `log` is used,
      the bin spacing can be controlled by ``fmin`` and ``fmax``. If 'no' is used, the bin will
      start at 0Hz and end at Nyquist frequency with linear spacing.
      Please make sure the value is the same as the forward STFT.
  
  center : bool
      Putting the iSTFT keneral at the center of the time-step or not. If ``False``, the time
      index is the beginning of the iSTFT kernel, if ``True``, the time index is the center of
      the iSTFT kernel. Default value if ``True``.
      Please make sure the value is the same as the forward STFT.
  
  fmin : int
      The starting frequency for the lowest frequency bin. If freq_scale is ``no``, this argument
      does nothing. Please make sure the value is the same as the forward STFT.
  
  fmax : int
      The ending frequency for the highest frequency bin. If freq_scale is ``no``, this argument
      does nothing. Please make sure the value is the same as the forward STFT.
  
  sr : int
      The sampling rate for the input audio. It is used to calucate the correct ``fmin`` and ``fmax``.
      Setting the correct sampling rate is very important for calculating the correct frequency.
  
  trainable_kernels : bool
      Determine if the STFT kenrels are trainable or not. If ``True``, the gradients for STFT
      kernels will also be caluclated and the STFT kernels will be updated during model training.
      Default value is ``False``.
  
  trainable_window : bool
      Determine if the window function is trainable or not.
      Default value is ``False``.
  
  verbose : bool
      If ``True``, it shows layer information. If ``False``, it suppresses all prints.
  
  Returns
  -------
  spectrogram : torch.tensor
      It returns a batch of waveforms.
  
  Examples
  --------
  >>> spec_layer = Spectrogram.iSTFT()
  >>> specs = spec_layer(x)
class_docstr_tok: ["This","class","is","to","convert","spectrograms","back","to","waveforms",".","It","only","works","for","the","complex","value","spectrograms",".","If","you","have","the","magnitude","spectrograms",",","please","use",":","func",":","`","~nnAudio.Spectrogram.Griffin_Lim","`",".","The","parameters","(","e.g",".","n_fft",",","window",")","need","to","be","the","same","as","the","STFT","in","order","to","obtain","the","correct","inverse",".","If","trainability","is","not","required",",","it","is","recommended","to","use","the","``","inverse","``","method","under","the","``","STFT","``","class","to","save","GPU\/RAM","memory",".","When","``","trainable=True","``","and","``","freq_scale","!","='no","'","``",",","there","is","no","guarantee","that","the","inverse","is","perfect",",","please","use","with","extra","care",".","Parameters","--","--","--","--","--","n_fft",":","int","The","window","size",".","Default","value","is","2048.","freq_bins",":","int","Number","of","frequency","bins",".","Default","is","``","None","``",",","which","means","``","n_fft\/\/2+1","``","bins","Please","make","sure","the","value","is","the","same","as","the","forward","STFT",".","hop_length",":","int","The","hop","(","or","stride",")","size",".","Default","value","is","``","None","``","which","is","equivalent","to","``","n_fft\/\/4","``",".","Please","make","sure","the","value","is","the","same","as","the","forward","STFT",".","window",":","str","The","windowing","function","for","iSTFT",".","It","uses","``","scipy.signal.get_window","``",",","please","refer","to","scipy","documentation","for","possible","windowing","functions",".","The","default","value","is","'hann","'",".","Please","make","sure","the","value","is","the","same","as","the","forward","STFT",".","freq_scale",":","'linear","'",",","'log","'",",","or","'no'","Determine","the","spacing","between","each","frequency","bin",".","When","`","linear","`","or","`","log","`","is","used",",","the","bin","spacing","can","be","controlled","by","``","fmin","``","and","``","fmax","``",".","If","'no","'","is","used",",","the","bin","will","start","at","0Hz","and","end","at","Nyquist","frequency","with","linear","spacing",".","Please","make","sure","the","value","is","the","same","as","the","forward","STFT",".","center",":","bool","Putting","the","iSTFT","keneral","at","the","center","of","the","time-step","or","not",".","If","``","False","``",",","the","time","index","is","the","beginning","of","the","iSTFT","kernel",",","if","``","True","``",",","the","time","index","is","the","center","of","the","iSTFT","kernel",".","Default","value","if","``","True","``",".","Please","make","sure","the","value","is","the","same","as","the","forward","STFT",".","fmin",":","int","The","starting","frequency","for","the","lowest","frequency","bin",".","If","freq_scale","is","``","no","``",",","this","argument","does","nothing",".","Please","make","sure","the","value","is","the","same","as","the","forward","STFT",".","fmax",":","int","The","ending","frequency","for","the","highest","frequency","bin",".","If","freq_scale","is","``","no","``",",","this","argument","does","nothing",".","Please","make","sure","the","value","is","the","same","as","the","forward","STFT",".","sr",":","int","The","sampling","rate","for","the","input","audio",".","It","is","used","to","calucate","the","correct","``","fmin","``","and","``","fmax","``",".","Setting","the","correct","sampling","rate","is","very","important","for","calculating","the","correct","frequency",".","trainable_kernels",":","bool","Determine","if","the","STFT","kenrels","are","trainable","or","not",".","If","``","True","``",",","the","gradients","for","STFT","kernels","will","also","be","caluclated","and","the","STFT","kernels","will","be","updated","during","model","training",".","Default","value","is","``","False","``",".","trainable_window",":","bool","Determine","if","the","window","function","is","trainable","or","not",".","Default","value","is","``","False","``",".","verbose",":","bool","If","``","True","``",",","it","shows","layer","information",".","If","``","False","``",",","it","suppresses","all","prints",".","Returns","--","--","--","-","spectrogram",":","torch.tensor","It","returns","a","batch","of","waveforms",".","Examples","--","--","--","--",">",">",">","spec_layer","=","Spectrogram.iSTFT","(",")",">",">",">","specs","=","spec_layer","(","x",")"]
code: def __init__(
      self,
      n_fft=2048,
      win_length=None,
      freq_bins=None,
      hop_length=None,
      window="hann",
      freq_scale="no",
      center=True,
      fmin=50,
      fmax=6000,
      sr=22050,
      trainable_kernels=False,
      trainable_window=False,
      verbose=True,
      refresh_win=True,
  ):
      super().__init__()
  
      # Trying to make the default setting same as librosa
      if win_length == None:
          win_length = n_fft
      if hop_length == None:
          hop_length = int(win_length // 4)
  
      self.n_fft = n_fft
      self.win_length = win_length
      self.stride = hop_length
      self.center = center
  
      self.pad_amount = self.n_fft // 2
      self.refresh_win = refresh_win
  
      start = time()
  
      # Create the window function and prepare the shape for batch-wise-time-wise multiplication
  
      # Create filter windows for inverse
      (
          kernel_sin,
          kernel_cos,
          _,
          _,
          window_mask,
      ) = create_fourier_kernels(
          n_fft,
          win_length=win_length,
          freq_bins=n_fft,
          window=window,
          freq_scale=freq_scale,
          fmin=fmin,
          fmax=fmax,
          sr=sr,
          verbose=False,
      )
      window_mask = get_window(window, int(win_length), fftbins=True)
  
      # For inverse, the Fourier kernels do not need to be windowed
      window_mask = torch.tensor(window_mask).unsqueeze(0).unsqueeze(-1)
  
      # kernel_sin and kernel_cos have the shape (freq_bins, 1, n_fft, 1) to support 2D Conv
      kernel_sin = torch.tensor(
          kernel_sin, dtype=torch.float
      ).unsqueeze(-1)
      kernel_cos = torch.tensor(
          kernel_cos, dtype=torch.float
      ).unsqueeze(-1)
  
      # Decide if the Fourier kernels are trainable
      if trainable_kernels:
          # Making all these variables trainable
          kernel_sin = nn.Parameter(
              kernel_sin, requires_grad=trainable_kernels
          )
          kernel_cos = nn.Parameter(
              kernel_cos, requires_grad=trainable_kernels
          )
          self.register_parameter("kernel_sin", kernel_sin)
          self.register_parameter("kernel_cos", kernel_cos)
  
      else:
          self.register_buffer("kernel_sin", kernel_sin)
          self.register_buffer("kernel_cos", kernel_cos)
  
      # Decide if the window function is trainable
      if trainable_window:
          window_mask = nn.Parameter(
              window_mask, requires_grad=trainable_window
          )
          self.register_parameter("window_mask", window_mask)
      else:
          self.register_buffer("window_mask", window_mask)
  
      if verbose == True:
          print(
              "iSTFT kernels created, time used = {:.4f} seconds".format(
                  time() - start
              )
          )
      else:
          pass
  
file_path: nnAudio/Installation/nnAudio/features/stft.py
imports: from torch.nn.functional import conv1d, conv2d, fold
  import torch.nn
  import torch
  import numpy
  from time import time
  from ..utils import *
  from scipy.signal import get_window
label_desc: Use image node_id 1 to create a new iSTFT object from inherited base classes: STFTBase with example: obj = iSTFT(n_fft, win_length, freq_bins, hop_length, window, freq_scale, center, fmin, fmax, sr, trainable_kernels, trainable_window, verbose, refresh_win)