Exemplo n.º 1
0
    def _update_play_cursor(self):
        if not self._al_source:
            return

        self._lock.acquire()
        context.lock()

        # 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)
        context.unlock()

        if processed:
            if len(self._buffer_timestamps) == processed:
                # Underrun, take note of timestamp
                self._underrun_timestamp = \
                    self._buffer_timestamps[-1] + \
                    self._buffer_sizes[-1] / \
                        float(self.source_group.audio_format.bytes_per_second)
            self._buffer_cursor += sum(self._buffer_sizes[:processed])
            del self._buffer_sizes[:processed]
            del self._buffer_timestamps[:processed]

            if not context.have_1_1:
                self._buffer_system_time = time.time()

        # Update play cursor using buffer cursor + estimate into current
        # buffer
        if context.have_1_1:
            bytes = al.ALint()
            context.lock()
            al.alGetSourcei(self._al_source, al.AL_BYTE_OFFSET, bytes)
            context.unlock()
            if _debug:
                print 'got bytes offset', bytes.value
            self._play_cursor = self._buffer_cursor + bytes.value
        else:
            # Interpolate system time past buffer timestamp
            self._play_cursor = \
                self._buffer_cursor + int(
                    (time.time() - self._buffer_system_time) * \
                        self.source_group.audio_format.bytes_per_second)

        # Process events
        while self._events and self._events[0][0] < self._play_cursor:
            _, event = self._events.pop(0)
            event._sync_dispatch_to_player(self.player)

        self._lock.release()
Exemplo n.º 2
0
    def _update_play_cursor(self):
        if not self._al_source:
            return

        self._lock.acquire()
        context.lock()

        # 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)
        context.unlock()

        if processed:
            if len(self._buffer_timestamps) == processed:
                # Underrun, take note of timestamp
                self._underrun_timestamp = \
                    self._buffer_timestamps[-1] + \
                    self._buffer_sizes[-1] / \
                        float(self.source_group.audio_format.bytes_per_second)
            self._buffer_cursor += sum(self._buffer_sizes[:processed])
            del self._buffer_sizes[:processed]
            del self._buffer_timestamps[:processed]

            if not context.have_1_1:
                self._buffer_system_time = time.time()

        # Update play cursor using buffer cursor + estimate into current
        # buffer
        if context.have_1_1:
            bytes = al.ALint()
            context.lock()
            al.alGetSourcei(self._al_source, al.AL_BYTE_OFFSET, bytes)
            context.unlock()
            if _debug:
                print 'got bytes offset', bytes.value
            self._play_cursor = self._buffer_cursor + bytes.value
        else:
            # Interpolate system time past buffer timestamp
            self._play_cursor = \
                self._buffer_cursor + int(
                    (time.time() - self._buffer_system_time) * \
                        self.source_group.audio_format.bytes_per_second)

        # Process events
        while self._events and self._events[0][0] < self._play_cursor:
            _, event = self._events.pop(0)
            event._sync_dispatch_to_player(self.player)

        self._lock.release()
Exemplo n.º 3
0
 def delete(self):
     """Delete all sources and free all buffers"""
     assert context._lock.locked()
     for source, buffers in self._sources.items():
         al.alDeleteSources(1, ctypes.byref(ctypes.c_uint(source)))
         for b in buffers:
             if not al.alIsBuffer(b):
                 # Protect against implementations that DO free buffers
                 # when they delete a source - carry on.
                 if _debug_buffers:
                     print("Found a bad buffer")
                 continue
             al.alDeleteBuffers(1, ctypes.byref(b))
     for b in self._buffers:
         al.alDeleteBuffers(1, ctypes.byref(b))
     self._buffers = []
     self._sources = {}