Ejemplo n.º 1
0
 def setUp(self):
     self.instream = None
     self.s = soundio.create()
     soundio.connect_backend(pysoundio.SoundIoBackendDummy)
     soundio.flush()
     default_index = soundio.default_input_device_index()
     self.device = soundio.get_input_device(default_index)
     self.buffer = soundio.input_ring_buffer_create(44100 * 8)
Ejemplo n.º 2
0
    def get_default_input_device(self):
        """
        Returns default input device

        Returns
        -------
        PySoundIoDevice input device

        Raises
        ------
        PySoundIoError if the input device is not available
        """
        device_id = soundio.default_input_device_index()
        return self.get_input_device(device_id)
Ejemplo n.º 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)
Ejemplo n.º 4
0
 def test_get_input_device(self):
     default_index = soundio.default_input_device_index()
     self.device = soundio.get_input_device(default_index)
     self.assertIsNotNone(self.device)
Ejemplo n.º 5
0
 def test_default_input_device_index(self):
     self.assertNotEqual(soundio.default_input_device_index(), -1)