Source code for csengine.audiochannel



from csengine import globals
from csengine.utility import DebugUtility
from threading import Thread

[docs] class AudioChannel: channel = None activeStack = None channelNr = 0 shutdown = False CHUNK = 1024 busy = False readerThread = None #TODO shutdown
[docs] def ReaderThread(self): # we open the pipe into our AudioEngine try: self.channel.open() if not self.channel.connected: return while not self.shutdown: buf = self.channel.read(self.CHUNK) if self.activeStack: self.activeStack.getAudio(buf) except Exception as e: #This exception will happen during shutdown when the pipes are closed - no need to print pass
#DebugUtility.Err("Error in AudioReader: ", e)
[docs] def openOutputChannel(self): try: self.channel.open() except Exception as e: DebugUtility.Err("Error during opening of Output Channel", e)
[docs] def write(self, chunk): if self.channel: self.channel.write(chunk)
def __init__(self, type, channelNr = 0): self.channelNr = channelNr try: if type == "input": self.channel = globals.AUDIO_THREAD.createAudioInput() self.readerThread = Thread(target=self.ReaderThread, daemon=True) self.readerThread.start() else: self.channel = globals.AUDIO_THREAD.createAudioOutput() Thread(target=self.openOutputChannel).start() except Exception as e: DebugUtility.Err("Exception opening Audio Channel: ", e)