o
    zî‚iâ  ã                   @   sˆ   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	„ d	eƒZG d
d„ deƒZdd„ ZG dd„ de	ƒZdS )zBUses standard-library modules to read AIFF, AIFF-C, and WAV files.é    Né   )ÚDecodeError)Ú	AudioFileé   )r   r   é   é   c                   @   ó   e Zd ZdZdS )ÚUnsupportedErrorz%File is not an AIFF, WAV, or Au file.N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   úT/home/ubuntu/maya3_transcribe/venv/lib/python3.10/site-packages/audioread/rawread.pyr	       ó    r	   c                   @   r   )ÚBitWidthErrorz'The file uses an unsupported bit width.Nr
   r   r   r   r   r   $   r   r   c                 C   sl   t | ƒd dks
J ‚g }tdt | ƒdƒD ]}| ||d … }tjdgt d|¡¢R Ž }| |¡ qd |¡S )z¤Swaps 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>hó    )ÚlenÚrangeÚstructÚpackÚunpackÚappendÚjoin)ÚsÚpartsÚiÚchunkÚnewchunkr   r   r   Úbyteswap(   s   
r    c                   @   sn   e Zd ZdZdd„ Zdd„ Zdd„ Zedd	„ ƒZed
d„ ƒZ	edd„ ƒZ
ddd„Zdd„ Zdd„ Zdd„ ZdS )ÚRawAudioFilez|An AIFF, WAV, or Au file that can be read by the Python standard
    library modules ``wave``, ``aifc``, and ``sunau``.
    c                 C   sî   t |dƒ| _z	t  | j¡| _W n tjy   | j d¡ Y n
w d| _|  ¡  d S z	t  | j¡| _W n tjyB   | j d¡ Y n
w d| _|  ¡  d S z	t	  | j¡| _W n t	jye   | j d¡ Y n
w d| _|  ¡  d S | j 
¡  tƒ ‚)NÚrbr   TF)ÚopenÚ_fhÚaifcÚ_fileÚErrorÚseekÚ_needs_byteswapÚ_checkÚwaveÚsunauÚcloser	   )ÚselfÚfilenamer   r   r   Ú__init__:   s:   þþþ
zRawAudioFile.__init__c                 C   s    | j  ¡ tvr|  ¡  tƒ ‚dS )zeCheck that the files' parameters allow us to decode it and
        raise an error otherwise.
        N)r&   ÚgetsampwidthÚSUPPORTED_WIDTHSr-   r   ©r.   r   r   r   r*   _   s   þzRawAudioFile._checkc                 C   s   | j  ¡  | j ¡  dS )zClose the underlying file.N)r&   r-   r$   r3   r   r   r   r-   g   s   
zRawAudioFile.closec                 C   ó
   | j  ¡ S )zNumber of audio channels.)r&   Úgetnchannelsr3   r   r   r   Úchannelsl   ó   
zRawAudioFile.channelsc                 C   r4   )zSample rate in Hz.)r&   Úgetframerater3   r   r   r   Ú
samplerateq   r7   zRawAudioFile.sampleratec                 C   s   t | j ¡ ƒ| j S )z)Length of the audio in seconds (a float).)Úfloatr&   Ú
getnframesr9   r3   r   r   r   Údurationv   s   zRawAudioFile.durationé   c                 c   sT    | j  ¡ }	 | j  |¡}|sdS t ||t¡}| jr&| j  ¡ dkr&t|ƒ}|V  q)z/Generates blocks of PCM data found in the file.TÚsowtN)	r&   r1   Ú
readframesÚaudioopÚlin2linÚTARGET_WIDTHr)   Úgetcomptyper    )r.   Úblock_samplesÚ	old_widthÚdatar   r   r   Ú	read_data{   s   €
özRawAudioFile.read_datac                 C   s   | S ©Nr   r3   r   r   r   Ú	__enter__Œ   s   zRawAudioFile.__enter__c                 C   s   |   ¡  dS )NF)r-   )r.   Úexc_typeÚexc_valÚexc_tbr   r   r   Ú__exit__   s   zRawAudioFile.__exit__c                 C   s   |   ¡ S rH   )rG   r3   r   r   r   Ú__iter__”   s   zRawAudioFile.__iter__N)r=   )r   r   r   r   r0   r*   r-   Úpropertyr6   r9   r<   rG   rI   rM   rN   r   r   r   r   r!   6   s    %



r!   )r   r%   r@   r   r,   r+   Ú
exceptionsr   Úbaser   rB   r2   r	   r   r    r!   r   r   r   r   Ú<module>   s   