diff --git a/README.md b/README.md index 52c7443..6b1c39c 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,7 @@ int main(int argc, char **argv) { } ``` -### "Best Backend" +### Backend Priority When you use `soundio_connect`, libsoundio tries these backends in order. If unable to connect to that backend, due to the backend not being installed, @@ -238,12 +238,12 @@ view `coverage/index.html` in a browser. ## Roadmap - 0. pipe record to playback example working with dummy linux, osx, windows 0. pipe record to playback example working with pulseaudio linux 0. pipe record to playback example working with ALSA linux + 0. pipe record to playback example working with dummy linux, osx, windows + 0. implement JACK backend, get examples working 0. implement CoreAudio (OSX) backend, get examples working 0. implement WASAPI (Windows) backend, get examples working - 0. implement JACK backend, get examples working 0. Avoid calling `panic` in PulseAudio. 0. implement ASIO (Windows) backend, get examples working 0. clean up API and improve documentation @@ -266,6 +266,7 @@ view `coverage/index.html` in a browser. 0. instead of `void *backend_data` use a union for better cache locality and smaller mlock requirements 0. Consider testing on FreeBSD + 0. make rtprio warning a callback and have existing behavior be the default callback ## Planned Uses for libsoundio diff --git a/src/alsa.cpp b/src/alsa.cpp index 43d3a56..169f3d2 100644 --- a/src/alsa.cpp +++ b/src/alsa.cpp @@ -509,6 +509,8 @@ static int refresh_devices(SoundIoPrivate *si) { SoundIoDevicesInfo *devices_info = create(); if (!devices_info) return SoundIoErrorNoMem; + devices_info->default_output_index = -1; + devices_info->default_input_index = -1; void **hints; if (snd_device_name_hint(-1, "pcm", &hints) < 0) { diff --git a/src/pulseaudio.cpp b/src/pulseaudio.cpp index 2a0b864..074ce1f 100644 --- a/src/pulseaudio.cpp +++ b/src/pulseaudio.cpp @@ -259,20 +259,30 @@ static void finish_device_query(SoundIoPrivate *si) { } // based on the default sink name, figure out the default output index + // if the name doesn't match just pick the first one. if there are no + // devices then we need to set it to -1. sipa->current_devices_info->default_output_index = -1; sipa->current_devices_info->default_input_index = -1; - for (int i = 0; i < sipa->current_devices_info->input_devices.length; i += 1) { - SoundIoDevice *device = sipa->current_devices_info->input_devices.at(i); - assert(device->purpose == SoundIoDevicePurposeInput); - if (strcmp(device->name, sipa->default_source_name) == 0) { - sipa->current_devices_info->default_input_index = i; + + if (sipa->current_devices_info->input_devices.length > 0) { + sipa->current_devices_info->default_input_index = 0; + for (int i = 0; i < sipa->current_devices_info->input_devices.length; i += 1) { + SoundIoDevice *device = sipa->current_devices_info->input_devices.at(i); + assert(device->purpose == SoundIoDevicePurposeInput); + if (strcmp(device->name, sipa->default_source_name) == 0) { + sipa->current_devices_info->default_input_index = i; + } } } - for (int i = 0; i < sipa->current_devices_info->output_devices.length; i += 1) { - SoundIoDevice *device = sipa->current_devices_info->output_devices.at(i); - assert(device->purpose == SoundIoDevicePurposeOutput); - if (strcmp(device->name, sipa->default_sink_name) == 0) { - sipa->current_devices_info->default_output_index = i; + + if (sipa->current_devices_info->output_devices.length > 0) { + sipa->current_devices_info->default_output_index = 0; + for (int i = 0; i < sipa->current_devices_info->output_devices.length; i += 1) { + SoundIoDevice *device = sipa->current_devices_info->output_devices.at(i); + assert(device->purpose == SoundIoDevicePurposeOutput); + if (strcmp(device->name, sipa->default_sink_name) == 0) { + sipa->current_devices_info->default_output_index = i; + } } } diff --git a/src/soundio.h b/src/soundio.h index 30d0e8a..e3df62c 100644 --- a/src/soundio.h +++ b/src/soundio.h @@ -483,9 +483,11 @@ struct SoundIoDevice *soundio_get_input_device(struct SoundIo *soundio, int inde struct SoundIoDevice *soundio_get_output_device(struct SoundIo *soundio, int index); // returns the index of the default input device +// returns -1 if there are no devices. int soundio_get_default_input_device_index(struct SoundIo *soundio); // returns the index of the default output device +// returns -1 if there are no devices. int soundio_get_default_output_device_index(struct SoundIo *soundio); void soundio_device_ref(struct SoundIoDevice *device);