def __del__(self): """Deletes the SoundSink and also destroys the associated context and closes the bound audio output device.""" if self.context: for ssid, source in self._sources.items(): querystate = al.get_source_i(ssid, al.AL_SOURCE_STATE) if querystate != al.AL_STOPPED: al.source_stop(ssid) al.delete_sources([ssid]) source._ssid = None self._sources = {} al.delete_buffers(self._buffers.keys()) self._buffers = {} alc.destroy_context(self.context) if self._hasopened: alc.close_device(self.device) self.context = None self.device = None
def process_source(self, source): """Processes a SoundSource. Note: this does NOT activate the SoundSink. If another SoundSink is active, chances are good that the source is processed in that SoundSink. """ ssid = source._ssid if ssid is None: ssid = self._create_source(source) # TODO: this should be only set on changes. # al.source_f(ssid, al.AL_GAIN, source.gain) # al.source_f(ssid, al.AL_PITCH, source.pitch) # al.source_fv(ssid, al.AL_POSITION, source.position) # al.source_fv(ssid, al.AL_VELOCITY, source.velocity) self._create_buffers(source) querystate = al.get_source_i(ssid, al.AL_SOURCE_STATE) if source.request == SOURCE_NONE: # if no change is to be made, nothing will be done. pass elif source.request == SOURCE_REWIND: al.source_rewind(ssid) source.request = SOURCE_NONE elif source.request == SOURCE_PLAY: if querystate != al.AL_PLAYING: al.source_play(ssid) source.request = SOURCE_NONE elif source.request == SOURCE_STOP: if querystate != al.AL_STOPPED: al.source_stop(ssid) source.request = SOURCE_NONE elif source.request == SOURCE_PAUSE: if querystate != al.AL_PAUSED: al.source_pause(ssid) source.request = SOURCE_NONE else: raise ValueError("invalid request state on source")