
    h,                        S SK r S SKrS SKrS SKJrJrJrJr  S SKrS SK	r	SSK
Jr  SSKJr  \\\\ R                  4   r S'S\S\\   S\S	\4S
 jjr   S(S\S\S\S	\\   4S jjr  S)SSS\\   S\S	\R*                  4S jjr      S*S\S\S\S\S\S\\   S\S	\\R*                  \4   4S jjrS\R0                  S	\4S jrS	\4S jrS\S\S	\4S jrS rS\\   S\\   S\\   S\\   4S jr      S+S\S\R*                  S \S\S\\   S\\   S\\   S\S!\\	R<                  R>                     S	S4S" jjr S\S	\4S# jr!S\S\S	\4S$ jr" " S% S&\5      r#g),    N)BinaryIOOptionalTupleUnion   )Backend)AudioMetaDatasrcformatbuffer_sizereturnc                    [         R                  R                  XS U5      nUR                  UR                  5      nUR
                  S:X  a  [        U5      nUR                  S5      nOUR
                  n[        [        UR                  5      UUR                  UR                  UR                  R                  5       5      $ )Nr   r   )
torchaudioioStreamReaderget_src_stream_infodefault_audio_stream
num_frames_load_audiosizer	   intsample_ratenum_channelsbits_per_samplecodecupper)r
   r   r   ssinfowaveformr   s          R/var/www/auris/envauris/lib/python3.13/site-packages/torchaudio/_backend/ffmpeg.py
info_audior!      s    
 	""3kBA!!!"8"89E1q>]]1%
%%
E     frame_offsetr   convertc                 p   U S:  a  [        SR                  U 5      5      eUS:X  d  US:  a  [        SR                  U5      5      eU S:X  a  US:X  a  U(       d  g SnU S:X  a  US:X  a	  U(       a  U$ US:  a  SR                  X U-   5      nOSR                  U 5      nU(       d  U$ SR                  XC5      $ )	Nr   z>Invalid argument: frame_offset must be non-negative. Found: {}zDInvalid argument: num_frames must be -1 or greater than 0. Found: {}zaformat=sample_fmts=fltpz#atrim=start_sample={}:end_sample={}zatrim=start_sample={}z{},{})RuntimeErrorr   )r#   r   r$   aformatatrims        r    _get_load_filterr*   $   s    
 a[bbcopqqQ*r/ahhistuu qZ2-g(GqZ2-'A~5<<\ZdKde'..|<>>%))r"   r   ztorchaudio.io.StreamReaderfilterchannels_firstc                     U R                  SSUS9  U R                  5         U R                  5       S   nUc  [        S5      eUR                  nU(       a  UR
                  $ U$ )Nr&   )filter_descr   zFailed to decode audio.)add_audio_streamprocess_all_packets
pop_chunksr'   _elemT)r   r+   r,   chunkr   s        r    r   r   ?   s`    
 r262LLN1E}455{{H'8::5X5r"   c                    [        U S5      (       a  US:X  a  Sn[        R                  R                  XS U5      n[	        UR                  UR                  5      R                  5      n[        XU5      n	[        XyU5      n
X4$ )Nreadvorbisogg)
hasattrr   r   r   r   r   r   r   r*   r   )r
   r#   r   r$   r,   r   r   r   r   r+   r   s              r    
load_audior:   M   sw     sF( 2""3kBAa++A,B,BCOOPKl@F1n5H  r"   dtypec                 D   [         R                  S[         R                  S[         R                  S[         R                  S[         R
                  S[         R                  S0nUR                  U 5      nUc)  [        SU  S[        UR                  5       5       S	35      eU$ )
Nu8s16s32s64fltdblzNo format found for dtype z; dtype must be one of .)torchuint8int16int32int64float32float64get
ValueErrorlistkeys)r;   dtype_to_formatr   s      r    _get_sample_formatrP   _   s    TUUUuuO   'F~5eW<STXYhYmYmYoTpSqqrsttMr"   c                  .    [         R                  S:X  a  gg)Nlittlelebe)sys	byteorder r"   r    _native_endiannessrX   n   s    
}} r"   encodingr   c                    US;  a  [        SU S35      e[        5       nU (       d  U(       d  SU 3$ US:X  a  gSU U 3$ U S:X  a!  U(       d  S	nUS:X  a  [        S
5      eSU U 3$ U S:X  a  US;   a  g[        S5      eU S:X  a!  U(       d  SnUS;   a  SU U 3$ [        S5      eU S:X  a  US;   a  g[        S5      eU S:X  a  US;   a  g[        S5      e[        SU  S35      e)N>   N             @   zInvalid bits_per_sample z for WAV encoding.pcm_s16r[   pcm_u8pcm_sPCM_Sr\   z4For WAV signed PCM, 8-bit encoding is not supported.PCM_U)Nr[   z7For WAV unsigned PCM, only 8-bit encoding is supported.PCM_Fr^   )r^   r_   pcm_fz?For WAV float PCM, only 32- and 64-bit encodings are supported.ULAW	pcm_mulawz5For WAV PCM mu-law, only 8-bit encoding is supported.ALAWpcm_alawz4For WAV PCM A-law, only 8-bit encoding is supported.zWAV encoding z is not supported.)rL   rX   )rY   r   
endiannesss      r    _get_encoder_for_wavrl   u   s8   773O3DDVWXX#%JZL))a'
|447 OaSTT'
|447i'RSS7 Oh&?+J<88Z[[6i'PQQ6i'OPP
}XJ.@A
BBr"   c                 B    U b  U S:X  a  gU S:X  a  g[        SU  S35      e)Nr\   r>   r]   r?   z8FLAC only supports bits_per_sample values of 16 and 24 (z specified).)rL   )bpss    r    _get_flac_sample_fmtro      s1    
{cRi
by
OPSuT`a
bbr"   extrn   c                   ^ ^ U U4S jnU" S5      (       d  U" S5      (       a  Sn[        X#5      nS nOJU" S5      (       a  SnSnS nO6TnS nS nU" S5      (       a  [        U5      nU" S5      (       a  [        U5      nXVU4$ )Nc                 <   > TU :H  =(       d    TS L =(       a    TU :H  $ NrW   )specrp   r   s    r    _type_parse_save_args.<locals>._type   s!     ~A&D."@SD[Ar"   wavambr7   r8   flac)rl   ro   )rp   r   rY   rn   ru   muxerencoder
sample_fmts   ``      r    _parse_save_argsr}      s    .B
 U||uU|| &x5
	x 

==-c2J<<-c2J:%%r"   urir   compressionc	           	      X   S n	[        U S5      (       a  Uc  [        S5      eOV[        R                  R	                  U 5      n [        U 5      R                  S5      SS  =n
(       a  U
S   R                  5       n	[        XXV5      u  pnU(       a  UR                  n[        R                  R                  XUS9nUR                  UUR                  S5      [        UR                   5      UUUS9  UR#                  5          UR%                  SU5        S S S 5        g ! , (       d  f       g = f)	Nwritez0'format' is required when saving to file object.rC   r   r&   )r   r   )r   r   r{   encoder_formatcodec_configr   )r9   r'   ospathnormpathstrsplitlowerr}   r3   r   r   StreamWriterr/   r   rP   r;   openwrite_audio_chunk)r~   r
   r   r,   r   rY   r   r   r   rp   tokensrz   r{   enc_fmtr   s                  r    
save_audior      s    CsG>QRR  ggs#X^^C(,,6,*""$C.sHVEGee""3+"NAXXb\!#)),    
	As# 
s   ?D
D)c                 F    S H  nX;   d  M
  Us  $    U S:X  a  gU S:X  a  gU $ )N)rc   rd   re   	PCM_MULAWrg   PCM_ALAWri   rW   )rY   dsts     r    _map_encodingr     s3    *?J + ;	Z	Or"   c                     [         R                  " SU 5      =n(       a  [        UR                  S5      5      $ U S;   a  gU$ )NzPCM_\w(\d+)\w*r   )r   r   r[   )researchr   group)rY   r   ms      r    _get_bits_per_sampler     s=    II'22q21771:	.	.r"   c                      \ rS rSr\SS\S\\   S\S\	4S jj5       r
\      SS\S\S	\S
\S\S\\   S\S\\R                  \4   4S jj5       r\      SS\S\R                  S\S\S\\   S\\   S\\   S\S\\\R$                  R&                  \\4      SS4S jj5       r\S\S\\   S\4S j5       r\S\S\\   S\4S j5       rSrg)FFmpegBackendi  r~   r   r   r   c                     [        XU5      n[        UR                  UR                  5      Ul        [	        UR                  5      Ul        U$ rs   )r!   r   rY   r   r   )r~   r   r   metadatas       r    infoFFmpegBackend.info  sA    c;7#78I8I8KcKc#d )(*;*;<r"   Nr#   r   	normalizer,   c                     [        XX#XE5      $ rs   )r:   )r~   r#   r   r   r,   r   r   s          r    loadFFmpegBackend.load  s     #ZN[[r"   r
   r   rY   r   r   c	                     [        U[        R                  R                  [	        S 5      45      (       d  [        SS[	        U5       35      e[        U UUUUUUUU5	        g )NzLFFmpeg backend expects non-`None` value for argument `compression` to be of z=type `torchaudio.io.CodecConfig`, but received value of type )
isinstancer   r   CodecConfigtyperL   r   )	r~   r
   r   r,   r   rY   r   r   r   s	            r    saveFFmpegBackend.save+  sk     +
(A(A4:'NOO^OPTU`PaObc  	
	
r"   c                     gNTrW   r~   r   s     r    
can_decodeFFmpegBackend.can_decodeH      r"   c                     gr   rW   r   s     r    
can_encodeFFmpegBackend.can_encodeL  r   r"   rW      r   r&   TTNr   TNNNr   N)__name__
__module____qualname____firstlineno__staticmethod	InputTyper   r   r   r	   r   boolr   rD   Tensorr   r   r   r   r   floatr   r   r   __static_attributes__rW   r"   r    r   r     s   ) Xc]  P]    # $	\	\	\ 	\ 		\
 	\ 	\ 	\ 
u||S 	!	\ 	\ 
  $ $"&)-NR

\\
 
 	

 
 3-
 "#
 
 eJMM$=$=uc$IJK
 

 
8 	 8C= T   	 8C= T  r"   r   r   )r   r&   Tr   r   r   )$r   r   rU   typingr   r   r   r   rD   r   backendr   commonr	   r   PathLiker   r   r!   r   r*   r   r   r:   r;   rP   rX   rl   ro   r}   r   r   r   r   r   r   rW   r"   r    <module>r      s   	 	 
 3 3    !(C,-	 	SM  	, *** * c]	*: !6#6SM6 6 \\	6   !	!! ! 	!
 ! SM! ! 5<<!$ekk c C #C3 #C #C #CLc8&	#8&SM8& sm8& 
#	8&~   "%)7;#$	#$	#$ #$ 	#$
 SM#$ sm#$ c]#$ #$ *--334#$ 
#$LC C 3   7G 7r"   