%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3.12/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3.12/__pycache__/aifc.cpython-312.pyc

�

���f����b�dZddlZddlZddlZddgZej
ed��Gd�de�ZdZ	d	�Z
d
�Zd�Zd�Z
d
�ZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Zej.�5ej0de�ddlmZddd�ddlmZedd�Zdej>_dej@_dejB_dejD_dejF_d ejH_Gd!�d"�Z%Gd#�d$�Z&d6d%�Z'ed&k(�rkddl(Z(e(jRd'dse(jRjUd(�e(jRd'Z+e'e+d)�5Z,e-d*e+�e-d+e,j]��e-d,e,j_��e-d-e,ja��e-d.e,jc��e-d/e,je��e-d0e,jg��e(jRd1drye(jRd1Z4e-d2e4�e'e4d3�5Z5e5jme,jo��	e,jqd4�Z9e9sne5jue9��&	ddd�e-d5�ddd�yy#1swY��	xYw#1swY�(xYw#1swYyxYw)7aJStuff to parse AIFF-C and AIFF files.

Unless explicitly stated otherwise, the description below is true
both for AIFF-C files and AIFF files.

An AIFF-C file has the following structure.

  +-----------------+
  | FORM            |
  +-----------------+
  | <size>          |
  +----+------------+
  |    | AIFC       |
  |    +------------+
  |    | <chunks>   |
  |    |    .       |
  |    |    .       |
  |    |    .       |
  +----+------------+

An AIFF file has the string "AIFF" instead of "AIFC".

A chunk consists of an identifier (4 bytes) followed by a size (4 bytes,
big endian order), followed by the data.  The size field does not include
the size of the 8 byte header.

The following chunk types are recognized.

  FVER
      <version number of AIFF-C defining document> (AIFF-C only).
  MARK
      <# of markers> (2 bytes)
      list of markers:
          <marker ID> (2 bytes, must be > 0)
          <position> (4 bytes)
          <marker name> ("pstring")
  COMM
      <# of channels> (2 bytes)
      <# of sound frames> (4 bytes)
      <size of the samples> (2 bytes)
      <sampling frequency> (10 bytes, IEEE 80-bit extended
          floating point)
      in AIFF-C files only:
      <compression type> (4 bytes)
      <human-readable version of compression type> ("pstring")
  SSND
      <offset> (4 bytes, not used by this program)
      <blocksize> (4 bytes, not used by this program)
      <sound data>

A pstring consists of 1 byte length, a string of characters, and 0 or 1
byte pad to make the total length even.

Usage.

Reading AIFF files:
  f = aifc.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().
In some types of audio files, if the setpos() method is 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 AIFF files)
  getcompname()   -- returns human-readable version of
             compression type ('not compressed' for AIFF files)
  getparams() -- returns a namedtuple consisting of all of the
             above in the above order
  getmarkers()    -- get the list of marks in the audio file or None
             if there are no marks
  getmark(id) -- get mark with the specified id (raises an error
             if the mark does not exist)
  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(), the position given to setpos() and
the position of marks are all 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 AIFF files:
  f = aifc.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:
  aiff()      -- create an AIFF file (AIFF-C default)
  aifc()      -- create an AIFF-C file
  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
  setmark(id, pos, name)
          -- add specified mark to the list of marks
  tell()      -- return current position in output file (useful
             in combination with setmark())
  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.
Marks can be added anytime.  If there are any marks, you must call
close() after all frames have been written.
The close() method is called automatically when the class instance
is destroyed.

When a file is opened with the extension '.aiff', an AIFF file is
written, otherwise an AIFF-C file is written.  This default can be
changed by calling aiff() or aifc() before the first writeframes or
writeframesraw.
�N�Error�open)��
)�removec��eZdZy)rN)�__name__�
__module__�__qualname__���/usr/lib/python3.12/aifc.pyrr�s��r
l@QEc��	tjd|jd��dS#tj$rtd�wxYw)N�>l�r��struct�unpack�read�error�EOFError��files r�
_read_longr��@��!��}�}�T�4�9�9�Q�<�0��3�3���<�<�!��D� �!��	�'*�Ac��	tjd|jd��dS#tj$rtd�wxYw)N�>Lrrrrs r�_read_ulongr�rrc��	tjd|jd��dS#tj$rtd�wxYw)N�>h�rrrs r�_read_shortr#�rrc��	tjd|jd��dS#tj$rtd�wxYw)N�>Hr"rrrs r�_read_ushortr&�rrc��t|jd��}|dk(rd}n|j|�}|dzdk(r|jd�}|S)N�rr
)�ordr)r�length�data�dummys    r�_read_stringr-�sK��
����1��
�F�
��{����y�y�� ��
��z�Q���	�	�!����Kr
g�����c��t|�}d}|dkrd}|dz}t|�}t|�}||cxk(r|cxk(rdk(r
nnd}||zS|dk(rt}||zS|dz
}|dz|ztd	|d
z
�z}||zS)Nr(r�����g�i�?lg@�?)r#r�	_HUGE_VAL�pow)�f�expon�sign�himant�lomants     r�_read_floatr:�s�����N�E��D��q�y�������
��^�F�
��^�F���%�&�%�A�%����!�8�O�
�&�����!�8�O���
��
�k�
!�F�
*�c�#�u�r�z�.B�B���!�8�Or
c�N�|jtjd|��y)Nr!��writer�pack�r5�xs  r�_write_shortrA�����G�G�F�K�K��a� �!r
c�N�|jtjd|��y)Nr%r<r?s  r�
_write_ushortrD�rBr
c�N�|jtjd|��y)Nrr<r?s  r�_write_longrF�rBr
c�N�|jtjd|��y)Nrr<r?s  r�_write_ulongrH�rBr
c��t|�dkDrtd��|jtjdt|���|j|�t|�dzdk(r|jd�yy)N�z%string exceeds maximum pstring length�Br(r�)�len�
ValueErrorr=rr>)r5�ss  r�
_write_stringrP�s_��
�1�v��|��@�A�A��G�G�F�K�K��S��V�$�%��G�G�A�J�
�1�v��z�Q��	�����r
c���ddl}|dkrd}|dz}nd}|dk(rd}d}d}n�|j|�\}}|dkDs
|dk\s||k7r
|dz}d}d}n�|dz}|dkr|j||�}d}||z}|j|d�}|j|�}t	|�}|j||z
d�}|j|�}t	|�}t||�t
||�t
||�y)	Nrr0r/i@r(r1i�?� )�math�frexp�ldexp�floor�intrDrH)	r5r@rSr7r6r8r9�fmant�fsmants	         r�_write_floatrZ�s
����1�u���
��F�����A�v��������z�z�!�}���u��5�=�E�Q�J�%�5�.���K�E��F��F��E�M�E��q�y��
�
�5�%�0�����D�L�E��J�J�u�b�)�E��Z�Z��&�F���[�F��J�J�u�v�~�r�2�E��Z�Z��&�F���[�F��!�U����F����F�r
�ignore)�Chunk)�
namedtuple�_aifc_paramsz7nchannels sampwidth framerate nframes comptype compnamez3Number of audio channels (1 for mono, 2 for stereo)zSample width in byteszSampling frequencyzNumber of audio framesz(Compression type ("NONE" for AIFF files)zRA human-readable version of the compression type
('not compressed' for AIFF files)c��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�Zy)�	Aifc_readNc���d|_d|_g|_d|_||_t|�}|j
�dk7rtd��|jd�}|dk(rd|_	n|dk(rd|_	ntd��d|_
d|_	d|_	t|j�}|j
�}|d	k(r|j|�d|_
nQ|d
k(r ||_|jd�}d|_n,|dk(rt|�|_n|d
k(r|j!|�|j#���#t$rYnwxYw|jr|jstd��y)Nr�FORMz file does not start with FORM idr�AIFF�AIFCr(znot an AIFF or AIFF-C file�COMM�SSND��FVER�MARKz$COMM chunk and/or SSND chunk missing)�_version�_convert�_markers�	_soundpos�_filer\�getnamerr�_aifc�_comm_chunk_read�_ssnd_chunk�_ssnd_seek_neededr�_read_comm_chunkr�	_readmark�skip)�selfr�chunk�formdata�	chunknamer,s      r�initfpzAifc_read.initfp:sk����
���
���
������
��d����=�=�?�g�%��:�;�;��:�:�a�=���w���D�J�
��
 ��D�J��4�5�5� !�������%&�D�"�
��d�j�j�)���
�
��I��G�#��%�%�e�,�()��%��g�%�#(�� ��
�
�1�
��)*��&��g�%� +�E� 2��
��g�%����u�%��J�J�L�%���
��
���$�$�D�,<�,<��>�?�?�-=s�D?�?	E�
Ec���t|t�r)tj|d�}	|j	|�y|j	|�y#|j��xYw)N�rb)�
isinstance�str�builtinsrr{�close�rwr5�file_objects   r�__init__zAifc_read.__init__bsP���a���"�-�-��4�0�K�
����K�(�
�K�K��N��
��!�!�#��s�A�Ac��|S�Nr�rws r�	__enter__zAifc_read.__enter__n����r
c�$�|j�yr��r��rw�argss  r�__exit__zAifc_read.__exit__q����
�
�r
c��|jSr�)rnr�s r�getfpzAifc_read.getfpws���z�z�r
c� �d|_d|_y)Nr(r)rsrmr�s r�rewindzAifc_read.rewindzs��!"�����r
c�P�|j}|�d|_|j�yyr�)rnr��rwrs  rr�zAifc_read.close~s&���z�z�����D�J��J�J�L�r
c��|jSr�)rmr�s r�tellzAifc_read.tell�����~�~�r
c��|jSr�)�
_nchannelsr�s r�getnchannelszAifc_read.getnchannels�������r
c��|jSr�)�_nframesr�s r�
getnframeszAifc_read.getnframes�s���}�}�r
c��|jSr�)�
_sampwidthr�s r�getsampwidthzAifc_read.getsampwidth�r�r
c��|jSr�)�
_framerater�s r�getframeratezAifc_read.getframerate�r�r
c��|jSr���	_comptyper�s r�getcomptypezAifc_read.getcomptype�r�r
c��|jSr���	_compnamer�s r�getcompnamezAifc_read.getcompname�r�r
c	���t|j�|j�|j�|j	�|j�|j
��Sr�)r^r�r�r�r�r�r�r�s r�	getparamszAifc_read.getparams�sS���D�-�-�/��1B�1B�1D� �-�-�/����1B� �,�,�.��0@�0@�0B�D�	Dr
c�L�t|j�dk(ry|jS�Nr�rMrlr�s r�
getmarkerszAifc_read.getmarkers�� ���t�}�}���"���}�}�r
c�p�|jD]}||dk(s�|cStdj|����Nrzmarker {0!r} does not exist�rlr�format�rw�id�markers   r�getmarkzAifc_read.getmark��>���m�m�	�F��V�A�Y���
�	��1�8�8��<�=�=r
c�^�|dks||jkDrtd��||_d|_y)Nrzposition not in ranger()r�rrmrs)rw�poss  r�setposzAifc_read.setpos�s/����7�c�D�M�M�)��/�0�0����!"��r
c��|jrv|jjd�|jjd�}|j|j
z}|r|jj|dz�d|_|dk(ry|jj||j
z�}|jr|r|j
|�}|jt|�|j|jzzz|_|S)Nrrgr
)
rsrr�seekrrm�
_framesizerkrMr�r�)rw�nframesr,r�r+s     r�
readframeszAifc_read.readframes�s����!�!����!�!�!�$��$�$�)�)�!�,�E��.�.�4�?�?�2�C��� � �%�%�c�A�g�.�%&�D�"��a�<�����$�$�W�t���%>�?���=�=�T��=�=��&�D����#�d�)����:>�/�/�9J�+K�K����r
c��tj�5tjdt��ddl}ddd�j|d�S#1swY�xYw�Nr[��categoryrr")�warnings�catch_warnings�simplefilter�DeprecationWarning�audioop�alaw2lin�rwr+r�s   r�	_alaw2linzAifc_read._alaw2lin��L��
�
$�
$�
&�	��!�!�(�5G�H��	�����a�(�(�	�	��� A�Ac��tj�5tjdt��ddl}ddd�j|d�S#1swY�xYwr�)r�r�r�r�r��ulaw2linr�s   r�	_ulaw2linzAifc_read._ulaw2lin�r�r�c��tj�5tjdt��ddl}ddd�t|d�sd|_j|d|j�\}|_|S#1swY�CxYw�Nr[r�r�_adpcmstater")r�r�r�r�r��hasattrr��	adpcm2linr�s   r�
_adpcm2linzAifc_read._adpcm2lin�sr��
�
$�
$�
&�	��!�!�(�5G�H��	��t�]�+�#�D��!(�!2�!2�4��D�<L�<L�!M���d����	�	��� A7�7Bc��tj�5tjdt��ddl}ddd�j|d�S#1swY�xYwr��r�r�r�r�r��byteswapr�s   r�	_sowt2linzAifc_read._sowt2lin�r�r�c�4�t|�|_t|�|_t|�dzdz|_tt
|��|_|jdkrtd��|jdkrtd��|j|jz|_	|j�r\d}|jdk(rd}tjd�d	|_|jd
�|_|rat!|j"jd��}|dzdk(r|dz}|j|z|_|j"j%dd�t'|�|_|jdk7r�|jd
k(r|j*|_nk|jdvr|j.|_nK|jdvr|j0|_n+|jdvr|j2|_ntd��d|_yyd|_d|_y)N�rgr�bad sample width�bad # of channels�r(zWarning: bad COMM chunk size�rr/�NONE�G722��ulaw�ULAW��alaw�ALAW��sowt�SOWT�unsupported compression typer"�not compressed)r#r�rr�r�rWr:r�rr�rp�	chunksizer��warnrr�r)rr�r-r�r�rkr�r�r�)rwrx�kludger*s    rrtzAifc_read._read_comm_chunk�s���%�e�,���"�5�)��
�&�u�-��1�a�7����k�%�0�1����?�?�a���*�+�+��?�?�a���+�,�,��/�/�D�O�O�;����:�:��F����"�$����
�
�<�=�"$���"�Z�Z��]�D�N���U�Z�Z�_�_�Q�/�0���A�:��?�#�a�Z�F�"'�/�/�F�":����
�
����A�&�)�%�0�D�N��~�~��(��>�>�W�,�$(�O�O�D�M��^�^�'9�9�$(�N�N�D�M��^�^�'9�9�$(�N�N�D�M��^�^�'9�9�$(�N�N�D�M�� >�?�?�"#���)�%�D�N�.�D�Nr
c�|�t|�}	t|�D]F}t|�}t|�}t|�}|s|s�)|jj|||f��Hy#t$rPdt|j��dt|j�dk(rdnd�d|��}tj|�YywxYw)Nz"Warning: MARK chunk contains only z markerr(�rOz instead of )
r#�rangerr-rl�appendrrMr�r�)rwrx�nmarkers�ir�r��name�ws        rruzAifc_read._readmarks����u�%��	��8�_�
:�� ��'�� ��'��#�E�*���$��M�M�(�(�"�c�4��9�
:���	��d�m�m�$�C��
�
�,>�!�,C�b��&L���A�
�M�M�!��		�s�3A"� A"�"AB;�:B;)r	r
rrnr{r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rtrurr
rr`r`s���H
�E�&@�P
�������������D�
�
>�#��*)�)��)�*/�Xr
r`c���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�Zd�Z d�Z!d �Z"d!�Z#d"�Z$d#�Z%d$�Z&d%�Z'd&�Z(y)'�
Aifc_writeNc��t|t�rBtj|d�}	|j	|�|j
d�rd|_yy|j	|�y#|j��xYw)N�wbz.aiffr)r~rr�rr{r��endswithrpr�s   rr�zAifc_write.__init__Csj���a���"�-�-��4�0�K�
����K�(��z�z�'�"���
�#�
�K�K��N��
��!�!�#��s�A%�%A8c���||_t|_d|_d|_d|_d|_d|_d|_d|_	d|_
d|_d|_g|_
d|_d|_y)Nr�r�rr()rn�
_AIFC_versionrjr�r�rkr�r�r�r��_nframeswritten�_datawritten�_datalengthrl�_marklengthrpr�s  rr{zAifc_write.initfpSso����
�%��
� ���*�����
������������
� �����������
������
r
c�$�|j�yr�r�r�s r�__del__zAifc_write.__del__dr�r
c��|Sr�rr�s rr�zAifc_write.__enter__gr�r
c�$�|j�yr�r�r�s  rr�zAifc_write.__exit__jr�r
c�@�|jrtd��d|_y)N�0cannot change parameters after starting to writer�rrrpr�s r�aiffzAifc_write.aiffp�������J�K�K���
r
c�@�|jrtd��d|_y)Nrr(rr�s r�aifczAifc_write.aifcurr
c�`�|jrtd��|dkrtd��||_y)Nrr(r�)rrr�)rw�	nchannelss  r�setnchannelszAifc_write.setnchannelszs1������J�K�K��q�=��+�,�,�#��r
c�H�|jstd��|jS)Nznumber of channels not set)r�rr�s rr�zAifc_write.getnchannels�s������4�5�5����r
c�j�|jrtd��|dks|dkDrtd��||_y)Nrr(rr�)rrr�)rw�	sampwidths  r�setsampwidthzAifc_write.setsampwidth�s7������J�K�K��q�=�I��M��*�+�+�#��r
c�H�|jstd��|jS)Nzsample width not set)r�rr�s rr�zAifc_write.getsampwidth�s������.�/�/����r
c�`�|jrtd��|dkrtd��||_y)Nrrzbad frame rate)rrr�)rw�	framerates  r�setframeratezAifc_write.setframerate�s1������J�K�K���>��(�)�)�#��r
c�H�|jstd��|jS)Nzframe rate not set)r�rr�s rr�zAifc_write.getframerate�s������,�-�-����r
c�@�|jrtd��||_y)Nr)rrr�)rwr�s  r�
setnframeszAifc_write.setnframes�s������J�K�K���
r
c��|jSr��rr�s rr�zAifc_write.getnframes�����#�#�#r
c�l�|jrtd��|dvrtd��||_||_y�Nr)r�r�r�r�r�r�r�r�r�)rrr�r�)rw�comptype�compnames   r�setcomptypezAifc_write.setcomptype�s@������J�K�K��I�I��6�7�7�!���!��r
c��|jSr�r�r�s rr�zAifc_write.getcomptype�r�r
c��|jSr�r�r�s rr�zAifc_write.getcompname�r�r
c��|\}}}}}}|jrtd��|dvrtd��|j|�|j|�|j	|�|j|�|j
||�yr()rrrrr r#r+)rw�paramsrrrr�r)r*s        r�	setparamszAifc_write.setparams�s���GM�D�	�9�i��(�H�����J�K�K��I�I��6�7�7����)�$����)�$����)�$����� �����8�,r
c��|jr|jr|jstd��t	|j|j|j|j
|j|j�S)Nznot all parameters set)r�r�r�rr^r�r�r�r�s rr�zAifc_write.getparams�sU�����d�o�o�T�_�_��0�1�1��D�O�O�T�_�_�d�o�o� �M�M�4�>�>�4�>�>�K�	Kr
c�N�|dkrtd��|dkrtd��t|t�std��tt	|j
��D]+}||j
|dk(s�|||f|j
|<y|j
j
|||f�y)Nrzmarker ID must be > 0zmarker position must be >= 0zmarker name must be bytes)rr~�bytesr�rMrlr�)rwr�r�r�r�s     r�setmarkzAifc_write.setmark�s���
��7��/�0�0���7��6�7�7��$��&��3�4�4��s�4�=�=�)�*�	�A��T�]�]�1�%�a�(�(�#%�s�D�=��
�
�a� ��	�	
�
�
���b�#�t�_�-r
c�p�|jD]}||dk(s�|cStdj|���r�r�r�s   rr�zAifc_write.getmark�r�r
c�L�t|j�dk(ry|jSr�r�r�s rr�zAifc_write.getmarkers�r�r
c��|jSr�r%r�s rr�zAifc_write.tell�r&r
c��t|ttf�st|�j	d�}|jt
|��t
|�|j|jzz}|jr|j|�}|jj|�|j|z|_|jt
|�z|_
y)NrK)r~r3�	bytearray�
memoryview�cast�_ensure_header_writtenrMr�r�rkrnr=rr)rwr+r�s   r�writeframesrawzAifc_write.writeframesraw�s����$��	� 2�3��d�#�(�(��-�D��#�#�C��I�.��d�)����$�/�/� A�B���=�=��=�=��&�D��
�
�����#�3�3�g�=��� �-�-��D�	�9��r
c��|j|�|j|jk7s|j|jk7r|j�yyr�)r=rr�r	r�_patchheader)rwr+s  r�writeframeszAifc_write.writeframes�sG�����D�!����4�=�=�0����$�"3�"3�3�����4r
c�,�|j�y	|jd�|jdzr/|jjd�|jdz|_|j	�|j
|jk7s%|j|jk7s|jr|j�d|_
|j}d|_|j�y#d|_
|j}d|_|j�wxYw)Nrr(rL)rnr<rr=�
_writemarkersrr�r	r
r?rkr�)rwr5s  rr�zAifc_write.close�s����:�:���	��'�'��*�� � �1�$��
�
� � ��)�$(�$5�$5��$9��!���� ��#�#�t�}�}�4��"�"�d�&7�&7�7��"�"��!�!�#�!�D�M��
�
�A��D�J�
�G�G�I��!�D�M��
�
�A��D�J�
�G�G�I�s�B-C'�',Dc��tj�5tjdt��ddl}ddd�j|d�S#1swY�xYwr�)r�r�r�r�r��lin2alawr�s   r�	_lin2alawzAifc_write._lin2alawr�r�c��tj�5tjdt��ddl}ddd�j|d�S#1swY�xYwr�)r�r�r�r�r��lin2ulawr�s   r�	_lin2ulawzAifc_write._lin2ulawr�r�c��tj�5tjdt��ddl}ddd�t|d�sd|_j|d|j�\}|_|S#1swY�CxYwr�)r�r�r�r�r�r�r��	lin2adpcmr�s   r�
_lin2adpcmzAifc_write._lin2adpcmsr��
�
$�
$�
&�	��!�!�(�5G�H��	��t�]�+�#�D��!(�!2�!2�4��D�<L�<L�!M���d����
	�	�r�c��tj�5tjdt��ddl}ddd�j|d�S#1swY�xYwr�r�r�s   r�	_lin2sowtzAifc_write._lin2sowt'r�r�c�@�|js�|jdvr-|jsd|_|jdk7rtd��|jstd��|jstd��|j
std��|j
|�yy)N)r�r�r�r�r�r�r�r"z]sample width must be 2 when compressing with ulaw/ULAW, alaw/ALAW, sowt/SOWT or G7.22 (ADPCM)z# channels not specifiedzsample width not specifiedzsampling rate not specified)rr�r�rr�r��
_write_header)rw�datasizes  rr<z!Aifc_write._ensure_header_written-s����#�#��~�~�""�"����&'�D�O��?�?�a�'��!3�4�4��?�?��6�7�7��?�?��8�9�9��?�?��9�:�:����x�(�!$r
c��|jdk(r|j|_y|jdvr|j|_y|jdvr|j|_y|jdvr|j
|_yy)Nr�r�r�r�)r�rKrkrHrErMr�s r�_init_compressionzAifc_write._init_compression@sf���>�>�W�$� �O�O�D�M�
�^�^�1�
1� �N�N�D�M�
�^�^�1�
1� �N�N�D�M�
�^�^�1�
1� �N�N�D�M�2r
c�h�|jr|jdk7r|j�|jj	d�|j
s!||j|jzz|_|j
|jz|jz|_|jdzr|jdz|_|jr�|jdvr8|jdz|_|jdzr^|jdz|_nI|jdk(r:|jdzdz|_|jdzr|jdz|_	|jj�|_
|j|j�}|jrm|jj	d	�|jj	d
�t|jd�t|j|j�n|jj	d�|jj	d�t|j|�t!|j|j�|j�|jj�|_t|j|j
�|jd
vrt!|jd�n#t!|j|jdz�t%|j|j&�|jrE|jj	|j�t)|j|j*�|jj	d�|j�|jj�|_t|j|jdz�t|jd�t|jd�y#ttf$rd|_
Y���wxYw)Nr�rbr()r�r�r�r�r"r�rrrdrhrcre)r�r�r�r�r�rgrfr)rpr�rRrnr=r�r�r�r	r��_form_length_pos�AttributeError�OSError�_write_form_lengthrHrjrA�_nframes_posrZr�rPr��_ssnd_length_pos)rw�
initlength�
commlengths   rrOzAifc_write._write_headerJs���:�:�$�.�.�G�3��"�"�$��
�
����!��}�}�&�4�?�?�T�_�_�+L�M�D�M��=�=�4�?�?�:�T�_�_�L������a��#�/�/�!�3�D���:�:��~�~�!E�E�#'�#3�#3�q�#8�� ��#�#�a�'�'+�'7�'7�!�';�D�$����7�*�$(�$4�$4�q�$8�Q�#>�� ��#�#�a�'�'+�'7�'7�!�';�D�$�	)�$(�J�J�O�O�$5�D�!��,�,�T�-=�-=�>�
��:�:��J�J���W�%��J�J���W�%�����Q�'�����T�]�]�3��J�J���W�%��
�
����!��T�Z�Z��,��T�Z�Z����1�� � �,� $�
�
��� 1�D���T�Z�Z����/��>�>�J�J�����Q�'�����T�_�_�q�%8�9��T�Z�Z����1��:�:��J�J���T�^�^�,��$�*�*�d�n�n�5��
�
����!�� � �,�$(�J�J�O�O�$5�D�!��T�Z�Z��!1�!1�A�!5�6��T�Z�Z��#��T�Z�Z��#��;��(�	)�$(�D�!�	)�s�P�P1�0P1c���|jr%dt|j�z}|dzr|dz}d}nd}d}t|jd|z|j
zdz|zdz|z�|S)	Nr�r(�r�rrrg�)rprMr�rHrnr
)rw�
datalengthr[�
verslengths    rrWzAifc_write._write_form_length}s����:�:��#�d�n�n�"5�5�J��A�~�'�!�^�
��J��J��J��T�Z�Z��Z��$�2B�2B�!B��"�#�"$�&(�")�+5�"6�	7��r
c�L�|jj�}|jdzr+|jdz}|jjd�n|j}||jk(rE|j
|jk(r,|jdk(r|jj|d�y|jj|jd�|j|�}|jj|jd�t|j|j�|jj|jd�t|j|dz�|jj|d�|j|_||_y)Nr(rLrrg)rnr�rr=r	r�rr
r�rTrWrXrHrY)rw�curposr_r,s    rr?zAifc_write._patchheader�s5�������"�����q� ��*�*�Q�.�J��J�J���W�%��*�*�J���)�)�)��m�m�t�3�3�3����!�#��J�J�O�O�F�A�&���
�
����-�-�q�1��'�'�
�3���
�
����)�)�1�-��T�Z�Z��!5�!5�6��
�
����-�-�q�1��T�Z�Z��a��0��
�
�����"��,�,��
�%��r
c�8�t|j�dk(ry|jjd�d}|jD]3}|\}}}|t|�zdzdz}t|�dzdk(s�/|dz}�5t	|j|�|dz|_t
|jt|j��|jD]J}|\}}}t
|j|�t	|j|�t|j|��Ly)Nrrir"r(�rg)rMrlrnr=rHr
rArP)rwr*r�r�r�r�s      rrBzAifc_write._writemarkers�s����t�}�}���"���
�
����!����m�m�	$�F�"�M�B��T��c�$�i�'�!�+�a�/�F��4�y�1�}��!��!���		$�
	�T�Z�Z��(�!�A�:����T�Z�Z��T�]�]�!3�4��m�m�	,�F�"�M�B��T�����R�(�����S�)��$�*�*�d�+�		,r
))r	r
rrnr�r{rr�r�rrrr�rr�r r�r#r�r+r�r�r0r�r4r�r�r�r=r@r�rErHrKrMr<rRrOrWr?rBrr
rrr#s���<
�E�� �"����
�
$��
$��
$��
 �
$�"���-�K�.�>��
$�	:� ��2)�)��)�)�&+�1$�f�&�,,r
rc��|�t|d�r
|j}nd}|dvrt|�S|dvrt|�St	d��)N�moder})�rr})r�rz$mode must be 'r', 'rb', 'w', or 'wb')r�rfr`rr)r5rfs  rrr�sO���|��1�f���6�6�D��D��{����|��	
��	��!�}���:�;�;r
�__main__r(z/usr/demos/data/audio/bach.aiffrg�Readingznchannels =znframes   =zsampwidth =zframerate =zcomptype  =zcompname  =r"�Writingr�izDone.r�);�__doc__rr�r��__all__�_deprecatedr	�	Exceptionrrrrr#r&r-r3r:rArDrFrHrPrZr�r�r�rxr\�collectionsr]r^rrrr�r)r*r`rr�sys�argvr��fnr5�printr�r�r�r�r�r��gn�gr0r�r�r+r@rr
r�<module>rvs���F�P����F�
������X�g�.�	�I�	��
�!�!�!�!��
"�	��""�"�"�"���B�X������H���(�$6�7���#��.�S�U��"W�����!8�����!5�����7����� J�����"%�����
M�M�^N,�N,�`<��z����8�8�A�B�<������9�:�	���!��B�	
�b�#���!�
�i���
�m�Q�^�^�-�.�
�m�Q�\�\�^�,�
�m�Q�^�^�-�.�
�m�Q�^�^�-�.�
�m�Q�]�]�_�-�
�m�Q�]�]�_�-��8�8�A�B�<����!��B��)�R� ��b�#��
(�!����A�K�K�M�*���<�<��-�D����M�M�$�'�	��
(�
�'�N�%������^
(�
(����s2�+J�&CJ%�*AJ�2J%�J�J"	�J%�%J.

Zerion Mini Shell 1.0