§
    ïóÉj  ã                   ó>  — d Z ddl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 ddlmZ  G d	„ d
ej        j        ¦  «        Z G d„ dej        j        ¦  «        Z	 	 ddej        dee         dedededee         fd„Z	 	 ddej        dededededee         fd„ZdS )z$
FIR windowed sinc lowpass filters.
é    N)ÚSequenceÚOptional)Ú
functionalé   )Úsinc)Ú
fft_conv1d©Úsimple_reprc                   ób   ‡ — e Zd ZdZ	 	 ddee         deded	ed
ee         f
ˆ fd„Z	d„ Z
d„ Zˆ xZS )ÚLowPassFiltersa­
  
    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]
    r   Té   NÚcutoffsÚstrideÚpadÚzerosÚfftc                 ó¨  •— t          ¦   «                              ¦   «          t          |¦  «        | _        t	          | j        ¦  «        dk     rt          d¦  «        ‚t          | j        ¦  «        dk    rt          d¦  «        ‚|| _        || _        || _	        t          |t	          d„ | j        D ¦   «         ¦  «        z  dz  ¦  «        | _        |€| j        dk    }|| _        t          j        d| j        z  dz   d	¬
¦  «        }t          j        | j         | j        dz   ¦  «        }g }|D ]t}	|	dk    rt          j        |¦  «        }
nBd|	z  |z  t#          d|	z  t$          j        z  |z  ¦  «        z  }
|
|
                     ¦   «         z  }
|                     |
¦  «         Œu|                      dt          j        |¦  «        d d …d f         ¦  «         d S )Nr   z(Minimum cutoff must be larger than zero.g      à?z'A cutoff above 0.5 does not make sense.c                 ó   — g | ]
}|d k    ¯|‘ŒS )r   © )Ú.0Úcs     úq/home/lighthouse/badge-speaker-benchmark/.benchmark-venv-community/lib/python3.11/site-packages/julius/lowpass.pyú
<listcomp>z+LowPassFilters.__init__.<locals>.<listcomp>S   s   € Ð)KÐ)KÐ)K°ÀQÈÂUÀU¨!ÀUÀUÀUó    é   é    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   ÚwindowÚtimer   ÚcutoffÚfilter_Ú	__class__s              €r   r    zLowPassFilters.__init__H   sÀ  ø€ å‰Œ×ÒÑÔÐÝ˜G‘}”}ˆŒÝˆtŒ|ÑÔ˜qÒ Ð ÝÐGÑHÔHÐHÝˆtŒ|ÑÔ˜sÒ"Ð"ÝÐFÑGÔGÐGØˆŒØˆŒØˆŒ
Ý˜U¥SÐ)KÐ)K°T´\Ð)KÑ)KÔ)KÑ%LÔ%LÑLÈqÑPÑQÔQˆŒØˆ;Ø”. 2Ò%ˆCØˆŒÝÔ" 1 t¤~Ñ#5¸Ñ#9ÀEÐJÑJÔJˆÝŒ|˜Tœ^˜O¨T¬^¸aÑ-?Ñ@Ô@ˆØˆØð 	$ð 	$ˆFØ˜Š{ˆ{ÝÔ*¨4Ñ0Ô0��à˜f™* vÑ-µ°Q¸±ZÅ$Ä'Ñ5IÈDÑ5PÑ0QÔ0QÑQ�ð ˜7Ÿ;š;™=œ=Ñ(�Ø�NŠN˜7Ñ#Ô#Ð#Ð#Ø×Ò˜Y­¬°GÑ(<Ô(<¸Q¸Q¸QÀ¸WÔ(EÑFÔFÐFÐFÐFr   c                 ó  — t          |j        ¦  «        }|                     dd|d         ¦  «        }| j        r#t	          j        || j        | j        fd¬¦  «        }| j        rt          || j        | j	        ¬¦  «        }n!t	          j
        || j        | j	        ¬¦  «        }|                     dt          | j        ¦  «        ¦  «         |j        d         |d<   |                     ddd¦  «                             |¦  «        S )Néÿÿÿÿr   Ú	replicate)Úmode)r   r   r   )r!   ÚshapeÚviewr   ÚFr&   r   r   r   r   Úconv1dÚinsertÚlenr   ÚpermuteÚreshape)r1   Úinputr;   Úouts       r   ÚforwardzLowPassFilters.forwarde   sä   € Ý�U”[Ñ!Ô!ˆØ—
’
˜2˜q %¨¤)Ñ,Ô,ˆØŒ8ð 	UÝ”E˜% $¤.°$´.Ð!AÈÐTÑTÔTˆEØŒ8ð 	DÝ˜U D¤L¸¼ÐEÑEÔEˆCˆCå”(˜5 $¤,°t´{ÐCÑCÔCˆCØ�Š�Q�˜DœLÑ)Ô)Ñ*Ô*Ð*Ø”I˜b”Mˆˆb‰	Ø�{Š{˜1˜a Ñ#Ô#×+Ò+¨EÑ2Ô2Ð2r   c                 ó    — t          | ¦  «        S ©Nr	   ©r1   s    r   Ú__repr__zLowPassFilters.__repr__r   ó   € Ý˜4Ñ Ô Ð r   ©r   Tr   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úfloatr%   Úboolr   r    rE   rI   Ú__classcell__©r6   s   @r   r   r      s®   ø€ € € € € ð3ð 3ðj OSØ9=ðGð G ¨¤ð G¸ð GÀtð GØðGØ(0°¬ðGð Gð Gð Gð Gð Gð:3ð 3ð 3ð!ð !ð !ð !ð !ð !ð !r   r   c                   óÄ   ‡ — e Zd ZdZ	 	 ddededed	ed
ee         f
ˆ fd„Ze	d„ ¦   «         Z
e	d„ ¦   «         Ze	d„ ¦   «         Ze	d„ ¦   «         Ze	d„ ¦   «         Zd„ Zd„ Zˆ xZS )ÚLowPassFiltera7  
    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   Tr   Nr4   r   r   r   r   c                 óz   •— t          ¦   «                              ¦   «          t          |g||||¦  «        | _        d S rG   )r   r    r   Ú
_lowpasses)r1   r4   r   r   r   r   r6   s         €r   r    zLowPassFilter.__init__…   s6   ø€ å‰Œ×ÒÑÔÐÝ(¨&¨°6¸3ÀÀsÑKÔKˆŒˆˆr   c                 ó&   — | j         j        d         S ©Nr   )rW   r   rH   s    r   r4   zLowPassFilter.cutoffŠ   s   € àŒÔ& qÔ)Ð)r   c                 ó   — | j         j        S rG   )rW   r   rH   s    r   r   zLowPassFilter.strideŽ   s   € àŒÔ%Ð%r   c                 ó   — | j         j        S rG   )rW   r   rH   s    r   r   zLowPassFilter.pad’   ó   € àŒÔ"Ð"r   c                 ó   — | j         j        S rG   )rW   r   rH   s    r   r   zLowPassFilter.zeros–   s   € àŒÔ$Ð$r   c                 ó   — | j         j        S rG   )rW   r   rH   s    r   r   zLowPassFilter.fftš   r\   r   c                 ó8   — |                       |¦  «        d         S rY   )rW   )r1   rC   s     r   rE   zLowPassFilter.forwardž   s   € Ø�Š˜uÑ%Ô% aÔ(Ð(r   c                 ó    — t          | ¦  «        S rG   r	   rH   s    r   rI   zLowPassFilter.__repr__¡   rJ   r   rK   )rL   rM   rN   rO   rP   r%   rQ   r   r    Úpropertyr4   r   r   r   r   rE   rI   rR   rS   s   @r   rU   rU   v   s0  ø€ € € € € ðð ð DHØ9=ðLð L˜uð L¨cð L¸Dð LØðLØ(0°¬ðLð Lð Lð Lð Lð Lð
 ð*ð *ñ „Xð*ð ð&ð &ñ „Xð&ð ð#ð #ñ „Xð#ð ð%ð %ñ „Xð%ð ð#ð #ñ „Xð#ð)ð )ð )ð!ð !ð !ð !ð !ð !ð !r   rU   Tr   rC   r   r   r   r   r   c                 ó`   —  t          |||||¦  «                             | ¦  «        | ¦  «        S )z[
    Functional version of `LowPassFilters`, refer to this class for more information.
    )r   Úto)rC   r   r   r   r   r   s         r   Úlowpass_filtersrd   ¥   s3   € ð F�>˜' 6¨3°°sÑ;Ô;×>Ò>¸uÑEÔEÀeÑLÔLÐLr   r4   c                 ó8   — t          | |g||||¦  «        d         S )zƒ
    Same as `lowpass_filters` but with a single cutoff frequency.
    Output will not have a dimension inserted in the front.
    r   )rd   )rC   r4   r   r   r   r   s         r   Úlowpass_filterrf   ®   s#   € õ ˜5 6 (¨F°C¸ÀÑDÔDÀQÔGÐGr   rK   )rO   r+   Útypingr   r   r'   Útorch.nnr   r=   Úcorer   Úfftconvr   Úutilsr
   ÚnnÚModuler   rU   ÚTensorrP   r%   rQ   rd   rf   r   r   r   ú<module>ro      s¹  ððð ð €€€Ø %Ð %Ð %Ð %Ð %Ð %Ð %Ð %à €€€Ø $Ð $Ð $Ð $Ð $Ð $à Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð ða!ð a!ð a!ð a!ð a!�U”X”_ñ a!ô a!ð a!ðH,!ð ,!ð ,!ð ,!ð ,!�E”H”Oñ ,!ô ,!ð ,!ð` 26Ø<@ðMð M˜5œ<ð M°8¸E´?ð MØðMØ*.ðMà ðMà+3°D¬>ðMð Mð Mð Mð 15Ø;?ðHð H˜%œ,ð H°ð HØðHØ)-ðHàðHà*2°4¬.ðHð Hð Hð Hð Hð Hr   