ok

Mini Shell

Direktori : /opt/alt/python38/lib64/python3.8/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/__pycache__/aifc.cpython-38.opt-2.pyc

U

.��c.��
@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��r0e%j&d;Z1e*d<e1�e"e1d=��6Z2e2�3e)�4��e)�5d>�Z6e6�s�qe2�7e6��q�W5QRXe*d?�W5QRXdS)B�N�Error�open�openfpc@seZdZdS)rN)�__name__�
__module__�__qualname__�rr�)/opt/alt/python38/lib64/python3.8/aifc.pyr�sl@QEcCs:zt�d|�d��dWStjk
r4td�YnXdS)N�>l�r��structZunpack�read�error�EOFError��filerrr	�
_read_long�srcCs:zt�d|�d��dWStjk
r4td�YnXdS)N�>Lrrrrrrr	�_read_ulong�srcCs:zt�d|�d��dWStjk
r4td�YnXdS)N�>h�rrrrrr	�_read_short�srcCs:zt�d|�d��dWStjk
r4td�YnXdS)N�>Hrrrrrrr	�_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�sr3cCs|�t�d|��dS)Nrr.r1rrr	�
_write_ushort�sr4cCs|�t�d|��dS)Nr
r.r1rrr	�_write_long�sr5cCs|�t�d|��dS)Nrr.r1rrr	�_write_ulong�sr6cCsRt|�dkrtd��|�t�dt|���|�|�t|�d@dkrN|�d�dS)N�z%string exceeds maximum pstring length�Brr�)�len�
ValueErrorr/r
r0)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�intr4r6)	r(r2r?r*r)r+r,ZfmantZfsmantrrr	�_write_float�s8




rA)�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|_d|_zt|j�}Wnt
k
r�Y�qYnX|��}|d	kr�|�|�d|_
nH|d
kr�||_|�d�}d|_n(|dkr�t|�|_n|d
k�r|�|�|��qx|j
�r,|j�s4td��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�_filerBZgetnamerr�_aifcZ_comm_chunk_read�_ssnd_chunk�_ssnd_seek_neededr�_read_comm_chunkr�	_readmark�skip)�selfr�chunkZformdataZ	chunknamer rrr	�initfp4sH





zAifc_read.initfpcCsLt|t�r>t�|d�}z|�|�WqH|���YqHXn
|�|�dS)N�rb)�
isinstance�str�builtinsrr[�close�rYr(Zfile_objectrrr	�__init__\s

zAifc_read.__init__cCs|S�Nr�rYrrr	�	__enter__hszAifc_read.__enter__cGs|��dSrc�r`�rY�argsrrr	�__exit__kszAifc_read.__exit__cCs|jSrc)rRrdrrr	�getfpqszAifc_read.getfpcCsd|_d|_dS)Nrr)rUrQrdrrr	�rewindtszAifc_read.rewindcCs |j}|dk	rd|_|��dSrc)rRr`�rYrrrr	r`xszAifc_read.closecCs|jSrc)rQrdrrr	�tell~szAifc_read.tellcCs|jSrc)�
_nchannelsrdrrr	�getnchannels�szAifc_read.getnchannelscCs|jSrc)�_nframesrdrrr	�
getnframes�szAifc_read.getnframescCs|jSrc)�
_sampwidthrdrrr	�getsampwidth�szAifc_read.getsampwidthcCs|jSrc)�
_frameraterdrrr	�getframerate�szAifc_read.getframeratecCs|jSrc��	_comptyperdrrr	�getcomptype�szAifc_read.getcomptypecCs|jSrc��	_compnamerdrrr	�getcompname�szAifc_read.getcompnamecCs*t|��|��|��|��|��|���Src)rDrorsrurqrxr{rdrrr	�	getparams�s�zAifc_read.getparamscCst|j�dkrdS|jS�Nr�r:rPrdrrr	�
getmarkers�szAifc_read.getmarkerscCs2|jD]}||dkr|Sqtd�|���dS�Nrzmarker {0!r} does not exist�rPr�format�rY�id�markerrrr	�getmark�s

zAifc_read.getmarkcCs*|dks||jkrtd��||_d|_dS)Nrzposition not in ranger)rprrQrU)rY�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)NrrKr)
rUrT�seekrrQ�
_framesizerOr:rnrr)rY�nframesr r�rrrr	�
readframes�s 

�
zAifc_read.readframescCsddl}|�|d�S�Nrr)�audioopZalaw2lin�rYrr�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|jdk�r |j|_n|jdk�r6|j|_ntd��d|_nd|_d|_dS)N�rKr�bad sample width�bad # of channels�rzWarning: bad COMM chunk size�rr"�NONE�G722��ulaw�ULAW��alaw�ALAW�unsupported compression typer�not compressed)rrnrrprrr@r-rtrr�rSZ	chunksize�warnings�warnrrwrrr�r!rzr�rOr�r�)rYrZZkludgerrrr	rV�sD









zAifc_read._read_comm_chunkcCs�t|�}zDt|�D]6}t|�}t|�}t|�}|s6|r|j�|||f�qWnDtk
r�dt|j�t|j�dkrxdnd|f}t�	|�YnXdS)Nz;Warning: MARK chunk contains only %s marker%s instead of %sr�r<)
r�rangerr!rP�appendrr:r�r�)rYrZZnmarkers�ir�r��name�wrrr	rW�s��zAifc_read._readmark)rrrrRr[rbrerirjrkr`rmrorqrsrurxr{r|rr�r�r�r�r�r�rVrWrrrr	rEs2$(*rEc@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|���YnX|�d�rXd|_n
|�|�dS)N�wbz.aiffr)r]r^r_rr[r`�endswithrSrarrr	rb/s

zAifc_write.__init__cCs^||_t|_d|_d|_d|_d|_d|_d|_d|_	d|_
d|_d|_g|_
d|_d|_dS)Nr�r�rr)rR�
_AIFC_versionrNrwrzrOrnrrrtrp�_nframeswritten�_datawritten�_datalengthrP�_marklengthrSrlrrr	r[?szAifc_write.initfpcCs|��dSrcrfrdrrr	�__del__PszAifc_write.__del__cCs|Srcrrdrrr	reSszAifc_write.__enter__cGs|��dSrcrfrgrrr	riVszAifc_write.__exit__cCs|jrtd��d|_dS)N�0cannot change parameters after starting to writer�r�rrSrdrrr	�aiff\szAifc_write.aiffcCs|jrtd��d|_dS)Nr�rr�rdrrr	�aifcaszAifc_write.aifccCs(|jrtd��|dkrtd��||_dS)Nr�rr�)r�rrn)rY�	nchannelsrrr	�setnchannelsfs
zAifc_write.setnchannelscCs|jstd��|jS)Nznumber of channels not set)rnrrdrrr	romszAifc_write.getnchannelscCs0|jrtd��|dks|dkr&td��||_dS)Nr�rrr�)r�rrr)rY�	sampwidthrrr	�setsampwidthrs
zAifc_write.setsampwidthcCs|jstd��|jS)Nzsample width not set)rrrrdrrr	rsyszAifc_write.getsampwidthcCs(|jrtd��|dkrtd��||_dS)Nr�rzbad frame rate)r�rrt)rY�	frameraterrr	�setframerate~s
zAifc_write.setframeratecCs|jstd��|jS)Nzframe rate not set)rtrrdrrr	ru�szAifc_write.getframeratecCs|jrtd��||_dS)Nr�)r�rrp)rYr�rrr	�
setnframes�szAifc_write.setnframescCs|jSrc�r�rdrrr	rq�szAifc_write.getnframescCs.|jrtd��|dkrtd��||_||_dS�Nr�)r�r�r�r�r�r�r�)r�rrwrz)rY�comptype�compnamerrr	�setcomptype�szAifc_write.setcomptypecCs|jSrcrvrdrrr	rx�szAifc_write.getcomptypecCs|jSrcryrdrrr	r{�szAifc_write.getcompnamecCsf|\}}}}}}|jrtd��|dkr.td��|�|�|�|�|�|�|�|�|�||�dSr�)r�rr�r�r�r�r�)rYZparamsr�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)rnrrrtrrDrprwrzrdrrr	r|�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�r:rPr�)rYr�r�r�r�rrr	�setmark�s
zAifc_write.setmarkcCs2|jD]}||dkr|Sqtd�|���dSr�r�r�rrr	r��s

zAifc_write.getmarkcCst|j�dkrdS|jSr}r~rdrrr	r�szAifc_write.getmarkerscCs|jSrcr�rdrrr	rm�szAifc_write.tellcCszt|ttf�st|��d�}|�t|��t|�|j|j}|j	rN|�	|�}|j
�|�|j||_|j
t|�|_
dS)Nr8)r]r��	bytearray�
memoryview�cast�_ensure_header_writtenr:rrrnrOrRr/r�r�)rYrr�rrr	�writeframesraw�s
zAifc_write.writeframesrawcCs.|�|�|j|jks"|j|jkr*|��dSrc)r�r�rpr�r��_patchheader)rYrrrr	�writeframes�s


�zAifc_write.writeframescCs�|jdkrdSz^|�d�|jd@r<|j�d�|jd|_|��|j|jksb|j	|jksb|j
rj|��W5d|_|j}d|_|��XdS)Nrrr9)rRrOr`r�r�r/�
_writemarkersr�rpr�r�r�)rYr(rrr	r`�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|jdkr.|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�rwrrrrnrt�
_write_header)rYZdatasizerrr	r�
s

z!Aifc_write._ensure_header_writtencCs>|jdkr|j|_n&|jdkr(|j|_n|jdkr:|j|_dS)Nr�r�r�)rwr�rOr�r�rdrrr	�_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|_z|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)Nr�rFr)r�r�r�r�rr��rrHrLrGrIr�rKrJr)rSrwr�rRr/rprnrrr�rm�_form_length_pos�AttributeError�OSError�_write_form_lengthr6rNr3�_nframes_posrArtr=rz�_ssnd_length_pos)rYZ
initlength�
commlengthrrr	r�%s^




zAifc_write._write_headercCs\|jr*dt|j�}|d@r$|d}d}nd}d}t|jd||jd|d|�|S)	Nr�r�r�rrrK�)rSr:rzr6rRr�)rY�
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)Nrr9rrK)rRrmr�r/r�rpr�r�r�r�r�r�r6r�)rYZcurposr�r rrr	r�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)NrrMrr�rK)r:rPrRr/r6r�r3r=)rYrr�r�r�r�rrr	r�{s"





zAifc_write._writemarkers)(rrrrRrbr[r�rerir�r�r�ror�rsr�rur�rqr�rxr{r�r|r�r�rrmr�r�r`r�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�moder\)�rr\)r�r�z$mode must be 'r', 'rb', 'w', or 'wb')r�r�rEr�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�)r�r��DeprecationWarningrr�rrr	r�s
��__main__rz/usr/demos/data/audio/bach.aiffr�ZReadingznchannels =znframes   =zsampwidth =zframerate =zcomptype  =zcompname  =rZWritingr�izDone.)N)N)8r
r_r��__all__�	Exceptionrr�rrrrr!r&r-r3r4r5r6r=rArZrB�collectionsrCrDr��__doc__r�r�r�r�r�rEr�rrr�sys�argvr��fnr(�printrorqrsrurxr{Zgn�gr�r|r�rr�rrrr	�<module>�sz

!�









Zerion Mini Shell 1.0