python (3.12.0)

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

ˑebdZddlZddlZddlZddgZej
edGddeZdZ	d	Z
d
ZdZdZ
d
ZdZdZdZdZdZdZdZdZej.5ej0deddlmZdddddlmZeddZdej>_dej@_dejB_dejD_dejF_d ejH_Gd!d"Z%Gd#d$Z&d6d%Z'ed&k(rkddl(Z(e(jRd'dse(jRjUd(e(jRd'Z+e'e+d)5Z,e-d*e+e-d+e,j]e-d,e,j_e-d-e,jae-d.e,jce-d/e,jee-d0e,jge(jRd1drye(jRd1Z4e-d2e4e'e4d35Z5e5jme,jo	e,jqd4Z9e9sne5jue9&	ddde-d5dddyy#1swY	xYw#1swY(xYw#1swYyxYw)7aJStuff 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 namedtuple 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(b'') or
close() to patch up the sizes in the header.
Marks can be added anytime.  If there are any marks, you 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.
NErroropen)
)removeceZdZy)rN)__name__
__module____qualname__8/BuggyBox/python/3.12.0/bootstrap/lib/python3.12/aifc.pyrrsr
l@QEc	tjd|jddS#tj$rtdwxYw)N>lrstructunpackreaderrorEOFErrorfiles r
_read_longr@!}}T499Q<033<<!D !	'*Ac	tjd|jddS#tj$rtdwxYw)N>Lrrrrs r_read_ulongrrrc	tjd|jddS#tj$rtdwxYw)N>hrrrs r_read_shortr#rrc	tjd|jddS#tj$rtdwxYw)N>Hr"rrrs r_read_ushortr&rrct|jd}|dk(rd}n|j|}|dzdk(r|jd}|S)Nrr
)ordr)rlengthdatadummys    r_read_stringr-sK
1
F
{yy 
zQ		!Kr
gct|}d}|dkrd}|dz}t|}t|}||cxk(r|cxk(rdk(r
nnd}||zS|dk(rt}||zS|dz
}|dz|ztd	|d
z
z}||zS)Nr(rgi?lg@?)r#r	_HUGE_VALpow)fexponsignhimantlomants     r_read_floatr:sNEDqy
^F
^F%&%A%!8O
&!8O

k
!F
*c#urz.BB!8Or
cN|jtjd|y)Nr!writerpackr5xs  r_write_shortrAGGFKKa !r
cN|jtjd|y)Nr%r<r?s  r
_write_ushortrDrBr
cN|jtjd|y)Nrr<r?s  r_write_longrFrBr
cN|jtjd|y)Nrr<r?s  r_write_ulongrHrBr
ct|dkDrtd|jtjdt||j|t|dzdk(r|jdyy)Nz%string exceeds maximum pstring lengthBr(r)len
ValueErrorr=rr>)r5ss  r
_write_stringrPs_
1v|@AAGGFKKSV$%GGAJ
1vzQ	r
cddl}|dkrd}|dz}nd}|dk(rd}d}d}n|j|\}}|dkDs
|dk\s||k7r
|dz}d}d}n|dz}|dkr|j||}d}||z}|j|d}|j|}t	|}|j||z
d}|j|}t	|}t||t
||t
||y)	Nrr0r/i@r(r1i? )mathfrexpldexpfloorintrDrH)	r5r@rSr7r6r8r9fmantfsmants	         r_write_floatrZs
1u
FAvzz!}u5=EQJ%5.KEFFEMEqy

5%0DLEJJub)EZZ&F[FJJuv~r2EZZ&F[F!UFFr
ignore)Chunk)
namedtuple_aifc_paramsz7nchannels sampwidth framerate nframes comptype compnamez3Number of audio channels (1 for mono, 2 for stereo)zSample width in byteszSampling frequencyzNumber of audio framesz(Compression type ("NONE" for AIFF files)zRA human-readable version of the compression type
('not compressed' for AIFF files)ceZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZy)	Aifc_readNcd|_d|_g|_d|_||_t|}|j
dk7rtd|jd}|dk(rd|_	n|dk(rd|_	ntdd|_
d|_	d|_	t|j}|j
}|d	k(r|j|d|_
nQ|d
k(r ||_|jd}d|_n,|dk(rt||_n|d
k(r|j!||j##t$rYnwxYw|jr|jstdy)NrFORMz file does not start with FORM idrAIFFAIFCr(znot an AIFF or AIFF-C fileCOMMSSNDFVERMARKz$COMM chunk and/or SSND chunk missing)_version_convert_markers	_soundpos_filer\getnamerr_aifc_comm_chunk_read_ssnd_chunk_ssnd_seek_neededr_read_comm_chunkr	_readmarkskip)selfrchunkformdata	chunknamer,s      rinitfpzAifc_read.initfp:sk



d==?g%:;;::a=wDJ

 DJ455 !%&D"
djj)

IG#%%e,()%g%#( 

1
)*&g% +E 2
g%u%JJL%

$$D,<,<>??-=sD??	E
Ect|tr)tj|d}	|j	|y|j	|y#|jxYw)Nrb)
isinstancestrbuiltinsrr{closerwr5file_objects   r__init__zAifc_read.__init__bsPa"--40K
K(
KKN
!!#sAAc|SNrrws r	__enter__zAifc_read.__enter__nr
c$|jyrrrwargss  r__exit__zAifc_read.__exit__q

r
c|jSr)rnrs rgetfpzAifc_read.getfpwszzr
c d|_d|_y)Nr(r)rsrmrs rrewindzAifc_read.rewindzs!"r
cP|j}|d|_|jyyr)rnrrwrs  rrzAifc_read.close~s&zzDJJJLr
c|jSr)rmrs rtellzAifc_read.tell~~r
c|jSr)
_nchannelsrs rgetnchannelszAifc_read.getnchannelsr
c|jSr)_nframesrs r
getnframeszAifc_read.getnframess}}r
c|jSr)
_sampwidthrs rgetsampwidthzAifc_read.getsampwidthrr
c|jSr)
_frameraters rgetframeratezAifc_read.getframeraterr
c|jSr	_comptypers rgetcomptypezAifc_read.getcomptyperr
c|jSr	_compnamers rgetcompnamezAifc_read.getcompnamerr
c	t|j|j|j|j	|j|j
Sr)r^rrrrrrrs r	getparamszAifc_read.getparamssSD--/1B1B1D --/1B ,,.0@0@0BD	Dr
cLt|jdk(ry|jSNrrMrlrs r
getmarkerszAifc_read.getmarkers t}}"}}r
cp|jD]}||dk(s|cStdj|Nrzmarker {0!r} does not existrlrformatrwidmarkers   rgetmarkzAifc_read.getmark>mm	FVAY
	188<==r
c^|dks||jkDrtd||_d|_y)Nrzposition not in ranger()rrrmrs)rwposs  rsetposzAifc_read.setposs/7cDMM)/00!"r
c|jrv|jjd|jjd}|j|j
z}|r|jj|dzd|_|dk(ry|jj||j
z}|jr|r|j
|}|jt||j|jzzz|_|S)Nrrgr
)
rsrrseekrrm
_framesizerkrMrr)rwnframesr,rr+s     r
readframeszAifc_read.readframess!!!!!$$$))!,E..4??2C  %%cAg.%&D"a<$$Wt%>?==T==&D#d):>//9J+KKr
ctj5tjdtddl}dddj|dS#1swYxYwNr[categoryrr")warningscatch_warningssimplefilterDeprecationWarningaudioopalaw2linrwr+rs   r	_alaw2linzAifc_read._alaw2linL

$
$
&	!!(5GH	a((		 AActj5tjdtddl}dddj|dS#1swYxYwr)rrrrrulaw2linrs   r	_ulaw2linzAifc_read._ulaw2linrrctj5tjdtddl}dddt|dsd|_j|d|j\}|_|S#1swYCxYwNr[rr_adpcmstater")rrrrrhasattrr	adpcm2linrs   r
_adpcm2linzAifc_read._adpcm2linsr

$
$
&	!!(5GH	t]+#D!(!2!24D<L<L!Md		 A77Bctj5tjdtddl}dddj|dS#1swYxYwrrrrrrbyteswaprs   r	_sowt2linzAifc_read._sowt2linrrc4t||_t||_t|dzdz|_tt
||_|jdkrtd|jdkrtd|j|jz|_	|jr\d}|jdk(rd}tjdd	|_|jd
|_|rat!|j"jd}|dzdk(r|dz}|j|z|_|j"j%ddt'||_|jdk7r|jd
k(r|j*|_nk|jdvr|j.|_nK|jdvr|j0|_n+|jdvr|j2|_ntdd|_yyd|_d|_y)Nrgrbad sample widthbad # of channelsr(zWarning: bad COMM chunk sizerr/NONEG722ulawULAWalawALAWsowtSOWTunsupported compression typer"not compressed)r#rrrrrWr:rrrrp	chunksizerwarnrrr)rrr-rrrkrrr)rwrxkludger*s    rrtzAifc_read._read_comm_chunks%e,"5)
&u-1a7k%01??a*++??a+,,//DOO;::F"$

<="$"ZZ]DNUZZ__Q/0A:?#aZF"'//F":

A&)%0DN~~(>>W,$(OODM^^'99$(NNDM^^'99$(NNDM^^'99$(NNDM >??"#)%DN.DNr
c|t|}	t|D]F}t|}t|}t|}|s|s)|jj|||fHy#t$rPdt|jdt|jdk(rdndd|}tj|YywxYw)Nz"Warning: MARK chunk contains only z markerr(rOz instead of )
r#rangerr-rlappendrrMrr)rwrxnmarkersirrnamews        rruzAifc_read._readmarksu%	8_
: ' '#E*$MM(("c49
:	dmm$C

,>!,Cb&LA
MM!		s3A" A""AB;:B;)r	r
rrnr{rrrrrrrrrrrrrrrrrrrrrrrtrurr
rr`r`sH
E&@P
D

>#*)))*/Xr
r`ceZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!d Z"d!Z#d"Z$d#Z%d$Z&d%Z'd&Z(y)'
Aifc_writeNct|trBtj|d}	|j	||j
drd|_yy|j	|y#|jxYw)Nwbz.aiffr)r~rrrr{rendswithrprs   rrzAifc_write.__init__Csja"--40K
K(zz'"
#
KKN
!!#sA%%A8c||_t|_d|_d|_d|_d|_d|_d|_d|_	d|_
d|_d|_g|_
d|_d|_y)Nrrrr()rn
_AIFC_versionrjrrrkrrrr_nframeswritten_datawritten_datalengthrl_marklengthrprs  rr{zAifc_write.initfpSso
%
 *

 

r
c$|jyrrrs r__del__zAifc_write.__del__drr
c|Srrrs rrzAifc_write.__enter__grr
c$|jyrrrs  rrzAifc_write.__exit__jrr
c@|jrtdd|_y)N0cannot change parameters after starting to writerrrrprs raiffzAifc_write.aiffpJKK
r
c@|jrtdd|_y)Nrr(rrs raifczAifc_write.aifcurr
c`|jrtd|dkrtd||_y)Nrr(r)rrr)rw	nchannelss  rsetnchannelszAifc_write.setnchannelszs1JKKq=+,,#r
cH|jstd|jS)Nznumber of channels not set)rrrs rrzAifc_write.getnchannelss455r
cj|jrtd|dks|dkDrtd||_y)Nrr(rr)rrr)rw	sampwidths  rsetsampwidthzAifc_write.setsampwidths7JKKq=IM*++#r
cH|jstd|jS)Nzsample width not set)rrrs rrzAifc_write.getsampwidths.//r
c`|jrtd|dkrtd||_y)Nrrzbad frame rate)rrr)rw	framerates  rsetframeratezAifc_write.setframerates1JKK>())#r
cH|jstd|jS)Nzframe rate not set)rrrs rrzAifc_write.getframerates,--r
c@|jrtd||_y)Nr)rrr)rwrs  r
setnframeszAifc_write.setnframessJKK
r
c|jSrrrs rrzAifc_write.getnframes###r
cl|jrtd|dvrtd||_||_yNr)rrrrrrrrr)rrrr)rwcomptypecompnames   rsetcomptypezAifc_write.setcomptypes@JKKII677!!r
c|jSrrrs rrzAifc_write.getcomptyperr
c|jSrrrs rrzAifc_write.getcompnamerr
c|\}}}}}}|jrtd|dvrtd|j||j||j	||j||j
||yr()rrrrr r#r+)rwparamsrrrrr)r*s        r	setparamszAifc_write.setparamssGMD	9i(HJKKII677)$)$)$ 8,r
c|jr|jr|jstdt	|j|j|j|j
|j|jS)Nznot all parameters set)rrrrr^rrrrs rrzAifc_write.getparamssUdooT__011DOOT__doo MM4>>4>>K	Kr
cN|dkrtd|dkrtdt|tstdtt	|j
D]+}||j
|dk(s|||f|j
|<y|j
j
|||fy)Nrzmarker ID must be > 0zmarker position must be >= 0zmarker name must be bytes)rr~bytesrrMrlr)rwrrrrs     rsetmarkzAifc_write.setmarks
7/007677$&344s4==)*	AT]]1%a((#%sD=

a 		


b#t_-r
cp|jD]}||dk(s|cStdj|rrrs   rrzAifc_write.getmarkrr
cLt|jdk(ry|jSrrrs rrzAifc_write.getmarkersrr
c|jSrr%rs rrzAifc_write.tellr&r
ct|ttfst|j	d}|jt
|t
||j|jzz}|jr|j|}|jj||j|z|_|jt
|z|_
y)NrK)r~r3	bytearray
memoryviewcast_ensure_header_writtenrMrrrkrnr=rr)rwr+rs   rwriteframesrawzAifc_write.writeframesraws$	 23d#((-D##CI.d)$// AB====&D

#33g= --D	9r
c|j||j|jk7s|j|jk7r|jyyr)r=rrr	r_patchheader)rwr+s  rwriteframeszAifc_write.writeframessGD!4==0$"3"334r
c,|jy	|jd|jdzr/|jjd|jdz|_|j	|j
|jk7s%|j|jk7s|jr|jd|_
|j}d|_|jy#d|_
|j}d|_|jwxYw)Nrr(rL)rnr<rr=
_writemarkersrrr	r
r?rkr)rwr5s  rrzAifc_write.closes::	''*  1$

  )$($5$5$9! ##t}}4""d&7&77""!!#!DM

ADJ
GGI!DM

ADJ
GGIsB-C'',Dctj5tjdtddl}dddj|dS#1swYxYwr)rrrrrlin2alawrs   r	_lin2alawzAifc_write._lin2alawrrctj5tjdtddl}dddj|dS#1swYxYwr)rrrrrlin2ulawrs   r	_lin2ulawzAifc_write._lin2ulawrrctj5tjdtddl}dddt|dsd|_j|d|j\}|_|S#1swYCxYwr)rrrrrrr	lin2adpcmrs   r
_lin2adpcmzAifc_write._lin2adpcmsr

$
$
&	!!(5GH	t]+#D!(!2!24D<L<L!Md
		rctj5tjdtddl}dddj|dS#1swYxYwrrrs   r	_lin2sowtzAifc_write._lin2sowt'rrc@|js|jdvr-|jsd|_|jdk7rtd|jstd|jstd|j
std|j
|yy)N)rrrrrrrr"z]sample width must be 2 when compressing with ulaw/ULAW, alaw/ALAW, sowt/SOWT or G7.22 (ADPCM)z# channels not specifiedzsample width not specifiedzsampling rate not specified)rrrrrr
_write_header)rwdatasizes  rr<z!Aifc_write._ensure_header_written-s##~~"""&'DO??a'!344??677??899??9::x(!$r
c|jdk(r|j|_y|jdvr|j|_y|jdvr|j|_y|jdvr|j
|_yy)Nrrrr)rrKrkrHrErMrs r_init_compressionzAifc_write._init_compression@sf>>W$ OODM
^^1
1 NNDM
^^1
1 NNDM
^^1
1 NNDM2r
ch|jr|jdk7r|j|jj	d|j
s!||j|jzz|_|j
|jz|jz|_|jdzr|jdz|_|jr|jdvr8|jdz|_|jdzr^|jdz|_nI|jdk(r:|jdzdz|_|jdzr|jdz|_	|jj|_
|j|j}|jrm|jj	d	|jj	d
t|jdt|j|jn|jj	d|jj	dt|j|t!|j|j|j|jj|_t|j|j
|jd
vrt!|jdn#t!|j|jdzt%|j|j&|jrE|jj	|jt)|j|j*|jj	d|j|jj|_t|j|jdzt|jdt|jdy#ttf$rd|_
YwxYw)Nrrbr()rrrrr"rrrrdrhrcre)rrrrrrgrfr)rprrRrnr=rrrr	r_form_length_posAttributeErrorOSError_write_form_lengthrHrjrA_nframes_posrZrrPr_ssnd_length_pos)rw
initlength
commlengths   rrOzAifc_write._write_headerJs::$..G3""$

!}}&4??T__+LMDM==4??:T__La#//!3D::~~!EE#'#3#3q#8 ##a''+'7'7!';D$7*$($4$4q$8Q#> ##a''+'7'7!';D$	)$(JJOO$5D!,,T-=-=>
::JJW%JJW%Q'T]]3JJW%

!TZZ,TZZ1  , $

 1DTZZ/>>JJQ'T__q%89TZZ1::JJT^^,$**dnn5

!  ,$(JJOO$5D!TZZ!1!1A!56TZZ#TZZ#;(	)$(D!	)sPP10P1c|jr%dt|jz}|dzr|dz}d}nd}d}t|jd|z|j
zdz|zdz|z|S)	Nrr(rrrrg)rprMrrHrnr
)rw
datalengthr[
verslengths    rrWzAifc_write._write_form_length}s::#dnn"55JA~'!^
JJJTZZZ$2B2B!B"#"$&(")+5"6	7r
cL|jj}|jdzr+|jdz}|jjdn|j}||jk(rE|j
|jk(r,|jdk(r|jj|dy|jj|jd|j|}|jj|jdt|j|j|jj|jdt|j|dz|jj|d|j|_||_y)Nr(rLrrg)rnrrr=r	rrr
rrTrWrXrHrY)rwcurposr_r,s    rr?zAifc_write._patchheaders5"q **Q.JJJW%**J)))mmt333!#JJOOFA&

--q1''
3

))1-TZZ!5!56

--q1TZZa0

",,
%r
c8t|jdk(ry|jjdd}|jD]3}|\}}}|t|zdzdz}t|dzdk(s/|dz}5t	|j||dz|_t
|jt|j|jD]J}|\}}}t
|j|t	|j|t|j|Ly)Nrrir"r(rg)rMrlrnr=rHr
rArP)rwr*rrrrs      rrBzAifc_write._writemarkersst}}"

!mm	$F"MBTc$i'!+a/F4y1}!!		$
	TZZ(!A:TZZT]]!34mm	,F"MBTR(S)$**d+		,r
))r	r
rrnrr{rrrrrrrrrr rr#rr+rrr0rr4rrrr=r@rrErHrKrMr<rRrOrWr?rBrr
rrr#s<
E "

$
$
$
 
$"-K.>
$	: 2))))&+1$f&,,r
rc|t|dr
|j}nd}|dvrt|S|dvrt|St	d)Nmoder})rr})rrz$mode must be 'r', 'rb', 'w', or 'wb')rrfr`rr)r5rfs  rrrsO|1f66DD{|	
	!}:;;r
__main__r(z/usr/demos/data/audio/bach.aiffrgReadingznchannels =znframes   =zsampwidth =zframerate =zcomptype  =zcompname  =r"WritingrizDone.r);__doc__rrr__all___deprecatedr		Exceptionrrrrr#r&r-r3r:rArDrFrHrPrZrrrrxr\collectionsr]r^rrrrr)r*r`rrsysargvrfnr5printrrrrrrgngr0rrr+r@rr
r<module>rvsFPF
Xg.	I	
!!!!
"	"""""BXH($67#.SU"W!8!57 J"%
MM^N,N,`<z88AB<9:	!B	
b#!
i
mQ^^-.
mQ\\^,
mQ^^-.
mQ^^-.
mQ]]_-
mQ]]_-88AB<!B)R b#
(!AKKM*<<-DMM$'	
(
'N%^
(
(s2+J&CJ%*AJ2J%JJ"	J%%J.