
    dj                     Z    d dl Z d dlmZ d dlmZ e j         G d d                      ZdS )    N)alloc_audio_frame)	err_checkc                   "   e Zd ZdZd Zd Zej        dedz  fd            Z	ej        dd	ej
        d
ej        fd            Zej        dd	ej
        d
ej        fd            Zed             Zed             Zed             Zed             ZdS )	AudioFifoz7A simple audio sample FIFO (First In First Out) buffer.c                     	 d| j         j         d| j         d| j         d| j         d| j         dt          |           dd}n1# t          $ r$ d| j         j         dt          |           dd}Y nw xY w|S )	Nz<av. z samples of zhz z at 0xx>z, uninitialized, use fifo.write(frame), at 0x)	__class____name__samplessample_ratelayoutformatidAttributeError)selfresults     H/home/agentuser/manim-venv/lib/python3.11/site-packages/av/audio/fifo.py__repr__zAudioFifo.__repr__
   s    		Wt~. W W W W#W W(,W W6:kW WIKDVW W W F  	 	 	't~. ' 'D&' ' ' FF	
 s   AA +A21A2c                 V    | j         r!t                              | j                    d S d S )N)ptrlibav_audio_fifo_freer   s    r   __dealloc__zAudioFifo.__dealloc__   s2    8 	-""48,,,,,	- 	-    frameNc           	         |t          d          |j        j        sdS | j        s!t                      | _        | j                            |           | j                                         |j        j        rR|j        j	        rF|j        j
        t          |j        j                  z  | _        | xj        |j        j	        z  c_        nd| _        t                              t          j        t          j        |j        j                  |j        j        |j        j        dz            | _        | j        st+          d          n|j        j        | j        j        j        k    sz|j        j	        | j        j        j	        k    s[|j        j        r^| j        j        j        rM|j        j        | j        j        j        k    s|j        j
        | j        j        j
        k    rt-          d          t          j        t0                    }| j        ro|j        j        t          j        k    rUt          j        t0          | j        | j        z            }|j        j        |k    rt-          d|j        j        |fz            t9          t                              | j        t          j        t          j        t          j                 |j        j                   |j        j                             | xj        |j        j        z  c_        dS )a  write(frame)

        Push a frame of samples into the queue.

        :param AudioFrame frame: The frame of samples to push.

        The FIFO will remember the attributes from the first frame, and use those
        to populate all output frames.

        If there is a :attr:`~.Frame.pts` and :attr:`~.Frame.time_base` and
        :attr:`~.AudioFrame.sample_rate`, then the FIFO will assert that the incoming
        timestamps are continuous.

        Nz&AudioFifo must be given an AudioFrame.r      zCould not allocate AVAudioFifo.z*Frame does not match AudioFifo parameters.z4Frame.pts (%d) != expected (%d); fix or set to None.)!	TypeErrorr   
nb_samplesr   template_copy_internal_attributes_init_user_attributes
_time_basenumr   denfloatpts_per_sampler   av_audio_fifo_alloccythoncastAVSampleFormatr   r   nb_channelsRuntimeError
ValueErrordeclareint64_tptsAV_NOPTS_VALUEsamples_writtenr   av_audio_fifo_writepointerp_voidextended_data)r   r   expected_ptss      r   writezAudioFifo.write   s   " =DEEEy# 	Fx %	K .//DMM33E:::M//111 # (	(= (&+&6&:U5CSCW=X=X&X###uy'<<###&'#..C.	0@AA(	$ DH 8 F"#DEEEF
 I 1 888y$(9(EEE $ F M,0 F
 $(DM,D,HHH'+t}/G/KKK IJJJ ~g.. 	59=C4F#F#F!;,t/CC L y},, Jy}l34  
 	##FN6=959;RSS	$ 	
 	
 	
 		 44r   r   Fr   partialc           	      @   | j         sdS t                              | j                   }|dk     rdS |p|}||k     r|r|}ndS t                      }|                    | j                   |                    t          j        t          j	        | j        j         j
                  t          j        t          j        | j        j         j                  |d           t          t                              | j         t          j        t          j        t          j                 |j         j                  |                     | j        r2t          j        t&          | j        | j        z            |j         _        nt          j        |j         _        | xj        |z  c_        |S )a  read(samples=0, partial=False)

        Read samples from the queue.

        :param int samples: The number of samples to pull; 0 gets all.
        :param bool partial: Allow returning less than requested.
        :returns: New :class:`AudioFrame` or ``None`` (if empty).

        If the incoming frames had valid a :attr:`~.Frame.time_base`,
        :attr:`~.AudioFrame.sample_rate` and :attr:`~.Frame.pts`, the returned frames
        will have accurate timing.

        N   )r   r   av_audio_fifo_sizer   r$   r#   _initr,   r-   r.   r   AVChannelLayout	ch_layoutr   av_audio_fifo_readr8   r9   r:   r*   uint64_tsamples_readr4   r5   )r   r   r=   buffered_samplesr   s        r   readzAudioFifo.reado   s{     x 	F'*'='=dh'G'GaF--g%% *-//''666K*DM,=,DEEK+T]->-HII		
 	
 	
 	""FN6=959;RSS 	
 	
 	
  	/"K$-0AA EIMM  .EIMW$r   c                 n    g }	 |                      ||          }||                    |           nn1|S )a  read_many(samples, partial=False)

        Read as many frames as we can.

        :param int samples: How large for the frames to be.
        :param bool partial: If we should return a partial frame.
        :returns: A ``list`` of :class:`AudioFrame`.

        T)r=   )rH   append)r   r   r=   framesr   s        r   	read_manyzAudioFifo.read_many   sM     	IIgwI77E e$$$$	 r   c                 X    | j         st          dt           d          | j        j        S )z'The :class:`.AudioFormat` of this FIFO.'z,.AudioFifo' object has no attribute 'format')r   r   r   r#   r   r   s    r   r   zAudioFifo.format   ;     x 	 JHJJJ   }##r   c                 X    | j         st          dt           d          | j        j        S )z'The :class:`.AudioLayout` of this FIFO.rN   z,.AudioFifo' object has no attribute 'layout')r   r   r   r#   r   r   s    r   r   zAudioFifo.layout   rO   r   c                 X    | j         st          dt           d          | j        j        S )NrN   z1.AudioFifo' object has no attribute 'sample_rate')r   r   r   r#   r   r   s    r   r   zAudioFifo.sample_rate   s9    x 	 OHOOO   }((r   c                 R    | j         rt                              | j                   ndS )z4Number of audio samples (per channel) in the buffer.r   )r   r   r@   r   s    r   r   zAudioFifo.samples   s&     488Bs%%dh///Br   )r   F)F)r   
__module____qualname____doc__r   r   r,   ccall
AudioFramer<   intbintrH   rL   propertyr   r   r   r    r   r   r   r      sP       AA  - - - \Q5:, Q5 Q5 Q5 \Q5f \7 7FJ 7V[ 7 7 7 \7r \  fk    \, $ $ X$ $ $ X$ ) ) X) C C XC C Cr   r   )r,   cython.cimports.av.audio.framer   cython.cimports.av.errorr   cclassr   r[   r   r   <module>r_      s     < < < < < < . . . . . . VC VC VC VC VC VC VC VC VC VCr   