
    0;ji                     >   d dl Zd dlmZ ddlmZ ddlmZmZmZm	Z	m
Z
 ddlmZ  ej                    ZdZdZd	ez  Zd
ZdZe
e
de
de
e	e	de	de	eededeeededeeededeiZd Zd Z G d d          Zd!dedededej        fdZd!dej        dededej        fd ZdS )"    N)	ArrayLike   )soxr_ext)QQLQMQHQVHQ)versioni   zJInput should be a `np.ndarray` with matching dtype for ResampleStream({}).z2Channel num({}) out of limit. Should be in [1, %d]zAData type must be one of [float32, float64, int16, int32], not {}z,Quality must be one of [QQ, LQ, MQ, HQ, VHQ]vhqsoxr_vhqhqsoxr_hqmqsoxr_mqlqsoxr_lqqqsoxr_qqc                     t          | t                    r|                                 } 	 t          |          S # t          t
          f$ r t          t                    w xY wN)
isinstancestrlower_QUALITY_ENUM_DICTKeyError	TypeError
ValueError_QUALITY_ERR_STR)qs    G/root/voice-cloning/.venv/lib/python3.11/site-packages/soxr/__init__.py_quality_to_enumr"   &   s`    !S GGII+!!$$i  + + +)***+s	   8 &Ac                 0   | t           j        k    rt          j        S | t           j        k    rt          j        S | t           j        k    rt          j        S | t           j        k    rt          j	        S t          t                              |                     r   )npfloat32r   SOXR_FLOAT32_Ifloat64SOXR_FLOAT64_Iint32SOXR_INT32_Iint16SOXR_INT16_Ir   _DTYPE_ERR_STRformat)ntypes    r!   _to_soxr_datatyper0   0   sv    
&&	"*		&&	"(		$$	"(		$$--e44555    c                   p    e Zd ZdZ	 ddededefdZdd	ej        d
ej        fdZ	d
efdZ
d
efdZddZdS )ResampleStreama?   Streaming resampler

        Use `ResampleStream` for real-time processing or very long signal.

        Parameters
        ----------
        in_rate : float
            Input sample-rate.
        out_rate : float
            Output sample-rate.
        num_channels : int
            Number of channels.
        dtype : type or str, optional
            Internal data type processed with.
            Should be one of float32, float64, int16, int32.
        quality : int or str, optional
            Quality setting.
            One of `QQ`, `LQ`, `MQ`, `HQ`, `VHQ`.
    r%   r	   in_rateout_ratenum_channelsc                    |dk    s|dk    rt          d          |dk     st          |k     r't          t                              |                    t	          j        |          | _        t          | j                  }t          |          }t          j
        |||||          | _        t          | j        d| j                   | _        d S )Nr   Sample rate should be over 0r   process_)r   	_CH_LIMIT_CH_EXEED_ERR_STRr.   r$   dtype_typer0   r"   r   CSoxr_csoxrgetattr_process)selfr4   r5   r6   r<   qualitystyper    s           r!   __init__zResampleStream.__init__R   s     a<<8q==;<<<!y<77.55lCCDDDXe__
!$*--W%%nWheQOO-D
-D-DEEr1   Fxreturnc                    t          |          t          j        k    s|j        | j        k    r,t          t                              | j                            |j        dk    r@| 	                    |ddt          j
        f         |          }t          j        |d          S |j        dk    r| 	                    ||          S t          d          )a/   Resample chunk with streaming resampler

        Parameters
        ----------
        x : np.ndarray
            Input array. Input can be mono(1D) or multi-channel(2D of [frame, channel]).
            dtype should match with constructor.

        last : bool, optional
            Set True at final chunk to flush last outputs.
            It should be `True` only once at the end of a continuous sequence.

        Returns
        -------
        np.ndarray
            Resampled data.
            Output is np.ndarray with same ndim with input.

        r   Naxis   Input must be 1-D or 2-D array)typer$   ndarrayr<   r=   r   _DTYPE_UNMATCH_ERR_STRr.   ndimrA   newaxissqueezer   )rB   rF   lastys       r!   resample_chunkzResampleStream.resample_chunkc   s    ( 77bj  AGtz$9$9299$*EEFFF6Q;;a2:.55A:aa((((Vq[[==D)))=>>>r1   c                 4    | j                                         S )zx Clip counter. (for int I/O)

        Returns
        -------
        int
            Count of clipped samples.
        )r?   	num_clipsrB   s    r!   rW   zResampleStream.num_clips   s     {$$&&&r1   c                 4    | j                                         S )z Get current delay.

        SoXR output has an algorithmic delay. This function returns the length of current pending output.

        Returns
        -------
        float
            Current delay in output samples.
        )r?   delayrX   s    r!   rZ   zResampleStream.delay   s     {  """r1   Nc                 8    | j                                          dS )zv Reset resampler. Ready for fresh signal, same config.

        This can be used to save initialization time.
        N)r?   clearrX   s    r!   r\   zResampleStream.clear   s    
 	r1   )r%   r	   )F)rG   N)__name__
__module____qualname____doc__floatintrE   r$   rN   rU   rW   rZ   r\    r1   r!   r3   r3   =   s         , +/F FF+0F@CF F F F"? ?
 ?2: ? ? ? ?>'3 ' ' ' '
#u 
# 
# 
# 
#     r1   r3   r	   rF   r4   r5   rG   c                 J   |dk    s|dk    rt          d          t          |           t          j        k    r t          j        | t          j                  } 	 | j        d         | j        k    rt          t          d| j
                   }nt          t          d| j
                   }n:# t          $ r- t          t                              | j
                            w xY wt          |          }| j        dk    r8 |||| ddt          j        f         |          }t          j        |d          S | j        d	k    rS| j        d         }|dk     st(          |k     r't          t*                              |                     |||| |          S t          d
          )a   Resample signal

    Parameters
    ----------
    x : array_like
        Input array. Input can be mono(1D) or multi-channel(2D of [frame, channel]).
        If input is not `np.ndarray`, it will be converted to `np.ndarray(dtype='float32')`.
        Its dtype should be one of float32, float64, int16, int32.
    in_rate : float
        Input sample-rate.
    out_rate : float
        Output sample-rate.
    quality : int or str, optional
        Quality setting.
        One of `QQ`, `LQ`, `MQ`, `HQ`, `VHQ`.

    Returns
    -------
    np.ndarray
        Resampled data.
        Output is `np.ndarray` with same ndim and dtype with input.
    r   r8   )r<   csoxr_split_ch_csoxr_divide_proc_r   NrI   rK   rL   )r   rM   r$   rN   asarrayr%   stridesitemsizer@   r   r<   AttributeErrorr   r-   r.   r"   rP   rQ   rR   shaper:   r;   )rF   r4   r5   rC   divide_procr    rT   r6   s           r!   resamplerm      s   . !||x1}}7888Aww"*Jq
+++89Q<1:%%!(,Gag,G,GHHKK!(,J,J,JKKK 8 8 8--ag667778 	!!Av{{K1QQQ
]+;Q??z!!$$$$	
1wqz!y<77.55lCCDDD{7Ha3339:::s   AB, ,7C#c                    	 t          t          d| j                   }n:# t          $ r- t	          t
                              | j                            w xY w| j        dk    rE |||| ddt          j	        f         t          |                    }t          j        |d          S  |||| t          |                    S )z
    Resample using libsoxr's `soxr_oneshot()`. Use `resample()` for general use.
    `soxr_oneshot()` becomes slow with long input.
    This function exists for test purpose.
    csoxr_oneshot_r   NrI   )r@   r   r<   rj   r   r-   r.   rP   r$   rQ   r"   rR   )rF   r4   r5   rC   oneshotrT   s         r!   _resample_oneshotrq      s    8($>QW$>$>?? 8 8 8--ag667778 	v{{GGXqBJ'79I'9R9RSSz!!$$$$77Ha)9')B)BCCCs	     7A)r	   )numpyr$   numpy.typingr    r   r   r   r   r	   r
   _versionr   __version__libsoxr_version__libsoxr_version__r:   rO   r;   r-   r   r   r"   r0   r3   ra   rN   rm   rq   rc   r1   r!   <module>ry      s       " " " " " "       ) ) ) ) ) ) ) ) ) ) ) ) ) ) , , , , , , /h.00  	e H9T TA  eS*cD"iD"iD"iD"i + + +
6 
6 
6` ` ` ` ` ` ` `F1; 1;	 1;E 1;U 1;RZ 1; 1; 1; 1;hD D De Du DWYWa D D D D D Dr1   