Your IP : 3.145.69.185


Current Path : /opt/alt/python39/lib64/python3.9/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/__pycache__/aifc.cpython-39.opt-2.pyc

a

R�f]�	@s^ddlZddlZddlZddgZGdd�de�ZdZdd�Zdd	�Zd
d�Z	dd
�Z
dd�ZdZdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�ZddlmZdd 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�rZddl$Z$e$j%d/d��s>e$j%�&d0�e$j%d/Z'e"e'd1���Z(e)d2e'�e)d3e(�*��e)d4e(�+��e)d5e(�,��e)d6e(�-��e)d7e(�.��e)d8e(�/��e$j%d9d��r:e$j%d9Z0e)d:e0�e"e0d;��@Z1e1�2e(�3��e(�4d<�Z5e5�s�qe1�6e5��q�Wd�n1�s(0Ye)d=�Wd�n1�sP0YdS)?�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)7rr^r��__all__�	Exceptionrr�rrrrr r%r,r2r3r4r5r<r@rYrA�collectionsrBrCr��__doc__r�r�r�r�r�rDr�rr�sys�argvr��fnr'�printrnrprrrtrwrzZgn�gr�r{r�rr�rrrr�<module>�sx
!�






.

?>