Пример #1
0
 def setUp(self):
     self.outstream = None
     self.s = soundio.create()
     soundio.connect_backend(pysoundio.SoundIoBackendDummy)
     soundio.flush()
     default_index = soundio.default_output_device_index()
     self.device = soundio.get_output_device(default_index)
     self.buffer = soundio.input_ring_buffer_create(44100 * 8)
Пример #2
0
    def get_output_device(self, device_id):
        """
        Return an output device by index

        Parameters
        ----------
        device_id: (int) output device index

        Returns
        -------
        PySoundIoDevice output device

        Raises
        ------
        PySoundIoError if an invalid device id is used, or device is unavailable
        """
        if device_id < 0 or device_id > soundio.get_output_device_count():
            raise PySoundIoError('Invalid output device id')
        self.output['device'] = soundio.get_output_device(device_id)
        return self.output['device']
Пример #3
0
    def list_devices(self):
        """
        Return a list of available devices

        Returns
        -------
        (list)(dict) containing information on available input / output devices.
        """
        output_count = soundio.get_output_device_count()
        input_count = soundio.get_input_device_count()

        default_output = soundio.default_output_device_index()
        default_input = soundio.default_input_device_index()

        input_devices = []
        output_devices = []

        for i in range(0, input_count):
            device = soundio.get_input_device(i)
            pydevice = _ctypes.cast(device, _ctypes.POINTER(SoundIoDevice))
            input_devices.append({
                'id':
                pydevice.contents.id.decode(),
                'name':
                pydevice.contents.name.decode(),
                'is_raw':
                pydevice.contents.is_raw,
                'is_default':
                default_input == i,
                'sample_rates':
                self.get_sample_rates(device),
                'formats':
                self.get_formats(device),
                'layouts':
                self.get_layouts(device),
                'software_latency_min':
                pydevice.contents.software_latency_min,
                'software_latency_max':
                pydevice.contents.software_latency_max,
                'software_latency_current':
                pydevice.contents.software_latency_current,
                'probe_error':
                PySoundIoError(soundio.strerror(pydevice.contents.probe_error))
                if pydevice.contents.probe_error else None
            })
            soundio.device_unref(device)

        for i in range(0, output_count):
            device = soundio.get_output_device(i)
            pydevice = _ctypes.cast(device, _ctypes.POINTER(SoundIoDevice))
            output_devices.append({
                'id':
                pydevice.contents.id.decode(),
                'name':
                pydevice.contents.name.decode(),
                'is_raw':
                pydevice.contents.is_raw,
                'is_default':
                default_output == i,
                'sample_rates':
                self.get_sample_rates(device),
                'formats':
                self.get_formats(device),
                'layouts':
                self.get_layouts(device),
                'software_latency_min':
                pydevice.contents.software_latency_min,
                'software_latency_max':
                pydevice.contents.software_latency_max,
                'software_latency_current':
                pydevice.contents.software_latency_current,
                'probe_error':
                PySoundIoError(soundio.strerror(pydevice.contents.probe_error))
                if pydevice.contents.probe_error else None
            })
            soundio.device_unref(device)

        LOGGER.info('%d devices found' % (input_count + output_count))
        return (input_devices, output_devices)
Пример #4
0
 def test_device_sort_channel_layouts(self):
     default_index = soundio.default_output_device_index()
     self.device = soundio.get_output_device(default_index)
     soundio.device_sort_channel_layouts(self.device)
Пример #5
0
 def test_device_supports_format(self):
     default_index = soundio.default_output_device_index()
     self.device = soundio.get_output_device(default_index)
     self.assertIsNotNone(soundio.device_supports_format(
         self.device, pysoundio.SoundIoFormatFloat32LE))
Пример #6
0
 def test_device_supports_sample_rate(self):
     default_index = soundio.default_output_device_index()
     self.device = soundio.get_output_device(default_index)
     self.assertIsNotNone(soundio.device_supports_sample_rate(self.device, 44100))
Пример #7
0
 def test_get_output_device(self):
     default_index = soundio.default_output_device_index()
     self.device = soundio.get_output_device(default_index)
     self.assertIsNotNone(self.device)