@@ -4203,13 +4203,8 @@ class WasapiResampler
4203
4203
// A structure to hold various information related to the WASAPI implementation.
4204
4204
struct WasapiHandle
4205
4205
{
4206
- #ifdef __IAudioClient3_INTERFACE_DEFINED__
4207
- IAudioClient3* captureAudioClient;
4208
- IAudioClient3* renderAudioClient;
4209
- #else
4210
4206
IAudioClient* captureAudioClient;
4211
4207
IAudioClient* renderAudioClient;
4212
- #endif
4213
4208
IAudioCaptureClient* captureClient;
4214
4209
IAudioRenderClient* renderClient;
4215
4210
HANDLE captureEvent;
@@ -4327,11 +4322,7 @@ RtAudio::DeviceInfo RtApiWasapi::getDeviceInfo( unsigned int device )
4327
4322
IMMDeviceCollection* renderDevices = NULL ;
4328
4323
IMMDevice* devicePtr = NULL ;
4329
4324
IMMDevice* defaultDevicePtr = NULL ;
4330
- #ifdef __IAudioClient3_INTERFACE_DEFINED__
4331
- IAudioClient3* audioClient = NULL ;
4332
- #else
4333
4325
IAudioClient* audioClient = NULL ;
4334
- #endif
4335
4326
IPropertyStore* devicePropStore = NULL ;
4336
4327
IPropertyStore* defaultDevicePropStore = NULL ;
4337
4328
@@ -4453,11 +4444,7 @@ RtAudio::DeviceInfo RtApiWasapi::getDeviceInfo( unsigned int device )
4453
4444
}
4454
4445
4455
4446
// channel count
4456
- #ifdef __IAudioClient3_INTERFACE_DEFINED__
4457
- hr = devicePtr->Activate ( __uuidof ( IAudioClient3 ), CLSCTX_ALL, NULL , ( void ** ) &audioClient );
4458
- #else
4459
4447
hr = devicePtr->Activate ( __uuidof ( IAudioClient ), CLSCTX_ALL, NULL , ( void ** ) &audioClient );
4460
- #endif
4461
4448
if ( FAILED ( hr ) ) {
4462
4449
errorText_ = " RtApiWasapi::getDeviceInfo: Unable to retrieve device audio client." ;
4463
4450
goto Exit;
@@ -4750,23 +4737,15 @@ bool RtApiWasapi::probeDeviceOpen( unsigned int device, StreamMode mode, unsigne
4750
4737
}
4751
4738
4752
4739
// retrieve captureAudioClient from devicePtr
4753
- #ifdef __IAudioClient3_INTERFACE_DEFINED__
4754
- IAudioClient3*& captureAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->captureAudioClient ;
4755
- #else
4756
4740
IAudioClient*& captureAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->captureAudioClient ;
4757
- #endif
4758
4741
4759
4742
hr = captureDevices->Item ( device - renderDeviceCount, &devicePtr );
4760
4743
if ( FAILED ( hr ) ) {
4761
4744
errorText_ = " RtApiWasapi::probeDeviceOpen: Unable to retrieve capture device handle." ;
4762
4745
goto Exit;
4763
4746
}
4764
4747
4765
- #ifdef __IAudioClient3_INTERFACE_DEFINED__
4766
- hr = devicePtr->Activate ( __uuidof ( IAudioClient3 ), CLSCTX_ALL,
4767
- #else
4768
4748
hr = devicePtr->Activate ( __uuidof ( IAudioClient ), CLSCTX_ALL,
4769
- #endif
4770
4749
NULL , ( void ** ) &captureAudioClient );
4771
4750
if ( FAILED ( hr ) ) {
4772
4751
errorText_ = " RtApiWasapi::probeDeviceOpen: Unable to retrieve capture device audio client." ;
@@ -4787,34 +4766,22 @@ bool RtApiWasapi::probeDeviceOpen( unsigned int device, StreamMode mode, unsigne
4787
4766
if ( device < renderDeviceCount && mode == INPUT )
4788
4767
{
4789
4768
// if renderAudioClient is not initialised, initialise it now
4790
- #ifdef __IAudioClient3_INTERFACE_DEFINED__
4791
- IAudioClient3*& renderAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->renderAudioClient ;
4792
- #else
4793
4769
IAudioClient*& renderAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->renderAudioClient ;
4794
- #endif
4795
4770
if ( !renderAudioClient )
4796
4771
{
4797
4772
probeDeviceOpen ( device, OUTPUT, channels, firstChannel, sampleRate, format, bufferSize, options );
4798
4773
}
4799
4774
4800
4775
// retrieve captureAudioClient from devicePtr
4801
- #ifdef __IAudioClient3_INTERFACE_DEFINED__
4802
- IAudioClient3*& captureAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->captureAudioClient ;
4803
- #else
4804
4776
IAudioClient*& captureAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->captureAudioClient ;
4805
- #endif
4806
4777
4807
4778
hr = renderDevices->Item ( device, &devicePtr );
4808
4779
if ( FAILED ( hr ) ) {
4809
4780
errorText_ = " RtApiWasapi::probeDeviceOpen: Unable to retrieve render device handle." ;
4810
4781
goto Exit;
4811
4782
}
4812
4783
4813
- #ifdef __IAudioClient3_INTERFACE_DEFINED__
4814
- hr = devicePtr->Activate ( __uuidof ( IAudioClient3 ), CLSCTX_ALL,
4815
- #else
4816
4784
hr = devicePtr->Activate ( __uuidof ( IAudioClient ), CLSCTX_ALL,
4817
- #endif
4818
4785
NULL , ( void ** ) &captureAudioClient );
4819
4786
if ( FAILED ( hr ) ) {
4820
4787
errorText_ = " RtApiWasapi::probeDeviceOpen: Unable to retrieve render device audio client." ;
@@ -4835,11 +4802,7 @@ bool RtApiWasapi::probeDeviceOpen( unsigned int device, StreamMode mode, unsigne
4835
4802
if ( device < renderDeviceCount && mode == OUTPUT )
4836
4803
{
4837
4804
// if renderAudioClient is already initialised, don't initialise it again
4838
- #ifdef __IAudioClient3_INTERFACE_DEFINED__
4839
- IAudioClient3*& renderAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->renderAudioClient ;
4840
- #else
4841
4805
IAudioClient*& renderAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->renderAudioClient ;
4842
- #endif
4843
4806
if ( renderAudioClient )
4844
4807
{
4845
4808
methodResult = SUCCESS;
@@ -4852,11 +4815,7 @@ bool RtApiWasapi::probeDeviceOpen( unsigned int device, StreamMode mode, unsigne
4852
4815
goto Exit;
4853
4816
}
4854
4817
4855
- #ifdef __IAudioClient3_INTERFACE_DEFINED__
4856
- hr = devicePtr->Activate ( __uuidof ( IAudioClient3 ), CLSCTX_ALL,
4857
- #else
4858
4818
hr = devicePtr->Activate ( __uuidof ( IAudioClient ), CLSCTX_ALL,
4859
- #endif
4860
4819
NULL , ( void ** ) &renderAudioClient );
4861
4820
if ( FAILED ( hr ) ) {
4862
4821
errorText_ = " RtApiWasapi::probeDeviceOpen: Unable to retrieve render device audio client." ;
@@ -4982,13 +4941,8 @@ void RtApiWasapi::wasapiThread()
4982
4941
4983
4942
HRESULT hr;
4984
4943
4985
- #ifdef __IAudioClient3_INTERFACE_DEFINED__
4986
- IAudioClient3* captureAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->captureAudioClient ;
4987
- IAudioClient3* renderAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->renderAudioClient ;
4988
- #else
4989
4944
IAudioClient* captureAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->captureAudioClient ;
4990
4945
IAudioClient* renderAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->renderAudioClient ;
4991
- #endif
4992
4946
IAudioCaptureClient* captureClient = ( ( WasapiHandle* ) stream_.apiHandle )->captureClient ;
4993
4947
IAudioRenderClient* renderClient = ( ( WasapiHandle* ) stream_.apiHandle )->renderClient ;
4994
4948
HANDLE captureEvent = ( ( WasapiHandle* ) stream_.apiHandle )->captureEvent ;
@@ -5050,43 +5004,37 @@ void RtApiWasapi::wasapiThread()
5050
5004
captureSrRatio = ( ( float ) captureFormat->nSamplesPerSec / stream_.sampleRate );
5051
5005
5052
5006
if ( !captureClient ) {
5053
- #ifdef __IAudioClient3_INTERFACE_DEFINED__
5054
- if ( !loopbackEnabled )
5007
+ IAudioClient3* captureAudioClient3 = nullptr ;
5008
+ captureAudioClient->QueryInterface ( __uuidof ( IAudioClient3 ), ( void ** ) &captureAudioClient3 );
5009
+ if ( captureAudioClient3 && !loopbackEnabled )
5055
5010
{
5056
5011
UINT32 Ignore;
5057
5012
UINT32 MinPeriodInFrames;
5058
- hr = captureAudioClient ->GetSharedModeEnginePeriod ( captureFormat,
5059
- &Ignore,
5060
- &Ignore,
5061
- &MinPeriodInFrames,
5062
- &Ignore );
5013
+ hr = captureAudioClient3 ->GetSharedModeEnginePeriod ( captureFormat,
5014
+ &Ignore,
5015
+ &Ignore,
5016
+ &MinPeriodInFrames,
5017
+ &Ignore );
5063
5018
if ( FAILED ( hr ) ) {
5064
5019
errorText = " RtApiWasapi::wasapiThread: Unable to initialize capture audio client." ;
5065
5020
goto Exit;
5066
5021
}
5067
5022
5068
- hr = captureAudioClient ->InitializeSharedAudioStream ( AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
5069
- MinPeriodInFrames,
5070
- captureFormat,
5071
- NULL );
5023
+ hr = captureAudioClient3 ->InitializeSharedAudioStream ( AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
5024
+ MinPeriodInFrames,
5025
+ captureFormat,
5026
+ NULL );
5072
5027
}
5073
5028
else
5074
5029
{
5075
5030
hr = captureAudioClient->Initialize ( AUDCLNT_SHAREMODE_SHARED,
5076
- AUDCLNT_STREAMFLAGS_LOOPBACK,
5031
+ loopbackEnabled ? AUDCLNT_STREAMFLAGS_LOOPBACK : AUDCLNT_STREAMFLAGS_EVENTCALLBACK ,
5077
5032
0 ,
5078
5033
0 ,
5079
5034
captureFormat,
5080
5035
NULL );
5081
5036
}
5082
- #else
5083
- hr = captureAudioClient->Initialize ( AUDCLNT_SHAREMODE_SHARED,
5084
- loopbackEnabled ? AUDCLNT_STREAMFLAGS_LOOPBACK : AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
5085
- 0 ,
5086
- 0 ,
5087
- captureFormat,
5088
- NULL );
5089
- #endif
5037
+
5090
5038
if ( FAILED ( hr ) ) {
5091
5039
errorText = " RtApiWasapi::wasapiThread: Unable to initialize capture audio client." ;
5092
5040
goto Exit;
@@ -5167,31 +5115,37 @@ void RtApiWasapi::wasapiThread()
5167
5115
renderSrRatio = ( ( float ) renderFormat->nSamplesPerSec / stream_.sampleRate );
5168
5116
5169
5117
if ( !renderClient ) {
5170
- #ifdef __IAudioClient3_INTERFACE_DEFINED__
5171
- UINT32 Ignore;
5172
- UINT32 MinPeriodInFrames;
5173
- hr = renderAudioClient->GetSharedModeEnginePeriod ( renderFormat,
5174
- &Ignore,
5175
- &Ignore,
5176
- &MinPeriodInFrames,
5177
- &Ignore );
5178
- if ( FAILED ( hr ) ) {
5179
- errorText = " RtApiWasapi::wasapiThread: Unable to initialize render audio client." ;
5180
- goto Exit;
5118
+ IAudioClient3* renderAudioClient3 = nullptr ;
5119
+ renderAudioClient->QueryInterface ( __uuidof ( IAudioClient3 ), ( void ** ) &renderAudioClient3 );
5120
+ if ( renderAudioClient3 )
5121
+ {
5122
+ UINT32 Ignore;
5123
+ UINT32 MinPeriodInFrames;
5124
+ hr = renderAudioClient3->GetSharedModeEnginePeriod ( renderFormat,
5125
+ &Ignore,
5126
+ &Ignore,
5127
+ &MinPeriodInFrames,
5128
+ &Ignore );
5129
+ if ( FAILED ( hr ) ) {
5130
+ errorText = " RtApiWasapi::wasapiThread: Unable to initialize render audio client." ;
5131
+ goto Exit;
5132
+ }
5133
+
5134
+ hr = renderAudioClient3->InitializeSharedAudioStream ( AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
5135
+ MinPeriodInFrames,
5136
+ renderFormat,
5137
+ NULL );
5181
5138
}
5182
-
5183
- hr = renderAudioClient->InitializeSharedAudioStream ( AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
5184
- MinPeriodInFrames,
5185
- renderFormat,
5186
- NULL );
5187
- #else
5188
- hr = renderAudioClient->Initialize ( AUDCLNT_SHAREMODE_SHARED,
5189
- AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
5190
- 0 ,
5191
- 0 ,
5192
- renderFormat,
5193
- NULL );
5194
- #endif
5139
+ else
5140
+ {
5141
+ hr = renderAudioClient->Initialize ( AUDCLNT_SHAREMODE_SHARED,
5142
+ AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
5143
+ 0 ,
5144
+ 0 ,
5145
+ renderFormat,
5146
+ NULL );
5147
+ }
5148
+
5195
5149
if ( FAILED ( hr ) ) {
5196
5150
errorText = " RtApiWasapi::wasapiThread: Unable to initialize render audio client." ;
5197
5151
goto Exit;
0 commit comments