AlkantarClanX12

Your IP : 3.139.108.99


Current Path : /opt/alt/python37/lib64/python3.7/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/__pycache__/aifc.cpython-37.opt-2.pyc

B

YI~d.��
@s@ddlZddlZddlZdddgZGdd�de�ZdZdd�Zd	d
�Zdd�Z	d
d�Z
dd�ZdZdd�Z
dd�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"dAd/d�Z#e$d0k�r<ddl%Z%e%j&d1d��sJe%j&�'d2�e%j&d1Z(e"e(d3���Z)e*d4e(�e*d5e)�+��e*d6e)�,��e*d7e)�-��e*d8e)�.��e*d9e)�/��e*d:e)�0��e%j&d;d��r2e%j&d;Z1e*d<e1�e"e1d=��8Z2e2�3e)�4��x"e)�5d>�Z6e6�sPe2�7e6��q�WWdQRXe*d?�WdQRXdS)B�N�Error�open�openfpc@seZdZdS)rN)�__name__�
__module__�__qualname__�rr�)/opt/alt/python37/lib64/python3.7/aifc.pyr�sl@QEcCs8yt�d|�d��dStjk
r2td�YnXdS)Nz>l�r)�struct�unpack�read�error�EOFError)�filerrr	�
_read_long�srcCs8yt�d|�d��dStjk
r2td�YnXdS)Nz>Lr
r)rrr
rr)rrrr	�_read_ulong�srcCs8yt�d|�d��dStjk
r2td�YnXdS)Nz>h�r)rrr
rr)rrrr	�_read_short�srcCs8yt�d|�d��dStjk
r2td�YnXdS)Nz>Hrr)rrr
rr)rrrr	�_read_ushort�srcCs@t|�d��}|dkrd}n
|�|�}|d@dkr<|�d�}|S)N�r�)�ordr
)r�length�data�dummyrrr	�_read_string�s

rg�����cCs�t|�}d}|dkr d}|d}t|�}t|�}||krN|krNdkrXnnd}n0|dkrft}n"|d}|d|td	|d
�}||S)Nrr���i�gi�i�?lg@�?)rr�	_HUGE_VAL�pow)�f�expon�sign�himant�lomantrrr	�_read_float�s"r&cCs|�t�d|��dS)Nz>h)�writer�pack)r!�xrrr	�_write_short�sr*cCs|�t�d|��dS)Nz>H)r'rr()r!r)rrr	�
_write_ushort�sr+cCs|�t�d|��dS)Nz>l)r'rr()r!r)rrr	�_write_long�sr,cCs|�t�d|��dS)Nz>L)r'rr()r!r)rrr	�_write_ulong�sr-cCsRt|�dkrtd��|�t�dt|���|�|�t|�d@dkrN|�d�dS)N�z%string exceeds maximum pstring length�Brr�)�len�
ValueErrorr'rr()r!�srrr	�
_write_string�s
r4c	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)	Nri�ri@ri�i�?� )�mathZfrexpZldexpZfloor�intr+r-)	r!r)r6r#r"r$r%ZfmantZfsmantrrr	�_write_float�s8




r8)�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_readNcCs8d|_d|_g|_d|_||_t|�}|��dkr:td��|�d�}|dkrTd|_	n|dkrdd|_	ntd��d|_
d|_x�d|_yt|j�}Wnt
k
r�PYnX|��}|d	kr�|�|�d|_
nH|d
kr�||_|�d�}d|_n(|dkr�t|�|_n|d
k�r|�|�|��qzW|j
�r,|j�s4td��dS)NrsFORMz file does not start with FORM idr
sAIFFsAIFCrznot an AIFF or AIFF-C filesCOMMsSSND�sFVERsMARKz$COMM chunk and/or SSND chunk missing)�_version�_convert�_markers�	_soundpos�_filer9Zgetnamerr
�_aifcZ_comm_chunk_read�_ssnd_chunk�_ssnd_seek_neededr�_read_comm_chunkr�	_readmark�skip)�selfr�chunkZformdataZ	chunknamerrrr	�initfp4sJ




zAifc_read.initfpcCsLt|t�r>t�|d�}y|�|�WqH|���YqHXn
|�|�dS)N�rb)�
isinstance�str�builtinsrrK�close)rIr!�file_objectrrr	�__init__\s

zAifc_read.__init__cCs|S)Nr)rIrrr	�	__enter__hszAifc_read.__enter__cGs|��dS)N)rP)rI�argsrrr	�__exit__kszAifc_read.__exit__cCs|jS)N)rB)rIrrr	�getfpqszAifc_read.getfpcCsd|_d|_dS)Nrr)rErA)rIrrr	�rewindtszAifc_read.rewindcCs |j}|dk	rd|_|��dS)N)rBrP)rIrrrr	rPxszAifc_read.closecCs|jS)N)rA)rIrrr	�tell~szAifc_read.tellcCs|jS)N)�
_nchannels)rIrrr	�getnchannels�szAifc_read.getnchannelscCs|jS)N)�_nframes)rIrrr	�
getnframes�szAifc_read.getnframescCs|jS)N)�
_sampwidth)rIrrr	�getsampwidth�szAifc_read.getsampwidthcCs|jS)N)�
_framerate)rIrrr	�getframerate�szAifc_read.getframeratecCs|jS)N)�	_comptype)rIrrr	�getcomptype�szAifc_read.getcomptypecCs|jS)N)�	_compname)rIrrr	�getcompname�szAifc_read.getcompnamecCs*t|��|��|��|��|��|���S)N)r;rZr^r`r\rbrd)rIrrr	�	getparams�szAifc_read.getparamscCst|j�dkrdS|jS)Nr)r1r@)rIrrr	�
getmarkers�szAifc_read.getmarkerscCs2x|jD]}||dkr|SqWtd�|���dS)Nrzmarker {0!r} does not exist)r@r�format)rI�id�markerrrr	�getmark�szAifc_read.getmarkcCs*|dks||jkrtd��||_d|_dS)Nrzposition not in ranger)r[rrArE)rI�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)Nrr=r)
rErD�seekr
rA�
_framesizer?r1rYr])rI�nframesrrkrrrr	�
readframes�s

zAifc_read.readframescCsddl}|�|d�S)Nrr)�audioopZalaw2lin)rIrrqrrr	�	_alaw2lin�szAifc_read._alaw2lincCsddl}|�|d�S)Nrr)rqZulaw2lin)rIrrqrrr	�	_ulaw2lin�szAifc_read._ulaw2lincCs2ddl}t|d�sd|_|�|d|j�\}|_|S)Nr�_adpcmstater)rq�hasattrrtZ	adpcm2lin)rIrrqrrr	�
_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|jdk�r |j|_n|jdk�r6|j|_ntd��d|_nd|_d|_dS)N�r=rzbad sample widthzbad # of channels�rzWarning: bad COMM chunk size�r
rsNONEsG722)sulawsULAW)salawsALAWzunsupported compression typersnot compressed)rrYrr[r]r7r&r_rrnrCZ	chunksize�warnings�warnr
rarrrmrrcrvr?rsrr)rIrJZkludgerrrr	rF�sD









zAifc_read._read_comm_chunkcCs�t|�}yHxBt|�D]6}t|�}t|�}t|�}|s8|r|j�|||f�qWWnDtk
r�dt|j�t|j�dkr|dnd|f}t�	|�YnXdS)Nz;Warning: MARK chunk contains only %s marker%s instead of %sr�r3)
r�rangerrr@�appendrr1rzr{)rIrJZnmarkers�irhrk�name�wrrr	rG�szAifc_read._readmark)rrrrBrKrRrSrUrVrWrPrXrZr\r^r`rbrdrerfrjrlrprrrsrvrFrGrrrr	r<s2$(*r<c@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�}y|�|�Wn|���YnX|�d�rXd|_n
|�|�dS)N�wbz.aiffr)rMrNrOrrKrP�endswithrC)rIr!rQrrr	rR/s

zAifc_write.__init__cCs^||_t|_d|_d|_d|_d|_d|_d|_d|_	d|_
d|_d|_g|_
d|_d|_dS)NsNONEsnot compressedrr)rB�
_AIFC_versionr>rarcr?rYr]r_r[�_nframeswritten�_datawritten�_datalengthr@�_marklengthrC)rIrrrr	rK?szAifc_write.initfpcCs|��dS)N)rP)rIrrr	�__del__PszAifc_write.__del__cCs|S)Nr)rIrrr	rSSszAifc_write.__enter__cGs|��dS)N)rP)rIrTrrr	rUVszAifc_write.__exit__cCs|jrtd��d|_dS)Nz0cannot change parameters after starting to writer)r�rrC)rIrrr	�aiff\szAifc_write.aiffcCs|jrtd��d|_dS)Nz0cannot change parameters after starting to writer)r�rrC)rIrrr	�aifcaszAifc_write.aifccCs(|jrtd��|dkrtd��||_dS)Nz0cannot change parameters after starting to writerzbad # of channels)r�rrY)rI�	nchannelsrrr	�setnchannelsfs
zAifc_write.setnchannelscCs|jstd��|jS)Nznumber of channels not set)rYr)rIrrr	rZmszAifc_write.getnchannelscCs0|jrtd��|dks|dkr&td��||_dS)Nz0cannot change parameters after starting to writerr
zbad sample width)r�rr])rI�	sampwidthrrr	�setsampwidthrs
zAifc_write.setsampwidthcCs|jstd��|jS)Nzsample width not set)r]r)rIrrr	r^yszAifc_write.getsampwidthcCs(|jrtd��|dkrtd��||_dS)Nz0cannot change parameters after starting to writerzbad frame rate)r�rr_)rI�	frameraterrr	�setframerate~s
zAifc_write.setframeratecCs|jstd��|jS)Nzframe rate not set)r_r)rIrrr	r`�szAifc_write.getframeratecCs|jrtd��||_dS)Nz0cannot change parameters after starting to write)r�rr[)rIrorrr	�
setnframes�szAifc_write.setnframescCs|jS)N)r�)rIrrr	r\�szAifc_write.getnframescCs.|jrtd��|dkrtd��||_||_dS)Nz0cannot change parameters after starting to write)sNONEsulawsULAWsalawsALAWsG722zunsupported compression type)r�rrarc)rI�comptype�compnamerrr	�setcomptype�szAifc_write.setcomptypecCs|jS)N)ra)rIrrr	rb�szAifc_write.getcomptypecCs|jS)N)rc)rIrrr	rd�szAifc_write.getcompnamecCsf|\}}}}}}|jrtd��|dkr.td��|�|�|�|�|�|�|�|�|�||�dS)Nz0cannot change parameters after starting to write)sNONEsulawsULAWsalawsALAWsG722zunsupported compression type)r�rr�r�r�r�r�)rI�paramsr�r�r�ror�r�rrr	�	setparams�s



zAifc_write.setparamscCs8|jr|jr|jstd��t|j|j|j|j|j|j�S)Nznot all parameters set)rYr]r_rr;r[rarc)rIrrr	re�szAifc_write.getparamscCs�|dkrtd��|dkr td��t|t�s2td��x<tt|j��D]*}||j|dkrB|||f|j|<dSqBW|j�|||f�dS)Nrzmarker ID must be > 0zmarker position must be >= 0zmarker name must be bytes)rrM�bytesr}r1r@r~)rIrhrkr�rrrr	�setmark�s
zAifc_write.setmarkcCs2x|jD]}||dkr|SqWtd�|���dS)Nrzmarker {0!r} does not exist)r@rrg)rIrhrirrr	rj�szAifc_write.getmarkcCst|j�dkrdS|jS)Nr)r1r@)rIrrr	rf�szAifc_write.getmarkerscCs|jS)N)r�)rIrrr	rX�szAifc_write.tellcCszt|ttf�st|��d�}|�t|��t|�|j|j}|j	rN|�	|�}|j
�|�|j||_|j
t|�|_
dS)Nr/)rMr��	bytearray�
memoryview�cast�_ensure_header_writtenr1r]rYr?rBr'r�r�)rIrrorrr	�writeframesraw�s
zAifc_write.writeframesrawcCs.|�|�|j|jks"|j|jkr*|��dS)N)r�r�r[r�r��_patchheader)rIrrrr	�writeframes�s
zAifc_write.writeframescCs�|jdkrdSz^|�d�|jd@r<|j�d�|jd|_|��|j|jksb|j|jksb|jrj|�	�Wdd|_
|j}d|_|��XdS)Nrrr0)rBr�r�r'�
_writemarkersr�r[r�r�r�r?rP)rIr!rrr	rP�s 


zAifc_write.closecCsddl}|�|d�S)Nrr)rqZlin2alaw)rIrrqrrr	�	_lin2alaw�szAifc_write._lin2alawcCsddl}|�|d�S)Nrr)rqZlin2ulaw)rIrrqrrr	�	_lin2ulawszAifc_write._lin2ulawcCs2ddl}t|d�sd|_|�|d|j�\}|_|S)Nrrtr)rqrurtZ	lin2adpcm)rIrrqrrr	�
_lin2adpcms

zAifc_write._lin2adpcmcCsf|jsb|jdkr.|jsd|_|jdkr.td��|js<td��|jsJtd��|jsXtd��|�|�dS)N)sULAWsulawsALAWsalawsG722rzRsample 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�rar]rrYr_�
_write_header)rIZdatasizerrr	r�
s

z!Aifc_write._ensure_header_writtencCs>|jdkr|j|_n&|jdkr(|j|_n|jdkr:|j|_dS)NsG722)sulawsULAW)salawsALAW)rar�r?r�r�)rIrrr	�_init_compressions




zAifc_write._init_compressionc	CsJ|jr|jdkr|��|j�d�|js<||j|j|_|j|j|j|_|jd@rf|jd|_|jr�|jdkr�|jd|_|jd@r�|jd|_n0|jdkr�|jdd|_|jd@r�|jd|_y|j�	�|_
Wnttfk
r�d|_
YnX|�
|j�}|j�rB|j�d	�|j�d
�t|jd�t|j|j�n|j�d�|j�d�t|j|�t|j|j�|j
dk	�r�|j�	�|_t|j|j�|jd
k�r�t|jd�nt|j|jd�t|j|j�|j�r�|j�|j�t|j|j�|j�d�|j
dk	�r|j�	�|_t|j|jd�t|jd�t|jd�dS)NsNONEsFORMr)sulawsULAWsalawsALAWrsG722�r
sAIFCsFVERsAIFFsCOMM)sULAWsulawsALAWsalawsG722r=sSSNDr)rCrar�rBr'r[rYr]r�rX�_form_length_pos�AttributeError�OSError�_write_form_lengthr-r>r*�_nframes_posr8r_r4rc�_ssnd_length_pos)rIZ
initlength�
commlengthrrr	r�%s^




zAifc_write._write_headercCs\|jr*dt|j�}|d@r$|d}d}nd}d}t|jd||jd|d|�|S)	Nryr�rxrr
r=�)rCr1rcr-rBr�)rI�
datalengthr�Z
verslengthrrr	r�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)Nrr0rr=)rBrXr�r'r�r[r�r�rmr�r�r�r-r�)rIZcurposr�rrrr	r�es&





zAifc_write._patchheadercCs�t|j�dkrdS|j�d�d}xD|jD]:}|\}}}|t|�dd}t|�d@dkr*|d}q*Wt|j|�|d|_t|jt|j��x<|jD]2}|\}}}t|j|�t|j|�t|j|�q�WdS)NrsMARKrr�r=)r1r@rBr'r-r�r*r4)rIrrirhrkr�rrr	r�{s"


zAifc_write._writemarkers)(rrrrBrRrKr�rSrUr�r�r�rZr�r^r�r`r�r\r�rbrdr�rer�rjrfrXr�r�rPr�r�r�r�r�r�r�r�r�rrrr	r�sJ	

3
r�cCsJ|dkrt|d�r|j}nd}|dkr.t|�S|dkr>t|�Std��dS)N�moderL)�rrL)r�r�z$mode must be 'r', 'rb', 'w', or 'wb')rur�r<r�r)r!r�rrr	r�s
cCstjdtdd�t||d�S)NzBaifc.openfp is deprecated since Python 3.7. Use aifc.open instead.r)�
stacklevel)r�)rzr{�DeprecationWarningr)r!r�rrr	r�s
�__main__rz/usr/demos/data/audio/bach.aiffr�ZReadingznchannels =znframes   =zsampwidth =zframerate =zcomptype  =zcompname  =rZWritingr�izDone.)N)N)8rrOrz�__all__�	Exceptionrr�rrrrrrr&r*r+r,r-r4r8rJr9�collectionsr:r;r��__doc__r�r�ror�r�r<r�rrr�sys�argvr~�fnr!�printrZr\r^r`rbrdZgn�gr�rerprr�rrrr	�<module>�sz

!