예제 #1
0
    def stop(self):
        super(OpenALStreamingSound, self).stop()

        # Release all buffers
        queued = al.ALint()
        al.alGetSourcei(self.source, al.AL_BUFFERS_QUEUED, queued)
        self._release_buffers(queued.value)
예제 #2
0
    def _get_time(self):
        buffer = al.ALint()
        al.alGetSourcei(self.source, al.AL_BUFFER, buffer)
        if not buffer:
            return 0.0

        # The playback position at the start of the current buffer
        buffer_timestamp = buffer_pool.timestamp(buffer.value)

        if _have_1_1:
            # Add buffer timestamp to sample offset
            # XXX this occasionally goes backwards
            buffer_samples = al.ALint()
            al.alGetSourcei(self.source, al.AL_SAMPLE_OFFSET, buffer_samples)
            sample_rate = al.ALint()
            al.alGetBufferi(buffer.value, al.AL_FREQUENCY, sample_rate)
            buffer_time = buffer_samples.value / float(sample_rate.value)
            return buffer_timestamp + buffer_time
        else:
            # Interpolate system time past buffer timestamp
            if not self.playing:
                return self._last_buffer_time + buffer_timestamp
            elif buffer.value == self._last_buffer:
                return time.time() - self._last_buffer_time + buffer_timestamp
            else:
                self._last_buffer = buffer.value
                self._last_buffer_time = time.time()
                return buffer_timestamp
예제 #3
0
    def _openal_play(self):
        if self.playing:
            return

        buffers = al.ALint()
        al.alGetSourcei(self.source, al.AL_BUFFERS_QUEUED, buffers)
        if buffers.value == 0:
            self.play_when_buffered = True
        else:
            al.alSourcePlay(self.source)
            self.play_when_buffered = False
            self.playing = True
            self._last_buffer_time = time.time() - self._last_buffer_time
예제 #4
0
    def dispatch_events(self):
        queued = al.ALint()
        processed = al.ALint()
        al.alGetSourcei(self.source, al.AL_BUFFERS_QUEUED, queued)
        al.alGetSourcei(self.source, al.AL_BUFFERS_PROCESSED, processed)
        if processed.value == queued.value:
            self.finished = True
            self.playing = False
            self.dispatch_event(EVENT_FINISHED)
        self._processed_buffers = processed.value
        self._queued_buffers = queued.value

        if self.play_when_buffered and queued.value:
            self._openal_play()