Esempio n. 1
0
class MockSourceGroup(object):
    audio_format = AudioFormat(1, 8, 44100)

    def __init__(self, duration, timestamp=0.):
        self.mock = mock.MagicMock()
        type(self.mock).audio_format = mock.PropertyMock(
            return_value=self.audio_format)
        self.mock.get_audio_data.side_effect = self._get_audio_data

        self.timestamp = timestamp
        self.duration = duration

        self.seconds_buffered = 0.
        self.bytes_buffered = 0

    def _get_audio_data(self, length):
        secs = length / self.audio_format.bytes_per_second
        if secs > self.duration:
            secs = self.duration
            length = int(secs * self.audio_format.bytes_per_second)

        if length == 0:
            return None

        data = AudioData('a' * length, length, self.timestamp, secs, ())
        self.timestamp += secs
        self.duration -= secs
        self.seconds_buffered += secs
        self.bytes_buffered += length
        return data
Esempio n. 2
0
def audio_format_3d(request):
    return AudioFormat(*request.param)
Esempio n. 3
0
def stream(context):
    context.connect()
    audio_format = AudioFormat(1, 16, 44100)
    with context:
        stream = context.create_stream(audio_format)
    return stream