o
    ´‹
jD	  ã                   @   s,   d dl Z d dlmZ G dd„ de jjƒZdS )é    N)Ú
functionalc                       s<   e Zd ZdZ										d‡ fd
d„	Zdd„ Z‡  ZS )ÚResidualBlockz!Residual block module in WaveNet.é   é@   é€   éP   ç        é   TFc
                    sÈ   t ƒ  ¡  || _|	r|d | }
n|d d dksJ dƒ‚|d d | }
|	| _tjj||||
||d| _|dkrEtjj||ddd| _nd | _|d }tjj||d|d| _	tjj||d|d| _
d S )Nr	   é   r   z$Not support even number kernel size.)ÚpaddingÚdilationÚbiasF)r   )ÚsuperÚ__init__ÚdropoutÚuse_causal_convÚtorchÚnnÚConv1dÚconvÚconv1x1_auxÚconv1x1_outÚconv1x1_skip)ÚselfÚkernel_sizeÚres_channelsÚgate_channelsÚskip_channelsÚaux_channelsr   r   r   r   r   Úgate_out_channels©Ú	__class__© úV/home/kuhnn/.local/lib/python3.10/site-packages/TTS/vocoder/layers/parallel_wavegan.pyr      s    
ÿzResidualBlock.__init__c           
      C   sò   |}t j|| j| jd}|  |¡}| jr$|dd…dd…d| d¡…f n|}d}|j| |¡d |d\}}|dur]| jdusAJ ‚|  |¡}|j| |¡d |d\}}|| || }}t 	|¡t 
|¡ }|  |¡}	|  |¡| d }||	fS )z;
        x: B x D_res x T
        c: B x D_aux x T
        )ÚpÚtrainingNéÿÿÿÿr	   r
   )Údimg      Ð?)ÚFr   r%   r   r   ÚsizeÚsplitr   r   ÚtanhÚsigmoidr   r   )
r   ÚxÚcÚresidualÚsplitdimÚxaÚxbÚcaÚcbÚsr"   r"   r#   Úforward.   s   
*

zResidualBlock.forward)	r   r   r   r   r   r   r	   TF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r6   Ú__classcell__r"   r"   r    r#   r      s    ö&r   )r   Útorch.nnr   r(   r   ÚModuler   r"   r"   r"   r#   Ú<module>   s    