def _al_play(self): if not self._timestamps: return state = al.ALint() al.alGetSourcei(self._al_source, al.AL_SOURCE_STATE, state) if state.value != al.AL_PLAYING: al.alSourcePlay(self._al_source)
def rec(self): if self.captureDev != None: s_available = al.ALint(0) #capture audio alc.alcGetIntegerv(self.captureDev, alc.ALC_CAPTURE_SAMPLES, 1, s_available) #transfer captured audio data into tmp buffer, add to main buffer box = ' ' * (s_available.value * 2) alc.alcCaptureSamples(self.captureDev, box, s_available) self.samplescaptured += box
def pump(self): # Release spent buffers processed = al.ALint() al.alGetSourcei(self._al_source, al.AL_BUFFERS_PROCESSED, processed) processed = processed.value if processed: buffers = (al.ALuint * processed)() al.alSourceUnqueueBuffers(self._al_source, len(buffers), buffers) al.alDeleteBuffers(len(buffers), buffers) # Pop timestamps and check for eos markers try: while processed: if not _have_1_1: self._timestamp_system_time = time.time() _, duration = self._timestamps.pop(0) self._buffered_time -= duration while self._timestamps[0][0] is None: self._eos_count += 1 self._timestamps.pop(0) processed -= 1 except IndexError: pass if _have_1_1: samples = al.ALint() al.alGetSourcei(self._al_source, al.AL_SAMPLE_OFFSET, samples) self._current_buffer_time = samples.value / \ float(self.audio_format.sample_rate) else: # Interpolate system time past buffer timestamp self._current_buffer_time = time.time() - \ self._timestamp_system_time # Check for underrun if self._playing: state = al.ALint() al.alGetSourcei(self._al_source, al.AL_SOURCE_STATE, state) if state.value != al.AL_PLAYING: al.alSourcePlay(self._al_source) return True # underrun notification
def get_time(self): state = al.ALint() al.alGetSourcei(self._al_source, al.AL_SOURCE_STATE, state) if state.value != al.AL_PLAYING: return self._pause_timestamp if not self._timestamps: return self._pause_timestamp ts, _ = self._timestamps[0] return ts + self._current_buffer_time
def clear(self): al.alSourceStop(self._al_source) self._playing = False processed = al.ALint() al.alGetSourcei(self._al_source, al.AL_BUFFERS_PROCESSED, processed) if processed.value: buffers = (al.ALuint * processed.value)() al.alSourceUnqueueBuffers(self._al_source, len(buffers), buffers) al.alDeleteBuffers(len(buffers), buffers) self._pause_timestamp = 0.0 self._buffered_time = 0.0 self._timestamps = []
def __init__(self): self.source = al.ALuint(0) al.alGenSources(1, self.source) al.alSourcef(self.source, al.AL_ROLLOFF_FACTOR, 0) al.alSourcei(self.source, al.AL_SOURCE_RELATIVE, 0) self.state = al.ALint(0) self._volume = 1.0 self._pitch = 1.0 self._position = [0, 0, 0] self._rolloff = 1.0 self._loop = False self.queue = []
def __init__(self): #load source player self.source = al.ALuint(0) al.alGenSources(1, self.source) #disable rolloff factor by default al.alSourcef(self.source, al.AL_ROLLOFF_FACTOR, 0) #disable source relative by default al.alSourcei(self.source, al.AL_SOURCE_RELATIVE, 0) #capture player state buffer self.state = al.ALint(0) #set internal variable tracking self._volume = 1.0 self._pitch = 1.0 self._position = [0, 0, 0] self._rolloff = 1.0 self._loop = False self.queue = []