Hacked By AnonymousFox

Current Path : /proc/thread-self/root/opt/alt/python39/lib64/python3.9/__pycache__/
Upload File :
Current File : //proc/thread-self/root/opt/alt/python39/lib64/python3.9/__pycache__/aifc.cpython-39.pyc

a

R�f]�	@sbdZddlZddlZddlZddgZGdd�de�ZdZdd�Zd	d
�Z	dd�Z
d
d�Zdd�ZdZ
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd lmZdd!lmZed"d#�Zd$ej_d%ej_d&ej_d'ej_d(ej_d)ej_Gd*d+�d+�Z Gd,d-�d-�Z!d?d.d�Z"e#d/k�r^ddl$Z$e$j%d0d��sBe$j%�&d1�e$j%d0Z'e"e'd2���Z(e)d3e'�e)d4e(�*��e)d5e(�+��e)d6e(�,��e)d7e(�-��e)d8e(�.��e)d9e(�/��e$j%d:d��r>e$j%d:Z0e)d;e0�e"e0d<��@Z1e1�2e(�3��e(�4d=�Z5e5�s�qe1�6e5��q�Wd�n1�s,0Ye)d>�Wd�n1�sT0YdS)@aJStuff 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�openc@seZdZdS)rN)�__name__�
__module__�__qualname__�rr�)/opt/alt/python39/lib64/python3.9/aifc.pyr�sl@QEcCs8zt�d|�d��dWStjy2td�Yn0dS)N�>l�r��structZunpack�read�error�EOFError��filerrr�
_read_long�srcCs8zt�d|�d��dWStjy2td�Yn0dS)N�>Lr
rrrrrr�_read_ulong�srcCs8zt�d|�d��dWStjy2td�Yn0dS)N�>h�rrrrrr�_read_short�srcCs8zt�d|�d��dWStjy2td�Yn0dS)N�>Hrrrrrrr�_read_ushort�srcCs@t|�d��}|dkrd}n
|�|�}|d@dkr<|�d�}|S)N�r�)�ordr
)r�length�data�dummyrrr�_read_string�s

r g�����cCs�t|�}d}|dkr d}|d}t|�}t|�}||krN|krNdkrXnnd}n0|dkrft}n"|d}|d|td	|d
�}||S)Nrr�����g�i�?lg@�?)rr�	_HUGE_VAL�pow)�f�expon�sign�himant�lomantrrr�_read_float�s"r,cCs|�t�d|��dS)Nr��writer�pack�r'�xrrr�_write_short�sr2cCs|�t�d|��dS)Nrr-r0rrr�
_write_ushort�sr3cCs|�t�d|��dS)Nr	r-r0rrr�_write_long�sr4cCs|�t�d|��dS)Nrr-r0rrr�_write_ulong�sr5cCsRt|�dkrtd��|�t�dt|���|�|�t|�d@dkrN|�d�dS)N�z%string exceeds maximum pstring length�Brr�)�len�
ValueErrorr.rr/)r'�srrr�
_write_string�s
r<c	Cs�ddl}|dkrd}|d}nd}|dkr8d}d}d}n�|�|�\}}|dks^|dks^||krp|dB}d}d}nh|d}|dkr�|�||�}d}||B}|�|d�}|�|�}t|�}|�||d�}|�|�}t|�}t||�t||�t||�dS)	Nrr"r!i@rr#i�?� )�mathZfrexpZldexpZfloor�intr3r5)	r'r1r>r)r(r*r+ZfmantZfsmantrrr�_write_float�s8




r@)�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@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�ZdS)2�	Aifc_readNcCs6d|_d|_g|_d|_||_t|�}|��dkr:td��|�d�}|dkrTd|_	n|dkrdd|_	ntd��d|_
d|_d|_zt|j�}Wnt
y�Y�qYn0|��}|d	kr�|�|�d|_
nH|d
kr�||_|�d�}d|_n(|dkr�t|�|_n|d
k�r|�|�|��qx|j
�r*|j�s2td��dS)Nr�FORMz file does not start with FORM idr
�AIFF�AIFCrznot an AIFF or AIFF-C file�COMM�SSND��FVER�MARKz$COMM chunk and/or SSND chunk missing)�_version�_convert�_markers�	_soundpos�_filerAZgetnamerr
�_aifcZ_comm_chunk_read�_ssnd_chunk�_ssnd_seek_neededr�_read_comm_chunkr�	_readmark�skip)�selfr�chunkZformdataZ	chunknamerrrr�initfp4sH





zAifc_read.initfpcCsLt|t�r>t�|d�}z|�|�WqH|���YqH0n
|�|�dS)N�rb)�
isinstance�str�builtinsrrZ�close�rXr'Zfile_objectrrr�__init__\s

zAifc_read.__init__cCs|S�Nr�rXrrr�	__enter__hszAifc_read.__enter__cGs|��dSrb�r_�rX�argsrrr�__exit__kszAifc_read.__exit__cCs|jSrb)rQrcrrr�getfpqszAifc_read.getfpcCsd|_d|_dS)Nrr)rTrPrcrrr�rewindtszAifc_read.rewindcCs |j}|durd|_|��dSrb)rQr_�rXrrrrr_xszAifc_read.closecCs|jSrb)rPrcrrr�tell~szAifc_read.tellcCs|jSrb)�
_nchannelsrcrrr�getnchannels�szAifc_read.getnchannelscCs|jSrb)�_nframesrcrrr�
getnframes�szAifc_read.getnframescCs|jSrb)�
_sampwidthrcrrr�getsampwidth�szAifc_read.getsampwidthcCs|jSrb)�
_frameratercrrr�getframerate�szAifc_read.getframeratecCs|jSrb��	_comptypercrrr�getcomptype�szAifc_read.getcomptypecCs|jSrb��	_compnamercrrr�getcompname�szAifc_read.getcompnamecCs*t|��|��|��|��|��|���Srb)rCrnrrrtrprwrzrcrrr�	getparams�s�zAifc_read.getparamscCst|j�dkrdS|jS�Nr�r9rOrcrrr�
getmarkers�szAifc_read.getmarkerscCs2|jD]}||dkr|Sqtd�|���dS�Nrzmarker {0!r} does not exist�rOr�format�rX�id�markerrrr�getmark�s

zAifc_read.getmarkcCs*|dks||jkrtd��||_d|_dS)Nrzposition not in ranger)rorrPrT)rX�posrrr�setpos�szAifc_read.setposcCs�|jrD|j�d�|j�d�}|j|j}|r>|j�|d�d|_|dkrPdS|j�||j�}|jrv|rv|�|�}|jt|�|j|j	|_|S)NrrJr)
rTrS�seekr
rP�
_framesizerNr9rmrq)rX�nframesrr�rrrr�
readframes�s 

�
zAifc_read.readframescCsddl}|�|d�S�Nrr)�audioopZalaw2lin�rXrr�rrr�	_alaw2lin�szAifc_read._alaw2lincCsddl}|�|d�Sr�)r�Zulaw2linr�rrr�	_ulaw2lin�szAifc_read._ulaw2lincCs2ddl}t|d�sd|_|�|d|j�\}|_|S�Nr�_adpcmstater)r��hasattrr�Z	adpcm2linr�rrr�
_adpcm2lin�s

zAifc_read._adpcm2lincCsVt|�|_t|�|_t|�dd|_tt|��|_|jdkrFtd��|jdkrXtd��|j|j|_	|j
�rFd}|jdkr�d}t�
d�d	|_|�d
�|_|r�t|j�d��}|d@dkr�|d}|j||_|j�dd�t|�|_|jdk�rR|jd
k�r
|j|_n4|jdv�r |j|_n|jdv�r6|j|_ntd��d|_nd|_d|_dS)N�rJr�bad sample width�bad # of channels�rzWarning: bad COMM chunk size�r
r!�NONE�G722��ulaw�ULAW��alaw�ALAW�unsupported compression typer�not compressed)rrmrrorqr?r,rsrr�rRZ	chunksize�warnings�warnr
rvrrr�r ryr�rNr�r�)rXrYZkludgerrrrrU�sD









zAifc_read._read_comm_chunkcCs�t|�}zDt|�D]6}t|�}t|�}t|�}|s6|r|j�|||f�qWnBty�dt|j�t|j�dkrvdnd|f}t�	|�Yn0dS)Nz;Warning: MARK chunk contains only %s marker%s instead of %sr�r;)
r�rangerr rO�appendrr9r�r�)rXrYZnmarkers�ir�r��name�wrrrrV�s��zAifc_read._readmark)rrrrQrZrardrhrirjr_rlrnrprrrtrwrzr{r~r�r�r�r�r�r�rUrVrrrrrDs2$(*rDc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dBdC�Z$dDdE�Z%dFdG�Z&dHdI�Z'dS)J�
Aifc_writeNcCs\t|t�rNt�|d�}z|�|�Wn|���Yn0|�d�rXd|_n
|�|�dS)N�wbz.aiffr)r\r]r^rrZr_�endswithrRr`rrrra/s

zAifc_write.__init__cCs^||_t|_d|_d|_d|_d|_d|_d|_d|_	d|_
d|_d|_g|_
d|_d|_dS)Nr�r�rr)rQ�
_AIFC_versionrMrvryrNrmrqrsro�_nframeswritten�_datawritten�_datalengthrO�_marklengthrRrkrrrrZ?szAifc_write.initfpcCs|��dSrbrercrrr�__del__PszAifc_write.__del__cCs|SrbrrcrrrrdSszAifc_write.__enter__cGs|��dSrbrerfrrrrhVszAifc_write.__exit__cCs|jrtd��d|_dS)N�0cannot change parameters after starting to writer�r�rrRrcrrr�aiff\szAifc_write.aiffcCs|jrtd��d|_dS)Nr�rr�rcrrr�aifcaszAifc_write.aifccCs(|jrtd��|dkrtd��||_dS)Nr�rr�)r�rrm)rX�	nchannelsrrr�setnchannelsfs
zAifc_write.setnchannelscCs|jstd��|jS)Nznumber of channels not set)rmrrcrrrrnmszAifc_write.getnchannelscCs0|jrtd��|dks|dkr&td��||_dS)Nr�rr
r�)r�rrq)rX�	sampwidthrrr�setsampwidthrs
zAifc_write.setsampwidthcCs|jstd��|jS)Nzsample width not set)rqrrcrrrrryszAifc_write.getsampwidthcCs(|jrtd��|dkrtd��||_dS)Nr�rzbad frame rate)r�rrs)rX�	frameraterrr�setframerate~s
zAifc_write.setframeratecCs|jstd��|jS)Nzframe rate not set)rsrrcrrrrt�szAifc_write.getframeratecCs|jrtd��||_dS)Nr�)r�rro)rXr�rrr�
setnframes�szAifc_write.setnframescCs|jSrb�r�rcrrrrp�szAifc_write.getnframescCs.|jrtd��|dvrtd��||_||_dS�Nr�)r�r�r�r�r�r�r�)r�rrvry)rX�comptype�compnamerrr�setcomptype�szAifc_write.setcomptypecCs|jSrbrurcrrrrw�szAifc_write.getcomptypecCs|jSrbrxrcrrrrz�szAifc_write.getcompnamecCsf|\}}}}}}|jrtd��|dvr.td��|�|�|�|�|�|�|�|�|�||�dSr�)r�rr�r�r�r�r�)rX�paramsr�r�r�r�r�r�rrr�	setparams�s



zAifc_write.setparamscCs8|jr|jr|jstd��t|j|j|j|j|j|j�S)Nznot all parameters set)rmrqrsrrCrorvryrcrrrr{�s
�zAifc_write.getparamscCs�|dkrtd��|dkr td��t|t�s2td��tt|j��D],}||j|dkr@|||f|j|<dSq@|j�|||f�dS)Nrzmarker ID must be > 0zmarker position must be >= 0zmarker name must be bytes)rr\�bytesr�r9rOr�)rXr�r�r�r�rrr�setmark�s
zAifc_write.setmarkcCs2|jD]}||dkr|Sqtd�|���dSrr�r�rrrr��s

zAifc_write.getmarkcCst|j�dkrdS|jSr|r}rcrrrr~�szAifc_write.getmarkerscCs|jSrbr�rcrrrrl�szAifc_write.tellcCszt|ttf�st|��d�}|�t|��t|�|j|j}|j	rN|�	|�}|j
�|�|j||_|j
t|�|_
dS)Nr7)r\r��	bytearray�
memoryview�cast�_ensure_header_writtenr9rqrmrNrQr.r�r�)rXrr�rrr�writeframesraw�s
zAifc_write.writeframesrawcCs.|�|�|j|jks"|j|jkr*|��dSrb)r�r�ror�r��_patchheader)rXrrrr�writeframes�s


�zAifc_write.writeframescCs�|jdurdSzx|�d�|jd@r<|j�d�|jd|_|��|j|jksb|j|jksb|jrj|�	�Wd|_
|j}d|_|��nd|_
|j}d|_|��0dS)Nrrr8)rQr�r�r.�
_writemarkersr�ror�r�r�rNr_)rXr'rrrr_�s,



��

�zAifc_write.closecCsddl}|�|d�Sr�)r�Zlin2alawr�rrr�	_lin2alaw�szAifc_write._lin2alawcCsddl}|�|d�Sr�)r�Zlin2ulawr�rrr�	_lin2ulawszAifc_write._lin2ulawcCs2ddl}t|d�sd|_|�|d|j�\}|_|Sr�)r�r�r�Z	lin2adpcmr�rrr�
_lin2adpcms

zAifc_write._lin2adpcmcCsf|jsb|jdvr.|jsd|_|jdkr.td��|js<td��|jsJtd��|jsXtd��|�|�dS)N�r�r�r�r�r�rzRsample width must be 2 when compressing with ulaw/ULAW, alaw/ALAW or G7.22 (ADPCM)z# channels not specifiedzsample width not specifiedzsampling rate not specified)r�rvrqrrmrs�
_write_header)rXZdatasizerrrr�
s

z!Aifc_write._ensure_header_writtencCs>|jdkr|j|_n&|jdvr(|j|_n|jdvr:|j|_dS)Nr�r�r�)rvr�rNr�r�rcrrr�_init_compressions




zAifc_write._init_compressionc	CsH|jr|jdkr|��|j�d�|js<||j|j|_|j|j|j|_|jd@rf|jd|_|jr�|jdvr�|jd|_|jd@r�|jd|_n0|jdkr�|jdd|_|jd@r�|jd|_z|j�	�|_
Wnttfy�d|_
Yn0|�
|j�}|j�r@|j�d	�|j�d
�t|jd�t|j|j�n|j�d�|j�d�t|j|�t|j|j�|j
du�r�|j�	�|_t|j|j�|jd
v�r�t|jd�nt|j|jd�t|j|j�|j�r�|j�|j�t|j|j�|j�d�|j
du�r|j�	�|_t|j|jd�t|jd�t|jd�dS)Nr�rEr)r�r�r�r�rr��r
rGrKrFrHr�rJrIr)rRrvr�rQr.rormrqr�rl�_form_length_pos�AttributeError�OSError�_write_form_lengthr5rMr2�_nframes_posr@rsr<ry�_ssnd_length_pos)rXZ
initlength�
commlengthrrrr�%s^




zAifc_write._write_headercCs\|jr*dt|j�}|d@r$|d}d}nd}d}t|jd||jd|d|�|S)	Nr�r�r�rr
rJ�)rRr9ryr5rQr�)rX�
datalengthr�Z
verslengthrrrr�Xs"����zAifc_write._write_form_lengthcCs�|j��}|jd@r,|jd}|j�d�n|j}||jkrd|j|jkrd|jdkrd|j�|d�dS|j�|j	d�|�
|�}|j�|jd�t|j|j�|j�|j
d�t|j|d�|j�|d�|j|_||_dS)Nrr8rrJ)rQrlr�r.r�ror�r�r�r�r�r�r5r�)rXZcurposr�rrrrr�es*




��
zAifc_write._patchheadercCs�t|j�dkrdS|j�d�d}|jD]:}|\}}}|t|�dd}t|�d@dkr(|d}q(t|j|�|d|_t|jt|j��|jD]2}|\}}}t|j|�t|j|�t|j|�q�dS)NrrLrr�rJ)r9rOrQr.r5r�r2r<)rXrr�r�r�r�rrrr�{s"





zAifc_write._writemarkers)(rrrrQrarZr�rdrhr�r�r�rnr�rrr�rtr�rpr�rwrzr�r{r�r�r~rlr�r�r_r�r�r�r�r�r�r�r�r�rrrrr�sJ	

3
r�cCsJ|durt|d�r|j}nd}|dvr.t|�S|dvr>t|�Std��dS)N�moder[)�rr[)r�r�z$mode must be 'r', 'rb', 'w', or 'wb')r�r�rDr�r)r'r�rrrr�s
�__main__rz/usr/demos/data/audio/bach.aiffr�ZReadingznchannels =znframes   =zsampwidth =zframerate =zcomptype  =zcompname  =rZWritingr�izDone.)N)7�__doc__rr^r��__all__�	Exceptionrr�rrrrr r%r,r2r3r4r5r<r@rYrA�collectionsrBrCr�r�r�r�r�r�rDr�rr�sys�argvr��fnr'�printrnrprrrtrwrzZgn�gr�r{r�rr�rrrr�<module>s|	
!�






.

Hacked By AnonymousFox1.0, Coded By AnonymousFox