%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python311/lib64/python3.11/__pycache__/
Upload File :
Create Path :
Current File : //opt/alt/python311/lib64/python3.11/__pycache__/aifc.cpython-311.pyc

�

c��f������dZddlZddlZddlZddgZejed���Gd�de��ZdZ	d	�Z
d
�Zd�Zd�Z
d
�ZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Zej��5ejde��ddlmZddd��n#1swxYwYddlmZedd��Zdej_dej _dej!_dej"_dej#_d ej$_Gd!�d"��Z%Gd#�d$��Z&d6d%�Z'ed&k�r�ddl(Z(e(j)d'd�se(j)�*d(��e(j)d'Z+e'e+d)��5Z,e-d*e+��e-d+e,�.����e-d,e,�/����e-d-e,�0����e-d.e,�1����e-d/e,�2����e-d0e,�3����e(j)d1d�r�e(j)d1Z4e-d2e4��e'e4d3��5Z5e5�6e,�7����	e,�8d4��Z9e9sne5�:e9���.	ddd��n#1swxYwYe-d5��ddd��dS#1swxYwYdSdS)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��eZdZdS)rN)�__name__�
__module__�__qualname__���+/opt/alt/python311/lib64/python3.11/aifc.pyrr�s�������Dr
l@QEc��	tjd|�d����dS#tj$r	td�wxYw)N�>l�r��struct�unpack�read�error�EOFError��files r�
_read_longr��M��!��}�T�4�9�9�Q�<�<�0�0��3�3���<�!�!�!��D� �!����	�-0�Ac��	tjd|�d����dS#tj$r	td�wxYw)N�>Lrrrrs r�_read_ulongr�rrc��	tjd|�d����dS#tj$r	td�wxYw)N�>h�rrrs r�_read_shortr#�rrc��	tjd|�d����dS#tj$r	td�wxYw)N�>Hr"rrrs r�_read_ushortr&�rrc���t|�d����}|dkrd}n|�|��}|dzdkr|�d��}|S)N�rr
)�ordr)r�length�data�dummys    r�_read_stringr-�s[��
����1���
�
�F�
��{�{�����y�y�� � ��
��z�Q����	�	�!�����Kr
g�����c��t|��}d}|dkrd}|dz}t|��}t|��}||cxkr
|cxkrdkrnnd}n/|dkrt}n!|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�N�E��D��q�y�y�������
��^�^�F�
��^�^�F���%�%�%�%�&�%�%�%�%�A�%�%�%�%�%����	�&��������
��
�k�
!�F�
*�c�#�u�r�z�.B�.B�B���!�8�Or
c�V�|�tjd|����dS)Nr!��writer�pack�r5�xs  r�_write_shortrA��&���G�G�F�K��a� � �!�!�!�!�!r
c�V�|�tjd|����dS)Nr%r<r?s  r�
_write_ushortrD�rBr
c�V�|�tjd|����dS)Nrr<r?s  r�_write_longrF�rBr
c�V�|�tjd|����dS)Nrr<r?s  r�_write_ulongrH�rBr
c�8�t|��dkrtd���|�tjdt|������|�|��t|��dzdkr|�d��dSdS)N�z%string exceeds maximum pstring length�Br(r�)�len�
ValueErrorr=rr>)r5�ss  r�
_write_stringrP�s���
�1�v�v��|�|��@�A�A�A��G�G�F�K��S��V�V�$�$�%�%�%��G�G�A�J�J�J�
�1�v�v��z�Q���	����������r
c�N�ddl}|dkrd}|dz}nd}|dkrd}d}d}n�|�|��\}}|dks|dks||kr
|dz}d}d}n�|dz}|dkr|�||��}d}||z}|�|d��}|�|��}t	|��}|�||z
d��}|�|��}t	|��}t||��t
||��t
||��dS)	Nrr0r/i@r(r1i�?� )�math�frexp�ldexp�floor�intrDrH)	r5r@rSr7r6r8r9�fmant�fsmants	         r�_write_floatrZ�sO���K�K�K��1�u�u���
��F������A�v�v���������z�z�!�}�}���u��5�=�=�E�Q�J�J�%�5�.�.���K�E��F��F�F��E�M�E��q�y�y��
�
�5�%�0�0�����D�L�E��J�J�u�b�)�)�E��Z�Z��&�&�F���[�[�F��J�J�u�v�~�r�2�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�ZdS)�	Aifc_readNc�B�d|_d|_g|_d|_||_t|��}|���dkrtd���|�d��}|dkrd|_	n|dkrd|_	ntd���d|_
d|_	d|_	t|j��}n#t$rYn�wxYw|���}|d	kr|�|��d|_
n`|d
kr$||_|�d��}d|_n6|dkrt|��|_n|d
kr|�|��|�����|j
r|jstd���dS)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:s�����
���
���
������
��d�����=�=�?�?�g�%�%��:�;�;�;��:�:�a�=�=���w����D�J�J�
��
 �
 ��D�J�J��4�5�5�5� !������	�%&�D�"�
��d�j�)�)�����
�
�
���
�����
�
���I��G�#�#��%�%�e�,�,�,�()��%�%��g�%�%�#(�� ��
�
�1�
�
��)*��&�&��g�%�%� +�E� 2� 2��
�
��g�%�%����u�%�%�%��J�J�L�L�L�%	�&�$�	@�D�,<�	@��>�?�?�?�	@�	@s�1C�
C�Cc���t|t��rGtj|d��}	|�|��dS#|����xYw|�|��dS)N�rb)�
isinstance�str�builtinsrr{�close�rwr5�file_objects   r�__init__zAifc_read.__init__bsu���a����		�"�-��4�0�0�K�
����K�(�(�(�(�(��
��!�!�#�#�#�����
�K�K��N�N�N�N�Ns�A�Ac��|S�Nr�rws r�	__enter__zAifc_read.__enter__n����r
c�.�|���dSr��r��rw�argss  r�__exit__zAifc_read.__exit__q����
�
�����r
c��|jSr�)rnr�s r�getfpzAifc_read.getfpws
���z�r
c�"�d|_d|_dS)Nr(r)rsrmr�s r�rewindzAifc_read.rewindzs��!"�������r
c�R�|j}|�d|_|���dSdSr�)rnr��rwrs  rr�zAifc_read.close~s/���z�����D�J��J�J�L�L�L�L�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|���|���|���|���|���|�����Sr�)r^r�r�r�r�r�r�r�s r�	getparamszAifc_read.getparams�sk���D�-�-�/�/��1B�1B�1D�1D� �-�-�/�/����1B�1B� �,�,�.�.��0@�0@�0B�0B�D�D�	Dr
c�D�t|j��dkrdS|jS�Nr�rMrlr�s r�
getmarkerszAifc_read.getmarkers��$���t�}����"�"��4��}�r
c�z�|jD]}||dkr|cS�td�|������Nrzmarker {0!r} does not exist�rlr�format�rw�id�markers   r�getmarkzAifc_read.getmark��K���m�	�	�F��V�A�Y����
�
�
���1�8�8��<�<�=�=�=r
c�b�|dks||jkrtd���||_d|_dS)Nrzposition not in ranger()r�rrmrs)rw�poss  r�setposzAifc_read.setpos�s;����7�7�c�D�M�)�)��/�0�0�0����!"����r
c���|jri|j�d��|j�d��}|j|jz}|r|j�|dz��d|_|dkrdS|j�||jz��}|jr|r|�|��}|jt|��|j|j	zzz|_|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�<�<��3���$�$�W�t��%>�?�?���=�	'�T�	'��=�=��&�&�D���#�d�)�)���:>�/�9J�+K�K����r
c���tj��5tjdt���ddl}ddd��n#1swxYwY|�|d��S�Nr[��categoryrr")�warnings�catch_warnings�simplefilter�DeprecationWarning�audioop�alaw2lin�rwr+r�s   r�	_alaw2linzAifc_read._alaw2lin����
�
$�
&�
&�	�	��!�(�5G�H�H�H�H��N�N�N�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�����a�(�(�(�� A�A�Ac���tj��5tjdt���ddl}ddd��n#1swxYwY|�|d��Sr�)r�r�r�r�r��ulaw2linr�s   r�	_ulaw2linzAifc_read._ulaw2lin�r�r�c��tj��5tjdt���ddl}ddd��n#1swxYwYt|d��sd|_|�|d|j��\}|_|S�Nr[r�r�_adpcmstater")r�r�r�r�r��hasattrr��	adpcm2linr�s   r�
_adpcm2linzAifc_read._adpcm2lin�s���
�
$�
&�
&�	�	��!�(�5G�H�H�H�H��N�N�N�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	��t�]�+�+�	$�#�D��!(�!2�!2�4��D�<L�!M�!M���d���r�c���tj��5tjdt���ddl}ddd��n#1swxYwY|�|d��Sr��r�r�r�r�r��byteswapr�s   r�	_sowt2linzAifc_read._sowt2lin�r�r�c��t|��|_t|��|_t|��dzdz|_tt
|����|_|jdkrtd���|jdkrtd���|j|jz|_	|j
�r8d}|jdkrd}tj
d��d	|_|�d
��|_|r_t!|j�d����}|dzdkr|dz}|j|z|_|j�dd��t'|��|_|jdkrr|jd
kr
|j|_nQ|jdvr
|j|_n;|jdvr
|j|_n%|jdvr
|j|_ntd���d|_dSdSd|_d|_dS)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�0�1�1����?�a����*�+�+�+��?�a����+�,�,�,��/�D�O�;����:� 	/��F���"�$�$����
�<�=�=�=�"$���"�Z�Z��]�]�D�N��
'��U�Z�_�_�Q�/�/�0�0���A�:��?�?�#�a�Z�F�"'�/�F�":����
����A�&�&�&�)�%�0�0�D�N��~��(�(��>�W�,�,�$(�O�D�M�M��^�'9�9�9�$(�N�D�M�M��^�'9�9�9�$(�N�D�M�M��^�'9�9�9�$(�N�D�M�M�� >�?�?�?�"#�����)�(�%�D�N�.�D�N�N�Nr
c��t|��}	t|��D]P}t|��}t|��}t|��}|s|r|j�|||f���QdS#t$rOdt|j���dt|j��dkrdnd�d|��}tj	|��YdSwxYw)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�(�(�"�c�4��9�9�9��
:�
:���	�	�	�	��d�m�$�$�$�$�C��
�,>�,>�!�,C�,C�b�b��&L�&L��(��A�
�M�!�������		���s�A A3�3AC�C)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�D�D�
���
>�>�>�#�#�#����*)�)�)�)�)�)����)�)�)�*/�*/�*/�X����r
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(dS)'�
Aifc_writeNc�&�t|t��rftj|d��}	|�|��n#|����xYw|�d��r	d|_dSdS|�|��dS)N�wbz.aiffr)r~rr�rr{r��endswithrpr�s   rr�zAifc_write.__init__Cs����a����
	�"�-��4�0�0�K�
����K�(�(�(�(��
��!�!�#�#�#������z�z�'�"�"�
���
�
�
�
�
�
�K�K��N�N�N�N�Ns�A�Ac���||_t|_d|_d|_d|_d|_d|_d|_d|_	d|_
d|_d|_g|_
d|_d|_dS)Nr�r�rr()rn�
_AIFC_versionrjr�r�rkr�r�r�r��_nframeswritten�_datawritten�_datalengthrl�_marklengthrpr�s  rr{zAifc_write.initfpSss����
�%��
� ���*�����
������������
� �����������
������
�
�
r
c�.�|���dSr�r�r�s r�__del__zAifc_write.__del__dr�r
c��|Sr�rr�s rr�zAifc_write.__enter__gr�r
c�.�|���dSr�r�r�s  rr�zAifc_write.__exit__jr�r
c�@�|jrtd���d|_dS)N�0cannot change parameters after starting to writer�rrrpr�s r�aiffzAifc_write.aiffp�(����	L��J�K�K�K���
�
�
r
c�@�|jrtd���d|_dS)Nrr(rr�s r�aifczAifc_write.aifcurr
c�j�|jrtd���|dkrtd���||_dS)Nrr(r�)rrr�)rw�	nchannelss  r�setnchannelszAifc_write.setnchannelszs@����	L��J�K�K�K��q�=�=��+�,�,�,�#����r
c�<�|jstd���|jS)Nznumber of channels not set)r�rr�s rr�zAifc_write.getnchannels�s#����	6��4�5�5�5���r
c�v�|jrtd���|dks|dkrtd���||_dS)Nrr(rr�)rrr�)rw�	sampwidths  r�setsampwidthzAifc_write.setsampwidth�sH����	L��J�K�K�K��q�=�=�I��M�M��*�+�+�+�#����r
c�<�|jstd���|jS)Nzsample width not set)r�rr�s rr�zAifc_write.getsampwidth�s#����	0��.�/�/�/���r
c�j�|jrtd���|dkrtd���||_dS)Nrrzbad frame rate)rrr�)rw�	framerates  r�setframeratezAifc_write.setframerate�s@����	L��J�K�K�K���>�>��(�)�)�)�#����r
c�<�|jstd���|jS)Nzframe rate not set)r�rr�s rr�zAifc_write.getframerate�s#����	.��,�-�-�-���r
c�@�|jrtd���||_dS)Nr)rrr�)rwr�s  r�
setnframeszAifc_write.setnframes�s(����	L��J�K�K�K���
�
�
r
c��|jSr��rr�s rr�zAifc_write.getnframes�����#�#r
c�t�|jrtd���|dvrtd���||_||_dS�Nr)r�r�r�r�r�r�r�r�r�)rrr�r�)rw�comptype�compnames   r�setcomptypezAifc_write.setcomptype�sS����	L��J�K�K�K��I�I�I��6�7�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���|�|��|�|��|�|��|�|��|�||��dSr')rrrrrr"r*)rw�paramsrrrr�r(r)s        r�	setparamszAifc_write.setparams�s���GM�D�	�9�i��(�H���	L��J�K�K�K��I�I�I��6�7�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�s[����	2�d�o�	2�T�_�	2��0�1�1�1��D�O�T�_�d�o� �M�4�>�4�>�K�K�	Kr
c�r�|dkrtd���|dkrtd���t|t��std���tt	|j����D])}||j|dkr|||f|j|<dS�*|j�|||f��dS)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�7��/�0�0�0���7�7��6�7�7�7��$��&�&�	5��3�4�4�4��s�4�=�)�)�*�*�	�	�A��T�]�1�%�a�(�(�(�#%�s�D�=��
�a� ����)�	
�
���b�#�t�_�-�-�-�-�-r
c�z�|jD]}||dkr|cS�td�|�����r�r�r�s   rr�zAifc_write.getmark�r�r
c�D�t|j��dkrdS|jSr�r�r�s rr�zAifc_write.getmarkers�r�r
c��|jSr�r$r�s rr�zAifc_write.tell�r%r
c���t|ttf��s"t|���d��}|�t
|����t
|��|j|jzz}|j	r|�	|��}|j
�|��|j|z|_|j
t
|��z|_
dS)NrK)r~r2�	bytearray�
memoryview�cast�_ensure_header_writtenrMr�r�rkrnr=rr)rwr+r�s   r�writeframesrawzAifc_write.writeframesraw�s����$��	� 2�3�3�	.��d�#�#�(�(��-�-�D��#�#�C��I�I�.�.�.��d�)�)���$�/� A�B���=�	'��=�=��&�&�D��
�������#�3�g�=��� �-��D�	�	�9����r
c��|�|��|j|jks|j|jkr|���dSdSr�)r<rr�rr�_patchheader)rwr+s  r�writeframeszAifc_write.writeframes�sW�����D�!�!�!���4�=�0�0���$�"3�3�3���������4�3r
c��|j�dS	|�d��|jdzr)|j�d��|jdz|_|���|j|jks|j|jks|jr|�	��d|_
|j}d|_|���dS#d|_
|j}d|_|���wxYw)Nrr(rL)rnr;rr=�
_writemarkersrr�rr	r>rkr�)rwr5s  rr�zAifc_write.close�s���:���F�	��'�'��*�*�*�� �1�$�
:��
� � ��)�)�)�$(�$5��$9��!���� � � ��#�t�}�4�4��"�d�&7�7�7��"�8��!�!�#�#�#�!�D�M��
�A��D�J�
�G�G�I�I�I�I�I��!�D�M��
�A��D�J�
�G�G�I�I�I�I���s�BC
�
+C8c���tj��5tjdt���ddl}ddd��n#1swxYwY|�|d��Sr�)r�r�r�r�r��lin2alawr�s   r�	_lin2alawzAifc_write._lin2alawr�r�c���tj��5tjdt���ddl}ddd��n#1swxYwY|�|d��Sr�)r�r�r�r�r��lin2ulawr�s   r�	_lin2ulawzAifc_write._lin2ulawr�r�c��tj��5tjdt���ddl}ddd��n#1swxYwYt|d��sd|_|�|d|j��\}|_|Sr�)r�r�r�r�r�r�r��	lin2adpcmr�s   r�
_lin2adpcmzAifc_write._lin2adpcms���
�
$�
&�
&�	�	��!�(�5G�H�H�H�H��N�N�N�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	��t�]�+�+�	$�#�D��!(�!2�!2�4��D�<L�!M�!M���d���r�c���tj��5tjdt���ddl}ddd��n#1swxYwY|�|d��Sr�r�r�s   r�	_lin2sowtzAifc_write._lin2sowt'r�r�c�(�|js�|jdvr(|jsd|_|jdkrtd���|jstd���|jstd���|jstd���|�|��dSdS)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�4��?�
8��6�7�7�7��?�
:��8�9�9�9��?�
;��9�:�:�:����x�(�(�(�(�(�!	)�	)r
c���|jdkr|j|_dS|jdvr|j|_dS|jdvr|j|_dS|jdvr|j|_dSdS)Nr�r�r�r�)r�rJrkrGrDrLr�s r�_init_compressionzAifc_write._init_compression@su���>�W�$�$� �O�D�M�M�M�
�^�1�
1�
1� �N�D�M�M�M�
�^�1�
1�
1� �N�D�M�M�M�
�^�1�
1�
1� �N�D�M�M�M�2�
1r
c��|jr|jdkr|���|j�d��|js||j|jzz|_|j|jz|jz|_|jdzr|jdz|_|jrh|jdvr)|jdz|_|jdzr|jdz|_n6|jdkr+|jdzdz|_|jdzr|jdz|_	|j�	��|_
n#ttf$r
d|_
YnwxYw|�
|j��}|jrd|j�d	��|j�d
��t|jd��t|j|j��n|j�d��|j�d��t|j|��t!|j|j��|j
�|j�	��|_t|j|j��|jd
vrt!|jd��nt!|j|jdz��t%|j|j��|jr9|j�|j��t)|j|j��|j�d��|j
�|j�	��|_t|j|jdz��t|jd��t|jd��dS)Nr�rbr()r�r�r�r�r"r�rrrdrhrcre)r�r�r�r�r�rgrfr)rpr�rQrnr=r�r�r�rr��_form_length_pos�AttributeError�OSError�_write_form_lengthrHrjrA�_nframes_posrZr�rPr��_ssnd_length_pos)rw�
initlength�
commlengths   rrNzAifc_write._write_headerJsb���:�	%�$�.�G�3�3��"�"�$�$�$��
����!�!�!��}�	N�&�4�?�T�_�+L�M�D�M��=�4�?�:�T�_�L�����a��	4�#�/�!�3�D���:�	<��~�!E�E�E�#'�#3�q�#8�� ��#�a�'�<�'+�'7�!�';�D�$����7�*�*�$(�$4�q�$8�Q�#>�� ��#�a�'�<�'+�'7�!�';�D�$�	)�$(�J�O�O�$5�$5�D�!�!����(�	)�	)�	)�$(�D�!�!�!�	)�����,�,�T�-=�>�>�
��:�	&��J���W�%�%�%��J���W�%�%�%����Q�'�'�'����T�]�3�3�3�3��J���W�%�%�%��
����!�!�!��T�Z��,�,�,��T�Z���1�1�1�� �,� $�
��� 1� 1�D���T�Z���/�/�/��>�J�J�J����Q�'�'�'�'����T�_�q�%8�9�9�9��T�Z���1�1�1��:�	6��J���T�^�,�,�,��$�*�d�n�5�5�5��
����!�!�!�� �,�$(�J�O�O�$5�$5�D�!��T�Z��!1�A�!5�6�6�6��T�Z��#�#�#��T�Z��#�#�#�#�#s�D#�#D>�=D>c��|jr$dt|j��z}|dzr|dz}d}nd}d}t|jd|z|jzdz|zdz|z��|S)	Nr�r(�r�rrrg�)rprMr�rHrnr	)rw�
datalengthrZ�
verslengths    rrVzAifc_write._write_form_length}s����:�	��#�d�n�"5�"5�5�J��A�~�
,�'�!�^�
��J�J��J��J��T�Z��Z��$�2B�!B��"�#�"$�&(�")�+5�"6�	7�	7�	7��r
c���|j���}|jdzr%|jdz}|j�d��n|j}||jkr8|j|jkr(|jdkr|j�|d��dS|j�|j	d��|�
|��}|j�|jd��t|j|j��|j�|j
d��t|j|dz��|j�|d��|j|_||_dS)Nr(rLrrg)rnr�rr=rr�rr	r�rSrVrWrHrX)rw�curposr^r,s    rr>zAifc_write._patchheader�sO������"�"����q� �	+��*�Q�.�J��J���W�%�%�%�%��*�J���)�)�)��m�t�3�3�3���!�#�#��J�O�O�F�A�&�&�&��F��
����-�q�1�1�1��'�'�
�3�3���
����)�1�-�-�-��T�Z��!5�6�6�6��
����-�q�1�1�1��T�Z��a��0�0�0��
�����"�"�"��,��
�%����r
c�"�t|j��dkrdS|j�d��d}|jD];}|\}}}|t|��zdzdz}t|��dzdkr|dz}�<t	|j|��|dz|_t
|jt|j����|jD]G}|\}}}t
|j|��t	|j|��t|j|���HdS)Nrrir"r(�rg)rMrlrnr=rHr	rArP)rwr*r�r�r�r�s      rrAzAifc_write._writemarkers�s%���t�}����"�"��F��
����!�!�!����m�	$�	$�F�"�M�B��T��c�$�i�i�'�!�+�a�/�F��4�y�y�1�}��!�!��!�����T�Z��(�(�(�!�A�:����T�Z��T�]�!3�!3�4�4�4��m�	,�	,�F�"�M�B��T����R�(�(�(����S�)�)�)��$�*�d�+�+�+�+�		,�	,r
))r	r
rrnr�r{rr�r�rrrr�rr�rr�r"r�r*r�r�r/r�r3r�r�r�r<r?r�rDrGrJrLr;rQrNrVr>rArr
rrr#sJ������<
�E���� ���"������������
���
$�$�$����
$�$�$����
$�$�$����
 � � �
$�$�$�"�"�"�������-�-�-�K�K�K�.�.�.�>�>�>����
$�$�$�	:�	:�	:� � � ����2)�)�)�)�)�)����)�)�)�)�)�)�&+�+�+�1$�1$�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�rer`rr)r5res  rrr�sd���|��1�f���	��6�D�D��D��{�����|�|��	
��	�	��!�}�}���:�;�;�;r
�__main__r(z/usr/demos/data/audio/bach.aiffrf�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�gr/r�r�r+r?rr
r�<module>rus%��F�F�P�
�
�
����������F�
�����X�g�.�.�.�.�	�	�	�	�	�I�	�	�	��
�!�!�!�!�!�!�!�!�!�!�!�!����
"�	����""�"�"�"�"�"�"�"�"�"�"�"�������B�X�������H��(�$6�7�7�7�������������������������#�"�"�"�"�"��z�.�S�U�U��"W����!8����!5����7���� J����"%����
M�M�M�M�M�M�M�M�^N,�N,�N,�N,�N,�N,�N,�N,�`<�<�<�<��z����J�J�J��8�A�B�B�<�;�����9�:�:�:�	��!��B�	
��b�#����!�
��i�����
��m�Q�^�^�-�-�.�.�.�
��m�Q�\�\�^�^�,�,�,�
��m�Q�^�^�-�-�.�.�.�
��m�Q�^�^�-�-�.�.�.�
��m�Q�]�]�_�_�-�-�-�
��m�Q�]�]�_�_�-�-�-��8�A�B�B�<�
	���!��B��E�)�R� � � ���b�#���
(�!����A�K�K�M�M�*�*�*�(��<�<��-�-�D�����M�M�$�'�'�'�	(��
(�
(�
(�
(�
(�
(�
(�
(�
(�
(�
(����
(�
(�
(�
(�
�E�'�N�N�N�%����������������������sJ�*B�B�B�C5K�AJ7�+K�7J;	�;K�>J;	�?K�K�!K

Zerion Mini Shell 1.0