AlkantarClanX12

Your IP : 18.225.56.79


Current Path : /opt/alt/python310/lib64/python3.10/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/__pycache__/aifc.cpython-310.opt-2.pyc

o

6��f]�	@sr	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�r7ddl$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�sne1�6e5�q�Wd�n	1�swYe)d=�Wd�dSWd�dS1�s0wYdSdS)?�N�Error�openc@seZdZdS)rN)�__name__�
__module__�__qualname__�rr�+/opt/alt/python310/lib64/python3.10/aifc.pyr�sl@QEcC�0zt�d|�d��dWStjytd�w)N�>l�r��structZunpack�read�error�EOFError��filerrr�
_read_long��
�rcCr	)N�>Lrrrrrrr�_read_ulong�rrcCr	)N�>h�rrrrrr�_read_short�rrcCr	)N�>Hrrrrrrr�_read_ushort�rrcCs@t|�d��}|dkrd}n|�|�}|d@dkr|�d�}|S)N�r�)�ordr)r�length�data�dummyrrr�_read_string�s

r"g�����cCs�t|�}d}|dkrd}|d}t|�}t|�}||kr'|kr'dkr/nnd}||S|dkr9t}||S|d}|d|td	|d
�}||S)Nrr�����g�i�?lg@�?)rr�	_HUGE_VAL�pow)�f�expon�sign�himant�lomantrrr�_read_float�s "��r.cC�|�t�d|��dS)Nr��writer
�pack�r)�xrrr�_write_short��r5cCr/)Nrr0r3rrr�
_write_ushort�r6r7cCr/)Nr
r0r3rrr�_write_long�r6r8cCr/)Nrr0r3rrr�_write_ulong�r6r9cCsVt|�dkr
td��|�t�dt|���|�|�t|�d@dkr)|�d�dSdS)N�z%string exceeds maximum pstring length�Brr�)�len�
ValueErrorr1r
r2)r)�srrr�
_write_string�s
�r@c	Cs�ddl}|dkrd}|d}nd}|dkrd}d}d}nP|�|�\}}|dks/|dks/||kr8|dB}d}d}n4|d}|dkrH|�||�}d}||B}|�|d�}|�|�}t|�}|�||d�}|�|�}t|�}t||�t||�t||�dS)	Nrr$r#i@rr%i�?� )�mathZfrexpZldexpZfloor�intr7r9)	r)r4rBr+r*r,r-ZfmantZfsmantrrr�_write_float�s8




rD)�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|�}|��dkrtd��|�d�}|dkr*d|_	n|dkr2d|_	ntd��d|_
d|_	d|_zt|j�}Wn	t
yPYn:w|��}|d	krb|�|�d|_
n#|d
krr||_|�d�}d|_n|dkr|t|�|_n	|d
kr�|�|�|��q=|j
r�|js�td��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�_filerEZgetnamerr�_aifcZ_comm_chunk_read�_ssnd_chunk�_ssnd_seek_neededr�_read_comm_chunkr�	_readmark�skip)�selfr�chunkZformdataZ	chunknamer!rrr�initfp4sP
�


��zAifc_read.initfpcCsFt|t�rt�|d�}z|�|�WdS|���|�|�dS)N�rb)�
isinstance�str�builtinsrr^�close�r\r)Zfile_objectrrr�__init__\s
zAifc_read.__init__cC�|S�Nr�r\rrr�	__enter__h�zAifc_read.__enter__cG�|��dSrg�rc�r\�argsrrr�__exit__k�zAifc_read.__exit__cC�|jSrg)rUrhrrr�getfpq�zAifc_read.getfpcCsd|_d|_dS)Nrr)rXrTrhrrr�rewindts
zAifc_read.rewindcCs$|j}|durd|_|��dSdSrg)rUrc�r\rrrrrcxs
�zAifc_read.closecCrqrg)rTrhrrr�tell~rszAifc_read.tellcCrqrg)�
_nchannelsrhrrr�getnchannels�rszAifc_read.getnchannelscCrqrg)�_nframesrhrrr�
getnframes�rszAifc_read.getnframescCrqrg)�
_sampwidthrhrrr�getsampwidth�rszAifc_read.getsampwidthcCrqrg)�
_frameraterhrrr�getframerate�rszAifc_read.getframeratecCrqrg��	_comptyperhrrr�getcomptype�rszAifc_read.getcomptypecCrqrg��	_compnamerhrrr�getcompname�rszAifc_read.getcompnamecCs*t|��|��|��|��|��|���Srg)rGrxr|r~rzr�r�rhrrr�	getparams�s�zAifc_read.getparamscC�t|j�dkr	dS|jS�Nr�r=rSrhrrr�
getmarkers��zAifc_read.getmarkerscC�.|jD]}||dkr|Sqtd�|����Nrzmarker {0!r} does not exist�rSr�format�r\�id�markerrrr�getmark��

�zAifc_read.getmarkcCs*|dks	||jkr
td��||_d|_dS)Nrzposition not in ranger)ryrrTrX)r\�posrrr�setpos�s
zAifc_read.setposcCs�|jr"|j�d�|j�d�}|j|j}|r|j�|d�d|_|dkr(dS|j�||j�}|jr;|r;|�|�}|jt|�|j|j	|_|S)NrrNr)
rXrW�seekrrT�
_framesizerRr=rwr{)r\�nframesr!r�r rrr�
readframes�s 


�zAifc_read.readframescC�ddl}|�|d�S�Nrr)�audioopZalaw2lin�r\r r�rrr�	_alaw2lin��zAifc_read._alaw2lincCr�r�)r�Zulaw2linr�rrr�	_ulaw2lin�r�zAifc_read._ulaw2lincC�2ddl}t|d�sd|_|�|d|j�\}|_|S�Nr�_adpcmstater)r��hasattrr�Z	adpcm2linr�rrr�
_adpcm2lin�s

zAifc_read._adpcm2lincCsRt|�|_t|�|_t|�dd|_tt|��|_|jdkr#td��|jdkr,td��|j|j|_	|j
r�d}|jdkrGd}t�
d�d	|_|�d
�|_|rnt|j�d��}|d@dkra|d}|j||_|j�dd�t|�|_|jdkr�|jd
kr�|j|_n|jdvr�|j|_n|jdvr�|j|_ntd��d|_dSdSd|_d|_dS)N�rNr�bad sample width�bad # of channels�rzWarning: bad COMM chunk size�rr#�NONE�G722��ulaw�ULAW��alaw�ALAW�unsupported compression typer�not compressed)rrwrryr{rCr.r}rr�rVZ	chunksize�warnings�warnrr�rrr�r"r�r�rRr�r�)r\r]ZkludgerrrrrY�sF














�
zAifc_read._read_comm_chunkcCs�t|�}z#t|�D]}t|�}t|�}t|�}|s|r$|j�|||f�q	WdStyIdt|j�t|j�dkr<dnd|f}t�	|�YdSw)Nz;Warning: MARK chunk contains only %s marker%s instead of %sr�r?)
r�rangerr"rS�appendrr=r�r�)r\r]Znmarkers�ir�r��name�wrrrrZ�s$��	���zAifc_read._readmark)rrrrUr^rerirorrrtrcrvrxrzr|r~r�r�r�r�r�r�r�r�r�r�rYrZrrrrrHs4$(*rHc@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�r't�|d�}z|�|�Wn|���|�d�r%d|_dSdS|�|�dS)N�wbz.aiffr)r`rarbrr^rc�endswithrVrdrrrre/s


�zAifc_write.__init__cCs^||_t|_d|_d|_d|_d|_d|_d|_d|_	d|_
d|_d|_g|_
d|_d|_dS)Nr�r�rr)rU�
_AIFC_versionrQr�r�rRrwr{r}ry�_nframeswritten�_datawritten�_datalengthrS�_marklengthrVrurrrr^?s
zAifc_write.initfpcCrkrgrlrhrrr�__del__PrpzAifc_write.__del__cCrfrgrrhrrrriSrjzAifc_write.__enter__cGrkrgrlrmrrrroVrpzAifc_write.__exit__cC�|jrtd��d|_dS)N�0cannot change parameters after starting to writer�r�rrVrhrrr�aiff\�
zAifc_write.aiffcCr�)Nr�rr�rhrrr�aifcar�zAifc_write.aifccCs(|jrtd��|dkrtd��||_dS)Nr�rr�)r�rrw)r\�	nchannelsrrr�setnchannelsf�

zAifc_write.setnchannelscC�|jstd��|jS)Nznumber of channels not set)rwrrhrrrrxm�zAifc_write.getnchannelscCs0|jrtd��|dks|dkrtd��||_dS)Nr�rrr�)r�rr{)r\�	sampwidthrrr�setsampwidthrs

zAifc_write.setsampwidthcCr�)Nzsample width not set)r{rrhrrrr|yr�zAifc_write.getsampwidthcCs(|jrtd��|dkrtd��||_dS)Nr�rzbad frame rate)r�rr})r\�	frameraterrr�setframerate~r�zAifc_write.setframeratecCr�)Nzframe rate not set)r}rrhrrrr~�r�zAifc_write.getframeratecCs|jrtd��||_dS)Nr�)r�rry)r\r�rrr�
setnframes�r�zAifc_write.setnframescCrqrg�r�rhrrrrz�rszAifc_write.getnframescCs.|jrtd��|dvrtd��||_||_dS�Nr�)r�r�r�r�r�r�r�)r�rr�r�)r\�comptype�compnamerrr�setcomptype�s
zAifc_write.setcomptypecCrqrgrrhrrrr��rszAifc_write.getcomptypecCrqrgr�rhrrrr��rszAifc_write.getcompnamecCsf|\}}}}}}|jrtd��|dvrtd��|�|�|�|�|�|�|�|�|�||�dSr�)r�rr�r�r�r�r�)r\�paramsr�r�r�r�r�r�rrr�	setparams�s



zAifc_write.setparamscCs8|jr	|jr	|js
td��t|j|j|j|j|j|j�S)Nznot all parameters set)rwr{r}rrGryr�r�rhrrrr��s
�zAifc_write.getparamscCs�|dkrtd��|dkrtd��t|t�std��tt|j��D]}||j|dkr6|||f|j|<dSq |j�|||f�dS)Nrzmarker ID must be > 0zmarker position must be >= 0zmarker name must be bytes)rr`�bytesr�r=rSr�)r\r�r�r�r�rrr�setmark�s
�zAifc_write.setmarkcCr�r�r�r�rrrr��r�zAifc_write.getmarkcCr�r�r�rhrrrr��r�zAifc_write.getmarkerscCrqrgr�rhrrrrv�rszAifc_write.tellcCszt|ttf�st|��d�}|�t|��t|�|j|j}|j	r'|�	|�}|j
�|�|j||_|j
t|�|_
dS)Nr;)r`r��	bytearray�
memoryview�cast�_ensure_header_writtenr=r{rwrRrUr1r�r�)r\r r�rrr�writeframesraw�s
zAifc_write.writeframesrawcCs2|�|�|j|jks|j|jkr|��dSdSrg)r�r�ryr�r��_patchheader)r\r rrr�writeframes�s

�zAifc_write.writeframescCs�|jdurdSzM|�d�|jd@r|j�d�|jd|_|��|j|jks1|j|jks1|jrE|�	�Wd|_
|j}d|_|��dSWd|_
|j}d|_|��dSd|_
|j}d|_|��w)Nrrr<)rUr�r�r1�
_writemarkersr�ryr�r�r�rRrc)r\r)rrrrc�s4


�
��
zAifc_write.closecCr�r�)r�Zlin2alawr�rrr�	_lin2alaw�r�zAifc_write._lin2alawcCr�r�)r�Zlin2ulawr�rrr�	_lin2ulawr�zAifc_write._lin2ulawcCr�r�)r�r�r�Z	lin2adpcmr�rrr�
_lin2adpcms

zAifc_write._lin2adpcmcCsj|js3|jdvr|jsd|_|jdkrtd��|jstd��|js%td��|js,td��|�|�dSdS)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�r�r{rrwr}�
_write_header)r\Zdatasizerrrr�
s

�z!Aifc_write._ensure_header_writtencCsF|jdkr|j|_dS|jdvr|j|_dS|jdvr!|j|_dSdS)Nr�r�r�)r�r�rRr�r�rhrrr�_init_compressions


�zAifc_write._init_compressionc	Cs@|jr|jdkr|��|j�d�|js||j|j|_|j|j|j|_|jd@r3|jd|_|jre|jdvrM|jd|_|jd@rL|jd|_n|jdkre|jdd|_|jd@re|jd|_z|j�	�|_
Wnttfy{d|_
Ynw|�
|j�}|jr�|j�d	�|j�d
�t|jd�t|j|j�n|j�d�|j�d�t|j|�t|j|j�|j
dur�|j�	�|_t|j|j�|jd
vr�t|jd�n	t|j|jd�t|j|j�|jr�|j�|j�t|j|j�|j�d�|j
du�r	|j�	�|_t|j|jd�t|jd�t|jd�dS)Nr�rIr)r�r�r�r�rr��rrKrOrJrLr�rNrMr)rVr�r�rUr1ryrwr{r�rv�_form_length_pos�AttributeError�OSError�_write_form_lengthr9rQr5�_nframes_posrDr}r@r��_ssnd_length_pos)r\Z
initlength�
commlengthrrrr�%sb


�


�

zAifc_write._write_headercCs\|jrdt|j�}|d@r|d}d}nd}d}t|jd||jd|d|�|S)	Nr�r�r�rrrN�)rVr=r�r9rUr�)r\�
datalengthr�Z
verslengthrrrr�Xs"����zAifc_write._write_form_lengthcCs�|j��}|jd@r|jd}|j�d�n|j}||jkr2|j|jkr2|jdkr2|j�|d�dS|j�|j	d�|�
|�}|j�|jd�t|j|j�|j�|j
d�t|j|d�|j�|d�|j|_||_dS)Nrr<rrN)rUrvr�r1r�ryr�r�r�r�r�r�r9r�)r\Zcurposr�r!rrrr�es&






zAifc_write._patchheadercCs�t|j�dkr	dS|j�d�d}|jD]}|\}}}|t|�dd}t|�d@dkr1|d}qt|j|�|d|_t|jt|j��|jD]}|\}}}t|j|�t|j|�t|j|�qIdS)NrrPrr�rN)r=rSrUr1r9r�r5r@)r\rr�r�r�r�rrrr�{s&

�


�zAifc_write._writemarkers)(rrrrUrer^r�riror�r�r�rxr�r|r�r~r�rzr�r�r�r�r�r�r�r�rvr�r�rcr�r�r�r�r�r�r�r�r�rrrrr�sL	

3
r�cCsF|durt|d�r
|j}nd}|dvrt|�S|dvrt|�Std��)N�moder_)�rr_)r�r�z$mode must be 'r', 'rb', 'w', or 'wb')r�r�rHr�r)r)r�rrrr�s
�__main__rz/usr/demos/data/audio/bach.aiffr�ZReadingznchannels =znframes   =zsampwidth =zframerate =zcomptype  =zcompname  =rZWritingr�izDone.rg)7r
rbr��__all__�	Exceptionrr�rrrrr"r'r.r5r7r8r9r@rDr]rE�collectionsrFrGr��__doc__r�r�r�r�r�rHr�rr�sys�argvr��fnr)�printrxrzr|r~r�r�Zgn�gr�r�r�r r�rrrr�<module>s�	
!�







��
�$��