<s> """<STR_LIT>""" <EOL> from warnings import warnpy3k <EOL> warnpy3k ( "<STR_LIT>" , stacklevel = <NUM_LIT:2> ) <EOL> del warnpy3k <EOL> __all__ = [ "<STR_LIT:error>" , "<STR_LIT>" ] <EOL> class error ( Exception ) : <EOL> pass <EOL> class Play_Audio_sgi : <EOL> classinited = <NUM_LIT:0> <EOL> frameratelist = nchannelslist = sampwidthlist = None <EOL> def initclass ( self ) : <EOL> import AL <EOL> self . frameratelist = [ <EOL> ( <NUM_LIT> , AL . RATE_48000 ) , <EOL> ( <NUM_LIT> , AL . RATE_44100 ) , <EOL> ( <NUM_LIT> , AL . RATE_32000 ) , <EOL> ( <NUM_LIT> , AL . RATE_22050 ) , <EOL> ( <NUM_LIT> , AL . RATE_16000 ) , <EOL> ( <NUM_LIT> , AL . RATE_11025 ) , <EOL> ( <NUM_LIT> , AL . RATE_8000 ) , <EOL> ] <EOL> self . nchannelslist = [ <EOL> ( <NUM_LIT:1> , AL . MONO ) , <EOL> ( <NUM_LIT:2> , AL . STEREO ) , <EOL> ( <NUM_LIT:4> , AL . QUADRO ) , <EOL> ] <EOL> self . sampwidthlist = [ <EOL> ( <NUM_LIT:1> , AL . SAMPLE_8 ) , <EOL> ( <NUM_LIT:2> , AL . SAMPLE_16 ) , <EOL> ( <NUM_LIT:3> , AL . SAMPLE_24 ) , <EOL> ] <EOL> self . classinited = <NUM_LIT:1> <EOL> def __init__ ( self ) : <EOL> import al , AL <EOL> if not self . classinited : <EOL> self . initclass ( ) <EOL> self . oldparams = [ ] <EOL> self . params = [ AL . OUTPUT_RATE , <NUM_LIT:0> ] <EOL> self . config = al . newconfig ( ) <EOL> self . inited_outrate = <NUM_LIT:0> <EOL> self . inited_width = <NUM_LIT:0> <EOL> self . inited_nchannels = <NUM_LIT:0> <EOL> self . converter = None <EOL> self . port = None <EOL> return <EOL> def __del__ ( self ) : <EOL> if self . port : <EOL> self . stop ( ) <EOL> if self . oldparams : <EOL> import al , AL <EOL> al . setparams ( AL . DEFAULT_DEVICE , self . oldparams ) <EOL> self . oldparams = [ ] <EOL> def wait ( self ) : <EOL> if not self . port : <EOL> return <EOL> import time <EOL> while self . port . getfilled ( ) > <NUM_LIT:0> : <EOL> time . sleep ( <NUM_LIT:0.1> ) <EOL> self . stop ( ) <EOL> def stop ( self ) : <EOL> if self . port : <EOL> self . port . closeport ( ) <EOL> self . port = None <EOL> if self . oldparams : <EOL> import al , AL <EOL> al . setparams ( AL . DEFAULT_DEVICE , self . oldparams ) <EOL> self . oldparams = [ ] <EOL> def setoutrate ( self , rate ) : <EOL> for ( raw , cooked ) in self . frameratelist : <EOL> if rate == raw : <EOL> self . params [ <NUM_LIT:1> ] = cooked <EOL> self . inited_outrate = <NUM_LIT:1> <EOL> break <EOL> else : <EOL> raise error , '<STR_LIT>' <EOL> def setsampwidth ( self , width ) : <EOL> for ( raw , cooked ) in self . sampwidthlist : <EOL> if width == raw : <EOL> self . config . setwidth ( cooked ) <EOL> self . inited_width = <NUM_LIT:1> <EOL> break <EOL> else : <EOL> if width == <NUM_LIT:0> : <EOL> import AL <EOL> self . inited_width = <NUM_LIT:0> <EOL> self . config . setwidth ( AL . SAMPLE_16 ) <EOL> self . converter = self . ulaw2lin <EOL> else : <EOL> raise error , '<STR_LIT>' <EOL> def setnchannels ( self , nchannels ) : <EOL> for ( raw , cooked ) in self . nchannelslist : <EOL> if nchannels == raw : <EOL> self . config . setchannels ( cooked ) <EOL> self . inited_nchannels = <NUM_LIT:1> <EOL> break <EOL> else : <EOL> raise error , '<STR_LIT>' <EOL> def writeframes ( self , data ) : <EOL> if not ( self . inited_outrate and self . inited_nchannels ) : <EOL> raise error , '<STR_LIT>' <EOL> if not self . port : <EOL> import al , AL <EOL> self . port = al . openport ( '<STR_LIT>' , '<STR_LIT:w>' , self . config ) <EOL> self . oldparams = self . params [ : ] <EOL> al . getparams ( AL . DEFAULT_DEVICE , self . oldparams ) <EOL> al . setparams ( AL . DEFAULT_DEVICE , self . params ) <EOL> if self . converter : <EOL> data = self . converter ( data ) <EOL> self . port . writesamps ( data ) <EOL> def getfilled ( self ) : <EOL> if self . port : <EOL> return self . port . getfilled ( ) <EOL> else : <EOL> return <NUM_LIT:0> <EOL> def getfillable ( self ) : <EOL> if self . port : <EOL> return self . port . getfillable ( ) <EOL> else : <EOL> return self . config . getqueuesize ( ) <EOL> def ulaw2lin ( self , data ) : <EOL> import audioop <EOL> return audioop . ulaw2lin ( data , <NUM_LIT:2> ) <EOL> class Play_Audio_sun : <EOL> def __init__ ( self ) : <EOL> self . outrate = <NUM_LIT:0> <EOL> self . sampwidth = <NUM_LIT:0> <EOL> self . nchannels = <NUM_LIT:0> <EOL> self . inited_outrate = <NUM_LIT:0> <EOL> self . inited_width = <NUM_LIT:0> <EOL> self . inited_nchannels = <NUM_LIT:0> <EOL> self . converter = None <EOL> self . port = None <EOL> return <EOL> def __del__ ( self ) : <EOL> self . stop ( ) <EOL> def setoutrate ( self , rate ) : <EOL> self . outrate = rate <EOL> self . inited_outrate = <NUM_LIT:1> <EOL> def setsampwidth ( self , width ) : <EOL> self . sampwidth = width <EOL> self . inited_width = <NUM_LIT:1> <EOL> def setnchannels ( self , nchannels ) : <EOL> self . nchannels = nchannels <EOL> self . inited_nchannels = <NUM_LIT:1> <EOL> def writeframes ( self , data ) : <EOL> if not ( self . inited_outrate and self . inited_width and self . inited_nchannels ) : <EOL> raise error , '<STR_LIT>' <EOL> if not self . port : <EOL> import sunaudiodev , SUNAUDIODEV <EOL> self . port = sunaudiodev . open ( '<STR_LIT:w>' ) <EOL> info = self . port . getinfo ( ) <EOL> info . o_sample_rate = self . outrate <EOL> info . o_channels = self . nchannels <EOL> if self . sampwidth == <NUM_LIT:0> : <EOL> info . o_precision = <NUM_LIT:8> <EOL> self . o_encoding = SUNAUDIODEV . ENCODING_ULAW <EOL> else : <EOL> info . o_precision = <NUM_LIT:8> * self . sampwidth <EOL> info . o_encoding = SUNAUDIODEV . ENCODING_LINEAR <EOL> self . port . setinfo ( info ) <EOL> if self . converter : <EOL> data = self . converter ( data ) <EOL> self . port . write ( data ) <EOL> def wait ( self ) : <EOL> if not self . port : <EOL> return <EOL> self . port . drain ( ) <EOL> self . stop ( ) <EOL> def stop ( self ) : <EOL> if self . port : <EOL> self . port . flush ( ) <EOL> self . port . close ( ) <EOL> self . port = None <EOL> def getfilled ( self ) : <EOL> if self . port : <EOL> return self . port . obufcount ( ) <EOL> else : <EOL> return <NUM_LIT:0> <EOL> def AudioDev ( ) : <EOL> try : <EOL> import al <EOL> except ImportError : <EOL> try : <EOL> import sunaudiodev <EOL> return Play_Audio_sun ( ) <EOL> except ImportError : <EOL> try : <EOL> import Audio_mac <EOL> except ImportError : <EOL> raise error , '<STR_LIT>' <EOL> else : <EOL> return Audio_mac . Play_Audio_mac ( ) <EOL> else : <EOL> return Play_Audio_sgi ( ) <EOL> def test ( fn = None ) : <EOL> import sys <EOL> if sys . argv [ <NUM_LIT:1> : ] : <EOL> fn = sys . argv [ <NUM_LIT:1> ] <EOL> else : <EOL> fn = '<STR_LIT>' <EOL> import aifc <EOL> af = aifc . open ( fn , '<STR_LIT:r>' ) <EOL> print fn , af . getparams ( ) <EOL> p = AudioDev ( ) <EOL> p . setoutrate ( af . getframerate ( ) ) <EOL> p . setsampwidth ( af . getsampwidth ( ) ) <EOL> p . setnchannels ( af . getnchannels ( ) ) <EOL> BUFSIZ = af . getframerate ( ) / af . getsampwidth ( ) / af . getnchannels ( ) <EOL> while <NUM_LIT:1> : <EOL> data = af . readframes ( BUFSIZ ) <EOL> if not data : break <EOL> print len ( data ) <EOL> p . writeframes ( data ) <EOL> p . wait ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> test ( ) </s>
