
    tKg                         d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	 dZ
dZ G d d	e      Z G d
 de      Zd Z G d de	      Zy)zBUses standard-library modules to read AIFF, AIFF-C, and WAV files.    N   )DecodeError)	AudioFile   )r   r         c                       e Zd ZdZy)UnsupportedErrorz%File is not an AIFF, WAV, or Au file.N__name__
__module____qualname____doc__     U/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/audioread/rawread.pyr
   r
       s    /r   r
   c                       e Zd ZdZy)BitWidthErrorz'The file uses an unsupported bit width.Nr   r   r   r   r   r   $   s    1r   r   c                 
   t        |       dz  dk(  sJ g }t        dt        |       d      D ]E  }| ||dz    }t        j                  dgt        j                  d|       }|j                  |       G dj                  |      S )zSwaps the endianness of the bytestring s, which must be an array
    of shorts (16-bit signed integers). This is probably less efficient
    than it should be.
    r   r   z<hz>hr   )lenrangestructpackunpackappendjoin)spartsichunknewchunks        r   byteswapr"   (   s}    
 q6A:??E1c!fa !AE
;;tAfmmD%&@AX ! 88E?r   c                   l    e Zd ZdZd Zd Zd Zed        Zed        Z	ed        Z
ddZd	 Zd
 Zd Zy)RawAudioFilez|An AIFF, WAV, or Au file that can be read by the Python standard
    library modules ``wave``, ``aifc``, and ``sunau``.
    c                    t        |d      | _        	 t        j                   | j                        | _        d| _        | j                          y # t        j                  $ r | j                  j                  d       Y nw xY w	 t        j                   | j                        | _        d| _        | j                          y # t        j                  $ r | j                  j                  d       Y nw xY w	 t        j                   | j                        | _        d| _        | j                          y # t        j                  $ r | j                  j                  d       Y nw xY w| j                  j                          t               )NrbTr   F)open_fhaifc_file_needs_byteswap_checkErrorseekwavesunaucloser
   )selffilenames     r   __init__zRawAudioFile.__init__:   s+   $'	488,DJ
 $(D KKM zz 	HHMM!		488,DJ
 $)D KKM zz 	HHMM!		DHH-DJ
 $(D KKM {{ 	HHMM!	 	  s5   $A .B ?B $C   .C10C15$D1 1.E"!E"c                 x    | j                   j                         t        vr| j                          t	               y)zeCheck that the files' parameters allow us to decode it and
        raise an error otherwise.
        N)r*   getsampwidthSUPPORTED_WIDTHSr1   r   r2   s    r   r,   zRawAudioFile._check_   s0     ::""$,<<JJL/! =r   c                 l    | j                   j                          | j                  j                          y)zClose the underlying file.N)r*   r1   r(   r8   s    r   r1   zRawAudioFile.closeg   s     

r   c                 6    | j                   j                         S )zNumber of audio channels.)r*   getnchannelsr8   s    r   channelszRawAudioFile.channelsl        zz&&((r   c                 6    | j                   j                         S )zSample rate in Hz.)r*   getframerater8   s    r   
sampleratezRawAudioFile.samplerateq   r=   r   c                 b    t        | j                  j                               | j                  z  S )z)Length of the audio in seconds (a float).)floatr*   
getnframesr@   r8   s    r   durationzRawAudioFile.durationv   s%     TZZ**,-??r   c              #   $  K   | j                   j                         }	 | j                   j                  |      }|syt        j                  ||t
              }| j                  r(| j                   j                         dk7  rt        |      }| rw)z/Generates blocks of PCM data found in the file.sowtN)	r*   r6   
readframesaudiooplin2linTARGET_WIDTHr+   getcomptyper"   )r2   block_samples	old_widthdatas       r   	read_datazRawAudioFile.read_data{   sy     JJ++-	::((7D ??4LAD##

(>(>(@F(J~J s   BBc                     | S Nr   r8   s    r   	__enter__zRawAudioFile.__enter__   s    r   c                 $    | j                          y)NF)r1   )r2   exc_typeexc_valexc_tbs       r   __exit__zRawAudioFile.__exit__   s    

r   c                 "    | j                         S rQ   )rO   r8   s    r   __iter__zRawAudioFile.__iter__   s    ~~r   N)i   )r   r   r   r   r4   r,   r1   propertyr<   r@   rD   rO   rR   rW   rY   r   r   r   r$   r$   6   si    #!J"
 ) ) ) ) @ @"
 r   r$   )r   r)   rH   r   r0   r/   
exceptionsr   baser   rJ   r7   r
   r   r"   r$   r   r   r   <module>r]      sZ    I      #     0{ 02K 2_ 9 _ r   