ok

Mini Shell

Direktori : /proc/self/root/opt/alt/python33/lib64/python3.3/__pycache__/
Upload File :
Current File : //proc/self/root/opt/alt/python33/lib64/python3.3/__pycache__/sunau.cpython-33.pyc

�
ryMasDc@s�dZdZdZdZdZdZdZdZdZd	Z	d
Z
dZdZd
Z
dZeeeeee
gZGdd�de�Zdd�Zdd�ZGdd�d�ZGdd�d�Zddd�ZeZdS(u�Stuff to parse Sun and NeXT audio files.

An audio file consists of a header followed by the data.  The structure
of the header is as follows.

        +---------------+
        | magic word    |
        +---------------+
        | header size   |
        +---------------+
        | data size     |
        +---------------+
        | encoding      |
        +---------------+
        | sample rate   |
        +---------------+
        | # of channels |
        +---------------+
        | info          |
        |               |
        +---------------+

The magic word consists of the 4 characters '.snd'.  Apart from the
info field, all header fields are 4 bytes in size.  They are all
32-bit unsigned integers encoded in big-endian byte order.

The header size really gives the start of the data.
The data size is the physical size of the data.  From the other
parameters the number of frames can be calculated.
The encoding gives the way in which audio samples are encoded.
Possible values are listed below.
The info field currently consists of an ASCII string giving a
human-readable description of the audio file.  The info field is
padded with NUL bytes to the header size.

Usage.

Reading audio files:
        f = sunau.open(file, 'r')
where file is either the name of a file or an open file pointer.
The open file pointer must have methods read(), seek(), and close().
When the setpos() and rewind() methods are not used, the seek()
method is not  necessary.

This returns an instance of a class with the following public methods:
        getnchannels()  -- returns number of audio channels (1 for
                           mono, 2 for stereo)
        getsampwidth()  -- returns sample width in bytes
        getframerate()  -- returns sampling frequency
        getnframes()    -- returns number of audio frames
        getcomptype()   -- returns compression type ('NONE' or 'ULAW')
        getcompname()   -- returns human-readable version of
                           compression type ('not compressed' matches 'NONE')
        getparams()     -- returns a tuple consisting of all of the
                           above in the above order
        getmarkers()    -- returns None (for compatibility with the
                           aifc module)
        getmark(id)     -- raises an error since the mark does not
                           exist (for compatibility with the aifc module)
        readframes(n)   -- returns at most n frames of audio
        rewind()        -- rewind to the beginning of the audio stream
        setpos(pos)     -- seek to the specified position
        tell()          -- return the current position
        close()         -- close the instance (make it unusable)
The position returned by tell() and the position given to setpos()
are compatible and have nothing to do with the actual position in the
file.
The close() method is called automatically when the class instance
is destroyed.

Writing audio files:
        f = sunau.open(file, 'w')
where file is either the name of a file or an open file pointer.
The open file pointer must have methods write(), tell(), seek(), and
close().

This returns an instance of a class with the following public methods:
        setnchannels(n) -- set the number of channels
        setsampwidth(n) -- set the sample width
        setframerate(n) -- set the frame rate
        setnframes(n)   -- set the number of frames
        setcomptype(type, name)
                        -- set the compression type and the
                           human-readable compression type
        setparams(tuple)-- set all parameters at once
        tell()          -- return current position in output file
        writeframesraw(data)
                        -- write audio frames without pathing up the
                           file header
        writeframes(data)
                        -- write audio frames and patch up the file header
        close()         -- patch up the file header and close the
                           output file
You should set the parameters before the first writeframesraw or
writeframes.  The total number of frames does not need to be set,
but when it is set to the correct value, the header does not have to
be patched up.
It is best to first set all parameters, perhaps possibly the
compression type, and then write audio frames using writeframesraw.
When all frames have been written, either call writeframes('') or
close() to patch up the sizes in the header.
The close() method is called automatically when the class instance
is destroyed.
idns.iiiiiiiiiiiil��cBs|EeZdZdS(uErrorN(u__name__u
__module__u__qualname__(u
__locals__((u*/opt/alt/python33/lib64/python3.3/sunau.pyuError�suErrorcCsSd}xFtd�D]8}|jd�}|s7t�n|dt|�}qW|S(Niiii(urangeureaduEOFErroruord(ufileuxuiubyte((u*/opt/alt/python33/lib64/python3.3/sunau.pyu	_read_u32�s	u	_read_u32cCseg}xEtd�D]7}t|d�\}}|jdt|��|}qW|jt|��dS(Niii(urangeudivmoduinsertuintuwriteubytes(ufileuxudatauiudum((u*/opt/alt/python33/lib64/python3.3/sunau.pyu
_write_u32�s
u
_write_u32cBs�|EeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%S(&uAu_readcCs\t|�td�krBddl}|j|d�}d|_n	d|_|j|�dS(NuiurbTF(utypeubuiltinsuopenuTrueu_openeduFalseuinitfp(uselfufubuiltins((u*/opt/alt/python33/lib64/python3.3/sunau.pyu__init__�s	uAu_read.__init__cCs|jr|j�ndS(N(u_fileuclose(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyu__del__�s	uAu_read.__del__cCs�||_d|_tt|��}|tkr?td��ntt|��|_|jdkrrtd��n|jdkr�td��nt|�|_|jtkr�t|j�|_ntt|��|_	|j	t
kr�td��n|j	ttfkr d|_
d	|_n�|j	tkrBd	|_|_
nr|j	tkrdd|_|_
nP|j	tkr�d
|_|_
n.|j	tkr�d|_|_
ntd��tt|��|_tt|��|_|j|j|_|jdkri|j|jd�|_xVtt|j��D]3}|j|d
kr/|jd|�|_Pq/q/Wn	d|_y|j�|_Wn!ttfk
r�d|_YnXdS(Niubad magic numberiuheader size too smalliduheader size ridiculously largeuencoding not (yet) supportediiiiuunknown encodingsu(u_fileu	_soundposuintu	_read_u32uAUDIO_FILE_MAGICuErroru	_hdr_sizeu
_data_sizeuAUDIO_UNKNOWN_SIZEu	_encodingu_simple_encodingsuAUDIO_FILE_ENCODING_MULAW_8uAUDIO_FILE_ENCODING_ALAW_8u
_sampwidthu
_framesizeuAUDIO_FILE_ENCODING_LINEAR_8uAUDIO_FILE_ENCODING_LINEAR_16uAUDIO_FILE_ENCODING_LINEAR_24uAUDIO_FILE_ENCODING_LINEAR_32u
_framerateu
_nchannelsureadu_infourangeulenutellu	_data_posuAttributeErroruOSErroruNone(uselfufileumagicui((u*/opt/alt/python33/lib64/python3.3/sunau.pyuinitfp�sV					uAu_read.initfpcCs|jS(N(u_file(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyugetfp�su
Au_read.getfpcCs|jS(N(u
_nchannels(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyugetnchannels�suAu_read.getnchannelscCs|jS(N(u
_sampwidth(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyugetsampwidth�suAu_read.getsampwidthcCs|jS(N(u
_framerate(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyugetframerate�suAu_read.getframeratecCs4|jtkrtS|jtkr0|j|jSdS(Ni(u
_data_sizeuAUDIO_UNKNOWN_SIZEu	_encodingu_simple_encodingsu
_framesize(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyu
getnframes�s
uAu_read.getnframescCs.|jtkrdS|jtkr&dSdSdS(NuULAWuALAWuNONE(u	_encodinguAUDIO_FILE_ENCODING_MULAW_8uAUDIO_FILE_ENCODING_ALAW_8(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyugetcomptype�s
uAu_read.getcomptypecCs.|jtkrdS|jtkr&dSdSdS(NuCCITT G.711 u-lawuCCITT G.711 A-lawunot compressed(u	_encodinguAUDIO_FILE_ENCODING_MULAW_8uAUDIO_FILE_ENCODING_ALAW_8(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyugetcompname�s
uAu_read.getcompnamecCs:|j�|j�|j�|j�|j�|j�fS(N(ugetnchannelsugetsampwidthugetframerateu
getnframesugetcomptypeugetcompname(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyu	getparams�suAu_read.getparamscCsdS(N(uNone(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyu
getmarkers�suAu_read.getmarkerscCstd��dS(Nuno marks(uError(uselfuid((u*/opt/alt/python33/lib64/python3.3/sunau.pyugetmarksuAu_read.getmarkcCs�|jtkr�|tkr-|jj�}n|jj||j�}|jt|�|j7_|jtkr�ddl	}|j
||j�}n|SdS(Ni(
u	_encodingu_simple_encodingsuAUDIO_UNKNOWN_SIZEu_fileureadu
_framesizeu	_soundposulenuAUDIO_FILE_ENCODING_MULAW_8uaudioopuulaw2linu
_sampwidthuNone(uselfunframesudatauaudioop((u*/opt/alt/python33/lib64/python3.3/sunau.pyu
readframessuAu_read.readframescCs>|jdkrtd��n|jj|j�d|_dS(Nucannot seeki(u	_data_posuNoneuOSErroru_fileuseeku	_soundpos(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyurewindsuAu_read.rewindcCs|jS(N(u	_soundpos(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyutellsuAu_read.tellcCsv|dks||j�kr-td��n|jdkrKtd��n|jj|j||j�||_dS(Niuposition not in rangeucannot seek(	u
getnframesuErroru	_data_posuNoneuOSErroru_fileuseeku
_framesizeu	_soundpos(uselfupos((u*/opt/alt/python33/lib64/python3.3/sunau.pyusetpossuAu_read.setposcCs/|jr"|jr"|jj�nd|_dS(N(u_openedu_fileucloseuNone(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyuclose!su
Au_read.closeN(u__name__u
__module__u__qualname__u__init__u__del__uinitfpugetfpugetnchannelsugetsampwidthugetframerateu
getnframesugetcomptypeugetcompnameu	getparamsu
getmarkersugetmarku
readframesurewindutellusetposuclose(u
__locals__((u*/opt/alt/python33/lib64/python3.3/sunau.pyuAu_read�s$	/
uAu_readcBs(|EeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�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/S(0uAu_writecCs\t|�td�krBddl}|j|d�}d|_n	d|_|j|�dS(NuiuwbTF(utypeubuiltinsuopenuTrueu_openeduFalseuinitfp(uselfufubuiltins((u*/opt/alt/python33/lib64/python3.3/sunau.pyu__init__(s	uAu_write.__init__cCs#|jr|j�nd|_dS(N(u_fileucloseuNone(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyu__del__1s	
uAu_write.__del__cCsg||_d|_d|_d|_d|_t|_d|_d|_d|_	d|_
d|_dS(NisuULAW(u_fileu
_framerateu
_nchannelsu
_sampwidthu
_framesizeuAUDIO_UNKNOWN_SIZEu_nframesu_nframeswrittenu_datawrittenu_datalengthu_infou	_comptype(uselfufile((u*/opt/alt/python33/lib64/python3.3/sunau.pyuinitfp6s										uAu_write.initfpcCs@|jrtd��n|dkr3td��n||_dS(Nu0cannot change parameters after starting to writeiiiu"only 1, 2, or 4 channels supported(iii(u_nframeswrittenuErroru
_nchannels(uselfu	nchannels((u*/opt/alt/python33/lib64/python3.3/sunau.pyusetnchannelsCs
	uAu_write.setnchannelscCs|jstd��n|jS(Nunumber of channels not set(u
_nchannelsuError(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyugetnchannelsJs	uAu_write.getnchannelscCs@|jrtd��n|dkr3td��n||_dS(Nu0cannot change parameters after starting to writeiiiubad sample width(iii(u_nframeswrittenuErroru
_sampwidth(uselfu	sampwidth((u*/opt/alt/python33/lib64/python3.3/sunau.pyusetsampwidthOs
	uAu_write.setsampwidthcCs|jstd��n|jS(Nusample width not specified(u
_framerateuErroru
_sampwidth(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyugetsampwidthVs	uAu_write.getsampwidthcCs%|jrtd��n||_dS(Nu0cannot change parameters after starting to write(u_nframeswrittenuErroru
_framerate(uselfu	framerate((u*/opt/alt/python33/lib64/python3.3/sunau.pyusetframerate[s	uAu_write.setframeratecCs|jstd��n|jS(Nuframe rate not set(u
_framerateuError(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyugetframerate`s	uAu_write.getframeratecCs@|jrtd��n|dkr3td��n||_dS(Nu0cannot change parameters after starting to writeiu# of frames cannot be negative(u_nframeswrittenuErroru_nframes(uselfunframes((u*/opt/alt/python33/lib64/python3.3/sunau.pyu
setnframeses
	uAu_write.setnframescCs|jS(N(u_nframeswritten(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyu
getnframeslsuAu_write.getnframescCs(|dkr||_ntd��dS(NuNONEuULAWuunknown compression type(uNONEuULAW(u	_comptypeuError(uselfutypeuname((u*/opt/alt/python33/lib64/python3.3/sunau.pyusetcomptypeosuAu_write.setcomptypecCs|jS(N(u	_comptype(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyugetcomptypeusuAu_write.getcomptypecCs.|jdkrdS|jdkr&dSdSdS(NuULAWuCCITT G.711 u-lawuALAWuCCITT G.711 A-lawunot compressed(u	_comptype(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyugetcompnamexs
uAu_write.getcompnamecCs`|\}}}}}}|j|�|j|�|j|�|j|�|j||�dS(N(usetnchannelsusetsampwidthusetframerateu
setnframesusetcomptype(uselfuparamsu	nchannelsu	sampwidthu	framerateunframesucomptypeucompname((u*/opt/alt/python33/lib64/python3.3/sunau.pyu	setparams�s



uAu_write.setparamscCs:|j�|j�|j�|j�|j�|j�fS(N(ugetnchannelsugetsampwidthugetframerateu
getnframesugetcomptypeugetcompname(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyu	getparams�suAu_write.getparamscCs|jS(N(u_nframeswritten(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyutell�su
Au_write.tellcCs�|j�|jdkr=ddl}|j||j�}nt|�|j}|jj|�|j	||_	|j
t|�|_
dS(NuULAWi(u_ensure_header_writtenu	_comptypeuaudioopulin2ulawu
_sampwidthulenu
_framesizeu_fileuwriteu_nframeswrittenu_datawritten(uselfudatauaudioopunframes((u*/opt/alt/python33/lib64/python3.3/sunau.pyuwriteframesraw�s
uAu_write.writeframesrawcCsB|j|�|j|jks1|j|jkr>|j�ndS(N(uwriteframesrawu_nframeswrittenu_nframesu_datalengthu_datawrittenu_patchheader(uselfudata((u*/opt/alt/python33/lib64/python3.3/sunau.pyuwriteframes�s
uAu_write.writeframescCs�|jr�zn|j�|j|jks:|j|jkrG|j�n|jj�|jrv|jrv|jj	�nWdd|_XndS(N(u_fileu_ensure_header_writtenu_nframeswrittenu_nframesu_datalengthu_datawrittenu_patchheaderuflushu_openeducloseuNone(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyuclose�s	


uAu_write.closecCsb|js^|js!td��n|js9td��n|jsQtd��n|j�ndS(Nu# of channels not specifiedusample width not specifieduframe rate not specified(u_nframeswrittenu
_nchannelsuErroru
_sampwidthu
_framerateu
_write_header(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyu_ensure_header_written�s				uAu_write._ensure_header_writtenc
Cs�|jdkr�|jdkr0t}d|_q�|jdkrQt}d|_q�|jdkrrt}d|_q�td��n-|jdkr�t}d|_ntd��|j|j|_t	|j
t�dt|j
�}|dd@}t	|j
|�|jtkrt}n|j|j}y|j
j�|_Wn!ttfk
rcd|_YnXt	|j
|�||_t	|j
|�t	|j
|j�t	|j
|j�|j
j|j
�|j
jd	|t|j
�d
�dS(NuNONEiiiuinternal erroruULAWiisii����(u	_comptypeu
_sampwidthuAUDIO_FILE_ENCODING_LINEAR_8u
_framesizeuAUDIO_FILE_ENCODING_LINEAR_16uAUDIO_FILE_ENCODING_LINEAR_32uErroruAUDIO_FILE_ENCODING_MULAW_8u
_nchannelsu
_write_u32u_fileuAUDIO_FILE_MAGICulenu_infou_nframesuAUDIO_UNKNOWN_SIZEutellu_form_length_posuAttributeErroruOSErroruNoneu_datalengthu
_framerateuwrite(uselfuencodinguheader_sizeulength((u*/opt/alt/python33/lib64/python3.3/sunau.pyu
_write_header�sD		uAu_write._write_headercCsg|jdkrtd��n|jj|j�t|j|j�|j|_|jjdd�dS(Nucannot seekii(u_form_length_posuNoneuOSErroru_fileuseeku
_write_u32u_datawrittenu_datalength(uself((u*/opt/alt/python33/lib64/python3.3/sunau.pyu_patchheader�suAu_write._patchheaderN(u__name__u
__module__u__qualname__u__init__u__del__uinitfpusetnchannelsugetnchannelsusetsampwidthugetsampwidthusetframerateugetframerateu
setnframesu
getnframesusetcomptypeugetcomptypeugetcompnameu	setparamsu	getparamsutelluwriteframesrawuwriteframesucloseu_ensure_header_writtenu
_write_headeru_patchheader(u
__locals__((u*/opt/alt/python33/lib64/python3.3/sunau.pyuAu_write&s.	


'uAu_writecCsl|dkr0t|d�r'|j}q0d}n|dkrFt|�S|dkr\t|�Std��dS(	Numodeurburuwuwbu$mode must be 'r', 'rb', 'w', or 'wb'(ururb(uwuwb(uNoneuhasattrumodeuAu_readuAu_writeuError(ufumode((u*/opt/alt/python33/lib64/python3.3/sunau.pyuopen�s	

uopenN(u__doc__uAUDIO_FILE_MAGICuAUDIO_FILE_ENCODING_MULAW_8uAUDIO_FILE_ENCODING_LINEAR_8uAUDIO_FILE_ENCODING_LINEAR_16uAUDIO_FILE_ENCODING_LINEAR_24uAUDIO_FILE_ENCODING_LINEAR_32uAUDIO_FILE_ENCODING_FLOATuAUDIO_FILE_ENCODING_DOUBLEuAUDIO_FILE_ENCODING_ADPCM_G721uAUDIO_FILE_ENCODING_ADPCM_G722u AUDIO_FILE_ENCODING_ADPCM_G723_3u AUDIO_FILE_ENCODING_ADPCM_G723_5uAUDIO_FILE_ENCODING_ALAW_8uAUDIO_UNKNOWN_SIZEu_simple_encodingsu	ExceptionuErroru	_read_u32u
_write_u32uAu_readuAu_writeuNoneuopenuopenfp(((u*/opt/alt/python33/lib64/python3.3/sunau.pyu<module>hs6		��

Zerion Mini Shell 1.0