python (3.12.0)

(root)/
lib/
python3.12/
__pycache__/
wave.cpython-312.pyc

ˑeXdZddlmZddlZddlZddlZgdZGddeZdZ	dZ
d	Zd
ZeddZ
d
ZGddZGddZGddZddZy)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_writeceZdZy)rN)__name__
__module____qualname__8/BuggyBox/python/3.12.0/bootstrap/lib/python3.12/wave.pyrrRsr
ris8q)NbhNi_wave_paramsz7nchannels sampwidth framerate nframes comptype compnamectt|}tdt||D]&}t|D]}|||z|||zdz
|z
<(t|S)Nrr)	bytearraylenrangebytes)datawidthswapped_datarjs     r	_byteswapr`skSY'L
1c$i
':u	:A.21q5kLUQ*+	::r
c<eZdZd	dZdZdZd
dZdZddZdZ	y)_Chunkcd|_||_|rd}nd}||_|jd|_t|jdkrt	tj|dz|jdd|_	|r|jdz
|_	d|_	|jj|_
d|_y#tj$rtdwxYw#tt f$r
d|_YywxYw)	NF><LrT)closedalignfileread	chunknamerEOFErrorstructunpack_from	chunksizeerror	size_readtelloffsetseekableAttributeErrorOSError)selfr(r'	bigendian
inclheaderstrflags      r__init__z_Chunk.__init__ks
GG	1t~~"N	%#//TYYq\J1MDN!^^a/DN	!))..*DK!DM||	%$	%(	"!DM	"s0C C%C"%C>=C>c|jS)z*Return the name (ID) of the current chunk.)r*r6s rgetnamez_Chunk.getnames~~r
cf|js	|jd|_yy#d|_wxYw)NT)r&skipr<s rclosez_Chunk.closes.{{
#		"	#s'	0cF|jrtd|jstd|dk(r||jz}n|dk(r||j
z}|dks||j
kDrt|jj|j|zd||_y)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;&C
q[&C7cDNN*		t{{S(!,r
cH|jrtd|jS)NrB)r&rDr0r<s rr1z_Chunk.tells;;;<<~~r
cV|jrtd|j|jk\ry|dkr|j|jz
}||j|jz
kDr|j|jz
}|jj|}|jt
|z|_|j|jk(rS|jrG|jdzr8|jjd}|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^^+!8>>DNN2D$..4>>11>>DNN2Dyy~~d##d)3>>T^^+::NNQIINN1%E!^^c%j8DNr
c|jrtd|jrk	|j|jz
}|j
r|jdzr|dz}|jj|d|j|z|_y|j|jkrWtd|j|jz
}|j|}|st|j|jkrVyy#t$rY|wxYw)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+)r6nrLs   rr?z_Chunk.skips;;;<<==	
NNT^^3::4>>A#5AA		q!$!%!!3nnt~~-D$..4>>9:AIIaLE	nnt~~-

sA)D	DDN)TTF)r))
r	r
rr:r=r@rFr1r)r?rr
rrrjs%!2#&
.r
rceZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZdZdZdZdZdZy)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|_|jj	dk7rtd|jj
ddk7rtdd|_d|_	d|_		t|jd}|j	}|d	k(r|j|d|_nI|d
k(rD|jstd||_|j|jz|_d|_	n|j|jr|jstdy#t$rY/wxYw)
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.initfpsE
Da0
::7*:;;::??1()** %&D"
tzzq9

IG#$$U+'($g%++ =>>#(  %4?? B
)*&JJL#$##4+;+;=>>,<

s	E	EEcd|_t|trtj|d}||_	|j|y#|jr|j
xYw)Nrb_i_opened_the_file
isinstancestrbuiltinsrrar@r6fs  rr:zWave_read.__init__sX"&a

a&A&'D#	KKN	&&	AA'c$|jyNr@r<s r__del__zWave_read.__del__$

r
c|Srmrr<s r	__enter__zWave_read.__enter__'r
c$|jyrmrnr6argss  r__exit__zWave_read.__exit__*rpr
c|jSrm)rYr<s rgetfpzWave_read.getfp0szzr
c d|_d|_y)Nrr)r\rXr<s rrewindzWave_read.rewind3s!"r
c^d|_|j}|rd|_|jyyrm)rYrer@r6r(s  rr@zWave_read.close7s-
&&&*D#JJLr
c|jSrm)rXr<s rr1zWave_read.tell>~~r
c|jSrm)
_nchannelsr<s rgetnchannelszWave_read.getnchannelsAr
c|jSrm)r_r<s r
getnframeszWave_read.getnframesDs}}r
c|jSrm)
_sampwidthr<s rgetsampwidthzWave_read.getsampwidthGrr
c|jSrm)
_framerater<s rgetframeratezWave_read.getframerateJrr
c|jSrm	_comptyper<s rgetcomptypezWave_read.getcomptypeMrr
c|jSrm	_compnamer<s rgetcompnamezWave_read.getcompnamePrr
c	t|j|j|j|j	|j|j
Srm)rrrrrrrr<s r	getparamszWave_read.getparamsSsQD--/1B1B1D((*DOO,='')4+;+;+=?	?r
cyrmrr<s r
getmarkerszWave_read.getmarkersXr
ctdNzno marksrr6ids  rgetmarkzWave_read.getmark[
Jr
c^|dks||jkDrtd||_d|_y)Nrzposition not in ranger)r_rrXr\)r6rGs  rsetposzWave_read.setpos^s/7cDMM)/00!"r
cJ|jrZ|jjdd|j|jz}|r|jj|dd|_|dk(ry|jj||jz}|jdk7r)tjdk(rt||j}|jr|r|j|}|jt||j|jzzz|_|S)Nrr
rbig)
r\r[rFrXr^r)rsys	byteorderrrWrr)r6nframesrGrs    r
readframeszWave_read.readframesds!!!!!Q'..4??2C  %%c1-%&D"a<$$Wt%>???aCMMU$:T4??3D==T==&D#d)$//8Y*ZZr
c	tjd|jd\}|_|_}}|tk7r|tk7rtd|	tjd|jdd}|tk(r~	tjd|jd\}}}|jd	}	t|	d	krt	|	tk7r%	ddl}
d
|
j|	}t||d
zdz|_|jstd|jstd|j|jz|_d|_d|_y#tj
$rtdwxYw#tj
$rtdwxYw#tj
$rtdwxYw#t$rd}Yt|wxYw)Nz<HHLLHzunknown format: z<HrCrz<HHLr%zunknown extended format: )bytes_lezunknown extended formatbad sample widthbad # of channelsNONEznot compressed)r,r-r)rrr/r+WAVE_FORMAT_PCMWAVE_FORMAT_EXTENSIBLErrKSDATAFORMAT_SUBTYPE_PCMuuidUUID	Exceptionrr^rr)r6r`
wFormatTagdwAvgBytesPerSecwBlockAlign	sampwidthcbSizewValidBitsPerSample
dwChannelMask	SubFormatr
subformat_msgs            rr]zWave_read._read_fmt_chunkys	%Z`ZlZlmuw|xBxBCExF[GWJ:JK(Z;Q-Q
<==	%**4A?BI//
)=C=O=OPVX]XbXbcdXe=f:+]!JJrN	y>B&"N'44>&?		S\	@]?^$_MM**$q=Q.*+++,,//DOO;)?||	%$	%||	%$	%<<
)D(
)!>$=MM**>s65E/(F

AF+#G	/F

F(+G	G! G!N)r	r
r__doc__rar:rorrrwryr{r@r1rrrrrrrrrrrr]rr
rrrsp<?>?
 #*"*r
rceZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZy)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}||_	|j|y#|jr|j
xYw)Nwbrdris  rr:zWave_write.__init__sX"&a

a&A&'D#	KKN	&&	rkc||_d|_d|_d|_d|_d|_d|_d|_d|_d|_	y)NrF)
rYrWrrrr__nframeswritten_datawritten_datalength_headerwrittenr}s  rrazWave_write.initfpsL


 #r
c$|jyrmrnr<s rrozWave_write.__del__rpr
c|Srmrr<s rrrzWave_write.__enter__rsr
c$|jyrmrnrus  rrwzWave_write.__exit__rpr
c`|jrtd|dkrtd||_y)N0cannot change parameters after starting to writerr)rrr)r6	nchannelss  rsetnchannelszWave_write.setnchannelss1JKKq=+,,#r
cH|jstd|jS)Nznumber of channels not set)rrr<s rrzWave_write.getnchannelss455r
cj|jrtd|dks|dkDrtd||_y)Nrrr#r)rrr)r6rs  rsetsampwidthzWave_write.setsampwidths7JKKq=IM*++#r
cH|jstd|jS)Nzsample width not set)rrr<s rrzWave_write.getsampwidths.//r
c|jrtd|dkrtdtt||_y)Nrrzbad frame rate)rrintroundr)r6	framerates  rsetframeratezWave_write.setframerates;JKK>())eI./r
cH|jstd|jS)Nzframe rate not set)rrr<s rrzWave_write.getframerates,--r
c@|jrtd||_yNr)rrr_)r6rs  r
setnframeszWave_write.setnframessJKK
r
c|jSrmrr<s rrzWave_write.getnframes###r
cl|jrtd|dvrtd||_||_y)Nr)rzunsupported compression type)rrrr)r6comptypecompnames   rsetcomptypezWave_write.setcomptypes9JKK9$677!!r
c|jSrmrr<s rrzWave_write.getcomptyperr
c|jSrmrr<s rrzWave_write.getcompnamerr
c|\}}}}}}|jrtd|j||j||j	||j||j
||yr)rrrrrrr)r6paramsrrrrrrs        r	setparamszWave_write.setparamssoGMD	9i(HJKK)$)$)$ 8,r
c|jr|jr|jstdt	|j|j|j|j
|j|jS)Nznot all parameters set)rrrrrr_rrr<s rrzWave_write.getparams sSdooT__011DOOT__doommT^^T^^=	=r
ctd)Nzsetmark() not supportedr)r6rrGnames    rsetmarkzWave_write.setmark&s-..r
ctdrrrs  rrzWave_write.getmark)rr
cyrmrr<s rrzWave_write.getmarkers,rr
c|jSrmrr<s rr1zWave_write.tell/rr
c&t|ttfst|j	d}|jt
|t
||j|jzz}|jr|j|}|jdk7r)tjdk(rt||j}|jj||xjt
|z
c_|j |z|_y)NBrr)rfrr
memoryviewcast_ensure_header_writtenrrrrWrrrrYwriterr)r6rrs   rwriteframesrawzWave_write.writeframesraw2s$	 23d#((-D##CI.d)$// AB====&D??aCMMU$:T4??3D

SY&#33g=r
cz|j||j|jk7r|jyyrm)rrr_patchheader)r6rs  rwriteframeszWave_write.writeframes?s5D!t0001r
c	|jrT|jd|j|jk7r|j	|jjd|_|j}|rd|_|jyy#d|_|j}|rd|_|jwwxYw)Nr)rYrrrrflushrer@r}s  rr@zWave_write.closeDs	zz++A.##t'8'88%%'

  "DJ**D*.'

DJ**D*.'

sA B/B?c|jsW|jstd|jstd|jstd|j|yy)Nz# channels not specifiedzsample width not specifiedzsampling rate not specified)rrrrr
_write_header)r6datasizes  rrz!Wave_write._ensure_header_writtenVsW""??677??899??9::x(#r
c|jrJ|jjd|js!||j|j
zz|_|j|jz|j
z|_	|jj|_|jjtjdd|jzdddt|j|j|j|jz|j
z|j|j
z|j
dzd|j|jj|_|jjtjd	|jd
|_y#ttf$rd|_Y+wxYw)NrSz<L4s4sLHHLLHH4s$rTrUrr%rV<LT)rrYrr_rrrr1_form_length_posr4r5r,packrr_data_length_pos)r6
initlengths  rrzWave_write._write_header`s\&&&

!}}&4??T__+LMDM==4??:T__L	)$(JJOO$5D!	

%6!!!7GRT__dooOOdoo-?OOdoo-OOa*	+  ,$(JJOO$5D!

T4+;+;<="(	)$(D!	)sF44G
Gcd|jsJ|j|jk(ry|jj	}|jj|jd|jjtjdd|jz|jj|jd|jjtjd|j|jj|d|j|_y)Nrrr)rrrrYr1rFrrr,rr)r6curposs  rrzWave_write._patchheaderus""" 0 00"

--q1

T20A0A+ABC

--q1

T4+<+<=>

",,r
N) r	r
rrr:rarorrrwrrrrrrrrrrrrrrrrr1rrr@rrrrr
rrrs2

$$
$
0
 
$"-=/ $> 
$)#*
-r
rc|t|dr
|j}nd}|dvrt|S|dvrt|St	d)Nmoderc)rrc)wrz$mode must be 'r', 'rb', 'w', or 'wb')hasattrrrrr)rjrs  rrrsO|1f66DD{|	
	!}:;;r
rm)rcollectionsrrhr,r__all__rrrrr_array_fmtsrrrrrrrr
r<module>rsGR#

7	I	X'.NPll^B*B*Ja-a-H<r