
    Vh                         d Z ddlmZmZ ddlZddlmZ ddlmZ ddl	m
Z
  G d d	ej        j                  Z	 	 	 ddej        dedee         deee                  dededee         fdZdS )zH
Decomposition of a signal over frequency bands in the waveform domain.
    )OptionalSequenceN   )mel_frequencies)LowPassFilters)simple_reprc                        e Zd ZdZ	 	 	 ddedee         deee                  ded	ed
ee         f fdZ	d Z
ed             Zd Z xZS )
SplitBandsa  
    Decomposes a signal over the given frequency bands in the waveform domain using
    a cascade of low pass filters as implemented by `julius.lowpass.LowPassFilters`.
    You can either specify explicitely the frequency cutoffs, or just the number of bands,
    in which case the frequency cutoffs will be spread out evenly in mel scale.

    Args:
        sample_rate (float): Sample rate of the input signal in Hz.
        n_bands (int or None): number of bands, when not giving them explictely with `cutoffs`.
            In that case, the cutoff frequencies will be evenly spaced in mel-space.
        cutoffs (list[float] or None): list of frequency cutoffs in Hz.
        pad (bool): if True, appropriately pad the input with zero over the edge. If `stride=1`,
            the output will have the same length as the input.
        zeros (float): Number of zero crossings to keep. See `LowPassFilters` for more informations.
        fft (bool or None): See `LowPassFilters` for more info.

    ..note::
        The sum of all the bands will always be the input signal.

    ..warning::
        Unlike `julius.lowpass.LowPassFilters`, the cutoffs frequencies must be provided in Hz along
        with the sample rate.

    Shape:

        - Input: `[*, T]`
        - Output: `[B, *, T']`, with `T'=T` if `pad` is True.
            If `n_bands` was provided, `B = n_bands` otherwise `B = len(cutoffs) + 1`

    >>> bands = SplitBands(sample_rate=128, n_bands=10)
    >>> x = torch.randn(6, 4, 1024)
    >>> list(bands(x).shape)
    [10, 6, 4, 1024]
    NT   sample_raten_bandscutoffspadzerosfftc                 Z   t                                                       |d u |d u z   dk    rt          d          | _        || _        |t          |          nd | _        || _        || _        || _	        |J|t          d          |dk    st          d| d          t          |dz   ddz            dd         }n%t          |          d	z  k    rt          d
          t          |          dk    r&t          fd|D             |||          | _        d S d | _        d S )Nr   z;You must provide either n_bands, or cutoffs, but not boths.z+You must provide one of n_bands or cutoffs.z&n_bands must be greater than one (got )r      g      ?z1A cutoff above sample_rate/2 does not make sense.c                     g | ]}|z  S  r   ).0cr   s     R/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/julius/bands.py
<listcomp>z'SplitBands.__init__.<locals>.<listcomp>K   s    222Q[222    )r   r   r   )super__init__
ValueErrorr   r   list_cutoffsr   r   r   r   maxlenr   lowpass)selfr   r   r   r   r   r   	__class__s    `     r   r   zSplitBands.__init__2   sZ    	tO40A55Z[[[&)0)<W$
? !NOOOa<< !T'!T!T!TUUU%gk1kAoFFqtLGG7||cK/// !TUUUw<<!)2222'2225cS S SDLLL
  DLLLr   c                 
   | j         |d          S |                      |          }|d         }|g}|dd          D ]}||z
  }|                    |           |}|                    ||z
             t          j        |          S )Nr   r   )r$   appendtorchstack)r%   inputlowslowbandslow_and_bandbands          r   forwardzSplitBands.forwardQ   s    <;||E""1g H 	 	L#%DLLCCUS[!!!{5!!!r   c                 b      j          j         S  j         fd j        j        D             S g S )Nc                 $    g | ]}|j         z  S r   )r   )r   r   r%   s     r   r   z&SplitBands.cutoffs.<locals>.<listcomp>e   s!    GGGQA((GGGr   )r!   r$   r   r%   s   `r   r   zSplitBands.cutoffs`   s?    =$= \%GGGG$,2FGGGGIr   c                 2    t          | d| j        i          S )Nr   )	overrides)r   r!   r4   s    r   __repr__zSplitBands.__repr__i   s    4It}+EFFFFr   NNTr   N)__name__
__module____qualname____doc__floatr   intr   boolr   r1   propertyr   r7   __classcell__)r&   s   @r   r
   r
      s        ! !F EIHL9=   E  HSM  "8E?3 AE  (0           >" " "   XG G G G G G Gr   r
   Tr   signalr   r   r   r   r   r   c           	      b     t          ||||||                              |           |           S )z
    Functional version of `SplitBands`, refer to this class for more information.

    >>> x = torch.randn(6, 4, 1024)
    >>> list(split_bands(x, sample_rate=64, cutoffs=[12, 24]).shape)
    [3, 6, 4, 1024]
    )r
   to)rB   r   r   r   r   r   r   s          r   split_bandsrE   m   s6     Q:k7GS%EEHHPPQWXXXr   r8   )r<   typingr   r   r)   corer   r$   r   utilsr   nnModuler
   Tensorr=   r>   r?   rE   r   r   r   <module>rL      s-    & % % % % % % %  ! ! ! ! ! ! # # # # # #      \G \G \G \G \G \G \G \G~ TXGK8<
Y 
Y 
Y5 
Y8C= 
Y!(5/2
Y@D
Y
Y'/~
Y 
Y 
Y 
Y 
Y 
Yr   