
    C1i                         S SK r S SKJr  S SKJr  S SKJr  S SKJr  S SK	J
r
  \" 5       r\ R                  S\4S j5       rS	S	S
S
SSSSSSS.
r\ R"                   " S S\5      5       rg)    N)get_audio_format)get_audio_layout)
AudioPlane)	err_check)check_ndarrayreturnc                       [        [        5      $ N)
AudioFrame_cinit_bypass_sentinel     H/home/james-whalen/.local/lib/python3.13/site-packages/av/audio/frame.pyalloc_audio_framer      s    ,--r   f8f4i2i4u1)
dbldblpfltfltps16s16ps32s32pu8u8pc            	       |   \ rS rSrSrSS jr\R                  S\R                  S\R                  S\R                  S\R                  4S j5       rS	 r\R                  S
 5       rS r\SS j5       r\S 5       r\S 5       r\S 5       r\R,                  S 5       r\S 5       r\R,                  S 5       rS rSrg)r      zA frame of audio.c                     U[         L a  g [        U5      n[        U5      nU R                  UR                  UR
                  X45        g r
   )r   AudioFormatAudioLayout_init
sample_fmtlayout)selfformatr'   samplesalign	cy_format	cy_layouts          r   	__cinit__AudioFrame.__cinit__"   s>    ++!,V!4	!,V!4	

9'')9)97Jr   r)   r'   
nb_samplesr+   c           
         X0R                   l        XR                   l        X R                   l        U R	                  5         U R
                  R                  S:w  Ga{  U(       Gar  [        R                  [        R                  " U R                  5      5        [        [        R                  [        R                  U R
                  R                  X1U5      5      U l        [        R                   " [        R"                  [$           [        R'                  U R                  5      5      U l        U R                  (       d  [)        S5      e[        [        R+                  U R                   U R
                  R                  [        R                   " [        R,                  U R                   R                  5      U R                  U R                  U5      5        g g g )Nr   z!cannot allocate AudioFrame buffer)ptrr0   r)   	ch_layout_init_user_attributesr'   nb_channelslibav_freepcythonaddress_bufferr   av_samples_get_buffer_sizeNULL_buffer_sizecastpointeruint8_t	av_mallocMemoryErroravcodec_fill_audio_frameAVSampleFormat)r(   r)   r'   r0   r+   s        r   r%   AudioFrame._init*   s7    ) # 	""$;;""a'JLL56 !*..KK!8!8*e!D
 ";;w't7H7H)IDL <<!"EFF ,,HHKK++KK 2 2DHHOODLL%%	# -7'r   c                 j    [         R                  [        R                  " U R                  5      5        g r
   )r6   r7   r8   r9   r:   r(   s    r   __dealloc__AudioFrame.__dealloc__U   s    V^^DLL12r   c                     [        U R                  R                  5      U l        [	        [
        R                  " [        R                  U R                  R                  5      5      U l	        g r
   )
r   r2   r3   r'   r   r8   r>   r6   rD   r)   rG   s    r   r4    AudioFrame._init_user_attributesX   s=    &txx'9'9:&v{{33E3Etxx'WXr   c                     SU R                   R                   SU R                   SU R                   SU R                   SU R
                  R                   SU R                  R                   S[        U 5      S S3$ )	Nz<av.z pts=z, z samples at zHz, z at 0xx>)		__class____name__ptsr*   rater'   namer)   idrG   s    r   __repr__AudioFrame.__repr__]   sx    4>>**+5
"T\\N K))D)9)9(:"T[[=M=M<NfUWX\U]^_T``ac	
r   c                    SSK n[        U[        5      (       a  UO
[        U5      n[        U[        5      (       a  UO
[        U5      nUR                  n UR                  [        U   5      nUR                  n[        XS5        UR                  (       aB  U R                  S   U:w  a  [        SU SU R                  S    S35      eU R                  S	   nOAU R                  S   S	:w  a  [        S
U R                  S    S35      eU R                  S	   U-  n[        XEUS9n	[        U	R                  5       H  u  pUR!                  X
SS24   5        M     U	$ ! [         a    [        SU S35      ef = f)z'
Construct a frame from a numpy array.
r   Nz)Conversion from numpy array with format `z` is not yet supported   z+Expected planar `array.shape[0]` to equal `z` but got ``   z7Expected packed `array.shape[0]` to equal `1` but got `)r)   r'   r*   )numpy
isinstancer#   r$   rS   dtypeformat_dtypesKeyError
ValueErrorr5   r   	is_planarshaper   	enumerateplanesupdate)arrayr)   r'   np	py_format	py_layoutr]   r5   r*   frameiplanes               r   from_ndarrayAudioFrame.from_ndarrayc   sp   
 	(==F;vCV	(==F;vCV		HH]623E  ++eA&{{1~, A+kZ_ZeZefgZhYiijk  kk!nG{{1~" MekkZ[nM]]^_  kk!n3G)wO!%,,/HALL!t% 01  	;F8CYZ 	s   E E5c           	          SnU R                   R                  U   (       a%  US-  nU R                   R                  U   (       a  M%  [        [        U5       Vs/ s H  n[	        X5      PM     sn5      $ s  snf )z?
A tuple of :class:`~av.audio.plane.AudioPlane`.

:type: tuple
r   rZ   )r2   extended_datatupleranger   )r(   plane_countrk   s      r   rd   AudioFrame.planes   sg     #$hh$$[11K hh$$[11 53EF3Eaj)3EFGGFs   A4c                 .    U R                   R                  $ )z4
Number of audio samples (per channel).

:type: int
)r2   r0   rG   s    r   r*   AudioFrame.samples   s     xx"""r   c                 .    U R                   R                  $ )zC
Sample rate of the audio data, in samples per second.

:type: int
r2   sample_raterG   s    r   ry   AudioFrame.sample_rate   s     xx###r   c                 $    XR                   l        g r
   rx   r(   values     r   ry   rz          $r   c                 .    U R                   R                  $ )z%Another name for :attr:`sample_rate`.rx   rG   s    r   rR   AudioFrame.rate   s     xx###r   c                 $    XR                   l        g r
   rx   r|   s     r   rR   r      r~   r   c                    SSK n UR                  [        U R                  R                     5      nU R                  R                  (       a  U R                  nO#U R                  U R                  R                  -  nUR                  U R                   Vs/ s H  oAR                  XBUS9PM     sn5      $ ! [
         a%    [        SU R                  R                  < S35      ef = fs  snf )zFGet a numpy array of this frame.

.. note:: Numpy must be installed.

r   NzConversion from z( format to numpy array is not supported.)r]   count)r[   r]   r^   r)   rS   r_   r`   ra   r*   r'   r5   vstackrd   
frombuffer)r(   rg   r]   r   rM   s        r   
to_ndarrayAudioFrame.to_ndarray   s     		HH]4;;+;+;<=E ;;  LLELL4;;#:#::EyyAEMA]]1]7M
 	
  	"4;;#3#3"66^_ 	 Ns   ,B6 C(6/C%)r:   r=   r)   r'   N)r   stereor   rZ   )r   r   )rP   
__module____qualname____firstlineno____doc__r.   r8   cfuncr6   rD   AVChannelLayoutuintr%   rH   r4   rU   staticmethodrm   propertyrd   r*   ry   setterrR   r   __static_attributes__r   r   r   r   r      s    K \\(""( ##( KK	(
 {{( (T3 \\Y Y
 % %N 
H 
H # # $ $ % % $ $ 
[[% %
r   r   )r8   cython.cimports.av.audio.formatr   cython.cimports.av.audio.layoutr   cython.cimports.av.audio.planer   cython.cimports.av.errorr   cython.cimports.av.utilsr   objectr   r   r   r   r^   cclassFramer   r   r   <module>r      s     < < 5 . 2  .: . .
 
 n
 n
 n
r   