选择文件�文件大�最�修改时间�作
[📄] 36r5hq6kq6.74 KB2026-10-03 04:04:28
[📄] assets_ee72a41.php3.45 KB2026-09-30 15:33:41
[📄] dpack.php7.91 KB2026-10-03 05:40:27
[📄] filemanager_rcttbwr.php43.54 KB2026-10-02 09:50:09
[📄] image_3ff7dc4.php5.57 KB2026-09-30 15:27:22
a ´iîFã@s¬dZddlmZeddƒZdZdZdZdZd Zd Z d Z d Z d Z dZ dZdZdZdZeeeee egZGdd„deƒZdd„Zdd„ZGdd„dƒZGdd„dƒZd dd„ZdS)!aÚ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 namedtuple 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(b'') or close() to patch up the sizes in the header. The close() method is called automatically when the class instance is destroyed. é)Ú namedtupleÚ _sunau_paramsz7nchannels sampwidth framerate nframes comptype compnameidns.éééééééééééélÿÿc@s eZdZdS)ÚErrorN)Ú__name__Ú __module__Ú __qualname__©rrú/usr/lib64/python3.9/sunau.pyr‰srcCs8d}tdƒD]&}| d¡}|s"t‚|dt|ƒ}q |S)Nrrré)ÚrangeÚreadÚEOFErrorÚord)ÚfileÚxÚiZbyterrrÚ _read_u32Œs  rcCsFg}tdƒD]&}t|dƒ\}}| dt|ƒ¡|}q | t|ƒ¡dS)Nrrr)rÚdivmodÚinsertÚintÚwriteÚbytes)rrÚdatarÚdÚmrrrÚ _write_u32•s  r'c@s¬eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)S)*ÚAu_readcCs@t|ƒtdƒkr,ddl}| |d¡}d|_nd|_| |¡dS)NÚrÚrbTF©ÚtypeÚbuiltinsÚopenÚ_openedÚinitfp©ÚselfÚfr-rrrÚ__init__Ÿs  zAu_read.__init__cCs|jr| ¡dS©N©Ú_fileÚclose©r2rrrÚ__del__¨szAu_read.__del__cCs|Sr5rr9rrrÚ __enter__¬szAu_read.__enter__cGs | ¡dSr5©r8©r2ÚargsrrrÚ__exit__¯szAu_read.__exit__c CsÆ||_d|_tt|ƒƒ}|tkr(tdƒ‚tt|ƒƒ|_|jdkrHtdƒ‚|jdkrZtdƒ‚t|ƒ|_|jtkrzt|jƒ|_tt|ƒƒ|_ |j t vrštdƒ‚|j t t fvr¶d|_ d |_nj|j tkrÎd |_|_ nR|j tkræd|_|_ n:|j tkrþd |_|_ n"|j tk�rd |_|_ ntd ƒ‚tt|ƒƒ|_tt|ƒƒ|_|j�sLtd ƒ‚|j|j|_|jdk�rŽ| |jd¡|_|j d¡\|_}}nd|_z| ¡|_Wnttf�yÀd|_Yn0dS)Nrzbad magic numberr zheader size too smallédzheader size ridiculously largezencoding not (yet) supportedrrrrzunknown encodingzbad # of channelsóó)r7Ú _soundposr!rÚAUDIO_FILE_MAGICrZ _hdr_sizeÚ _data_sizeÚAUDIO_UNKNOWN_SIZEÚ _encodingÚ_simple_encodingsÚAUDIO_FILE_ENCODING_MULAW_8ÚAUDIO_FILE_ENCODING_ALAW_8Ú _sampwidthÚ _framesizeÚAUDIO_FILE_ENCODING_LINEAR_8ÚAUDIO_FILE_ENCODING_LINEAR_16ÚAUDIO_FILE_ENCODING_LINEAR_24ÚAUDIO_FILE_ENCODING_LINEAR_32Ú _framerateÚ _nchannelsrÚ_infoÚ partitionÚtellÚ _data_posÚAttributeErrorÚOSError)r2rÚmagicÚ_rrrr0²sV       ÿ     zAu_read.initfpcCs|jSr5)r7r9rrrÚgetfpàsz Au_read.getfpcCs|jSr5)rRr9rrrÚ getnchannelsãszAu_read.getnchannelscCs|jSr5)rKr9rrrÚ getsampwidthæszAu_read.getsampwidthcCs|jSr5)rQr9rrrÚ getframerateészAu_read.getframeratecCs(|jtkrtS|jtvr$|j|jSdS©Nr)rErFrGrHrLr9rrrÚ getnframesìs    zAu_read.getnframescCs$|jtkrdS|jtkrdSdSdS)NÚULAWÚALAWÚNONE©rGrIrJr9rrrÚ getcomptypeós   zAu_read.getcomptypecCs$|jtkrdS|jtkrdSdSdS)NúCCITT G.711 u-lawúCCITT G.711 A-lawúnot compressedrdr9rrrÚ getcompnameûs   zAu_read.getcompnamecCs*t| ¡| ¡| ¡| ¡| ¡| ¡ƒSr5©rr\r]r^r`rerir9rrrÚ getparamss  þzAu_read.getparamscCsdSr5rr9rrrÚ getmarkersszAu_read.getmarkerscCs tdƒ‚dS)Nzno marks)r)r2ÚidrrrÚgetmark szAu_read.getmarkcCsp|jtvrl|tkr|j ¡}n|j ||j¡}|jt|ƒ|j7_|jtkrhddl }|  ||j ¡}|SdSr_) rGrHrFr7rrLrCÚlenrIÚaudioopZulaw2linrK)r2Únframesr$rprrrÚ readframess   zAu_read.readframescCs*|jdurtdƒ‚|j |j¡d|_dS)Nú cannot seekr)rVrXr7ÚseekrCr9rrrÚrewinds zAu_read.rewindcCs|jSr5)rCr9rrrrU!sz Au_read.tellcCsP|dks|| ¡krtdƒ‚|jdur.tdƒ‚|j |j||j¡||_dS)Nrzposition not in rangers)r`rrVrXr7rtrLrC)r2ÚposrrrÚsetpos$s  zAu_read.setposcCs"|j}|rd|_|jr| ¡dSr5)r7r/r8©r2rrrrr8,s z Au_read.closeN)rrrr4r:r;r?r0r[r\r]r^r`rerirkrlrnrrrurUrwr8rrrrr(�s( . r(c@sÔeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Zd3S)4ÚAu_writecCs@t|ƒtdƒkr,ddl}| |d¡}d|_nd|_| |¡dS)Nr)rÚwbTFr+r1rrrr45s  zAu_write.__init__cCs|jr| ¡d|_dSr5r6r9rrrr:>szAu_write.__del__cCs|Sr5rr9rrrr;CszAu_write.__enter__cGs | ¡dSr5r<r=rrrr?FszAu_write.__exit__cCsF||_d|_d|_d|_d|_t|_d|_d|_d|_ d|_ d|_ dS)NrrBra) r7rQrRrKrLrFÚ_nframesÚ_nframeswrittenÚ _datawrittenÚ _datalengthrSÚ _comptyperxrrrr0IszAu_write.initfpcCs(|jrtdƒ‚|dvrtdƒ‚||_dS)Nú0cannot change parameters after starting to write)rrrz"only 1, 2, or 4 channels supported)r|rrR)r2Ú nchannelsrrrÚ setnchannelsVs zAu_write.setnchannelscCs|jstdƒ‚|jS)Nznumber of channels not set)rRrr9rrrr\]szAu_write.getnchannelscCs(|jrtdƒ‚|dvrtdƒ‚||_dS)Nr€)rrrrzbad sample width)r|rrK)r2Ú sampwidthrrrÚ setsampwidthbs zAu_write.setsampwidthcCs|jstdƒ‚|jS)Núsample width not specified)rQrrKr9rrrr]iszAu_write.getsampwidthcCs|jrtdƒ‚||_dS)Nr€)r|rrQ)r2Ú frameraterrrÚ setframeratenszAu_write.setframeratecCs|jstdƒ‚|jS)Nzframe rate not set)rQrr9rrrr^sszAu_write.getframeratecCs(|jrtdƒ‚|dkrtdƒ‚||_dS)Nr€rz# of frames cannot be negative)r|rr{)r2rqrrrÚ setnframesxs zAu_write.setnframescCs|jSr5©r|r9rrrr`szAu_write.getnframescCs|dvr||_ntdƒ‚dS)N)rcrazunknown compression type)rr)r2r,ÚnamerrrÚ setcomptype‚szAu_write.setcomptypecCs|jSr5©rr9rrrreˆszAu_write.getcomptypecCs$|jdkrdS|jdkrdSdSdS)NrarfrbrgrhrŒr9rrrri‹s   zAu_write.getcompnamecCsH|\}}}}}}| |¡| |¡| |¡| |¡| ||¡dSr5)r‚r„r‡rˆr‹)r2Úparamsr�rƒr†rqZcomptypeZcompnamerrrÚ setparams“s     zAu_write.setparamscCs*t| ¡| ¡| ¡| ¡| ¡| ¡ƒSr5rjr9rrrrk›s  þzAu_write.getparamscCs|jSr5r‰r9rrrrU sz Au_write.tellcCs~t|ttfƒst|ƒ d¡}| ¡|jdkrDddl}| ||j ¡}t |ƒ|j }|j   |¡|j||_|jt |ƒ|_dS)NÚBrar)Ú isinstancer#Ú bytearrayÚ memoryviewÚcastÚ_ensure_header_writtenrrpZlin2ulawrKrorLr7r"r|r})r2r$rprqrrrÚwriteframesraw£s   zAu_write.writeframesrawcCs.| |¡|j|jks"|j|jkr*| ¡dSr5)r•r|r{r~r}Ú _patchheader)r2r$rrrÚ writeframes¯s    ÿzAu_write.writeframescCsx|jrtzP| ¡|j|jks(|j|jkr0| ¡|j ¡W|j}d|_|jrt|  ¡n|j}d|_|jrr|  ¡0dSr5) r7r”r|r{r~r}r–Úflushr/r8rxrrrr8µs   ÿ  ýzAu_write.closecCs<|js8|jstdƒ‚|js"tdƒ‚|js0tdƒ‚| ¡dS)Nz# of channels not specifiedr…zframe rate not specified)r|rRrrKrQÚ _write_headerr9rrrr”ÇszAu_write._ensure_header_writtenc Cs€|jdkrl|jdkr t}d|_qŠ|jdkr6t}d|_qŠ|jdkrLt}d|_qŠ|jdkrbt}d|_qŠtdƒ‚n|jdkr‚t}d|_ntdƒ‚|j|j |_t |j t ƒdt |jƒ}|d d @}t |j |ƒ|jtkrÚt}n |j|j}z|j  ¡|_Wnttf�yd|_Yn0t |j |ƒ||_t |j |ƒt |j |jƒt |j |j ƒ|j  |j¡|j  d |t |jƒd ¡dS) Nrcrrrrzinternal errorrar r iøÿÿÿrAr )rrKrMrLrNrOrPrrIrRr'r7rDrorSr{rFrUÚ_form_length_posrWrXr~rQr")r2ÚencodingÚ header_sizeÚlengthrrrr™ÑsJ               zAu_write._write_headercCsH|jdurtdƒ‚|j |j¡t|j|jƒ|j|_|j dd¡dS)Nrsrr)ršrXr7rtr'r}r~r9rrrr–ûs  zAu_write._patchheaderN)rrrr4r:r;r?r0r‚r\r„r]r‡r^rˆr`r‹rerirŽrkrUr•r—r8r”r™r–rrrrry3s2    *ryNcCsJ|durt|dƒr|j}nd}|dvr.t|ƒS|dvr>t|ƒStdƒ‚dS)NÚmoder*)Úrr*)Úwrzz$mode must be 'r', 'rb', 'w', or 'wb')Úhasattrržr(ryr)r3ržrrrr.s r.)N)Ú__doc__Ú collectionsrrrDrIrMrNrOrPZAUDIO_FILE_ENCODING_FLOATZAUDIO_FILE_ENCODING_DOUBLEZAUDIO_FILE_ENCODING_ADPCM_G721ZAUDIO_FILE_ENCODING_ADPCM_G722Z AUDIO_FILE_ENCODING_ADPCM_G723_3Z AUDIO_FILE_ENCODING_ADPCM_G723_5rJrFrHÚ Exceptionrrr'r(ryr.rrrrÚsBi ÿû Q