class_docstr: This function is to calculate the CQT of the input signal.
  Input signal should be in either of the following shapes.
  
  1. ``(len_audio)``
  
  2. ``(num_audio, len_audio)``
  
  3. ``(num_audio, 1, len_audio)``
  
  The correct shape will be inferred autommatically if the input follows these 3 shapes.
  Most of the arguments follow the convention from librosa.
  This class inherits from ``nn.Module``, therefore, the usage is same as ``nn.Module``.
  
  This alogrithm uses the resampling method proposed in [1].
  Instead of convoluting the STFT results with a gigantic CQT kernel covering the full frequency
  spectrum, we make a small CQT kernel covering only the top octave. Then we keep downsampling the
  input audio by a factor of 2 to convoluting it with the small CQT kernel.
  Everytime the input audio is downsampled, the CQT relative to the downsampled input is equivalent
  to the next lower octave.
  The kernel creation process is still same as the 1992 algorithm. Therefore, we can reuse the
  code from the 1992 alogrithm [2]
  [1] Schörkhuber, Christian. “CONSTANT-Q TRANSFORM TOOLBOX FOR MUSIC PROCESSING.” (2010).
  [2] Brown, Judith C.C. and Miller Puckette. “An efficient algorithm for the calculation of a
  constant Q transform.” (1992).
  
  Early downsampling factor is to downsample the input audio to reduce the CQT kernel size.
  The result with and without early downsampling are more or less the same except in the very low
  frequency region where freq < 40Hz.
  
  Parameters
  ----------
  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.
  
  hop_length : int
      The hop (or stride) size. Default value is 512.
  
  fmin : float
      The frequency for the lowest CQT bin. Default is 32.70Hz, which coresponds to the note C0.
  
  fmax : float
      The frequency for the highest CQT bin. Default is ``None``, therefore the higest CQT bin is
      inferred from the ``n_bins`` and ``bins_per_octave``.  If ``fmax`` is not ``None``, then the
      argument ``n_bins`` will be ignored and ``n_bins`` will be calculated automatically.
      Default is ``None``
  
  n_bins : int
      The total numbers of CQT bins. Default is 84. Will be ignored if ``fmax`` is not ``None``.
  
  bins_per_octave : int
      Number of bins per octave. Default is 12.
  
  norm : bool
      Normalization for the CQT result.
  
  basis_norm : int
      Normalization for the CQT kernels. ``1`` means L1 normalization, and ``2`` means L2 normalization.
      Default is ``1``, which is same as the normalization used in librosa.
  
  window : str
      The windowing function for CQT. It uses ``scipy.signal.get_window``, please refer to
      scipy documentation for possible windowing functions. The default value is 'hann'
  
  pad_mode : str
      The padding method. Default value is 'reflect'.
  
  trainable : bool
      Determine if the CQT kernels are trainable or not. If ``True``, the gradients for CQT kernels
      will also be caluclated and the CQT kernels will be updated during model training.
      Default value is ``False``
  
  output_format : str
      Determine the return type.
      'Magnitude' will return the magnitude of the STFT result, shape = ``(num_samples, freq_bins, time_steps)``;
      'Complex' will return the STFT result in complex number, shape = ``(num_samples, freq_bins, time_steps, 2)``;
      'Phase' will return the phase of the STFT reuslt, shape = ``(num_samples, freq_bins,time_steps, 2)``.
      The complex number is stored as ``(real, imag)`` in the last axis. Default value is 'Magnitude'.
  
  verbose : bool
      If ``True``, it shows layer information. If ``False``, it suppresses all prints.
  
  Returns
  -------
  spectrogram : torch.tensor
  It returns a tensor of spectrograms.
  shape = ``(num_samples, freq_bins,time_steps)`` if ``output_format='Magnitude'``;
  shape = ``(num_samples, freq_bins,time_steps, 2)`` if ``output_format='Complex' or 'Phase'``;
  
  Examples
  --------
  >>> spec_layer = Spectrogram.CQT2010v2()
  >>> specs = spec_layer(x)
class_docstr_tok: ["This","function","is","to","calculate","the","CQT","of","the","input","signal",".","Input","signal","should","be","in","either","of","the","following","shapes",".","1",".","``","(","len_audio",")","``","2",".","``","(","num_audio",",","len_audio",")","``","3",".","``","(","num_audio",",","1",",","len_audio",")","``","The","correct","shape","will","be","inferred","autommatically","if","the","input","follows","these","3","shapes",".","Most","of","the","arguments","follow","the","convention","from","librosa",".","This","class","inherits","from","``","nn.Module","``",",","therefore",",","the","usage","is","same","as","``","nn.Module","``",".","This","alogrithm","uses","the","resampling","method","proposed","in","[","1","]",".","Instead","of","convoluting","the","STFT","results","with","a","gigantic","CQT","kernel","covering","the","full","frequency","spectrum",",","we","make","a","small","CQT","kernel","covering","only","the","top","octave",".","Then","we","keep","downsampling","the","input","audio","by","a","factor","of","2","to","convoluting","it","with","the","small","CQT","kernel",".","Everytime","the","input","audio","is","downsampled",",","the","CQT","relative","to","the","downsampled","input","is","equivalent","to","the","next","lower","octave",".","The","kernel","creation","process","is","still","same","as","the","1992","algorithm",".","Therefore",",","we","can","reuse","the","code","from","the","1992","alogrithm","[","2","]","[","1","]","Sch\u00f6rkhuber",",","Christian",".","\u201c","CONSTANT-Q","TRANSFORM","TOOLBOX","FOR","MUSIC","PROCESSING.","\u201d","(","2010",")",".","[","2","]","Brown",",","Judith","C.C",".","and","Miller","Puckette",".","\u201c","An","efficient","algorithm","for","the","calculation","of","a","constant","Q","transform.","\u201d","(","1992",")",".","Early","downsampling","factor","is","to","downsample","the","input","audio","to","reduce","the","CQT","kernel","size",".","The","result","with","and","without","early","downsampling","are","more","or","less","the","same","except","in","the","very","low","frequency","region","where","freq","<","40Hz",".","Parameters","--","--","--","--","--","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",".","hop_length",":","int","The","hop","(","or","stride",")","size",".","Default","value","is","512.","fmin",":","float","The","frequency","for","the","lowest","CQT","bin",".","Default","is","32.70Hz",",","which","coresponds","to","the","note","C0",".","fmax",":","float","The","frequency","for","the","highest","CQT","bin",".","Default","is","``","None","``",",","therefore","the","higest","CQT","bin","is","inferred","from","the","``","n_bins","``","and","``","bins_per_octave","``",".","If","``","fmax","``","is","not","``","None","``",",","then","the","argument","``","n_bins","``","will","be","ignored","and","``","n_bins","``","will","be","calculated","automatically",".","Default","is","``","None","``","n_bins",":","int","The","total","numbers","of","CQT","bins",".","Default","is","84",".","Will","be","ignored","if","``","fmax","``","is","not","``","None","``",".","bins_per_octave",":","int","Number","of","bins","per","octave",".","Default","is","12.","norm",":","bool","Normalization","for","the","CQT","result",".","basis_norm",":","int","Normalization","for","the","CQT","kernels",".","``","1","``","means","L1","normalization",",","and","``","2","``","means","L2","normalization",".","Default","is","``","1","``",",","which","is","same","as","the","normalization","used","in","librosa",".","window",":","str","The","windowing","function","for","CQT",".","It","uses","``","scipy.signal.get_window","``",",","please","refer","to","scipy","documentation","for","possible","windowing","functions",".","The","default","value","is","'hann'","pad_mode",":","str","The","padding","method",".","Default","value","is","'reflect","'",".","trainable",":","bool","Determine","if","the","CQT","kernels","are","trainable","or","not",".","If","``","True","``",",","the","gradients","for","CQT","kernels","will","also","be","caluclated","and","the","CQT","kernels","will","be","updated","during","model","training",".","Default","value","is","``","False","``","output_format",":","str","Determine","the","return","type",".","'Magnitude","'","will","return","the","magnitude","of","the","STFT","result",",","shape","=","``","(","num_samples",",","freq_bins",",","time_steps",")","``",";","'Complex","'","will","return","the","STFT","result","in","complex","number",",","shape","=","``","(","num_samples",",","freq_bins",",","time_steps",",","2",")","``",";","'Phase","'","will","return","the","phase","of","the","STFT","reuslt",",","shape","=","``","(","num_samples",",","freq_bins",",","time_steps",",","2",")","``",".","The","complex","number","is","stored","as","``","(","real",",","imag",")","``","in","the","last","axis",".","Default","value","is","'Magnitude","'",".","verbose",":","bool","If","``","True","``",",","it","shows","layer","information",".","If","``","False","``",",","it","suppresses","all","prints",".","Returns","--","--","--","-","spectrogram",":","torch.tensor","It","returns","a","tensor","of","spectrograms",".","shape","=","``","(","num_samples",",","freq_bins",",","time_steps",")","``","if","``","output_format='Magnitude","'","``",";","shape","=","``","(","num_samples",",","freq_bins",",","time_steps",",","2",")","``","if","``","output_format='Complex","'","or","'Phase","'","``",";","Examples","--","--","--","--",">",">",">","spec_layer","=","Spectrogram.CQT2010v2","(",")",">",">",">","specs","=","spec_layer","(","x",")"]
docstr: Convert a batch of waveforms to CQT spectrograms.
  
  Parameters
  ----------
  x : torch tensor
      Input signal should be in either of the following shapes.
  
      1. ``(len_audio)``
  
      2. ``(num_audio, len_audio)``
  
      3. ``(num_audio, 1, len_audio)``
      It will be automatically broadcast to the right shape
docstr_tok: ["Convert","a","batch","of","waveforms","to","CQT","spectrograms",".","Parameters","--","--","--","--","--","x",":","torch","tensor","Input","signal","should","be","in","either","of","the","following","shapes",".","1",".","``","(","len_audio",")","``","2",".","``","(","num_audio",",","len_audio",")","``","3",".","``","(","num_audio",",","1",",","len_audio",")","``","It","will","be","automatically","broadcast","to","the","right","shape"]
code: def forward(
      self, x, output_format=None, normalization_type="librosa"
  ):
      """
      Convert a batch of waveforms to CQT spectrograms.
  
      Parameters
      ----------
      x : torch tensor
          Input signal should be in either of the following shapes.\n
          1. ``(len_audio)``\n
          2. ``(num_audio, len_audio)``\n
          3. ``(num_audio, 1, len_audio)``
          It will be automatically broadcast to the right shape
      """
      output_format = output_format or self.output_format
  
      x = broadcast_dim(x)
      if self.earlydownsample == True:
          x = downsampling_by_n(
              x, self.early_downsample_filter, self.downsample_factor
          )
      hop = self.hop_length
      CQT = get_cqt_complex(
          x,
          self.cqt_kernels_real,
          self.cqt_kernels_imag,
          hop,
          self.padding,
      )  # Getting the top octave CQT
  
      x_down = x  # Preparing a new variable for downsampling
  
      for i in range(self.n_octaves - 1):
          hop = hop // 2
          x_down = downsampling_by_2(x_down, self.lowpass_filter)
          CQT1 = get_cqt_complex(
              x_down,
              self.cqt_kernels_real,
              self.cqt_kernels_imag,
              hop,
              self.padding,
          )
          CQT = torch.cat((CQT1, CQT), 1)
  
      CQT = CQT[:, -self.n_bins :, :]  # Removing unwanted bottom bins
      # print("downsample_factor = ",self.downsample_factor)
      # print(CQT.shape)
      # print(self.lenghts.view(-1,1).shape)
  
      # Normalizing the output with the downsampling factor, 2**(self.n_octaves-1) is make it
      # same mag as 1992
      CQT = CQT * self.downsample_factor
      # Normalize again to get same result as librosa
      if normalization_type == "librosa":
          CQT = CQT * torch.sqrt(self.lenghts.view(-1, 1, 1))
      elif normalization_type == "convolutional":
          pass
      elif normalization_type == "wrap":
          CQT *= 2
      else:
          raise ValueError(
              "The normalization_type %r is not part of our current options."
              % normalization_type
          )
  
      if output_format == "Magnitude":
          if self.trainable == False:
              # Getting CQT Amplitude
              return torch.sqrt(CQT.pow(2).sum(-1))
          else:
              return torch.sqrt(CQT.pow(2).sum(-1) + 1e-8)
  
      elif output_format == "Complex":
          return CQT
  
      elif output_format == "Phase":
          phase_real = torch.cos(
              torch.atan2(CQT[:, :, :, 1], CQT[:, :, :, 0])
          )
          phase_imag = torch.sin(
              torch.atan2(CQT[:, :, :, 1], CQT[:, :, :, 0])
          )
          return torch.stack((phase_real, phase_imag), -1)
  
imports: import torch.nn
  import torch
  import numpy
  from time import time
  from ..utils import *
  from ..utils import *
label_desc: Use image node_id 2 for calling the CQT2010v2 obj's underlying member method code with example usage: obj.forward(x, output_format, normalization_type) and returns: torch, torch, CQT, torch