AlkantarClanX12

Your IP : 18.216.53.7


Current Path : /usr/lib64/python3.6/__pycache__/
Upload File :
Current File : //usr/lib64/python3.6/__pycache__/aifc.cpython-36.opt-2.pyc

3


 \�~�@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"e"Z#e$d/k�r6ddl%Z%e%j&d0d��sDe%j&j'd1�e%j&d0Z(e"e(d2���Z)e*d3e(�e*d4e)j+��e*d5e)j,��e*d6e)j-��e*d7e)j.��e*d8e)j/��e*d9e)j0��e%j&d:d��r,e%j&d:Z1e*d;e1�e"e1d<��8Z2e2j3e)j4��x"e)j5d=�Z6e6�s
Pe2j7e6��q�WWdQRXe*d>�WdQRXdS)@�N�Error�open�openfpc@seZdZdS)rN)�__name__�
__module__�__qualname__�rr�/usr/lib64/python3.6/aifc.pyr�sl@QEcCs6ytjd|jd��dStjk
r0t�YnXdS)Nz>l�r)�struct�unpack�read�error�EOFError)�filerrr	�
_read_long�srcCs6ytjd|jd��dStjk
r0t�YnXdS)Nz>Lr
r)rrr
rr)rrrr	�_read_ulong�srcCs6ytjd|jd��dStjk
r0t�YnXdS)Nz>h�r)rrr
rr)rrrr	�_read_short�srcCs6ytjd|jd��dStjk
r0t�YnXdS)Nz>Hrr)rrr
rr)rrrr	�_read_ushort�srcCs@t|jd��}|dkrd}n
|j|�}|d@dkr<|jd�}|S)N�r�)�ordr
)r�length�data�dummyrrr	�_read_string�s

rg�����cCs�t|�}d}|dkr d
}|d}t|�}t|�}||koL|koLdknrXd}n0|dkrft}n"|d}|d|td|d	�}||S)Nrri�gi�i�?lg@�?���)rr�	_HUGE_VAL�pow)�f�expon�sign�himant�lomantrrr	�_read_float�s"r&cCs|jtjd|��dS)Nz>h)�writer�pack)r!�xrrr	�_write_short�sr*cCs|jtjd|��dS)Nz>H)r'rr()r!r)rrr	�
_write_ushort�sr+cCs|jtjd|��dS)Nz>l)r'rr()r!r)rrr	�_write_long�sr,cCs|jtjd|��dS)Nz>L)r'rr()r!r)rrr	�_write_ulong�sr-cCsRt|�dkrtd��|jtjdt|���|j|�t|�d@dkrN|jd�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�|j|�\}}|dks^|dks^||krp|dB}d}d}nh|d}|dkr�|j||�}d}||B}|j|d�}|j|�}t|�}|j||d�}|j|�}t|�}t||�t||�t||�dS)	Nri�ri@i�i�?� r)�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_readNcCs<d|_d|_g|_d|_||_t|�}|j�dkr:td��|jd�}|dkrTd|_	n|dkrdd|_	ntd��d|_
d|_x�d|_yt|j�}Wnt
k
r�PYnX|j�}|d	kr�|j|�d|_
nH|d
kr�||_|jd�}d|_n(|dkr�t|�|_n|d
k�r|j|�|j�qzW|j
�s0|j�r8td��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.initfpc	CsLt|t�r>tj|d�}y|j|�WqH|j��YqHXn
|j|�dS)N�rb)�
isinstance�str�builtinsrrK�close)rIr!�file_objectrrr	�__init__\s

zAifc_read.__init__cCs|S)Nr)rIrrr	�	__enter__hszAifc_read.__enter__cGs|j�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|_|j�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|j�|j�|j�|j�|j�|j��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|SqWtdj|���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|jjd�|jjd�}|j|j}|r>|jj|d�d|_|dkrPdS|jj||j�}|jrv|rv|j|�}|jt|�|j|j	|_|S)Nrr=r)
rErD�seekr
rA�
_framesizer?r1rYr])rI�nframesrrkrrrr	�
readframes�s

zAifc_read.readframescCsddl}|j|d�S)Nrr)�audioopZalaw2lin)rIrrqrrr	�	_alaw2lin�szAifc_read._alaw2lincCsddl}|j|d�S)Nrr)rqZulaw2lin)rIrrqrrr	�	_ulaw2lin�szAifc_read._ulaw2lincCs2ddl}t|d�sd|_|j|d|j�\}|_|S)Nr�_adpcmstater)rq�hasattrrtZ	adpcm2lin)rIrrqrrr	�
_adpcm2lin�s

zAifc_read._adpcm2lincCs.t|�|_t|�|_t|�dd|_tt|��|_|j|j|_|j	�rd}|j
dkrld}tjd�d|_
|j
d�|_|r�t|jj
d��}|d@dkr�|d}|j
||_
|jjdd�t|�|_|jd	k�r*|jd
kr�|j|_n2|jdkr�|j|_n|jdk�r|j|_ntd��d|_nd	|_d|_dS)N�r=r�rzWarning: bad COMM chunk size�r
sNONEsG722�ulaw�ULAW�alaw�ALAWzunsupported compression typersnot compressedr)rzr{)r|r})rrYrr[r]r7r&r_rnrCZ	chunksize�warnings�warnr
rarrrmrrcrvr?rsrrr)rIrJZkludgerrrr	rF�s<









zAifc_read._read_comm_chunkcCs�t|�}yHxBt|�D]6}t|�}t|�}t|�}|s8|r|jj|||f�qWWnDtk
r�dt|j�t|j�dkr|dnd|f}tj	|�YnXdS)Nz;Warning: MARK chunk contains only %s marker%s instead of %sr�r3)
r�rangerrr@�appendrr1r~r)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_writeNc	Cs\t|t�rNtj|d�}y|j|�Wn|j��YnX|jd�rXd|_n
|j|�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|j�dS)N)rP)rIrrr	�__del__LszAifc_write.__del__cCs|S)Nr)rIrrr	rSOszAifc_write.__enter__cGs|j�dS)N)rP)rIrTrrr	rURszAifc_write.__exit__cCs|jrtd��d|_dS)Nz0cannot change parameters after starting to writer)r�rrC)rIrrr	�aiffXszAifc_write.aiffcCs|jrtd��d|_dS)Nz0cannot change parameters after starting to writer)r�rrC)rIrrr	�aifc]szAifc_write.aifccCs(|jrtd��|dkrtd��||_dS)Nz0cannot change parameters after starting to writerzbad # of channels)r�rrY)rI�	nchannelsrrr	�setnchannelsbs
zAifc_write.setnchannelscCs|jstd��|jS)Nznumber of channels not set)rYr)rIrrr	rZiszAifc_write.getnchannelscCs0|jrtd��|dks|dkr&td��||_dS)Nz0cannot change parameters after starting to writerr
zbad sample width)r�rr])rI�	sampwidthrrr	�setsampwidthns
zAifc_write.setsampwidthcCs|jstd��|jS)Nzsample width not set)r]r)rIrrr	r^uszAifc_write.getsampwidthcCs(|jrtd��|dkrtd��||_dS)Nz0cannot change parameters after starting to writerzbad frame rate)r�rr_)rI�	frameraterrr	�setframeratezs
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��|d	krtd��||_||_dS)
Nz0cannot change parameters after starting to write�NONE�ulaw�ULAW�alaw�ALAW�G722zunsupported compression type)r�r�r�r�r�r�)r�rrarc)rI�comptype�compnamerrr	�setcomptype�szAifc_write.setcomptypecCs|jS)N)ra)rIrrr	rb�szAifc_write.getcomptypecCs|jS)N)rc)rIrrr	rd�szAifc_write.getcompnamecCsf|\}}}}}}|jrtd��|d	kr.td��|j|�|j|�|j|�|j|�|j||�dS)
Nz0cannot change parameters after starting to write�NONE�ulaw�ULAW�alaw�ALAW�G722zunsupported compression type)r�r�r�r�r�r�)r�rr�r�r�r�r�)rIZparamsr�r�r�ror�r�rrr	�	setparams�s



zAifc_write.setparamscCs>|js|js|jr td��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|jj|||f�dS)Nrzmarker ID must be > 0zmarker position must be >= 0zmarker name must be bytes)rrM�bytesr�r1r@r�)rIrhrkr�r�rrr	�setmark�s
zAifc_write.setmarkcCs2x|jD]}||dkr|SqWtdj|���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|�jd�}|jt|��t|�|j|j}|j	rN|j	|�}|j
j|�|j||_|j
t|�|_
dS)Nr/)rMr��	bytearray�
memoryview�cast�_ensure_header_writtenr1r]rYr?rBr'r�r�)rIrrorrr	�writeframesraw�s
zAifc_write.writeframesrawcCs.|j|�|j|jks"|j|jkr*|j�dS)N)r�r�r[r�r��_patchheader)rIrrrr	�writeframes�s
zAifc_write.writeframescCs�|jdkrdSz^|jd�|jd@r<|jjd�|jd|_|j�|j|jksb|j|jksb|jrj|j	�Wdd|_
|j}d|_|j�XdS)Nrrr0)rBr�r�r'�
_writemarkersr�r[r�r�r�r?rP)rIr!rrr	rP�s 


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

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

z!Aifc_write._ensure_header_writtencCs>|jdkr|j|_n&|jdkr(|j|_n|jdkr:|j|_dS)NsG722�ulaw�ULAW�alaw�ALAW)r�r�)r�r�)rar�r?r�r�)rIrrr	�_init_compressions




zAifc_write._init_compressioncCsL|jr|jdkr|j�|jjd�|js<||j|j|_|j|j|j|_|jd@rf|jd|_|jr�|jdkr�|jd|_|jd@r�|jd|_n0|jd	kr�|jd
d|_|jd@r�|jd|_y|jj	�|_
Wn ttfk
�r�d|_
YnX|j
|j�}|j�rD|jjd�|jjd
�t|jd�t|j|j�n|jjd�|jjd�t|j|�t|j|j�|j
dk	�r�|jj	�|_t|j|j�|jdk�r�t|jd�nt|j|jd�t|j|j�|j�r�|jj|j�t|j|j�|jjd�|j
dk	�r|jj	�|_t|j|jd�t|jd�t|jd�dS)NsNONEsFORMr�ulaw�ULAW�alaw�ALAWr�G722�r
sAIFCsFVERsAIFFsCOMMr=sSSNDr)r�r�r�r�)r�r�r�r�r�)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*d	t|j�}|d@r$|d}d}nd}d}t|jd||jd|d|�|S)
Nrx�r�rr
r=�ry)rCr1rcr-rBr�)rI�
datalengthr�Z
verslengthrrr	r�Ts zAifc_write._write_form_lengthcCs�|jj�}|jd@r,|jd}|jjd�n|j}||jkrd|j|jkrd|jdkrd|jj|d�dS|jj|j	d�|j
|�}|jj|jd�t|j|j�|jj|j
d�t|j|d�|jj|d�|j|_||_dS)Nrr0rr=)rBrXr�r'r�r[r�r�rmr�r�r�r-r�)rIZcurposr�rrrr	r�as&





zAifc_write._patchheadercCs�t|j�dkrdS|jjd�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�ws"


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�rr�r�z$mode must be 'r', 'rb', 'w', or 'wb')r�rL)r�r�)rur�r<r�r)r!r�rrr	r�s
�__main__rz/usr/demos/data/audio/bach.aiffr�ZReadingznchannels =znframes   =zsampwidth =zframerate =zcomptype  =zcompname  =rZWritingr�izDone.)N)8rrOr~�__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>�sx

!~