b374k
m1n1 1.01
Apache/2.2.15 (CentOS)
Linux obd60-6c49958d75-2q7cw 5.4.0-174-generic #193-Ubuntu SMP Thu Mar 7 14:29:28 UTC 2024 x86_64
uid=48(apache) gid=48(apache) groups=48(apache)
server ip : 172.67.192.52 | your ip : 10.244.126.0
safemode OFF
 >  / usr / lib64 / python2.6 /
Filename/usr/lib64/python2.6/aifc.pyc
Size28.87 kb
Permissionrw-r--r--
Ownerapache
Create time23-Dec-2025 17:41
Last modified20-Jun-2019 19:45
Last accessed22-Apr-2026 05:30
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
Ñò
§ÚêLc @s=dZddkZddkZdddgZdefd��YZdZd�Zd �Zd
�Z d �Z
d Z d
�Z d�Z
d�Zd�Zd�ZddklZdfd��YZdfd��YZed�ZeZedjoDddkZeid oeiid�neidZeed�ZdGeGHdGei�GHdGei�GHdGei �GHd Gei!�GHd!Gei"�GHd"Gei#�GHeid#o�eid#Z$d$Ge$GHee$d%�Z%e%i&ei'��x,ei(d&�Z)e) oPne%i*e)�qìe%i+�ei+�d'GHnndS((sDStuff to parse AIFF-C and AIFF files.

Unless explicitly stated otherwise, the description below is true
both for AIFF-C files and AIFF files.

An AIFF-C file has the following structure.

+-----------------+
| FORM |
+-----------------+
| <size> |
+----+------------+
| | AIFC |
| +------------+
| | <chunks> |
| | . |
| | . |
| | . |
+----+------------+

An AIFF file has the string "AIFF" instead of "AIFC".

A chunk consists of an identifier (4 bytes) followed by a size (4 bytes,
big endian order), followed by the data. The size field does not include
the size of the 8 byte header.

The following chunk types are recognized.

FVER
<version number of AIFF-C defining document> (AIFF-C only).
MARK
<# of markers> (2 bytes)
list of markers:
<marker ID> (2 bytes, must be > 0)
<position> (4 bytes)
<marker name> ("pstring")
COMM
<# of channels> (2 bytes)
<# of sound frames> (4 bytes)
<size of the samples> (2 bytes)
<sampling frequency> (10 bytes, IEEE 80-bit extended
floating point)
in AIFF-C files only:
<compression type> (4 bytes)
<human-readable version of compression type> ("pstring")
SSND
<offset> (4 bytes, not used by this program)
<blocksize> (4 bytes, not used by this program)
<sound data>

A pstring consists of 1 byte length, a string of characters, and 0 or 1
byte pad to make the total length even.

Usage.

Reading AIFF files:
f = aifc.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().
In some types of audio files, if the setpos() method is 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' for AIFF files)
getcompname() -- returns human-readable version of
compression type ('not compressed' for AIFF files)
getparams() -- returns a tuple consisting of all of the
above in the above order
getmarkers() -- get the list of marks in the audio file or None
if there are no marks
getmark(id) -- get mark with the specified id (raises an error
if the mark does not exist)
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(), the position given to setpos() and
the position of marks are all 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 AIFF files:
f = aifc.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:
aiff() -- create an AIFF file (AIFF-C default)
aifc() -- create an AIFF-C file
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
setmark(id, pos, name)
-- add specified mark to the list of marks
tell() -- return current position in output file (useful
in combination with setmark())
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.
Marks can be added anytime. If there are any marks, ypu must call
close() after all frames have been written.
The close() method is called automatically when the class instance
is destroyed.

When a file is opened with the extension '.aiff', an AIFF file is
written, otherwise an AIFF-C file is written. This default can be
changed by calling aiff() or aifc() before the first writeframes or
writeframesraw.
iÿÿÿÿNtErrortopentopenfpcBseZRS((t__name__t
__module__(((s/usr/lib64/python2.6/aifc.pyR�sl@QEcCsDy!tid|id��dSWntij
o
t�nXdS(Ns>lii(tstructtunpacktreadterrortEOFError(tfile((s/usr/lib64/python2.6/aifc.pyt
_read_long�s!cCsDy!tid|id��dSWntij
o
t�nXdS(Ns>Lii(RRRRR (R
((s/usr/lib64/python2.6/aifc.pyt _read_ulong�s!cCsDy!tid|id��dSWntij
o
t�nXdS(Ns>hii(RRRRR (R
((s/usr/lib64/python2.6/aifc.pyt _read_short�s!cCsct|id��}|djo
d}n|i|�}|d@djo|id�}n|S(Niit(tordR(R
tlengthtdatatdummy((s/usr/lib64/python2.6/aifc.pyt _read_string¥s

gâÿÿÿÿÿïcCsÇt|�}d}|djod}|d}nt|�}t|�}||jo|jo
djno
d}nA|djo
t}n*|d}|d|td |d
�}||S( Niiiÿÿÿÿi�giÿiÿ?lg@i?(R
R t _HUGE_VALtpow(tftexpontsignthimanttlomant((s/usr/lib64/python2.6/aifc.pyt _read_float±s 
  *



cCs|itid|��dS(Ns>h(twriteRtpack(Rtx((s/usr/lib64/python2.6/aifc.pyt _write_shortÂscCs|itid|��dS(Ns>L(RRR(RR((s/usr/lib64/python2.6/aifc.pyt _write_longÅscCs{t|�djotd��n|itt|���|i|�t|�d@djo|itd��ndS(Niÿs%string exceeds maximum pstring lengthii(tlent
ValueErrorRtchr(Rts((s/usr/lib64/python2.6/aifc.pyt
_write_stringÈs 
c Cseddk}|djod}|d}nd}|djod}d}d}nå|i|�\}}|djp
|djo|dB}d}d}n�|d}|djo|i||�}d}n||B}|i|d�}|i|�}t|�}|i||d�}|i|�}t|�}t||�t||�t||�dS( Niÿÿÿÿii�i@iiÿiþ?i (tmathtfrexptldexptfloortlongRR ( RRR&RRRRtfmanttfsmant((s/usr/lib64/python2.6/aifc.pyt _write_floatÐs8 








  

(tChunkt Aifc_readcBsÎeZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z
d �Z d
�Z d �Z
d �Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�ZRS(cCsnd|_d|_d|_g|_d|_||_t|�}|i�djo
t d�n|i
d�}|djo
d|_ n$|djo
d|_ n
t d�d|_ xãd|_
yt|i�}Wntj
oPnX|i�}|d jo|i|�d|_ nq|d
jo%||_|i
d �}d|_
n?|d jot|�|_n|d
jo|i|�n|i�qº|i p |i o
t d�n|i o |io�ddk}|id|i|id |i|ig}|idjo|i|d<n+|idjo|i|d<n
t d�|ii|�ndS(NitFORMs file does not start with FORM iditAIFFtAIFCisnot an AIFF or AIFF-C filetCOMMtSSNDitFVERtMARKs$COMM chunk and/or SSND chunk missingiÿÿÿÿis$cannot compress more than 2 channels(t_versiontNonet_decompt_convertt_markerst _soundpost_fileR.tgetnameRRt_aifct_comm_chunk_readt_ssnd_seek_neededR t_read_comm_chunkt _ssnd_chunkR t _readmarktskiptcltORIGINAL_FORMATtBITS_PER_COMPONENTt
_sampwidtht
FRAME_RATEt
_frameratet
_nchannelstMONOtSTEREO_INTERLEAVEDt SetParams(tselfR
tchunktformdatat chunknameRRFtparams((s/usr/lib64/python2.6/aifc.pytinitfps`       




    



 




   cCs@t|�td�joti|d�}n|i|�dS(NRtrb(ttypet __builtin__RRU(RPR((s/usr/lib64/python2.6/aifc.pyt__init__KscCs|iS(N(R=(RP((s/usr/lib64/python2.6/aifc.pytgetfpTscCsd|_d|_dS(Nii(RAR<(RP((s/usr/lib64/python2.6/aifc.pytrewindWs cCs5|io|ii�d|_n|ii�dS(N(R9tCloseDecompressorR8R=tclose(RP((s/usr/lib64/python2.6/aifc.pyR][s


cCs|iS(N(R<(RP((s/usr/lib64/python2.6/aifc.pyttellascCs|iS(N(RL(RP((s/usr/lib64/python2.6/aifc.pyt getnchannelsdscCs|iS(N(t_nframes(RP((s/usr/lib64/python2.6/aifc.pyt
getnframesgscCs|iS(N(RI(RP((s/usr/lib64/python2.6/aifc.pyt getsampwidthjscCs|iS(N(RK(RP((s/usr/lib64/python2.6/aifc.pyt getframeratemscCs|iS(N(t _comptype(RP((s/usr/lib64/python2.6/aifc.pyt getcomptypepscCs|iS(N(t _compname(RP((s/usr/lib64/python2.6/aifc.pyt getcompnamesscCs:|i�|i�|i�|i�|i�|i�fS(N(R_RbRcRaReRg(RP((s/usr/lib64/python2.6/aifc.pyt getparamsyscCs"t|i�djodS|iS(Ni(R!R;R8(RP((s/usr/lib64/python2.6/aifc.pyt
getmarkers~scCs>x'|iD]}||djo|Sq
Wtd|f�dS(Nismarker %r does not exist(R;R(RPtidtmarker((s/usr/lib64/python2.6/aifc.pytgetmark�s

 cCs@|djp||ijo
td�n||_d|_dS(Nisposition not in rangei(R`RR<RA(RPtpos((s/usr/lib64/python2.6/aifc.pytsetpos�s
 cCsß|io^|iid�|iid�}|i|i}|o|ii|d�nd|_n|djodS|ii||i�}|io|o|i|�}n|it|�|i|i |_|S(NiiR(
RARCtseekRR<t
_framesizeR:R!RLRI(RPtnframesRRmR((s/usr/lib64/python2.6/aifc.pyt
readframes�s


$cCsNddk}|ii|it|�d�}|iit|�|i|�S(Niÿÿÿÿi(RFR9tSetParamtFRAME_BUFFER_SIZER!t
DecompressRL(RPRRFR((s/usr/lib64/python2.6/aifc.pyt _decomp_data£s
 cCsddk}|i|d�S(Niÿÿÿÿi(taudiooptulaw2lin(RPRRw((s/usr/lib64/python2.6/aifc.pyt _ulaw2linªs cCsNddk}t|d�p
d|_n|i|d|i�\}|_|S(Niÿÿÿÿt _adpcmstatei(RwthasattrR8Rzt adpcm2lin(RPRRw((s/usr/lib64/python2.6/aifc.pyt
_adpcm2lin®s  
 c
Cs­t|�|_t|�|_t|�dd|_tt|��|_|i|i|_|i o0d}|i
djod}dGHd|_
n|i d�|_ |o^t
|ii d��}|d@djo|d}n|i
||_
|iid d�nt|�|_|i d
joh|i d joJyd dk}Wntj
oq�X|i|_|id|_dSnyd dk}Wnvtj
oj|i d joJy0d dk}|i|_|id
|_dSWqtj
oqXntd�nX|i d jo|i}|id
|_n7|i djo|i}|id
|_n
td�|i|�|_|i|_q©nd
|_ d|_dS(NiiiiisWarning: bad COMM chunk sizeiiiÿÿÿÿtNONEtG722tULAWis#cannot read compressed AIFF-C filestALAWsunsupported compression typesnot compressed(R
RLR R`RItintRRKRpR?t chunksizeRRdRR
RoRRfRwt ImportErrorR}R:RFRyRt G711_ULAWt G711_ALAWtOpenDecompressorR9Rv(RPRQtkludgeRRwRFtscheme((s/usr/lib64/python2.6/aifc.pyRB·sf

        cCsÌt|�}yjxct|�D]U}t|�}t|�}t|�}|p|o|ii|||f�qqWWnOtj
oCdGt|i�Gt|i�djodGndGdG|GHnXdS(Ns!Warning: MARK chunk contains onlyiRktmarkerss
instead of(R
trangeR RR;tappendR R!(RPRQtnmarkerstiRjRmtname((s/usr/lib64/python2.6/aifc.pyRDôs  
   %
(RRRURYRZR[R]R^R_RaRbRcReRgRhRiRlRnRrRvRyR}RBRD(((s/usr/lib64/python2.6/aifc.pyR/ós,$ 4                  =t
Aifc_writecBs:eZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z
d �Z d
�Z d �Z
d �Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d �Z"d!�Z#RS("cCsst|�td�jo|}ti|d�}nd}|i|�|ddjo
d|_n
d|_dS(NRtwbs???iûÿÿÿs.aiffii(RWRXRRUR?(RPRtfilename((s/usr/lib64/python2.6/aifc.pyRY's

cCs�||_t|_d|_d|_d|_d|_d|_d|_ d|_
d|_ d|_ d|_
d|_g|_d|_d|_dS(NR~snot compressedii(R=t
_AIFC_versionR7RdRfR8t_compR:RLRIRKR`t_nframeswrittent _datawrittent _datalengthR;t _marklengthR?(RPR
((s/usr/lib64/python2.6/aifc.pyRU4s                cCs|io|i�ndS(N(R=R](RP((s/usr/lib64/python2.6/aifc.pyt__del__Fs
cCs$|io
td�nd|_dS(Ns0cannot change parameters after starting to writei(R�RR?(RP((s/usr/lib64/python2.6/aifc.pytaiffMs

cCs$|io
td�nd|_dS(Ns0cannot change parameters after starting to writei(R�RR?(RP((s/usr/lib64/python2.6/aifc.pytaifcRs

cCs>|io
td�n|djo
td�n||_dS(Ns0cannot change parameters after starting to writeisbad # of channels(R�RRL(RPt nchannels((s/usr/lib64/python2.6/aifc.pyt setnchannelsWs




cCs|ip
td�n|iS(Nsnumber of channels not set(RLR(RP((s/usr/lib64/python2.6/aifc.pyR_^s

cCsK|io
td�n|djp
|djo
td�n||_dS(Ns0cannot change parameters after starting to writeiisbad sample width(R�RRI(RPt sampwidth((s/usr/lib64/python2.6/aifc.pyt setsampwidthcs



cCs|ip
td�n|iS(Nssample width not set(RIR(RP((s/usr/lib64/python2.6/aifc.pyRbjs

cCs>|io
td�n|djo
td�n||_dS(Ns0cannot change parameters after starting to writeisbad frame rate(R�RRK(RPt framerate((s/usr/lib64/python2.6/aifc.pyt setframerateos




cCs|ip
td�n|iS(Nsframe rate not set(RKR(RP((s/usr/lib64/python2.6/aifc.pyRcvs

cCs$|io
td�n||_dS(Ns0cannot change parameters after starting to write(R�RR`(RPRq((s/usr/lib64/python2.6/aifc.pyt
setnframes{s

cCs|iS(N(R�(RP((s/usr/lib64/python2.6/aifc.pyRa�scCsG|io
td�n|djo
td�n||_||_dS(Ns0cannot change parameters after starting to writeR~R�R�Rsunsupported compression type(sNONEsULAWsALAWsG722(R�RRdRf(RPtcomptypetcompname((s/usr/lib64/python2.6/aifc.pyt setcomptype�s 



 cCs|iS(N(Rd(RP((s/usr/lib64/python2.6/aifc.pyRe�scCs|iS(N(Rf(RP((s/usr/lib64/python2.6/aifc.pyRg�scCs�|\}}}}}}|io
td�n|djo
td�n|i|�|i|�|i|�|i|�|i||�dS(Ns0cannot change parameters after starting to writeR~R�R�Rsunsupported compression type(sNONEsULAWsALAWsG722(R�RR�R�R¡R¢R¥(RPtinfoR�R�R RqR£R¤((s/usr/lib64/python2.6/aifc.pyt setparams�s







cCsV|i p|i p |i o
td�n|i|i|i|i|i|ifS(Nsnot all parameters set(RLRIRKRR`RdRf(RP((s/usr/lib64/python2.6/aifc.pyRh¢s!
cCsÊ|djo
td�n|djo
td�nt|�td�jo
td�nxPtt|i��D]9}||i|djo|||f|i|<dSqpW|ii|||f�dS(Nismarker ID must be > 0smarker position must be >= 0Rsmarker name must be a string(RRWR�R!R;R�(RPRjRmR�R�((s/usr/lib64/python2.6/aifc.pytsetmark¨s




 cCs>x'|iD]}||djo|Sq
Wtd|f�dS(Nismarker %r does not exist(R;R(RPRjRk((s/usr/lib64/python2.6/aifc.pyRlµs

 cCs"t|i�djodS|iS(Ni(R!R;R8(RP((s/usr/lib64/python2.6/aifc.pyRi»scCs|iS(N(R�(RP((s/usr/lib64/python2.6/aifc.pyR^ÀscCs�|it|��t|�|i|i}|io|i|�}n|ii|�|i||_|it|�|_dS(N( t_ensure_header_writtenR!RIRLR:R=RR�R�(RPRRq((s/usr/lib64/python2.6/aifc.pytwriteframesrawÃs
cCsE|i|�|i|ijp|i|ijo|i�ndS(N(RªR�R`R�R�t _patchheader(RPR((s/usr/lib64/python2.6/aifc.pyt writeframesÌs
cCsÂ|id�|id@o*|iitd��|id|_n|i�|i|ijp|i|ijp
|i o|i
�n|i o|i i �d|_ n|ii�dS(Nii(R©R�R=RR#t
_writemarkersR�R`R�R�R«R�tCloseCompressorR8R](RP((s/usr/lib64/python2.6/aifc.pyR]Òs





cCs^ddk}|ii|it|��}|ii|it|��}|ii|i|�S(Niÿÿÿÿ(RFR�RsRtR!tCOMPRESSED_BUFFER_SIZEtCompressR`(RPRRFR((s/usr/lib64/python2.6/aifc.pyt
_comp_dataæs cCsddk}|i|d�S(Niÿÿÿÿi(Rwtlin2ulaw(RPRRw((s/usr/lib64/python2.6/aifc.pyt _lin2ulawìs cCsNddk}t|d�p
d|_n|i|d|i�\}|_|S(NiÿÿÿÿRzi(RwR{R8Rzt lin2adpcm(RPRRw((s/usr/lib64/python2.6/aifc.pyt
_lin2adpcmðs  
 cCsô|ipæ|id
jo8|ip
d|_n|idjo
td�qRn|idjo8|ip
d|_n|idjo
td�q�n|ip
td�n|ip
td�n|ip
td �n|i|�ndS( NR�R�is9sample width must be 2 when compressing with ULAW or ALAWRs:sample width must be 2 when compressing with G7.22 (ADPCM)s# channels not specifiedssample width not specifiedssampling rate not specified(sULAWsALAW(R�RdRIRRLRKt
_write_header(RPtdatasize((s/usr/lib64/python2.6/aifc.pyR©øs$










cCs¬|idjo|i|_dSyddk}Wnftj
oZ|idjo:y ddk}|i|_dSWq�tj
oq�Xntd�nX|idjo
|i}n'|idjo
|i }n
td�|i
|�|_ |i d|i
|id|i|i|id |id g
}|id
jo|i|d
<n+|id jo|i|d
<n
td �|i i|�|i idd
�}|i|_dS(NRiÿÿÿÿR�s$cannot write compressed AIFF-C filesR�sunsupported compression typeiiidiis$cannot compress more than 2 channelsR(RdRµR:RFR�RwR³RR�R�tOpenCompressorR�RGRHRIRJRKRtR¯RLRMRNROR°R±(RPRFRwR�RTR((s/usr/lib64/python2.6/aifc.pyt_init_compression sB    

     cCsÏ|io|idjo|i�n|iid�|ip||i|i|_n|i|i|i|_|id@o|id|_n|io�|idjo6|id|_|id@o|id|_q3q7|idjo:|idd |_|id@o|id|_q3q7n|ii �|_
|i |i�}|ioG|iid
�|iid �t |id �t |i|i
�n|iid �|iid
�t |i|�t|i|i�|ii �|_t |i|i�t|i|id�t|i|i�|io*|ii|i�t|i|i�n|iid�|ii �|_t |i|id�t |id�t |id�dS(NR~R0iR�R�iRiiR2R5R1R3iR4i(sULAWsALAW(R?RdR¹R=RR`RLRIR�R^t_form_length_post_write_form_lengthR R7Rt _nframes_posR-RKR%Rft_ssnd_length_pos(RPt
initlengtht
commlength((s/usr/lib64/python2.6/aifc.pyR¶2sP



cCs{|io6d t|i�}|d@o|d}nd}n
d}d}t|id||id|d|�|S(
Niiii iiiii(R?R!RfR R=R�(RPt
datalengthR¿t
verslength((s/usr/lib64/python2.6/aifc.pyR»]s
 
 "cCs<|ii�}|id@o'|id}|iitd��n
|i}||ijo;|i|ijo(|idjo|ii |d�dS|ii |i
d�|i |�}|ii |i d�t
|i|i�|ii |id�t
|i|d�|ii |d�|i|_||_dS(Niii(R=R^R�RR#R�R`R�R�RoRºR»R¼R R½(RPtcurposRÀR((s/usr/lib64/python2.6/aifc.pyR«js&
  cCst|i�djodS|iid�d}x]|iD]R}|\}}}|t|�dd}t|�d@djo|d}q;q;Wt|i|�|d|_t|it|i��xP|iD]E}|\}}}t|i|�t|i|�t|i|�qÑWdS(NiR6iiii(R!R;R=RR R�RR%(RPRRkRjRmR�((s/usr/lib64/python2.6/aifc.pyR­�s&


($RRRYRUR�R�R�R�R_R�RbR¡RcR¢RaR¥ReRgR§RhR¨RlRiR^RªR¬R]R±R³RµR©R¹R¶R»R«R­(((s/usr/lib64/python2.6/aifc.pyR� sD
               
         & +
cCsq|djo't|d�o
|i}q4d}n|djo t|�S|djo t|�Std�dS( NtmodeRVtrtwR�s$mode must be 'r', 'rb', 'w', or 'wb'(RÄsrb(RÅswb(R8R{RÃR/R�R(RRÃ((s/usr/lib64/python2.6/aifc.pyR�s



 
 t__main__is/usr/demos/data/audio/bach.aiffRÄtReadings nchannels =s nframes =s sampwidth =s framerate =s comptype =s compname =itWritingRÅisDone.(,t__doc__RRXt__all__t ExceptionRR�R R R
RRRRR R%R-RQR.R/R�R8RRRtsystargvR�tfnRR_RaRbRcReRgtgntgR§RhRrRR¬R](((s/usr/lib64/python2.6/aifc.pyt<module>�s`     
     !ÿÿ�