
    ]i                     b   S r SSKrSSKJrJr  SSKrSSKJr  SSK	J
r
  SSKJr  SSKJr   " S	 S
\R                  R                   5      r " S S\R                  R                   5      r  SS\R&                  S\\   S\S\S\S\\   4S jjr  SS\R&                  S\S\S\S\S\\   4S jjrg)z$
FIR windowed sinc lowpass filters.
    N)SequenceOptional)
functional   )sinc)
fft_conv1dsimple_reprc                   d   ^  \ rS rSrSr  SS\\   S\S\S\S\	\   4
U 4S jjjr
S	 rS
 rSrU =r$ )LowPassFilters   a	  
Bank of low pass filters. Note that a high pass or band pass filter can easily
be implemented by substracting a same signal processed with low pass filters with different
frequencies (see `julius.bands.SplitBands` for instance).
This uses a windowed sinc filter, very similar to the one used in
`julius.resample`. However, because we do not change the sample rate here,
this filter can be much more efficiently implemented using the FFT convolution from
`julius.fftconv`.

Args:
    cutoffs (list[float]): list of cutoff frequencies, in [0, 0.5] expressed as `f/f_s` where
        f_s is the samplerate and `f` is the cutoff frequency.
        The upper limit is 0.5, because a signal sampled at `f_s` contains only
        frequencies under `f_s / 2`.
    stride (int): how much to decimate the output. Keep in mind that decimation
        of the output is only acceptable if the cutoff frequency is under `1/ (2 * stride)`
        of the original sampling rate.
    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.
        Controls the receptive field of the Finite Impulse Response filter.
        For lowpass filters with low cutoff frequency, e.g. 40Hz at 44.1kHz,
        it is a bad idea to set this to a high value.
        This is likely appropriate for most use. Lower values
        will result in a faster filter, but with a slower attenuation around the
        cutoff frequency.
    fft (bool or None): if True, uses `julius.fftconv` rather than PyTorch convolutions.
        If False, uses PyTorch convolutions. If None, either one will be chosen automatically
        depending on the effective filter size.


..warning::
    All the filters will use the same filter size, aligned on the lowest
    frequency provided. If you combine a lot of filters with very diverse frequencies, it might
    be more efficient to split them over multiple modules with similar frequencies.

..note::
    A lowpass with a cutoff frequency of 0 is defined as the null function
    by convention here. This allows for a highpass with a cutoff of 0 to
    be equal to identity, as defined in `julius.filters.HighPassFilters`.

Shape:

    - Input: `[*, T]`
    - Output: `[F, *, T']`, with `T'=T` if `pad` is True and `stride` is 1, and
        `F` is the numer of cutoff frequencies.

>>> lowpass = LowPassFilters([1/4])
>>> x = torch.randn(4, 12, 21, 1024)
>>> list(lowpass(x).shape)
[1, 4, 12, 21, 1024]
cutoffsstridepadzerosfftc           
        > [         TU ]  5         [        U5      U l        [	        U R                  5      S:  a  [        S5      e[        U R                  5      S:  a  [        S5      eX l        X0l        X@l	        [        U[	        U R                   Vs/ s H  ofS:  d  M
  UPM     sn5      -  S-  5      U l        Uc  U R                  S:  nXPl        [        R                  " SU R                  -  S-   SS	9n[        R                  " U R                  * U R                  S-   5      n/ n	U Hn  n
U
S:X  a  [        R                   " U5      nO=SU
-  U-  [#        SU
-  [$        R&                  -  U-  5      -  nXR)                  5       -  nU	R+                  U5        Mp     U R-                  S
[        R.                  " U	5      S S 2S 4   5        g s  snf )Nr   z(Minimum cutoff must be larger than zero.g      ?z'A cutoff above 0.5 does not make sense.       r   F)periodicfilters)super__init__listr   min
ValueErrormaxr   r   r   int	half_sizer   torchhann_windowarange
zeros_liker   mathpisumappendregister_bufferstack)selfr   r   r   r   r   cwindowtimer   cutofffilter_	__class__s               K/mnt/rpi/tmp/demucs-venv-sys/lib/python3.13/site-packages/julius/lowpass.pyr   LowPassFilters.__init__H   s   G}t||q GHHt||s"FGG
UST\\)K\U!\)K%LLqPQ;..2%C""1t~~#5#9EJ||T^^OT^^a-?@F{**40f*v-QZ$''5ID5P0QQ ;;=(NN7#  	YG(<QW(EF! *Ls   	G Gc                 4   [        UR                  5      nUR                  SSUS   5      nU R                  (       a+  [        R                  " XR
                  U R
                  4SS9nU R                  (       a  [        XR                  U R                  S9nO)[        R                  " XR                  U R                  S9nUR                  S[        U R                  5      5        UR                  S   US'   UR                  SSS5      R                  U5      $ )Nr   	replicate)mode)r   r   r   )r   shapeviewr   Fr   r   r   r   r   conv1dinsertlenr   permutereshape)r*   inputr7   outs       r1   forwardLowPassFilters.forwarde   s    U[[!

2q%),88EE%..$..!ATE88ULLEC((5,,t{{CCQDLL)*IIbMb	{{1a#++E22    c                     [        U 5      $ Nr	   r*   s    r1   __repr__LowPassFilters.__repr__r       4  rC   )r   r   r   r   r   r   r   T   N)__name__
__module____qualname____firstlineno____doc__r   floatr   boolr   r   rA   rG   __static_attributes____classcell__r0   s   @r1   r   r      s`    3j OS9=G G Gt GG(0G G:3! !rC   r   c                      ^  \ rS rSrSr  SS\S\S\S\S\\   4
U 4S jjjr	\
S	 5       r\
S
 5       r\
S 5       r\
S 5       r\
S 5       rS rS rSrU =r$ )LowPassFilterv   a  
Same as `LowPassFilters` but applies a single low pass filter.

Shape:

    - Input: `[*, T]`
    - Output: `[*, T']`, with `T'=T` if `pad` is True and `stride` is 1.

>>> lowpass = LowPassFilter(1/4, stride=2)
>>> x = torch.randn(4, 124)
>>> list(lowpass(x).shape)
[4, 62]
r.   r   r   r   r   c                 H   > [         TU ]  5         [        U/X#XE5      U l        g rE   )r   r   r   
_lowpasses)r*   r.   r   r   r   r   r0   s         r1   r   LowPassFilter.__init__   s     (&6KrC   c                 4    U R                   R                  S   $ Nr   )rZ   r   rF   s    r1   r.   LowPassFilter.cutoff   s    &&q))rC   c                 .    U R                   R                  $ rE   )rZ   r   rF   s    r1   r   LowPassFilter.stride   s    %%%rC   c                 .    U R                   R                  $ rE   )rZ   r   rF   s    r1   r   LowPassFilter.pad       """rC   c                 .    U R                   R                  $ rE   )rZ   r   rF   s    r1   r   LowPassFilter.zeros   s    $$$rC   c                 .    U R                   R                  $ rE   )rZ   r   rF   s    r1   r   LowPassFilter.fft   rc   rC   c                 *    U R                  U5      S   $ r]   rZ   )r*   r?   s     r1   rA   LowPassFilter.forward   s    u%a((rC   c                     [        U 5      $ rE   r	   rF   s    r1   rG   LowPassFilter.__repr__   rI   rC   ri   rJ   )rL   rM   rN   rO   rP   rQ   r   rR   r   r   propertyr.   r   r   r   r   rA   rG   rS   rT   rU   s   @r1   rW   rW   v   s     DH9=Lu Lc LD LL(0L L
 * * & & # # % % # #)! !rC   rW   r?   r   r   r   r   r   c                 F    [        XX4U5      R                  U 5      " U 5      $ )zS
Functional version of `LowPassFilters`, refer to this class for more information.
)r   to)r?   r   r   r   r   r   s         r1   lowpass_filtersrp      s#     '3s;>>uEeLLrC   r.   c                 $    [        X/X#XE5      S   $ )zw
Same as `lowpass_filters` but with a single cutoff frequency.
Output will not have a dimension inserted in the front.
r   )rp   )r?   r.   r   r   r   r   s         r1   lowpass_filterrr      s     5(FDQGGrC   rJ   )rP   r$   typingr   r   r    torch.nnr   r9   corer   fftconvr   utilsr
   nnModuler   rW   TensorrQ   r   rR   rp   rr    rC   r1   <module>r|      s     %  $   a!UXX__ a!H,!EHHOO ,!` 26<@M5<< M8E? MM*.M M+3D>M 15;?H%,, H HH)-HH*24.HrC   