python (3.11.7)

(root)/
lib/
python3.11/
__pycache__/
sunau.cpython-311.pyc

e0HdZddlmZddlZejededdZdZd	Zd
Z	dZ
dZd
ZdZ
dZdZdZdZdZdZdZee	e
eeegZGddeZdZdZGddZGddZddZdS) aStuff 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.
)
namedtupleN)
)remove
_sunau_paramsz7nchannels sampwidth framerate nframes comptype compnameidns.rlceZdZdS)ErrorN)__name__
__module____qualname__9/BuggyBox/python/3.11.7/bootstrap/lib/python3.11/sunau.pyrrsDrrcd}tdD]5}|d}|st|dzt|z}6|S)Nrr
r)rangereadEOFErrorord)filexibytes    r	_read_u32r%sS	A
1XXyy||	N
cECIIHrcg}tdD]:}t|d\}}|dt||};|t|dS)Nr
rr)rdivmodinsertintwritebytes)r!r"datar#dms      r
_write_u32r/sl
D
1XXa~~1As1vv
JJuT{{rceZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZdZdZdZdS)Au_readct|tdkr"ddl}||d}d|_nd|_||dS)NrrbTFtypebuiltinsopen_openedinitfpselffr7s   r__init__zAu_read.__init__X77d2hhOOO

a&&ADLL DLArc@|jr|dSdSN_filecloser<s r__del__zAu_read.__del__s':	JJLLLLL		rc|SrArrEs r	__enter__zAu_read.__enter__rc.|dSrArDr<argss  r__exit__zAu_read.__exit__

rc||_d|_tt|}|tkrtdtt||_|jdkrtd|jdkrtdt||_|jtkrt|j|_tt||_	|j	tvrtd|j	ttfvrd|_
d	|_n|j	tkrd	x|_|_
nl|j	t krdx|_|_
nM|j	t"krd
x|_|_
n.|j	t$krdx|_|_
ntdtt||_tt||_|jstd
|j|jz|_|jdkrF||jdz
|_|jd\|_}}nd|_	||_dS#t4t6f$rd|_YdSwxYw)Nrzbad magic numberrzheader size too smalldzheader size ridiculously largezencoding not (yet) supportedr	rrr
zunknown encodingzbad # of channelsr)rC	_soundposr)r%AUDIO_FILE_MAGICr	_hdr_size
_data_sizeAUDIO_UNKNOWN_SIZE	_encoding_simple_encodingsAUDIO_FILE_ENCODING_MULAW_8AUDIO_FILE_ENCODING_ALAW_8
_sampwidth
_framesizeAUDIO_FILE_ENCODING_LINEAR_8AUDIO_FILE_ENCODING_LINEAR_16AUDIO_FILE_ENCODING_LINEAR_24AUDIO_FILE_ENCODING_LINEAR_32
_framerate
_nchannelsr_info	partitiontell	_data_posAttributeErrorOSError)r<r!magic_s    rr:zAu_read.initfps
IdOO$$$$$*+++Yt__-->B/000>C8999#D//?000!$/22DOYt__-->!2226777>9,...DODOO
^;
;
;011DOdoo
^<
<
<011DOdoo
^<
<
<011DOdoo
^<
<
<011DOdoo*+++ioo..ioo..	-+,,,/DO;>B4>B#677DJ#z33E::DJ11DJ	"!YY[[DNNN(	"	"	"!DNNNN	"s	J$$K?Kc|jSrA)rCrEs rgetfpz
Au_read.getfps
zrc|jSrA)rcrEs rgetnchannelszAu_read.getnchannels
rc|jSrA)r\rEs rgetsampwidthzAu_read.getsampwidthrprc|jSrA)rbrEs rgetframeratezAu_read.getframeraterprcn|jtkrtS|jtvr|j|jzSdS)Nr)rVrWrXrYr]rEs r
getnframeszAu_read.getnframess8?000%%>...?do55qrcN|jtkrdS|jtkrdSdS)NULAWALAWNONErXrZr[rEs rgetcomptypezAu_read.getcomptypes->8886
^9
9
966rcN|jtkrdS|jtkrdSdS)NCCITT G.711 u-lawCCITT G.711 A-lawnot compressedr{rEs rgetcompnamezAu_read.getcompnames0>888&&
^9
9
9&&##rc	t||||||SrArrorrrtrvr|rrEs r	getparamszAu_read.getparamshT..00$2C2C2E2E##%%t'8'8""$$d&6&6&8&8::	:rcdSrArrEs r
getmarkerszAu_read.getmarkersstrc td)Nzno marks)r)r<ids  rgetmarkzAu_read.getmarksJrc|jtvr|tkr|j}n"|j||jz}|xjt||jzz
c_|jtkretj
5tjdtddl
}dddn#1swxYwY|||j}|SdS)Nignorecategoryr)rXrYrWrCrr]rSlenrZwarningscatch_warningssimplefilterDeprecationWarningaudioopulaw2linr\)r<nframesr,rs    r
readframeszAu_read.readframess>...,,,z((zw'@AANNc$ii4?::NN~!<<<,..##)(=OPPPP"NNN###############''do>>Kts C

CCc~|jtd|j|jd|_dS)Ncannot seekr)rgrirCseekrSrEs rrewindzAu_read.rewind s9>!-(((
'''rc|jSrA)rSrEs rrfzAu_read.tell&
~rc|dks||krtd|jtd|j|j||jzz||_dS)Nrzposition not in ranger)rvrrgrirCrr]rS)r<poss  rsetposzAu_read.setpos)sq77cDOO----/000>!-(((
t)>>???rcd|j}|r$d|_|jr|dSdSdSrA)rCr9rDr<r!s  rrDz
Au_read.close1sGz	DJ|


		

rN)rrrr>rFrHrNr:rmrorrrtrvr|rrrrrrrfrrDrrrr1r1sA,",","\$$$:::
   


rr1ceZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZdZdZdZdZdZdZdZdZdS)Au_writect|tdkr"ddl}||d}d|_nd|_||dS)Nr3rwbTFr5r;s   rr>zAu_write.__init__:r?rcJ|jr|d|_dSrArBrEs rrFzAu_write.__del__Cs$:	JJLLL


rc|SrArrEs rrHzAu_write.__enter__HrIrc.|dSrArKrLs  rrNzAu_write.__exit__KrOrc||_d|_d|_d|_d|_t
|_d|_d|_d|_	d|_
d|_dS)Nrrrx)rCrbrcr\r]rW_nframes_nframeswritten_datawritten_datalengthrd	_comptypers  rr:zAu_write.initfpNsV
*
 
rcf|jrtd|dvrtd||_dS)N0cannot change parameters after starting to write)rr	r
z"only 1, 2, or 4 channels supported)rrrc)r<	nchannelss  rsetnchannelszAu_write.setnchannels[sB	LJKKKI%%<===#rc<|jstd|jS)Nznumber of channels not set)rcrrEs rrozAu_write.getnchannelsb#	64555rcf|jrtd|dvrtd||_dS)Nr)rr	rr
zbad sample width)rrr\)r<	sampwidths  rsetsampwidthzAu_write.setsampwidthgsB	LJKKKL((*+++#rc<|jstd|jS)Nsample width not specified)rbrr\rEs rrrzAu_write.getsampwidthnrrc@|jrtd||_dS)Nr)rrrb)r<	framerates  rsetframeratezAu_write.setframeratess(	LJKKK#rc<|jstd|jS)Nzframe rate not set)rbrrEs rrtzAu_write.getframeratexs#	.,---rcj|jrtd|dkrtd||_dS)Nrrz# of frames cannot be negative)rrr)r<rs  r
setnframeszAu_write.setnframes}s@	LJKKKQ;;8999


rc|jSrArrEs rrvzAu_write.getnframes##rc:|dvr	||_dStd)N)rzrxzunknown compression type)rr)r<r6names   rsetcomptypezAu_write.setcomptypes(###!DNNN2333rc|jSrArrEs rr|zAu_write.getcomptyperrc:|jdkrdS|jdkrdSdS)Nrxr~ryrrrrEs rrzAu_write.getcompnames.>V##&&
^v
%
%&&##rc|\}}}}}}|||||||||||dSrA)rrrrr)r<paramsrrrrcomptypecompnames        r	setparamszAu_write.setparamss~GMD	9i(H)$$$)$$$)$$$   8,,,,,rc	t||||||SrArrEs rrzAu_write.getparamsrrc|jSrArrEs rrfz
Au_write.tellrrcBt|ttfs"t|d}||jdkretj5tj	dtddl}dddn#1swxYwY|||j
}t||jz}|j||j|z|_|jt|z|_dS)NBrxrrr)
isinstancer+	bytearray
memoryviewcast_ensure_header_writtenrrrrrrlin2ulawr\rr]rCr*rr)r<r,rrs    rwriteframesrawzAu_write.writeframesrawsD$	 233	.d##((--D##%%%>V##(**

%h9KLLLL














##D$/::Dd))t.
#3g= -D		9s1 BB!$B!c|||j|jks|j|jkr|dSdSrA)rrrrr_patchheader)r<r,s  rwriteframeszAu_write.writeframessWD!!!4=00"d&77787rc|jr	||j|jks|j|jkr||j|j}d|_|jr|	dSdS#|j}d|_|jr|	wwxYwdSrA)
rCrrrrrrflushr9rDrs  rrDzAu_write.closes:	!

!++---'4=88(D,===%%'''
  """z!
<!JJLLLLL!!z!
<!JJLLLL!	!	!sA!B,Cc|jsX|jstd|jstd|jstd|dSdS)Nz# of channels not specifiedrzframe rate not specified)rrcrr\rb
_write_headerrEs rrzAu_write._ensure_header_writtensz#	!?
;9:::?
:8999?
86777     	!	!rc\|jdkrw|jdkrt}d|_n|jdkrt}d|_nl|jdkrt
}d|_nR|jdkrt}d|_n8td|jdkrt}d|_ntd|j|j	z|_t|jtdt|jz}|d	zd
z}t|j||jt krt }n|j|jz}	|j|_n#t&t(f$r
d|_YnwxYwt|j|||_t|j|t|j|jt|j|j	|j|j|jd|t|jz
dz
zdS)
Nrzrr	rr
zinternal errorrxrr
irRr)rr\r^r]r_r`rarrZrcr/rCrTrrdrrWrf_form_length_posrhrirrbr*)r<encodingheader_sizelengths    rrzAu_write._write_headers>V##!##7"#A%%8"#A%%8"#A%%8"#,---
^v
%
%2HDOO()))/DO;4:/0003tz??*"Q",4:{+++=...'FF]T_4F	)$(JOO$5$5D!!(	)	)	)$(D!!!	)4:v&&&!4:x(((4:t///4:t///
$$$
c$*oo = BCDDDDDs6EE0/E0c|jtd|j|jt	|j|j|j|_|jdddS)Nrrr	)rrirCrr/rrrEs rrzAu_write._patchheadersl (-(((
-...4:t0111,
1rN)rrrr>rFrHrNr:rrorrrrrtrrvrr|rrrrfrrrDrrrrrrrr8s
   $$$
$$$
$$$

   $$$444$$$---:::
$$$:::   !!!$!!!(E(E(ETrrc|t|dr|j}nd}|dvrt|S|dvrt|St	d)Nmoder4)rr4)wrz$mode must be 'r', 'rb', 'w', or 'wb')hasattrrr1rr)r=rs  rr8r8
sd|1f	6DDD{qzz	
		{{:;;;rrA)__doc__collectionsrr_deprecatedrrrTrZr^r_r`raAUDIO_FILE_ENCODING_FLOATAUDIO_FILE_ENCODING_DOUBLEAUDIO_FILE_ENCODING_ADPCM_G721AUDIO_FILE_ENCODING_ADPCM_G722 AUDIO_FILE_ENCODING_ADPCM_G723_3 AUDIO_FILE_ENCODING_ADPCM_G723_5r[rWrY	Exceptionrr%r/r1rr8rrr<module>rsggR#"""""Xg....
?TVV
  ! ! !!#!##% #%  01222/1					I			


VVVVVVVVpPPPPPPPPd<<<<<<r