QfX ddlmZddlZddlZddlZgdZGddeZdZdZ dZ d Z ed d Z d Z Gd dZGddZGddZddZy)) namedtupleN)openError Wave_read Wave_writec eZdZy)rN)__name__ __module__ __qualname__+/opt/alt/python312/lib64/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`saSY'L 1c$i 'uA.21q5kLUQ* +(  r c<eZdZd dZdZdZd dZdZd dZdZ 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 chunknamerEOFErrorstruct unpack_from chunksizeerror size_readtelloffsetseekableAttributeErrorOSError)selfr(r' bigendian inclheaderstrflags r__init__z_Chunk.__init__ks  GG 1 t~~  "N %#// TYYq\J1MDN !^^a/DN !))..*DK!DM|| % $ %( "!DM "s0C C%C"%C>=C>c |jSN)r*r6s rgetnamez_Chunk.getnames8~~r cf|js |jd|_yy#d|_wxYw)NT)r&skipr=s rclosez _Chunk.closes.{{ # " # s' 0cH |jr td|js td|dk(r||jz}n|dk(r||j z}|dks||j kDrt |jj|j|zd||_y)NI/O operation on closed filez cannot seekrr) r& ValueErrorr3r5r0r. RuntimeErrorr(seekr2)r6poswhences rrGz _Chunk.seeks ;;;< <}}-( ( Q;&C q[&C 7cDNN*  t{{S(!,r cH|jr td|jS)NrC)r&rEr0r=s rr1z _Chunk.tells ;;;< <~~r cX |jr td|j|jk\ry|dkr|j|jz }||j|jz kDr|j|jz }|jj |}|jt |z|_|j|jk(rS|jrG|jdzr8|jj d}|jt |z|_|S)NrCr rr)r&rEr0r.r(r)rr')r6sizerdummys rr)z _Chunk.reads ;;;< < >>T^^ + !8>>DNN2D $..4>>1 1>>DNN2Dyy~~d##d)3 >>T^^ + :: NNQ IINN1%E!^^c%j8DN r c  |jr td|jrk |j|jz }|j r|jdzr|dz}|j j|d|j|z|_y|j|jkrWtd|j|jz }|j|}|st|j|jkrVyy#t$rY|wxYw)NrCri ) r&rEr3r.r0r'r(rGr5minr)r+)r6nrMs 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 r r:r>rArGr1r)r@r r rrrjs%!2#& .r rceZdZ dZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZy)rcd|_d|_t|d|_|jj dk7r t d|jj ddk7r t dd|_d|_ d|_ t|jd}|j }|d k(r|j|d|_nI|d k(rD|js t d ||_|j|jz|_d|_ n|j|jr |js t d 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 isinstancestrbuiltinsrrbrAr6fs rr:zWave_read.__init__sX"& a  a&A&'D #  KKN &&  AA'c$|jyr<rAr=s r__del__zWave_read.__del__$  r c|Sr<r r=s r __enter__zWave_read.__enter__' r c$|jyr<rnr6argss r__exit__zWave_read.__exit__*rpr c|jSr<)rZr=s rgetfpzWave_read.getfp0s zzr c d|_d|_y)Nrr)r]rYr=s rrewindzWave_read.rewind3s!"r c^d|_|j}|rd|_|jyyr<)rZrfrAr6r(s rrAzWave_read.close7s- && &*D # JJL r c|jSr<)rYr=s rr1zWave_read.tell> ~~r c|jSr<) _nchannelsr=s r getnchannelszWave_read.getnchannelsA r c|jSr<)r`r=s r getnframeszWave_read.getnframesDs }}r c|jSr<) _sampwidthr=s r getsampwidthzWave_read.getsampwidthGrr c|jSr<) _framerater=s r getframeratezWave_read.getframerateJrr c|jSr< _comptyper=s r getcomptypezWave_read.getcomptypeMrr c|jSr< _compnamer=s r getcompnamezWave_read.getcompnamePrr c t|j|j|j|j |j |j Sr<)rrrrrrrr=s r getparamszWave_read.getparamsSsQD--/1B1B1D((*DOO,='')4+;+;+=? ?r cyr<r r=s r getmarkerszWave_read.getmarkersXr ctdNzno marksrr6ids rgetmarkzWave_read.getmark[ Jr c^|dks||jkDr td||_d|_y)Nrzposition not in ranger)r`rrYr])r6rHs 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\rGrYr_r)rsys byteorderrrXrr)r6nframesrHrs r readframeszWave_read.readframesds  ! !    ! !!Q '..4??2C  %%c1-%&D " a<$$Wt%>? ??a CMMU$:T4??3D ==T==&D#d)$//8Y*ZZ r c tjd|jd\}|_|_}}|tk7r|tk7rtd| tjd|jdd}|tk(r~ tjd|jd\}}}|jd } t| d krt  | tk7r% ddl } d | j| } t| |d zdz|_|js td|js td|j|jz|_d|_d|_y#tj $rt dwxYw#tj $rt dwxYw#tj $rt dwxYw#t$rd } Yt| wxYw)NzB&"N'44>&? S\ @]?^$_MM**$q=Q.*+ ++, ,//DOO;)?|| % $ % || % $ %<< )D( ) !>$=MM**>s65E/(F AF+#G /F  F(+G G! G!N)r r r rbr:rorrrwryr{rAr1rrrrrrrrrrrr^r r rrrsp<?>  ?  # *"*r rceZdZ dZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZy)rcd|_t|trtj|d}||_ |j |y#|jr|j xYw)Nwbrerjs rr:zWave_write.__init__sX"& a  a&A&'D #  KKN && rlc||_d|_d|_d|_d|_d|_d|_d|_d|_d|_ y)NrF) rZrXrrrr`_nframeswritten _datawritten _datalength_headerwrittenr}s rrbzWave_write.initfpsL    #r c$|jyr<rnr=s rrozWave_write.__del__rpr c|Sr<r r=s rrrzWave_write.__enter__rsr c$|jyr<rnrus rrwzWave_write.__exit__rpr c`|jr td|dkr td||_y)N0cannot change parameters after starting to writerr)rrr)r6 nchannelss r setnchannelszWave_write.setnchannelss1   JK K q=+, ,#r cH|js td|jS)Nznumber of channels not set)rrr=s rrzWave_write.getnchannelss45 5r cj|jr td|dks|dkDr td||_y)Nrrr#r)rrr)r6rs r setsampwidthzWave_write.setsampwidths7   JK K q=IM*+ +#r cH|js td|jS)Nzsample width not set)rrr=s rrzWave_write.getsampwidths./ /r c|jr td|dkr tdtt||_y)Nrrzbad frame rate)rrintroundr)r6 framerates r setframeratezWave_write.setframerates;   JK K >() )eI./r cH|js td|jS)Nzframe rate not set)rrr=s rrzWave_write.getframerates,- -r c@|jr td||_yNr)rrr`)r6rs r setnframeszWave_write.setnframess   JK K r c|jSr<rr=s rrzWave_write.getnframes###r cl|jr td|dvr td||_||_y)Nr)rzunsupported compression type)rrrr)r6comptypecompnames r setcomptypezWave_write.setcomptypes9   JK K 9 $67 7!!r c|jSr<rr=s rrzWave_write.getcomptyperr c|jSr<rr=s rrzWave_write.getcompnamerr c|\}}}}}}|jr td|j||j||j ||j ||j ||yr)rrrrrrr)r6paramsrrrrrrs r setparamszWave_write.setparamssoGMD 9i(H   JK K )$ )$ )$   8,r c|jr|jr |js tdt |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)r6rrHnames rsetmarkzWave_write.setmark&s-..r ctdrrrs rrzWave_write.getmark)rr cyr<r r=s rrzWave_write.getmarkers,rr c|jSr<rr=s rr1zWave_write.tell/rr c&t|ttfst|j d}|j t |t ||j|jzz}|jr|j|}|jdk7r)tjdk(rt||j}|jj||xjt |z c_|j |z|_y)NBrr)rgrr memoryviewcast_ensure_header_writtenrrrrXrrrrZwriterr)r6rrs rwriteframesrawzWave_write.writeframesraw2s$ 23d#((-D ##CI.d)$// AB ====&D ??a CMMU$:T4??3D  SY&#33g=r cz|j||j|jk7r|jyyr<)rrr _patchheader)r6rs r writeframeszWave_write.writeframes?s5 D!   t00 0     1r c |jrT|jd|j|jk7r|j |jj d|_|j }|rd|_|jyy#d|_|j }|rd|_|jwwxYw)Nr)rZrrrrflushrfrAr}s rrAzWave_write.closeDs zz++A.##t'8'88%%'   "DJ**D*.' DJ**D*.' s A B/B?c|jsW|js td|js td|js td|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|jjd|js!||j|jzz|_|j|jz|jz|_ |jj |_|jjtjdd|j zdddt|j|j|j|jz|jz|j|jz|jdzd |j|jj |_|jjtjd |j d |_y#ttf$r d|_Y+wxYw) NrTz ",,r N)r r r r:rbrorrrwrrrrrrrrrrrrrrrrr1rrrArrrr r rrrs2  $ $ $ 0  $"-= / $ > $)#* -r rc|t|dr |j}nd}|dvr t|S|dvr t|St d)Nmoderd)rrd)wrz$mode must be 'r', 'rb', 'w', or 'wb')hasattrrrrr)rkrs rrrsO | 1f 66DD {|  !}:;;r r<) collectionsrrir,r__all__rrrrr _array_fmtsrrrrrrr r rrsGR#  7 I X' .NP ll^B*B*Ja-a-H