python (3.11.7)

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

e:UdZddlmZddlZddlZddlZgdZGddeZdZ	dZ
ed	d
ZdZGdd
Z
GddZGddZddZdS)a%
Stuff to parse WAVE files.

Usage.

Reading WAVE files:
      f = wave.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' for linear samples)
      getcompname()   -- returns human-readable version of
                         compression type ('not compressed' linear samples)
      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 WAVE files:
      f = wave.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 patching 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)openError	Wave_read
Wave_writeceZdZdS)rN)__name__
__module____qualname__8/BuggyBox/python/3.11.7/bootstrap/lib/python3.11/wave.pyrrRsDr
r)NbhNi_wave_paramsz7nchannels sampwidth framerate nframes comptype compnamectt|}tdt||D]+}t|D]}|||z|||zdz
|z
<,t|S)Nrr)	bytearraylenrangebytes)datawidthswapped_datarjs     r	_byteswapr]sSYY''L
1c$ii
'
'::u	:	:A.21q5kLUQ*++	:r
c>eZdZd
dZdZdZddZdZdd
ZdZ	dS)_ChunkTFcd|_||_|rd}nd}||_|d|_t|jdkrt	tj|dz|dd|_	n#tj
$r	tdwxYw|r|j	dz
|_	d|_	|j|_
d|_dS#tt f$rd|_YdSwxYw)	NF><LrT)closedalignfileread	chunknamerEOFErrorstructunpack_from	chunksizeerror	size_readtelloffsetseekableAttributeErrorOSError)selfr(r'	bigendian
inclheaderstrflags      r__init__z_Chunk.__init__hs
	GGG	1t~""N	%#/TYYq\\JJ1MDNN|	%	%	%$	%	0!^a/DN	!)..**DK!DMMM(	"	"	"!DMMMM	"s6BB&C))DDc|jS)z*Return the name (ID) of the current chunk.)r*r6s rgetnamez_Chunk.getnames
~r
ch|js*	|d|_dS#d|_wxYwdS)NT)r&skipr<s rclosez_Chunk.closesF{	#
#		"d""""		#	#s&	/rc$|jrtd|jstd|dkr||jz}n|dkr
||jz}|dks||jkrt|j|j	|zd||_dS)zSeek to specified position into the chunk.
        Default position is 0 (start of chunk).
        If the file is not seekable, this will result in an error.
        I/O operation on closed filezcannot seekrrN)
r&
ValueErrorr3r5r0r.RuntimeErrorr(seekr2)r6poswhences   rrFz_Chunk.seeks;	=;<<<}	)-(((Q;;&CC
q[[&C77cDN**	t{S(!,,,r
c<|jrtd|jS)NrB)r&rDr0r<s rr1z_Chunk.tells#;	=;<<<~r
c|jrtd|j|jkrdS|dkr|j|jz
}||j|jz
kr|j|jz
}|j|}|jt
|z|_|j|jkrG|jr@|jdzr6|jd}|jt
|z|_|S)zRead at most size bytes from the chunk.
        If size is omitted or negative, read until the end
        of the chunk.
        rBr
rr)r&rDr0r.r(r)rr')r6sizerdummys    rr)z_Chunk.reads;	=;<<<>T^++3!88>DN2D$.4>111>DN2Dy~~d###d))3>T^++:,NQ,INN1%%E!^c%jj8DNr
c|jrtd|jrb	|j|jz
}|jr|jdzr|dz}|j|d|j|z|_dS#t$rYnwxYw|j|jkrMtd|j|jz
}|
|}|st|j|jkKdSdS)zSkip the rest of the chunk.
        If you are not interested in the contents of the chunk,
        this method should be called so that the file points to
        the start of the next chunk.
        rBrNi )r&rDr3r.r0r'r(rFr5minr)r+)r6nrMs   rr?z_Chunk.skips;	=;<<<=
		
NT^3:4>A#5AA	q!$$$!%!!3



nt~--D$.4>9::AIIaLLE
	nt~------sAA00
A=<A=N)TTF)r)rJ)
r	r
rr:r=r@rFr1r)r?rr
rrrgs!!!!2###&
.r
rceZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZdZdZdZdZdZdS)raPVariables used in this class:

    These variables are available to the user though appropriate
    methods of this class:
    _file -- the open file with methods read(), close(), and seek()
              set through the __init__() method
    _nchannels -- the number of audio channels
              available through the getnchannels() method
    _nframes -- the number of audio frames
              available through the getnframes() method
    _sampwidth -- the number of bytes per audio sample
              available through the getsampwidth() method
    _framerate -- the sampling frequency
              available through the getframerate() method
    _comptype -- the AIFF-C compression type ('NONE' if AIFF)
              available through the getcomptype() method
    _compname -- the human-readable AIFF-C compression type
              available through the getcomptype() method
    _soundpos -- the position in the audio stream
              available through the tell() method, set through the
              setpos() method

    These variables are used internally only:
    _fmt_chunk_read -- 1 iff the FMT chunk has been read
    _data_seek_needed -- 1 iff positioned correctly in audio
              file for readframes()
    _data_chunk -- instantiation of a chunk class for the DATA chunk
    _framesize -- size of one frame in the file
    cd|_d|_t|d|_|jdkrtd|jddkrtdd|_d|_	d|_		t|jd}n#t$rYnwxYw|}|d	kr||d|_n?|d
kr9|jstd||_|j|j
z|_d|_	n||jr|jstddS)
Nr)r7RIFFz file does not start with RIFF idr#WAVEznot a WAVE filerfmt datazdata chunk before fmt chunkz#fmt chunk and/or data chunk missing)_convert	_soundposr_filer=rr)_fmt_chunk_read_data_chunk_data_seek_neededr+_read_fmt_chunkr.
_framesize_nframesr?)r6r(chunkr*s    rinitfpzWave_read.initfps
Da000
:7**:;;;:??1(()*** 	%&D"
tzq999





IG##$$U+++'($$g%%+? =>>>#(  %4? B
)*&JJLLL#	$#	?4+;	?=>>>	?	?sB,,
B98B9cd|_t|trtj|d}||_	||dS#|jr|xYw)Nrb_i_opened_the_file
isinstancestrbuiltinsrrar@r6fs  rr:zWave_read.__init__sq"&a	(
a&&A&'D#	KKNNNNN	&
			AA/c.|dSNr@r<s r__del__zWave_read.__del__!

r
c|Srmrr<s r	__enter__zWave_read.__enter__$r
c.|dSrmrnr6argss  r__exit__zWave_read.__exit__'rpr
c|jSrm)rYr<s rgetfpzWave_read.getfp-s
zr
c"d|_d|_dS)Nrr)r\rXr<s rrewindzWave_read.rewind0s!"r
c`d|_|j}|rd|_|dSdSrm)rYrer@r6r(s  rr@zWave_read.close4s<
&	&*D#JJLLLLL		r
c|jSrm)rXr<s rr1zWave_read.tell;
~r
c|jSrm)
_nchannelsr<s rgetnchannelszWave_read.getnchannels>
r
c|jSrm)r_r<s r
getnframeszWave_read.getnframesAs
}r
c|jSrm)
_sampwidthr<s rgetsampwidthzWave_read.getsampwidthDrr
c|jSrm)
_framerater<s rgetframeratezWave_read.getframerateGrr
c|jSrm	_comptyper<s rgetcomptypezWave_read.getcomptypeJrr
c|jSrm	_compnamer<s rgetcompnamezWave_read.getcompnameMrr
c	t||||||Srm)rrrrrrrr<s r	getparamszWave_read.getparamsPshD--//1B1B1D1D((**DOO,=,=''))4+;+;+=+=??	?r
cdSrmrr<s r
getmarkerszWave_read.getmarkersUtr
c tdNzno marksrr6ids  rgetmarkzWave_read.getmarkXJr
cb|dks||jkrtd||_d|_dS)Nrzposition not in ranger)r_rrXr\)r6rGs  rsetposzWave_read.setpos[s;77cDM))/000!"r
c|jrN|jdd|j|jz}|r|j|dd|_|dkrdS|j||jz}|jdkr%tjdkrt||j}|j
r|r|
|}|jt||j|jzzz|_|S)Nrr
rbig)
r\r[rFrXr^r)rsys	byteorderrrWrr)r6nframesrGrs    r
readframeszWave_read.readframesas!	'!!!Q'''.4?2C
. %%c1---%&D"a<<3$$Wt%>???aCMU$:$:T4?33D=	'T	'==&&D#d))$/8Y*ZZr
c8	tjd|d\}|_|_}}n#tj$r	tdwxYw|tkro	tjd|dd}n#tj$r	tdwxYw|dzdz|_|jstdntd	||jstd
|j|jz|_
d|_d|_dS)
Nz<HHLLHz<HrCrr%bad sample widthzunknown format: bad # of channelsNONEznot compressed)
r,r-r)rrr/r+WAVE_FORMAT_PCMrrr^rr)r6r`
wFormatTagdwAvgBytesPerSecwBlockAlign	sampwidths      rr]zWave_read._read_fmt_chunkvsU	%Z`Zlmuw|xBxBCExFxF[G[GWJ:JKK|	%	%	%$	%((
)".tUZZ]]CCAF		<
)
)
)D(
)(1}2DO?
0.///
0%

<===	-+,,,/DO;)s8;A".BB)N)r	r
r__doc__rar:rorrrwryr{r@r1rrrrrrrrrrrr]rr
rrrsY<???>???
   ###******r
rceZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdS)raVariables used in this class:

    These variables are user settable through appropriate methods
    of this class:
    _file -- the open file with methods write(), close(), tell(), seek()
              set through the __init__() method
    _comptype -- the AIFF-C compression type ('NONE' in AIFF)
              set through the setcomptype() or setparams() method
    _compname -- the human-readable AIFF-C compression type
              set through the setcomptype() or setparams() method
    _nchannels -- the number of audio channels
              set through the setnchannels() or setparams() method
    _sampwidth -- the number of bytes per audio sample
              set through the setsampwidth() or setparams() method
    _framerate -- the sampling frequency
              set through the setframerate() or setparams() method
    _nframes -- the number of audio frames written to the header
              set through the setnframes() or setparams() method

    These variables are used internally only:
    _datalength -- the size of the audio samples written to the header
    _nframeswritten -- the number of frames actually written
    _datawritten -- the size of the audio samples actually written
    cd|_t|trtj|d}||_	||dS#|jr|xYw)Nwbrdris  rr:zWave_write.__init__sq"&a	(
a&&A&'D#	KKNNNNN	&
			rkc||_d|_d|_d|_d|_d|_d|_d|_d|_d|_	dS)NrF)
rYrWrrrr__nframeswritten_datawritten_datalength_headerwrittenr}s  rrazWave_write.initfpsR


 #r
c.|dSrmrnr<s rrozWave_write.__del__rpr
c|Srmrr<s rrrzWave_write.__enter__rsr
c.|dSrmrnrus  rrwzWave_write.__exit__rpr
cj|jrtd|dkrtd||_dS)N0cannot change parameters after starting to writerr)rrr)r6	nchannelss  rsetnchannelszWave_write.setnchannelss@	LJKKKq==+,,,#r
c<|jstd|jS)Nznumber of channels not set)rrr<s rrzWave_write.getnchannelss#	64555r
cv|jrtd|dks|dkrtd||_dS)Nrrr#r)rrr)r6rs  rsetsampwidthzWave_write.setsampwidthsH	LJKKKq==IMM*+++#r
c<|jstd|jS)Nzsample width not set)rrr<s rrzWave_write.getsampwidths#	0.///r
c|jrtd|dkrtdtt||_dS)Nrrzbad frame rate)rrintroundr)r6	framerates  rsetframeratezWave_write.setframeratesP	LJKKK>>()))eI..//r
c<|jstd|jS)Nzframe rate not set)rrr<s rrzWave_write.getframerates#	.,---r
c@|jrtd||_dSNr)rrr_)r6rs  r
setnframeszWave_write.setnframess(	LJKKK


r
c|jSrmrr<s rrzWave_write.getnframes##r
ct|jrtd|dvrtd||_||_dS)Nr)rzunsupported compression type)rrrr)r6comptypecompnames   rsetcomptypezWave_write.setcomptypesI	LJKKK9$$6777!!r
c|jSrmrr<s rrzWave_write.getcomptyperr
c|jSrmrr<s rrzWave_write.getcompnamerr
c|\}}}}}}|jrtd|||||||||||dSr)rrrrrrr)r6paramsrrrrrrs        r	setparamszWave_write.setparamssGMD	9i(H	LJKKK)$$$)$$$)$$$   8,,,,,r
c|jr|jr|jstdt	|j|j|j|j|j|jS)Nznot all parameters set)rrrrrr_rrr<s rrzWave_write.getparamssX	2do	2T_	20111DOT_domT^T^==	=r
c td)Nzsetmark() not supportedr)r6rrGnames    rsetmarkzWave_write.setmarks-...r
c tdrrrs  rrzWave_write.getmarkrr
cdSrmrr<s rrzWave_write.getmarkersrr
c|jSrmrr<s rr1zWave_write.tellrr
c(t|ttfs"t|d}|t
|t
||j|jzz}|j	r|	|}|jdkr%tjdkrt||j}|j
||xjt
|z
c_|j|z|_dS)NBrr)rfrr
memoryviewcast_ensure_header_writtenrrrrWrrrrYwriterr)r6rrs   rwriteframesrawzWave_write.writeframesraw s$	 233	.d##((--D##CII...d))$/ AB=	'==&&D?aCMU$:$:T4?33D
SYY&#3g=r
c||||j|jkr|dSdSrm)rrr_patchheader)r6rs  rwriteframeszWave_write.writeframes-sGD!!!t00010r
cv	|jrR|d|j|jkr||jd|_|j}|rd|_|dSdS#d|_|j}|rd|_|wwxYw)Nr)rYrrrrflushrer@r}s  rr@zWave_write.close2s	z
#++A...#t'888%%'''
  """DJ*D
*.'



DJ*D
*.'


sAB

.B8c|jsY|jstd|jstd|jstd||dSdS)Nz# channels not specifiedzsample width not specifiedzsampling rate not specified)rrrrr
_write_header)r6datasizes  rrz!Wave_write._ensure_header_writtenDs|"	)?
86777?
:8999?
;9:::x(((((	)	)r
c|jrJ|jd|js||j|jzz|_|j|jz|jz|_	|j|_n#ttf$r
d|_YnwxYw|jtjdd|jzdddt|j|j|j|jz|jz|j|jz|jdzd|j|j|_|jtjd	|jd
|_dS)NrSz<L4s4sLHHLLHH4s$rTrUr%rV<LT)rrYrr_rrrr1_form_length_posr4r5r,packrr_data_length_pos)r6
initlengths  rrzWave_write._write_headerNsm&&&&
!!!}	N&4?T_+LMDM=4?:T_L	)$(JOO$5$5D!!(	)	)	)$(D!!!	)
%6!!7GRT_doOdo-?Odo-Oa**	+	+	+ ,$(JOO$5$5D!
T4+;<<==="sA>>BBc
|jsJ|j|jkrdS|j}|j|jd|jtj	dd|jz|j|j
d|jtj	d|j|j|d|j|_dS)Nrrr)rrrrYr1rFrrr,rr)r6curposs  rrzWave_write._patchheadercs"""" 000F""
-q111
T20A+ABBCCC
-q111
T4+<==>>>
""",r
N) r	r
rrr:rarorrrwrrrrrrrrrrrrrrrrr1rrr@rrrrr
rrrs2



$
$
$$$$
$$$
000
   
$$$"""---===///   $$$>>>   
$)))###*
-
-
-
-
-r
rc|t|dr|j}nd}|dvrt|S|dvrt|St	d)Nmoderc)rrc)wrz$mode must be 'r', 'rb', 'w', or 'wb')hasattrrrrr)rjrs  rrrpsd|1f	6DDD{||	
		!}}:;;;r
rm)rcollectionsrrhr,r__all__	Exceptionrr_array_fmtsrrrrrrrr
r<module>rs\GGR#"""""







7
6
6					I			'z.NPPllllllll^s*s*s*s*s*s*s*s*la-a-a-a-a-a-a-a-H<<<<<<r