Ë
      çi×  ã            	       ó  — d Z ddlZddlZddlZddlmZ dej                  fd„Z	ddej                  de
ded	efd
„Zdej                  fd„Zdej                  fd„Zde
dedefd„Zddej                  fd„Zddededefd„Zde
de
fd„Zy)z1
Signal processing or PyTorch related utilities.
é    N)Ú
functionalÚxc                 ó¶   — t        j                  | dk(  t        j                  d| j                  | j                  ¬«      t        j
                  | «      | z  «      S )zh
    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    ú`/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/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                 óX   — t        j                  | d|| j                  d   z
  f||¬«      S )zI
    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�˜!˜]¨V¯\©\¸"Ñ-=Ñ=Ð>ÀTÐQVÔWÐWr   Úfreqsc                 ó>   — dt        j                  d| dz  z   «      z  S )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                 ó   — dd| dz  z  dz
  z  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                 ó  — t        t        j                  t        |«      «      «      j	                  «       }t        t        j                  t        |«      «      «      j	                  «       }t        j
                  ||| «      }t        |«      S )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Ü�>‰>˜#˜t VÓ,€DÜ�T‹?Ðr   c                 ó\   — t        j                  || dz  j                  d«      z   «      dz  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                 óÂ   — t        j                  t        ||z  «      |¬«      j                  «       |z  }t        j                  dt
        j                  z  | z  |z  «      S )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   sK   € ô �<‰<œ˜B ™H›¨fÔ5×;Ñ;Ó=ÀÑB€DÜ�9‰9�QœŸ™‘[ 4Ñ'¨$Ñ.Ó/Ð/r   Úkernel_sizeÚstridec                 óø  — t        | j                  «      }|j                  d«      }t        j                  t        ||«      |z
  |z  «      dz   }|dz
  |z  |z   }t        j                  | d||z
  f«      j                  «       }g }t        |j                  «       «      D ]"  }	|j                  |j                  |	«      «       Œ$ |j                  d«      dk(  sJ d«       ‚||dgz   }|j                  |||gz   |«      S )aV  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   s
             r   ÚunfoldrP   Y   sï   € ô. �—‘Ó€EØ�Y‰Y�r‹]€FÜ�y‰yœ#˜f kÓ2°[Ñ@ÀFÑJÓKÈaÑO€HØ˜Q‘, &Ñ(¨;Ñ6€JÜ�U‰U�5˜1˜j¨6Ñ1Ð2Ó3×>Ñ>Ó@€FØ€GÜ�V—Z‘Z“\Ö"ˆØ�‰�v—}‘} SÓ)Õ*ð #à�;‰;�r‹?˜aÒÐ<Ð!<Ó<ÐØ˜ ˜Ñ#€GØ×Ñ˜U h°Ð%<Ñ<¸gÓFÐFr   )Úconstantr   )g:Œ0âŽyE>)é€   é   N)Ú__doc__r:   ÚtypingÚtpr   Útorch.nnr   r   ÚTensorr   r8   Ústrr(   r   r   r#   r-   r2   r=   rP   r"   r   r   Ú<module>rZ      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   