Hacked By AnonymousFox

Current Path : /opt/alt/python312/lib64/python3.12/__pycache__/
Upload File :
Current File : //opt/alt/python312/lib64/python3.12/__pycache__/wave.cpython-312.opt-1.pyc

�

0�f�X���dZddlmZddlZddlZddlZgd�ZGd�de�ZdZ	dZ
d	Zd
Zedd�Z
d
�ZGd�d�ZGd�d�ZGd�d�Zdd�Zy)a%
Stuff to parse WAVE files.

Usage.

Reading WAVE files:
      f = wave.open(file, 'r')
where file is either the name of a file or an open file pointer.
The open file pointer must have methods read(), seek(), and close().
When the setpos() and rewind() methods are not used, the seek()
method is not  necessary.

This returns an instance of a class with the following public methods:
      getnchannels()  -- returns number of audio channels (1 for
                         mono, 2 for stereo)
      getsampwidth()  -- returns sample width in bytes
      getframerate()  -- returns sampling frequency
      getnframes()    -- returns number of audio frames
      getcomptype()   -- returns compression type ('NONE' for linear samples)
      getcompname()   -- returns human-readable version of
                         compression type ('not compressed' linear samples)
      getparams()     -- returns a namedtuple consisting of all of the
                         above in the above order
      getmarkers()    -- returns None (for compatibility with the
                         aifc module)
      getmark(id)     -- raises an error since the mark does not
                         exist (for compatibility with the aifc module)
      readframes(n)   -- returns at most n frames of audio
      rewind()        -- rewind to the beginning of the audio stream
      setpos(pos)     -- seek to the specified position
      tell()          -- return the current position
      close()         -- close the instance (make it unusable)
The position returned by tell() and the position given to setpos()
are compatible and have nothing to do with the actual position in the
file.
The close() method is called automatically when the class instance
is destroyed.

Writing WAVE files:
      f = wave.open(file, 'w')
where file is either the name of a file or an open file pointer.
The open file pointer must have methods write(), tell(), seek(), and
close().

This returns an instance of a class with the following public methods:
      setnchannels(n) -- set the number of channels
      setsampwidth(n) -- set the sample width
      setframerate(n) -- set the frame rate
      setnframes(n)   -- set the number of frames
      setcomptype(type, name)
                      -- set the compression type and the
                         human-readable compression type
      setparams(tuple)
                      -- set all parameters at once
      tell()          -- return current position in output file
      writeframesraw(data)
                      -- write audio frames without patching up the
                         file header
      writeframes(data)
                      -- write audio frames and patch up the file header
      close()         -- patch up the file header and close the
                         output file
You should set the parameters before the first writeframesraw or
writeframes.  The total number of frames does not need to be set,
but when it is set to the correct value, the header does not have to
be patched up.
It is best to first set all parameters, perhaps possibly the
compression type, and then write audio frames using writeframesraw.
When all frames have been written, either call writeframes(b'') or
close() to patch up the sizes in the header.
The close() method is called automatically when the class instance
is destroyed.
�)�
namedtupleN)�open�Error�	Wave_read�
Wave_writec��eZdZy)rN)�__name__�
__module__�__qualname__���+/opt/alt/python312/lib64/python3.12/wave.pyrrRs��r
r�i��s��8�q)N�b�hN�i�_wave_paramsz7nchannels sampwidth framerate nframes comptype compnamec��tt|��}tdt|�|�D]&}t|�D]}|||z|||zdz
|z
<��(t|�S)Nrr)�	bytearray�len�range�bytes)�data�width�swapped_datar�js     r�	_byteswapr`sa���S��Y�'�L�
�1�c�$�i��
'���u��A�.2�1�q�5�k�L��U��Q���*�+��(����r
c�<�eZdZd	d�Zd�Zd�Zd
d�Zd�Zdd�Zd�Z	y)�_Chunkc��d|_||_|rd}nd}||_|jd�|_t|j�dkrt�	tj|dz|jd��d|_	|r|jdz
|_	d|_	|jj�|_
d|_y#tj$rtd�wxYw#tt f$r
d|_YywxYw)	NF�>�<��Lr�T)�closed�align�file�read�	chunknamer�EOFError�struct�unpack_from�	chunksize�error�	size_read�tell�offset�seekable�AttributeError�OSError)�selfr(r'�	bigendian�
inclheader�strflags      r�__init__z_Chunk.__init__ks��������
���G��G���	����1�����t�~�~���"��N�	%�#�/�/����T�Y�Y�q�\�J�1�M�D�N��!�^�^�a�/�D�N����	!��)�)�.�.�*�D�K�!�D�M���|�|�	%���$�	%����(�	"�!�D�M�	"�s�0C� C%�C"�%C>�=C>c��|jS)z*Return the name (ID) of the current chunk.)r*�r6s r�getnamez_Chunk.getname�s���~�~�r
c�f�|js	|j�d|_yy#d|_wxYw)NT)r&�skipr<s r�closez_Chunk.close�s.���{�{�
#��	�	��"���	��#���s�'�	0c�F�|jrtd��|jstd��|dk(r||jz}n|dk(r||j
z}|dks||j
kDrt�|jj|j|zd�||_y)z�Seek to specified position into the chunk.
        Default position is 0 (start of chunk).
        If the file is not seekable, this will result in an error.
        �I/O operation on closed filezcannot seekr�rN)
r&�
ValueErrorr3r5r0r.�RuntimeErrorr(�seekr2)r6�pos�whences   rrFz_Chunk.seek�s����;�;��;�<�<��}�}��-�(�(��Q�;�����&�C�
�q�[�����&�C���7�c�D�N�N�*����	�	���t�{�{�S�(�!�,���r
c�H�|jrtd��|jS)NrB)r&rDr0r<s rr1z_Chunk.tell�s���;�;��;�<�<��~�~�r
c�V�|jrtd��|j|jk\ry|dkr|j|jz
}||j|jz
kDr|j|jz
}|jj|�}|jt
|�z|_|j|jk(rS|jrG|jdzr8|jjd�}|jt
|�z|_|S)z�Read at most size bytes from the chunk.
        If size is omitted or negative, read until the end
        of the chunk.
        rBr
rr)r&rDr0r.r(r)rr')r6�sizer�dummys    rr)z_Chunk.read�s����;�;��;�<�<��>�>�T�^�^�+���!�8��>�>�D�N�N�2�D��$�.�.�4�>�>�1�1��>�>�D�N�N�2�D��y�y�~�~�d�#�����#�d�)�3����>�>�T�^�^�+��:�:��N�N�Q���I�I�N�N�1�%�E�!�^�^�c�%�j�8�D�N��r
c��|jrtd��|jrk	|j|jz
}|j
r|jdzr|dz}|jj|d�|j|z|_y|j|jkrWtd|j|jz
�}|j|�}|st�|j|jkr�Vyy#t$rY�|wxYw)z�Skip the rest of the chunk.
        If you are not interested in the contents of the chunk,
        this method should be called so that the file points to
        the start of the next chunk.
        rBrNi )r&rDr3r.r0r'r(rFr5�minr)r+)r6�nrLs   rr?z_Chunk.skip�s����;�;��;�<�<��=�=�	
��N�N�T�^�^�3���:�:�4�>�>�A�#5��A��A��	�	���q�!�$�!%���!�!3�����n�n�t�~�~�-��D�$�.�.�4�>�>�9�:�A��I�I�a�L�E����	�n�n�t�~�~�-���
��
�s�A)D�	D�DN)TTF)r)���)
r	r
rr:r=r@rFr1r)r?rr
rrrjs%��!�2�#��&�
�.r
rc��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)raPVariables used in this class:

    These variables are available to the user though appropriate
    methods of this class:
    _file -- the open file with methods read(), close(), and seek()
              set through the __init__() method
    _nchannels -- the number of audio channels
              available through the getnchannels() method
    _nframes -- the number of audio frames
              available through the getnframes() method
    _sampwidth -- the number of bytes per audio sample
              available through the getsampwidth() method
    _framerate -- the sampling frequency
              available through the getframerate() method
    _comptype -- the AIFF-C compression type ('NONE' if AIFF)
              available through the getcomptype() method
    _compname -- the human-readable AIFF-C compression type
              available through the getcomptype() method
    _soundpos -- the position in the audio stream
              available through the tell() method, set through the
              setpos() method

    These variables are used internally only:
    _fmt_chunk_read -- 1 iff the FMT chunk has been read
    _data_seek_needed -- 1 iff positioned correctly in audio
              file for readframes()
    _data_chunk -- instantiation of a chunk class for the DATA chunk
    _framesize -- size of one frame in the file
    c��d|_d|_t|d��|_|jj	�dk7rtd��|jj
d�dk7rtd��d|_d|_	d|_		t|jd��}|j	�}|d	k(r|j|�d|_nI|d
k(rD|jstd��||_|j|jz|_d|_	n|j���|jr|jstd��y#t$rY�/wxYw)
Nr)r7�RIFFz file does not start with RIFF idr#�WAVEznot a WAVE filer�fmt �datazdata chunk before fmt chunkz#fmt chunk and/or data chunk missing)�_convert�	_soundposr�_filer=rr)�_fmt_chunk_read�_data_chunk�_data_seek_neededr+�_read_fmt_chunkr.�
_framesize�_nframesr?)r6r(�chunkr*s    r�initfpzWave_read.initfp�sE����
�����D�a�0��
��:�:����7�*��:�;�;��:�:�?�?�1���(��)�*�*� �������%&�D�"�
��t�z�z�q�9���
�
��I��G�#��$�$�U�+�'(��$��g�%��+�+�� =�>�>�#(�� � %���4�?�?� B��
�)*��&���J�J�L�#�$�#�#�4�+;�+;��=�>�>�,<���
��
�s�	E�	E�Ec���d|_t|t�rtj|d�}||_	|j|�y#|jr|j
��xYw)N�rb��_i_opened_the_file�
isinstance�str�builtinsrrar@�r6�fs  rr:zWave_read.__init__sX��"&����a����
�
�a��&�A�&'�D�#�	��K�K��N��	��&�&����	����A�A'c�$�|j�y�N�r@r<s r�__del__zWave_read.__del__$����
�
�r
c��|Srmrr<s r�	__enter__zWave_read.__enter__'����r
c�$�|j�yrmrn�r6�argss  r�__exit__zWave_read.__exit__*rpr
c��|jSrm)rYr<s r�getfpzWave_read.getfp0s���z�z�r
c� �d|_d|_y)Nrr)r\rXr<s r�rewindzWave_read.rewind3s��!"�����r
c�^�d|_|j}|rd|_|j�yyrm)rYrer@�r6r(s  rr@zWave_read.close7s-����
��&�&���&*�D�#��J�J�L�r
c��|jSrm)rXr<s rr1zWave_read.tell>����~�~�r
c��|jSrm)�
_nchannelsr<s r�getnchannelszWave_read.getnchannelsA������r
c��|jSrm)r_r<s r�
getnframeszWave_read.getnframesDs���}�}�r
c��|jSrm)�
_sampwidthr<s r�getsampwidthzWave_read.getsampwidthGr�r
c��|jSrm)�
_framerater<s r�getframeratezWave_read.getframerateJr�r
c��|jSrm��	_comptyper<s r�getcomptypezWave_read.getcomptypeMrr
c��|jSrm��	_compnamer<s r�getcompnamezWave_read.getcompnamePrr
c	���t|j�|j�|j�|j	�|j�|j
��Srm)rr�r�r�r�r�r�r<s r�	getparamszWave_read.getparamsSsQ���D�-�-�/��1B�1B�1D��(�(�*�D�O�O�,=��'�'�)�4�+;�+;�+=�?�	?r
c��yrmrr<s r�
getmarkerszWave_read.getmarkersX���r
c��td���Nzno marks�r�r6�ids  r�getmarkzWave_read.getmark[�
���J��r
c�^�|dks||jkDrtd��||_d|_y)Nrzposition not in ranger)r_rrXr\)r6rGs  r�setposzWave_read.setpos^s/����7�c�D�M�M�)��/�0�0����!"��r
c�J�|jrZ|jjdd�|j|jz}|r|jj|d�d|_|dk(ry|jj||jz�}|jdk7r)tjdk(rt||j�}|jr|r|j|�}|jt|�|j|jzzz|_|S)Nrr
r�big)
r\r[rFrXr^r)r��sys�	byteorderrrWrr�)r6�nframesrGrs    r�
readframeszWave_read.readframesds����!�!����!�!�!�Q�'��.�.�4�?�?�2�C��� � �%�%�c�1�-�%&�D�"��a�<�����$�$�W�t���%>�?���?�?�a��C�M�M�U�$:��T�4�?�?�3�D��=�=�T��=�=��&�D����#�d�)����$�/�/�8Y�*Z�Z����r
c���	tjd|jd��\}|_|_}}|tk7r|tk7rtd|����	tjd|jd��d}|tk(r~	tjd|jd��\}}}|jd	�}	t|	�d	krt�	|	tk7r%	ddl}
d
|
j|	����}t|��|d
zdz|_|jstd��|jstd��|j|jz|_d|_d|_y#tj
$rtd�wxYw#tj
$rtd�wxYw#tj
$rtd�wxYw#t$rd}Yt|��wxYw)Nz<HHLLH�zunknown format: z<HrCrz<HHLr%�zunknown extended format: )�bytes_lezunknown extended format��bad sample width�bad # of channels�NONEznot compressed)r,r-r)r�r�r/r+�WAVE_FORMAT_PCM�WAVE_FORMAT_EXTENSIBLErr�KSDATAFORMAT_SUBTYPE_PCM�uuid�UUID�	Exceptionr�r^r�r�)r6r`�
wFormatTag�dwAvgBytesPerSec�wBlockAlign�	sampwidth�cbSize�wValidBitsPerSample�
dwChannelMask�	SubFormatr��
subformat_msgs            rr]zWave_read._read_fmt_chunkys���	%�Z`�Zl�Zl�mu�w|�xB�xB�CE�xF�[G�W�J�����:J�K���(�Z�;Q�-Q��
�<�=�=�	%��*�*�4����A��?��B�I��/�/�
)�=C�=O�=O�PV�X]�Xb�Xb�cd�Xe�=f�:��+�]�!�J�J�r�N�	��y�>�B�&�"�N�'��4�4�>��&?��	�	�S\�	�@]�?^�$_�M��M�*�*�$�q�=�Q�.�������*�+�+�����+�,�,��/�/�D�O�O�;������)����?�|�|�	%���$�	%���|�|�	%���$�	%���<�<�
)��D�(�
)��!�>�$=�M��M�*�*�>�s6�5E/�(F
�
AF+�#G	�/F
�
F(�+G�	G!� G!N)r	r
r�__doc__rar:rorrrwryr{r@r1r�r�r�r�r�r�r�r�r�r�r�r]rr
rrr�sp���<?�>��������������?�
� �#��*"*r
rc��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)ra�Variables used in this class:

    These variables are user settable through appropriate methods
    of this class:
    _file -- the open file with methods write(), close(), tell(), seek()
              set through the __init__() method
    _comptype -- the AIFF-C compression type ('NONE' in AIFF)
              set through the setcomptype() or setparams() method
    _compname -- the human-readable AIFF-C compression type
              set through the setcomptype() or setparams() method
    _nchannels -- the number of audio channels
              set through the setnchannels() or setparams() method
    _sampwidth -- the number of bytes per audio sample
              set through the setsampwidth() or setparams() method
    _framerate -- the sampling frequency
              set through the setframerate() or setparams() method
    _nframes -- the number of audio frames written to the header
              set through the setnframes() or setparams() method

    These variables are used internally only:
    _datalength -- the size of the audio samples written to the header
    _nframeswritten -- the number of frames actually written
    _datawritten -- the size of the audio samples actually written
    c���d|_t|t�rtj|d�}||_	|j|�y#|jr|j
��xYw)N�wbrdris  rr:zWave_write.__init__�sX��"&����a����
�
�a��&�A�&'�D�#�	��K�K��N��	��&�&����	��rkc��||_d|_d|_d|_d|_d|_d|_d|_d|_d|_	y)NrF)
rYrWr�r�r�r_�_nframeswritten�_datawritten�_datalength�_headerwrittenr}s  rrazWave_write.initfp�sL����
���
������������
� ���������#��r
c�$�|j�yrmrnr<s rrozWave_write.__del__�rpr
c��|Srmrr<s rrrzWave_write.__enter__�rsr
c�$�|j�yrmrnrus  rrwzWave_write.__exit__�rpr
c�`�|jrtd��|dkrtd��||_y)N�0cannot change parameters after starting to writerr�)r�rr�)r6�	nchannelss  r�setnchannelszWave_write.setnchannels�s1������J�K�K��q�=��+�,�,�#��r
c�H�|jstd��|jS)Nznumber of channels not set)r�rr<s rr�zWave_write.getnchannels�s������4�5�5����r
c�j�|jrtd��|dks|dkDrtd��||_y)Nr�rr#r�)r�rr�)r6r�s  r�setsampwidthzWave_write.setsampwidth�s7������J�K�K��q�=�I��M��*�+�+�#��r
c�H�|jstd��|jS)Nzsample width not set)r�rr<s rr�zWave_write.getsampwidth�s������.�/�/����r
c��|jrtd��|dkrtd��tt|��|_y)Nr�rzbad frame rate)r�r�int�roundr�)r6�	framerates  r�setframeratezWave_write.setframerate�s;������J�K�K���>��(�)�)��e�I�.�/��r
c�H�|jstd��|jS)Nzframe rate not set)r�rr<s rr�zWave_write.getframerate�s������,�-�-����r
c�@�|jrtd��||_y�Nr�)r�rr_)r6r�s  r�
setnframeszWave_write.setnframess������J�K�K���
r
c��|jSrm�r�r<s rr�zWave_write.getnframes����#�#�#r
c�l�|jrtd��|dvrtd��||_||_y)Nr�)r�zunsupported compression type)r�rr�r�)r6�comptype�compnames   r�setcomptypezWave_write.setcomptypes9������J�K�K��9�$��6�7�7�!���!��r
c��|jSrmr�r<s rr�zWave_write.getcomptyperr
c��|jSrmr�r<s rr�zWave_write.getcompnamerr
c���|\}}}}}}|jrtd��|j|�|j|�|j	|�|j|�|j
||�yr�)r�rr�r�r�r�r�)r6�paramsr�r�r�r�r�r�s        r�	setparamszWave_write.setparamsso��GM�D�	�9�i��(�H�����J�K�K����)�$����)�$����)�$����� �����8�,r
c��|jr|jr|jstd��t	|j|j|j|j
|j|j�S)Nznot all parameters set)r�r�r�rrr_r�r�r<s rr�zWave_write.getparams sS�����d�o�o�T�_�_��0�1�1��D�O�O�T�_�_�d�o�o��m�m�T�^�^�T�^�^�=�	=r
c��td��)Nzsetmark() not supportedr�)r6r�rG�names    r�setmarkzWave_write.setmark&s���-�.�.r
c��td��r�r�r�s  rr�zWave_write.getmark)r�r
c��yrmrr<s rr�zWave_write.getmarkers,r�r
c��|jSrmr�r<s rr1zWave_write.tell/r�r
c�&�t|ttf�st|�j	d�}|jt
|��t
|�|j|jzz}|jr|j|�}|jdk7r)tjdk(rt||j�}|jj|�|xjt
|�z
c_|j |z|_y)N�Brr�)rfrr�
memoryview�cast�_ensure_header_writtenrr�r�rWr�r�rrY�writer�r�)r6rr�s   r�writeframesrawzWave_write.writeframesraw2s����$��	� 2�3��d�#�(�(��-�D��#�#�C��I�.��d�)����$�/�/� A�B���=�=��=�=��&�D��?�?�a��C�M�M�U�$:��T�4�?�?�3�D��
�
��������S��Y�&��#�3�3�g�=��r
c�z�|j|�|j|jk7r|j�yyrm)r�r�r��_patchheader)r6rs  r�writeframeszWave_write.writeframes?s5�����D�!����t�0�0�0�����1r
c��	|jrT|jd�|j|jk7r|j	�|jj�d|_|j}|rd|_|j�yy#d|_|j}|rd|_|j�wwxYw)Nr)rYr�r�r�r��flushrer@r}s  rr@zWave_write.closeDs���	��z�z��+�+�A�.��#�#�t�'8�'8�8��%�%�'��
�
� � �"��D�J��*�*�D��*.��'��
�
�����D�J��*�*�D��*.��'��
�
���s�A B�/B?c���|jsW|jstd��|jstd��|jstd��|j|�yy)Nz# channels not specifiedzsample width not specifiedzsampling rate not specified)r�r�rr�r��
_write_header)r6�datasizes  rr�z!Wave_write._ensure_header_writtenVsW���"�"��?�?��6�7�7��?�?��8�9�9��?�?��9�:�:����x�(�#r
c��|jjd�|js!||j|jzz|_|j|jz|jz|_	|jj
�|_|jjtjdd|j
zdddt|j|j|j|jz|jz|j|jz|jdzd��|j�|jj
�|_|jjtjd	|j
��d
|_y#ttf$rd|_Y��+wxYw)NrSz<L4s4sLHHLLHH4s�$rTrUr�r%rV�<LT)rYr�r_r�r�r�r1�_form_length_posr4r5r,�packr�r��_data_length_posr�)r6�
initlengths  rr�zWave_write._write_header`sP���
�
����!��}�}�&�4�?�?�T�_�_�+L�M�D�M��=�=�4�?�?�:�T�_�_�L���	)�$(�J�J�O�O�$5�D�!�	
�
�
������%6���!�!�!�7�G�R��T�_�_�d�o�o��O�O�d�o�o�-����?��O�O�d�o�o�-��O�O�a���*�	+�� � �,�$(�J�J�O�O�$5�D�!��
�
������T�4�+;�+;�<�=�"������(�	)�$(�D�!�	)�s�5F&�&G�?Gc�H�|j|jk(ry|jj�}|jj	|j
d�|jj
tjdd|jz��|jj	|jd�|jj
tjd|j��|jj	|d�|j|_y)Nrrr�)
r�r�rYr1rFrr�r,rr)r6�curposs  rr�zWave_write._patchheaderus������� 0� 0�0�������"���
�
����-�-�q�1��
�
������T�2��0A�0A�+A�B�C��
�
����-�-�q�1��
�
������T�4�+<�+<�=�>��
�
�����"��,�,��r
N) r	r
rr�r:rarorrrwr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r1r�r�r@r�r�r�rr
rrr�s����2
�
$����$��
$��
0��
 �
$�"���-�=�/� ��$�>� �
�$)�#�*
-r
rc��|�t|d�r
|j}nd}|dvrt|�S|dvrt|�St	d��)N�moderc)�rrc)�wr�z$mode must be 'r', 'rb', 'w', or 'wb')�hasattrrrrr)rjrs  rrr�sO���|��1�f���6�6�D��D��{����|��	
��	��!�}���:�;�;r
rm)r��collectionsrrhr,r��__all__r�rr�r�r��_array_fmtsrrrrrrrr
r�<module>rs���G�R#��
�
�7��	�I�	�����X��'���.�N�P���l�l�^B*�B*�Ja-�a-�H<r

Hacked By AnonymousFox1.0, Coded By AnonymousFox