"""Classes for manipulating audio devices (currently only for Sun and SGI)"""
from warnings import warnpy3k
warnpy3k("the audiodev module has been removed in Python 3.0", stacklevel=2)
__all__ = ["error","AudioDev"]
# Private instance variables
## if 0: access frameratelist, nchannelslist, sampwidthlist, oldparams, \
## params, config, inited_outrate, inited_width, \
## inited_nchannels, port, converter, classinited: private
frameratelist = nchannelslist = sampwidthlist = None
self.params = [AL.OUTPUT_RATE, 0]
self.config = al.newconfig()
self.inited_nchannels = 0
al.setparams(AL.DEFAULT_DEVICE, self.oldparams)
while self.port.getfilled() > 0:
al.setparams(AL.DEFAULT_DEVICE, self.oldparams)
def setoutrate(self, rate):
for (raw, cooked) in self.frameratelist:
raise error, 'bad output rate'
def setsampwidth(self, width):
for (raw, cooked) in self.sampwidthlist:
self.config.setwidth(cooked)
self.config.setwidth(AL.SAMPLE_16)
self.converter = self.ulaw2lin
raise error, 'bad sample width'
def setnchannels(self, nchannels):
for (raw, cooked) in self.nchannelslist:
self.config.setchannels(cooked)
self.inited_nchannels = 1
raise error, 'bad # of channels'
def writeframes(self, data):
if not (self.inited_outrate and self.inited_nchannels):
raise error, 'params not specified'
self.port = al.openport('Python', 'w', self.config)
self.oldparams = self.params[:]
al.getparams(AL.DEFAULT_DEVICE, self.oldparams)
al.setparams(AL.DEFAULT_DEVICE, self.params)
data = self.converter(data)
self.port.writesamps(data)
return self.port.getfilled()
return self.port.getfillable()
return self.config.getqueuesize()
## if 0: access *: private
def ulaw2lin(self, data):
return audioop.ulaw2lin(data, 2)
## if 0: access outrate, sampwidth, nchannels, inited_outrate, inited_width, \
## inited_nchannels, converter: private
self.inited_nchannels = 0
def setoutrate(self, rate):
def setsampwidth(self, width):
def setnchannels(self, nchannels):
self.nchannels = nchannels
self.inited_nchannels = 1
def writeframes(self, data):
if not (self.inited_outrate and self.inited_width and self.inited_nchannels):
raise error, 'params not specified'
import sunaudiodev, SUNAUDIODEV
self.port = sunaudiodev.open('w')
info = self.port.getinfo()
info.o_sample_rate = self.outrate
info.o_channels = self.nchannels
self.o_encoding = SUNAUDIODEV.ENCODING_ULAW
# XXX Hack, hack -- leave defaults
info.o_precision = 8 * self.sampwidth
info.o_encoding = SUNAUDIODEV.ENCODING_LINEAR
data = self.converter(data)
return self.port.obufcount()
## # Nobody remembers what this method does, and it's broken. :-(
## def getfillable(self):
## return BUFFERSIZE - self.getfilled()
# Dynamically try to import and use a platform specific module.
raise error, 'no audio device'
return Audio_mac.Play_Audio_mac()
fn = 'f:just samples:just.aif'
p.setoutrate(af.getframerate())
p.setsampwidth(af.getsampwidth())
p.setnchannels(af.getnchannels())
BUFSIZ = af.getframerate()/af.getsampwidth()/af.getnchannels()
data = af.readframes(BUFSIZ)
if __name__ == '__main__':