@@ -281,6 +281,7 @@ App::App(std::string projectRoot, bool keepTempSessions, std::string tempRootOve
281281 tryLoadDefaultLayoutOnStartup ();
282282
283283 appendEngineLog (" [GUI] Select a source and layout, then click START." );
284+ scanDevices ();
284285
285286 int lw = 0 , lh = 0 , lch = 0 ;
286287 unsigned char * logoData = stbi_load_from_memory (
@@ -584,6 +585,12 @@ void App::renderEngineTab() {
584585 (mDeviceIdx >= 0 && mDeviceIdx < static_cast <int >(mDeviceOutputChannels .size ()))
585586 ? mDeviceOutputChannels [mDeviceIdx ]
586587 : 0 ;
588+ const int selectedDeviceBackendId =
589+ (mDeviceIdx >= 0 && mDeviceIdx < static_cast <int >(mDeviceBackendIds .size ()))
590+ ? mDeviceBackendIds [mDeviceIdx ]
591+ : -1 ;
592+ const int activeDeviceBackendId =
593+ (mStatus .outputDeviceId >= 0 ) ? mStatus .outputDeviceId : selectedDeviceBackendId;
587594 const double scannedDeviceSampleRate =
588595 (mDeviceIdx >= 0 && mDeviceIdx < static_cast <int >(mDeviceSampleRates .size ()))
589596 ? mDeviceSampleRates [mDeviceIdx ]
@@ -726,6 +733,9 @@ void App::renderEngineTab() {
726733 << (audioReady ? " Ready" : (audioNotReady ? " Not Ready" : " Unknown" )) << " \n "
727734 << " Backend: " << backendLabel << " \n "
728735 << " Device: " << activeDeviceName << " \n "
736+ << " Device ID: "
737+ << (activeDeviceBackendId >= 0 ? std::to_string (activeDeviceBackendId)
738+ : std::string (" system default" )) << " \n "
729739 << " Output Channels: "
730740 << (selectedOutputChannels > 0 ? std::to_string (selectedOutputChannels) : " unknown" ) << " \n "
731741 << " Required sample rate: " << requiredSampleRate << " Hz\n "
@@ -755,6 +765,10 @@ void App::renderEngineTab() {
755765 ImGui::SetNextItemWidth (ImGui::GetContentRegionAvail ().x );
756766 if (ImGui::Combo (" ##device" , &mDeviceIdx , items.data (), (int )items.size ())) {
757767 mDeviceName = (mDeviceIdx == 0 ) ? " " : mDeviceList [mDeviceIdx ];
768+ mDeviceBackendId =
769+ (mDeviceIdx >= 0 && mDeviceIdx < static_cast <int >(mDeviceBackendIds .size ()))
770+ ? mDeviceBackendIds [mDeviceIdx ]
771+ : -1 ;
758772 }
759773 }
760774 if (selectedOutputChannels > 0 ) {
@@ -1621,6 +1635,7 @@ void App::doLaunchEngine(const std::string& scenePath,
16211635 EngineOptions opts;
16221636 opts.sampleRate = 48000 ;
16231637 opts.bufferSize = kBufferSizes [mBufferSizeIdx ];
1638+ opts.outputDeviceId = mDeviceBackendId ;
16241639 opts.outputDeviceName = mDeviceName ;
16251640 opts.oscPort = 9009 ;
16261641 opts.elevationMode = static_cast <ElevationMode>(mElevationMode );
@@ -1823,23 +1838,38 @@ void App::resetRuntimeToDefaults() {
18231838}
18241839
18251840void App::scanDevices () {
1841+ const int previousDeviceId = mDeviceBackendId ;
1842+ const std::string previousDeviceName = mDeviceName ;
18261843 mDeviceList .clear ();
1844+ mDeviceBackendIds .clear ();
18271845 mDeviceOutputChannels .clear ();
18281846 mDeviceSampleRates .clear ();
18291847 mDeviceList .push_back (" (system default)" );
1848+ mDeviceBackendIds .push_back (-1 );
18301849 mDeviceOutputChannels .push_back (0 );
18311850 mDeviceSampleRates .push_back (0.0 );
18321851 const int n = al::AudioDevice::numDevices ();
18331852 for (int i = 0 ; i < n; ++i) {
18341853 al::AudioDevice dev (i);
18351854 if (dev.valid () && dev.hasOutput ()) {
18361855 mDeviceList .push_back (std::string (dev.name ()));
1856+ mDeviceBackendIds .push_back (dev.id ());
18371857 mDeviceOutputChannels .push_back (dev.channelsOutMax ());
18381858 mDeviceSampleRates .push_back (dev.defaultSampleRate ());
18391859 }
18401860 }
18411861 mDeviceIdx = 0 ;
1862+ mDeviceBackendId = -1 ;
18421863 mDeviceName = " " ;
1864+ for (int i = 1 ; i < static_cast <int >(mDeviceBackendIds .size ()); ++i) {
1865+ if ((previousDeviceId >= 0 && mDeviceBackendIds [i] == previousDeviceId) ||
1866+ (!previousDeviceName.empty () && mDeviceList [i] == previousDeviceName)) {
1867+ mDeviceIdx = i;
1868+ mDeviceBackendId = mDeviceBackendIds [i];
1869+ mDeviceName = mDeviceList [i];
1870+ break ;
1871+ }
1872+ }
18431873}
18441874
18451875void App::detectSource () {
0 commit comments