Allow loopback without having to define output parameters
authorMarcus Tomlinson <themarcustomlinson@gmail.com>
Fri, 2 Nov 2018 16:01:49 +0000 (16:01 +0000)
committerMarcus Tomlinson <themarcustomlinson@gmail.com>
Fri, 2 Nov 2018 16:01:49 +0000 (16:01 +0000)
RtAudio.cpp

index 34472d8958d34224312f5247ab83cddcb8127eea..91e4f2c31b7b0942ca49eab0610ff7f0aa9d40c9 100644 (file)
@@ -4764,6 +4764,13 @@ bool RtApiWasapi::probeDeviceOpen( unsigned int device, StreamMode mode, unsigne
   // if device index falls within render devices and is configured for loopback
   if ( device < renderDeviceCount && mode == INPUT )
   {
+    // if renderAudioClient is not initialised, initialise it now
+    IAudioClient*& renderAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->renderAudioClient;
+    if ( !renderAudioClient )
+    {
+      probeDeviceOpen( device, OUTPUT, channels, firstChannel, sampleRate, format, bufferSize, options );
+    }
+
     // retrieve captureAudioClient from devicePtr
     IAudioClient*& captureAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->captureAudioClient;
 
@@ -4793,8 +4800,12 @@ bool RtApiWasapi::probeDeviceOpen( unsigned int device, StreamMode mode, unsigne
   // if device index falls within render devices and is configured for output
   if ( device < renderDeviceCount && mode == OUTPUT )
   {
-    // retrieve renderAudioClient from devicePtr
+    // if renderAudioClient is already initialised, don't initialise it again
     IAudioClient*& renderAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->renderAudioClient;
+    if ( renderAudioClient )
+    {
+      return SUCCESS;
+    }
 
     hr = renderDevices->Item( device, &devicePtr );
     if ( FAILED( hr ) ) {