Plan 9 from Bell Labs’s /usr/web/sources/contrib/stallion/root/sys/lib/python2.7/sndhdr.pyo

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�`^c@s*dZddgZd�Zd�ZgZd�Zeje�d�Zeje�d�Zeje�d�Z	eje	�d	�Z
eje
�d
�Zeje�d�Zeje�d�Z
eje
�d
�Zd�Zd�Zd�Zd�Zd�Zedkr&e�ndS(s�Routines to help recognizing sound files.

Function whathdr() recognizes various types of sound file headers.
It understands almost all headers that SOX can decode.

The return tuple contains the following items, in this order:
- file type (as SOX understands it)
- sampling rate (0 if unknown or hard to decode)
- number of channels (0 if unknown or hard to decode)
- number of frames in the file (-1 if unknown or hard to decode)
- number of bits/sample, or 'U' for U-LAW, or 'A' for A-LAW

If the file doesn't have a recognizable type, it returns None.
If the file can't be opened, IOError is raised.

To compute the total time, divide the number of frames by the
sampling rate (a frame contains a sample for each channel).

Function what() calls whathdr().  (It used to also use some
heuristics for raw data, but this doesn't work very well.)

Finally, the function test() is a simple main program that calls
what() for all files mentioned on the argument list.  For directory
arguments it calls what() for all files in that directory.  Default
argument is "." (testing all files in the current directory).  The
option -r tells it to recurse down directories found inside
explicitly given directories.
twhattwhathdrcCst|�}|S(sGuess the type of a sound file(R(tfilenametres((s/sys/lib/python2.7/sndhdr.pyR#scCsLt|d�}|jd�}x'tD]}|||�}|r%|Sq%WdS(sRecognize sound headerstrbiN(topentreadtteststNone(RtfthttfR((s/sys/lib/python2.7/sndhdr.pyR)s
cCs�ddl}|d dkr dS|dd!dkr<d}n |dd!dkrXd	}ndS|jd
�y|j|d�}Wnt|jfk
r�dSX||j�|j�|j�d|j	�fS(Ni�itFORMiitAIFCtaifctAIFFtaiffitr(
RRtseektopenfptEOFErrortErrortgetframeratetgetnchannelst
getnframestgetsampwidth(R
R	Rtfmtta((s/sys/lib/python2.7/sndhdr.pyt	test_aifc:s		
cCs
|d dkrt}n|d dkr2t}ndSd}||dd!�}||dd!�}||dd!�}||dd	!�}||d	d
!�}d}|dkr�d}	n6|d
kr�d}	n!|dkr�}	d
}nd}	||}
|||||
|	fS(Nis.sndtds.sdns.tauiiiiiitUiit?(Rsdns.(tget_long_betget_long_leR(R
R	ttypethdr_sizet	data_sizetencodingtratet	nchannelstsample_sizetsample_bitst
frame_size((s/sys/lib/python2.7/sndhdr.pyttest_auOs,					
cCsT|dd!dks&|dd!dkr*dSt|dd!�}d	d
|ddd
fS(NiAiEtFSSDi�i�tHCOMiithcomi"Vii�ii�i�(RR!(R
R	tdivisor((s/sys/lib/python2.7/sndhdr.pyt	test_hcomls&cCs�|d dkrdSt|dd!�}d}d|koDdknr�||dkr�t||d�}tdd	|�}nd
|ddd
fS(NisCreative Voice Fileiii�sig�.Aitvocii�i(Rtget_short_letordtint(R
R	tsbseekR'tratecode((s/sys/lib/python2.7/sndhdr.pyttest_vocus,cCs�|d dks6|dd!dks6|dd!dkr:dSt|dd	!�}t|d	d
!�}t|d
d!�}t|dd
!�}d||d|fS(NitRIFFiitWAVEisfmt iiiii"i$twavi�(RR3R"(R
R	tstyleR(R'R*((s/sys/lib/python2.7/sndhdr.pyttest_wav�s6cCs+|d dks#|dd!dkr'dSd	S(
NiRiit8SVXt8svxii(R?iiii(R(R
R	((s/sys/lib/python2.7/sndhdr.pyt	test_8svx�s#cCsM|d dkrIt|dd!�}t|dd!�}d|d|dfSdS(	NitSOUNDiiiitsndti(R"R3(R
R	tnsamplesR'((s/sys/lib/python2.7/sndhdr.pyt	test_sndt�scCsY|d dkrUt|dd!�}d|ko:dknrUd|ddd	fSndS(
Nitii�i�tsndrii�i(R3(R
R	R'((s/sys/lib/python2.7/sndhdr.pyt	test_sndr�scCsDt|d�d>t|d�d>Bt|d�d>Bt|d�BS(Niiiiiii(R4(ts((s/sys/lib/python2.7/sndhdr.pyR!�scCsDt|d�d>t|d�d>Bt|d�d>Bt|d�BS(Niiiiiii(R4(RH((s/sys/lib/python2.7/sndhdr.pyR"�scCs t|d�d>t|d�BS(Niii(R4(RH((s/sys/lib/python2.7/sndhdr.pytget_short_be�scCs t|d�d>t|d�BS(Niii(R4(RH((s/sys/lib/python2.7/sndhdr.pyR3�scCs�ddl}d}|jdrH|jddkrH|jdd5d}ny>|jdrrt|jd|d�ntdg|d�Wn.tk
r�|jjd�|jd�nXdS(Ni�iis-rit.s
[Interrupted]
(tsystargvttestalltKeyboardInterrupttstderrtwritetexit(RKt	recursive((s/sys/lib/python2.7/sndhdr.pyttest�s 
	

cCs�ddl}ddl}x�|D]�}|jj|�r�|dG|sK|r�dGHddl}|j|jj|d��}t||d�q�dGHq|dG|jj�yt	|�GHWqt
k
r�dGHqXqWdS(	Ni�s/:srecursing down:t*is*** directory (use -r) ***t:s*** not found ***(RKtostpathtisdirtglobtjoinRMtstdouttflushRtIOError(tlistRRttoplevelRKRVRRYtnames((s/sys/lib/python2.7/sndhdr.pyRM�s"


t__main__N(t__doc__t__all__RRRRtappendR,R1R8R=R@RDRGR!R"RIR3RSRMt__name__(((s/sys/lib/python2.7/sndhdr.pyt<module>s8			
	
	
	

	

	
	
	
						

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].