ó
    â“,jõ  ã            	       ó,  • S r SSKrSSKrSSKrSSKJr  S\R                  4S jr	SS\R                  S\
S\S	\4S
 jjrS\R                  4S jrS\R                  4S jrS\
S\S\4S jrSS\R                  4S jjrSS\S\S\4S jjrS\
S\
4S jrg)z1
Signal processing or PyTorch related utilities.
é    N)Ú
functionalÚxc           	      ó¶   • [         R                  " U S:H  [         R                  " SU R                  U R                  S9[         R
                  " U 5      U -  5      $ )z\
Implementation of sinc, i.e. sin(x) / x

__Warning__: the input is not multiplied by `pi`!
r   g      ð?)ÚdeviceÚdtype)ÚtorchÚwhereÚtensorr   r   Úsin)r   s    Ú™C:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\julius/core.pyÚsincr      sC   € ô �;Š;�q˜A‘vœuŸ|š|¨B°q·x±xÀqÇwÁwÑOÔQV×QZÒQZÐ[\ÓQ]Ð`aÑQaÓbÐbó    r
   Útarget_lengthÚmodeÚvaluec                 óP   • [         R                  " U SXR                  S   -
  4X#S9$ )zA
Pad the given tensor to the given length, with 0s on the right.
r   éÿÿÿÿ)r   r   )ÚFÚpadÚshape)r
   r   r   r   s       r   Úpad_tor      s(   € ô �5Š5�˜!˜]¯\©\¸"Ñ-=Ñ=Ð>ÀTÑWÐWr   Úfreqsc                 ó@   • S[         R                  " SU S-  -   5      -  $ )z¨
Converts a Tensor of frequencies in hertz to the mel scale.
Uses the simple formula by O'Shaughnessy (1987).

Args:
    freqs (torch.Tensor): frequencies to convert.

é#
  é   é¼  )r   Úlog10)r   s    r   Ú	hz_to_melr      s    € ð ”%—+’+˜a %¨#¡+™oÓ.Ñ.Ð.r   Úmelsc                 ó   • SSU S-  -  S-
  -  $ )z¤
Converts a Tensor of mel scaled frequencies to Hertz.
Uses the simple formula by O'Shaughnessy (1987).

Args:
    mels (torch.Tensor): mel frequencies to convert.
r   é
   r   r   © )r   s    r   Ú	mel_to_hzr#   )   s   € ð �"�t˜d‘{Ñ# aÑ'Ñ(Ð(r   Ún_melsÚfminÚfmaxc                 ó  • [        [        R                  " [        U5      5      5      R	                  5       n[        [        R                  " [        U5      5      5      R	                  5       n[        R
                  " X4U 5      n[        U5      $ )zÞ
Return frequencies that are evenly spaced in mel scale.

Args:
    n_mels (int): number of frequencies to return.
    fmin (float): start from this frequency (in Hz).
    fmax (float): finish at this frequency (in Hz).


)r   r   r
   ÚfloatÚitemÚlinspacer#   )r$   r%   r&   ÚlowÚhighr   s         r   Úmel_frequenciesr-   4   s^   € ô ”E—L’L¤ t£Ó-Ó
.×
3Ñ
3Ó
5€CÜ”U—\’\¤%¨£+Ó.Ó/×4Ñ4Ó6€DÜ�>Š>˜# VÓ,€DÜ�T‹?Ðr   c                 ó\   • [         R                  " XS-  R                  S5      -   5      S-  $ )z
Return the volume in dBFS.
é   r   r!   )r   r   Úmean)r   Úfloors     r   Úvolumer2   E   s'   € ô �;Š;�u 1¡Ÿ{™{¨2›Ñ.Ó/°"Ñ4Ð4r   ÚfreqÚsrÚdurc                 ó¾   • [         R                  " [        X-  5      US9R                  5       U-  n[         R                  " S[
        R                  -  U -  U-  5      $ )z˜
Return a pure tone, i.e. cosine.

Args:
    freq (float): frequency (in Hz)
    sr (float): sample rate (in Hz)
    dur (float): duration (in seconds)
)r   r/   )r   ÚarangeÚintr(   ÚcosÚmathÚpi)r3   r4   r5   r   Útimes        r   Ú	pure_toner=   L   sI   € ô �<Š<œ˜B™H›¨fÑ5×;Ñ;Ó=ÀÑB€DÜ�9Š9�QœŸ™‘[ 4Ñ'¨$Ñ.Ó/Ð/r   Úkernel_sizeÚstridec                 óþ  • [        U R                  5      nUR                  S5      n[        R                  " [        XA5      U-
  U-  5      S-   nUS-
  U-  U-   n[        R                  " U SXd-
  45      R                  5       n/ n[        UR                  5       5       H#  n	UR                  UR                  U	5      5        M%     UR                  S5      n
U
S:X  d   S5       eX‚S/-   nUR                  X5U/-   U5      $ )a  1D only unfolding similar to the one from PyTorch.
However PyTorch unfold is extremely slow.

Given an input tensor of size `[*, T]` this will return
a tensor `[*, F, K]` with `K` the kernel size, and `F` the number
of frames. The i-th frame is a view onto `i * stride: i * stride + kernel_size`.
This will automatically pad the input to cover at least once all entries in `input`.

Args:
    input (Tensor): tensor for which to return the frames.
    kernel_size (int): size of each frame.
    stride (int): stride between each frame.

Shape:

    - Inputs: `input` is `[*, T]`
    - Output: `[*, F, kernel_size]` with `F = 1 + ceil((T - kernel_size) / stride)`


..Warning:: unlike PyTorch unfold, this will pad the input
    so that any position in `input` is covered by at least one frame.
r   r   r   zdata should be contiguous)Úlistr   Úpopr:   ÚceilÚmaxr   r   Ú
contiguousÚrangeÚdimÚappendr?   Ú
as_strided)Úinputr>   r?   r   ÚlengthÚn_framesÚ
tgt_lengthÚpaddedÚstridesrG   Úlast_strides              r   ÚunfoldrQ   Y   sì   € ô. �—‘Ó€EØ�Y‰Y�r‹]€FÜ�yŠyœ#˜fÓ2°[Ñ@ÀFÑJÓKÈaÑO€HØ˜Q‘, &Ñ(¨;Ñ6€JÜ�UŠU�5˜1˜jÑ1Ð2Ó3×>Ñ>Ó@€FØ€GÜ�V—Z‘Z“\Ö"ˆØ�‰�v—}‘} SÓ)Ö*ñ #à—+‘+˜b“/€KØ˜!ÓÐ8Ð8Ó8ÐØ ˜Ñ#€GØ×Ñ˜U°Ð%<Ñ<¸gÓFÐFr   )Úconstantr   )g:Œ0âŽyE>)é€   é   N)Ú__doc__r:   ÚtypingÚtpr   Útorch.nnr   r   ÚTensorr   r8   Ústrr(   r   r   r#   r-   r2   r=   rQ   r"   r   r   Ú<module>r[      sÏ   ðñó Û ã Ý $ðcˆE�L‰Lô cñX�5—<‘<ð X°ð X¸3ð XÐTYõ Xð	/�U—\‘\ô 	/ð)�E—L‘Lô )ð˜Cð  uð °Eô ñ"5ˆe�l‰lõ 5ñ
0�Eð 
0˜uð 
0°õ 
0ð"G˜sð "G¨Cõ "Gr   