예제 #1
0
 def get_buffer(self):
     if not self:
         buffer = al.ALuint()
         al.alGenBuffers(1, buffer)
     else:
         buffer = self.pop(0)
     return buffer
예제 #2
0
파일: avcodec.py 프로젝트: bitcraft/pyglet
 def get_buffer(self):
     if not self:
         buffer = al.ALuint()
         al.alGenBuffers(1, buffer)
     else:
         buffer = self.pop(0)
     return buffer
예제 #3
0
    def refill(self, write_size):
        if _debug:
            print 'refill', write_size

        self._lock.acquire()

        while write_size > self._min_buffer_size:
            audio_data = self.source_group.get_audio_data(write_size)
            if not audio_data:
                self._eos = True
                self._events.append(
                    (self._write_cursor, MediaEvent(0, 'on_eos')))
                self._events.append(
                    (self._write_cursor, MediaEvent(0, 'on_source_group_eos')))
                break

            for event in audio_data.events:
                cursor = self._write_cursor + event.timestamp * \
                    self.source_group.audio_format.bytes_per_second
                self._events.append((cursor, event))

            buffer = al.ALuint()
            context.lock()
            al.alGenBuffers(1, buffer)
            al.alBufferData(buffer, 
                            self._al_format,
                            audio_data.data,
                            audio_data.length,
                            self.source_group.audio_format.sample_rate)
            al.alSourceQueueBuffers(self._al_source, 1, ctypes.byref(buffer)) 
            context.unlock()

            self._write_cursor += audio_data.length
            self._buffer_sizes.append(audio_data.length)
            self._buffer_timestamps.append(audio_data.timestamp)
            write_size -= audio_data.length

        # Check for underrun stopping playback
        if self._playing:
            state = al.ALint()
            context.lock()
            al.alGetSourcei(self._al_source, al.AL_SOURCE_STATE, state)
            if state.value != al.AL_PLAYING:
                if _debug:
                    print 'underrun'
                al.alSourcePlay(self._al_source)
            context.unlock()

        self._lock.release()
예제 #4
0
    def refill(self, write_size):
        if _debug:
            print 'refill', write_size

        self._lock.acquire()

        while write_size > self._min_buffer_size:
            audio_data = self.source_group.get_audio_data(write_size)
            if not audio_data:
                self._eos = True
                self._events.append(
                    (self._write_cursor, mt_media.MediaEvent(0, 'on_eos')))
                self._events.append(
                    (self._write_cursor,
                     mt_media.MediaEvent(0, 'on_source_group_eos')))
                break

            for event in audio_data.events:
                cursor = self._write_cursor + event.timestamp * \
                    self.source_group.audio_format.bytes_per_second
                self._events.append((cursor, event))

            buffer = al.ALuint()
            context.lock()
            al.alGenBuffers(1, buffer)
            al.alBufferData(buffer, self._al_format, audio_data.data,
                            audio_data.length,
                            self.source_group.audio_format.sample_rate)
            al.alSourceQueueBuffers(self._al_source, 1, ctypes.byref(buffer))
            context.unlock()

            self._write_cursor += audio_data.length
            self._buffer_sizes.append(audio_data.length)
            self._buffer_timestamps.append(audio_data.timestamp)
            write_size -= audio_data.length

        # Check for underrun stopping playback
        if self._playing:
            state = al.ALint()
            context.lock()
            al.alGetSourcei(self._al_source, al.AL_SOURCE_STATE, state)
            if state.value != al.AL_PLAYING:
                if _debug:
                    print 'underrun'
                al.alSourcePlay(self._al_source)
            context.unlock()

        self._lock.release()
예제 #5
0
파일: __init__.py 프로젝트: wwoods/ramfull
 def getBuffers(self, alSource, i):
     """Returns an array containing i buffer names.  The returned list must
     not be modified in any way, and may get changed by subsequent 
     calls to getBuffers.
     """
     assert context._lock.locked()
     buffs = []
     try:
         while i > 0:
             b = self._buffers.pop()
             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
             buffs.append(b)
             i -= 1
     except IndexError:
         while i > 0:
             buffer = al.ALuint()
             al.alGenBuffers(1, buffer)
             if _debug_buffers:
                 error = al.alGetError()
                 if error != 0:
                     print("GEN BUFFERS: " + str(error))
             buffs.append(buffer)
             i -= 1
             
     alSourceVal = alSource.value
     if alSourceVal not in self._sources:
         self._sources[alSourceVal] = buffs
     else:
         self._sources[alSourceVal].extend(buffs)
             
     return buffs
예제 #6
0
    def getBuffers(self, alSource, i):
        """Returns an array containing i buffer names.  The returned list must
        not be modified in any way, and may get changed by subsequent calls to
        getBuffers.
        """
        assert context._lock.locked()
        buffs = []
        try:
            while i > 0:
                b = self._buffers.pop()
                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
                buffs.append(b)
                i -= 1
        except IndexError:
            while i > 0:
                buffer = al.ALuint()
                al.alGenBuffers(1, buffer)
                if _debug_buffers:
                    error = al.alGetError()
                    if error != 0:
                        print("GEN BUFFERS: " + str(error))
                buffs.append(buffer)
                i -= 1

        alSourceVal = alSource.value
        if alSourceVal not in self._sources:
            self._sources[alSourceVal] = buffs
        else:
            self._sources[alSourceVal].extend(buffs)

        return buffs