AlkantarClanX12

Your IP : 18.188.68.115


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

�

�Q�f.H����dZddlmZddlZejed��edd�ZdZd	Zd
Z	dZ
dZd
ZdZ
dZdZdZdZdZdZdZee	e
eeegZGd�de�Zd�Zd�ZGd�d�ZGd�d�Zdd�Zy) a�Stuff to parse Sun and NeXT audio files.

An audio file consists of a header followed by the data.  The structure
of the header is as follows.

        +---------------+
        | magic word    |
        +---------------+
        | header size   |
        +---------------+
        | data size     |
        +---------------+
        | encoding      |
        +---------------+
        | sample rate   |
        +---------------+
        | # of channels |
        +---------------+
        | info          |
        |               |
        +---------------+

The magic word consists of the 4 characters '.snd'.  Apart from the
info field, all header fields are 4 bytes in size.  They are all
32-bit unsigned integers encoded in big-endian byte order.

The header size really gives the start of the data.
The data size is the physical size of the data.  From the other
parameters the number of frames can be calculated.
The encoding gives the way in which audio samples are encoded.
Possible values are listed below.
The info field currently consists of an ASCII string giving a
human-readable description of the audio file.  The info field is
padded with NUL bytes to the header size.

Usage.

Reading audio files:
        f = sunau.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' or 'ULAW')
        getcompname()   -- returns human-readable version of
                           compression type ('not compressed' matches 'NONE')
        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 audio files:
        f = sunau.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 pathing 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)��
)�remove�
_sunau_paramsz7nchannels sampwidth framerate nframes comptype compnameidns.��r���������l��c��eZdZy)�ErrorN)�__name__�
__module__�__qualname__���,/opt/alt/python312/lib64/python3.12/sunau.pyrr�s��rrc�~�d}td�D],}|jd�}|st�|dzt|�z}�.|S)Nrr
r�)�range�read�EOFError�ord)�file�x�i�bytes    r�	_read_u32r%�sC��	�A�
�1�X���y�y��|����N�
�c�E�C��I���	�

�Hrc��g}td�D].}t|d�\}}|jdt|��|}�0|j	t|��y)Nr
rr)r�divmod�insert�int�write�bytes)r!r"�datar#�d�ms      r�
_write_u32r/�sM��
�D�
�1�X���a��~���1����A�s�1�v��
���	�J�J�u�T�{�rc��eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�Au_readc��t|t�rddl}|j|d�}d|_nd|_|j|�y)Nr�rbTF��
isinstance�str�builtins�open�_opened�initfp��self�fr7s   r�__init__zAu_read.__init__��8���a�����
�
�a��&�A��D�L� �D�L����A�rc�>�|jr|j�yy�N��_file�close�r<s r�__del__zAu_read.__del__�s���:�:��J�J�L�rc��|SrArrEs r�	__enter__zAu_read.__enter__�����rc�$�|j�yrA�rD�r<�argss  r�__exit__zAu_read.__exit__�����
�
�rc�R�||_d|_tt|��}|tk7rtd��tt|��|_|jdkrtd��|jdkDrtd��t|�|_|jtk7rt|j�|_tt|��|_	|jtvrtd��|jttfvrd|_
d	|_n�|jtk(rd	x|_|_
nq|jt k(rdx|_|_
nO|jt"k(rd
x|_|_
n-|jt$k(rdx|_|_
ntd��tt|��|_tt|��|_|j(std
��|j|j(z|_|jdkDrH|j+|jdz
�|_|j,j/d�\|_}}nd|_	|j1�|_y#t4t6f$r
d|_YywxYw)Nrzbad magic numberrzheader size too small�dzheader size ridiculously largezencoding not (yet) supportedr	rrr
zunknown encodingzbad # of channels�r)rC�	_soundposr)r%�AUDIO_FILE_MAGICr�	_hdr_size�
_data_size�AUDIO_UNKNOWN_SIZE�	_encoding�_simple_encodings�AUDIO_FILE_ENCODING_MULAW_8�AUDIO_FILE_ENCODING_ALAW_8�
_sampwidth�
_framesize�AUDIO_FILE_ENCODING_LINEAR_8�AUDIO_FILE_ENCODING_LINEAR_16�AUDIO_FILE_ENCODING_LINEAR_24�AUDIO_FILE_ENCODING_LINEAR_32�
_framerate�
_nchannelsr�_info�	partition�tell�	_data_pos�AttributeError�OSError)r<r!�magic�_s    rr:zAu_read.initfp�s����
�����I�d�O�$���$�$��*�+�+��Y�t�_�-����>�>�B���/�0�0��>�>�C���8�9�9�#�D�/����?�?�0�0�!�$�/�/�2�D�O��Y�t�_�-����>�>�!2�2��6�7�7��>�>�9�,�.�.��D�O��D�O�
�^�^�;�
;�01�1�D�O�d�o�
�^�^�<�
<�01�1�D�O�d�o�
�^�^�<�
<�01�1�D�O�d�o�
�^�^�<�
<�01�1�D�O�d�o��*�+�+��i��o�.����i��o�.�������+�,�,��/�/�D�O�O�;����>�>�B�����4�>�>�B�#6�7�D�J�#�z�z�3�3�E�:��D�J��1��D�J�	"�!�Y�Y�[�D�N����(�	"�!�D�N�	"�s�7J
�
J&�%J&c��|jSrA)rCrEs r�getfpz
Au_read.getfp�s���z�z�rc��|jSrA)rcrEs r�getnchannelszAu_read.getnchannels�������rc��|jSrA)r\rEs r�getsampwidthzAu_read.getsampwidth�rprc��|jSrA)rbrEs r�getframeratezAu_read.getframerate�rprc��|jtk(rtS|jtvr|j|jzSy)Nr)rVrWrXrYr]rEs r�
getnframeszAu_read.getnframes�s8���?�?�0�0�%�%��>�>�.�.��?�?�d�o�o�5�5�rc�T�|jtk(ry|jtk(ryy)N�ULAW�ALAW�NONE�rXrZr[rEs r�getcomptypezAu_read.getcomptype�s%���>�>�8�8��
�^�^�9�
9��rc�T�|jtk(ry|jtk(ryy)N�CCITT G.711 u-law�CCITT G.711 A-law�not compressedr{rEs r�getcompnamezAu_read.getcompname�s%���>�>�8�8�&�
�^�^�9�
9�&�#rc	���t|j�|j�|j�|j	�|j�|j
��SrA�rrorrrtrvr|r�rEs r�	getparamszAu_read.getparams�Q���T�.�.�0�$�2C�2C�2E��#�#�%�t���'8��"�"�$�d�&6�&6�&8�:�	:rc��yrArrEs r�
getmarkerszAu_read.getmarkerss��rc��td��)Nzno marks)r)r<�ids  r�getmarkzAu_read.getmarks
���J��rc��|jtvr�|tk(r|jj	�}n(|jj	||j
z�}|xjt|�|j
zz
c_|jtk(rXtj�5tjdt��ddl
}ddd�j||j�}|Sy#1swY�(xYw)N�ignore��categoryr)rXrYrWrCrr]rS�lenrZ�warnings�catch_warnings�simplefilter�DeprecationWarning�audioop�ulaw2linr\)r<�nframesr,r�s    r�
readframeszAu_read.readframess����>�>�.�.��,�,��z�z���(���z�z���w����'@�A���N�N�c�$�i�4�?�?�:�:�N��~�~�!<�<��,�,�.��)�)�(�=O�P�"�/��'�'��d�o�o�>���K��/�.�s�1 C8�8Dc��|j�td��|jj|j�d|_y)N�cannot seekr)rgrirC�seekrSrEs r�rewindzAu_read.rewind s2���>�>�!��-�(�(��
�
������'���rc��|jSrA)rSrEs rrfzAu_read.tell&����~�~�rc���|dks||j�kDrtd��|j�td��|jj|j||jzz�||_y)Nrzposition not in ranger�)rvrrgrirCr�r]rS)r<�poss  r�setposzAu_read.setpos)sa����7�c�D�O�O�-�-��/�0�0��>�>�!��-�(�(��
�
�������t���)>�>�?���rc�j�|j}|r%d|_|jr|j�yyyrA)rCr9rD�r<r!s  rrDz
Au_read.close1s/���z�z����D�J��|�|��
�
���rN)rrrr>rFrHrNr:rmrorrrtrvr|r�r�r�r�r�r�rfr�rDrrrr1r1�sg������,"�\������$�:�
� �
����rr1c��eZdZd�Zd�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�Zy)�Au_writec��t|t�rddl}|j|d�}d|_nd|_|j|�y)Nr�wbTFr4r;s   rr>zAu_write.__init__:r?rc�J�|jr|j�d|_yrArBrEs rrFzAu_write.__del__Cs���:�:��J�J�L���
rc��|SrArrEs rrHzAu_write.__enter__HrIrc�$�|j�yrArKrLs  rrNzAu_write.__exit__KrOrc��||_d|_d|_d|_d|_t
|_d|_d|_d|_	d|_
d|_y)Nrrrx)rCrbrcr\r]rW�_nframes�_nframeswritten�_datawritten�_datalengthrd�	_comptyper�s  rr:zAu_write.initfpNsR����
�������������*��
� �����������
���rc�^�|jrtd��|dvrtd��||_y)N�0cannot change parameters after starting to write)rr	r
z"only 1, 2, or 4 channels supported)r�rrc)r<�	nchannelss  r�setnchannelszAu_write.setnchannels[s2������J�K�K��I�%��<�=�=�#��rc�H�|jstd��|jS)Nznumber of channels not set)rcrrEs rrozAu_write.getnchannelsb�������4�5�5����rc�^�|jrtd��|dvrtd��||_y)Nr�)rr	rr
zbad sample width)r�rr\)r<�	sampwidths  r�setsampwidthzAu_write.setsampwidthgs2������J�K�K��L�(��*�+�+�#��rc�H�|jstd��|jS)N�sample width not specified)rbrr\rEs rrrzAu_write.getsampwidthnr�rc�@�|jrtd��||_y)Nr�)r�rrb)r<�	framerates  r�setframeratezAu_write.setframeratess������J�K�K�#��rc�H�|jstd��|jS)Nzframe rate not set)rbrrEs rrtzAu_write.getframeratexs������,�-�-����rc�`�|jrtd��|dkrtd��||_y)Nr�rz# of frames cannot be negative)r�rr�)r<r�s  r�
setnframeszAu_write.setnframes}s1������J�K�K��Q�;��8�9�9���
rc��|jSrA�r�rEs rrvzAu_write.getnframes�����#�#�#rc�0�|dvr||_ytd��)N)rzrxzunknown compression type)r�r)r<�type�names   r�setcomptypezAu_write.setcomptype�s���#�#�!�D�N��2�3�3rc��|jSrA�r�rEs rr|zAu_write.getcomptype�r�rc�D�|jdk(ry|jdk(ryy)Nrxr~ryrr�r�rEs rr�zAu_write.getcompname�s#���>�>�V�#�&�
�^�^�v�
%�&�#rc���|\}}}}}}|j|�|j|�|j|�|j|�|j	||�yrA)r�r�r�r�r�)r<�paramsr�r�r�r��comptype�compnames        r�	setparamszAu_write.setparams�sZ��GM�D�	�9�i��(�H����)�$����)�$����)�$����� �����8�,rc	���t|j�|j�|j�|j	�|j�|j
��SrAr�rEs rr�zAu_write.getparams�r�rc��|jSrAr�rEs rrfz
Au_write.tell�r�rc�2�t|ttf�st|�j	d�}|j�|jdk(rXtj�5tjdt��ddl}ddd�j||j�}t|�|jz}|j j#|�|j$|z|_|j&t|�z|_y#1swY��xYw)N�Brxr�r�r)r5r+�	bytearray�
memoryview�cast�_ensure_header_writtenr�r�r�r�r�r��lin2ulawr\r�r]rCr*r�r�)r<r,r�r�s    r�writeframesrawzAu_write.writeframesraw�s����$��	� 2�3��d�#�(�(��-�D��#�#�%��>�>�V�#��(�(�*��%�%�h�9K�L��+��#�#�D�$�/�/�:�D��d�)�t���.���
�
�����#�3�3�g�=��� �-�-��D�	�9���+�*�s�$ D
�
Dc��|j|�|j|jk7s|j|jk7r|j�yyrA)r�r�r�r�r��_patchheader)r<r,s  r�writeframeszAu_write.writeframes�sG�����D�!����4�=�=�0��"�"�d�&7�&7�7�����8rc���|jr�	|j�|j|jk7s|j|j
k7r|j
�|jj�|j}d|_|jr|j�yyy#|j}d|_|jr|j�wwxYwrA)
rCr�r�r�r�r�r��flushr9rDr�s  rrDzAu_write.close�s����:�:�

!��+�+�-��'�'�4�=�=�8��(�(�D�,=�,=�=��%�%�'��
�
� � �"��z�z��!��
��<�<��J�J�L� ����z�z��!��
��<�<��J�J�L� �s�A,B,�,2Cc���|jsV|jstd��|jstd��|jstd��|j�yy)Nz# of channels not specifiedr�zframe rate not specified)r�rcrr\rb�
_write_headerrEs rr�zAu_write._ensure_header_written�sU���#�#��?�?��9�:�:��?�?��8�9�9��?�?��6�7�7���� �$rc���|jdk(r|jdk(rt}d|_n�|jdk(rt}d|_nm|jdk(rt
}d|_nP|jdk(rt}d|_n3td��|jdk(rt}d|_ntd��|j|jz|_t|jt�dt|j�z}|d	zd
z}t|j|�|jt k(rt }n|j|jz}	|jj#�|_t|j|�||_t|j|�t|j|j,�t|j|j�|jj/|j�|jj/d|t|j�z
dz
z�y#t&t(f$r
d|_Y��wxYw)
Nrzrr	rr
zinternal errorrxrr
i����rRr)r�r\r^r]r_r`rarrZrcr/rCrTr�rdr�rWrf�_form_length_posrhrir�rbr*)r<�encoding�header_size�lengths    rr�zAu_write._write_header�s����>�>�V�#����!�#�7��"#������A�%�8��"#������A�%�8��"#������A�%�8��"#����,�-�-�
�^�^�v�
%�2�H��D�O��(�)�)��/�/�D�O�O�;����4�:�:�/�0��3�t�z�z�?�*��"�Q��"�,���4�:�:�{�+��=�=�.�.�'�F��]�]�T�_�_�4�F�	)�$(�J�J�O�O�$5�D�!�	�4�:�:�v�&�!����4�:�:�x�(��4�:�:�t���/��4�:�:�t���/��
�
������$��
�
�����c�$�*�*�o� =�� B�C�D����(�	)�$(�D�!�	)�s�I�I!� I!c��|j�td��|jj|j�t	|j|j
�|j
|_|jjdd�y)Nr�rr	)r�rirCr�r/r�r�rEs rr�zAu_write._patchheadersc��� � �(��-�(�(��
�
����-�-�.��4�:�:�t�0�0�1��,�,����
�
����1�rN)rrrr>rFrHrNr:r�ror�rrr�rtr�rvr�r|r�r�r�rfr�r�rDr�r�r�rrrr�r�8s�����
�� �$��
$��
$�
�
 �$�4��$�-�:�
$�:� �!�$!�(E�Trr�c��|�t|d�r
|j}nd}|dvrt|�S|dvrt|�St	d��)N�moder3)�rr3)�wr�z$mode must be 'r', 'rb', 'w', or 'wb')�hasattrr�r1r�r)r=r�s  rr8r8
sO���|��1�f���6�6�D��D��{���q�z��	
��	���{���:�;�;rrA)�__doc__�collectionsrr��_deprecatedrrrTrZr^r_r`ra�AUDIO_FILE_ENCODING_FLOAT�AUDIO_FILE_ENCODING_DOUBLE�AUDIO_FILE_ENCODING_ADPCM_G721�AUDIO_FILE_ENCODING_ADPCM_G722� AUDIO_FILE_ENCODING_ADPCM_G723_3� AUDIO_FILE_ENCODING_ADPCM_G723_5r[rWrY�	Exceptionrr%r/r1r�r8rrr�<module>r�s���g�R#������X�g�.��?�T�V�
����� �� !�� !�� !������!#��!#��#%� �#%� ��� ��0�1�2�2�2�/�1��	�I�	�
��V�V�pP�P�d<r