@@ -845,14 +845,15 @@ int32_t AudioDeviceWindowsCore::SpeakerVolumeIsAvailable(bool& available) {
845
845
IAudioSessionManager* pManager = NULL ;
846
846
ISimpleAudioVolume* pVolume = NULL ;
847
847
848
+ float volume (0 .0f );
849
+
848
850
hr = _ptrDeviceOut->Activate (__uuidof (IAudioSessionManager), CLSCTX_ALL, NULL ,
849
851
(void **)&pManager);
850
852
EXIT_ON_ERROR (hr);
851
853
852
854
hr = pManager->GetSimpleAudioVolume (NULL , FALSE , &pVolume);
853
855
EXIT_ON_ERROR (hr);
854
856
855
- float volume (0 .0f );
856
857
hr = pVolume->GetMasterVolume (&volume);
857
858
if (FAILED (hr)) {
858
859
available = false ;
@@ -1031,12 +1032,13 @@ int32_t AudioDeviceWindowsCore::SetSpeakerMute(bool enable) {
1031
1032
HRESULT hr = S_OK;
1032
1033
IAudioEndpointVolume* pVolume = NULL ;
1033
1034
1035
+ const BOOL mute (enable);
1036
+
1034
1037
// Set the speaker system mute state.
1035
1038
hr = _ptrDeviceOut->Activate (__uuidof (IAudioEndpointVolume), CLSCTX_ALL, NULL ,
1036
1039
reinterpret_cast <void **>(&pVolume));
1037
1040
EXIT_ON_ERROR (hr);
1038
1041
1039
- const BOOL mute (enable);
1040
1042
hr = pVolume->SetMute (mute, NULL );
1041
1043
EXIT_ON_ERROR (hr);
1042
1044
@@ -1138,12 +1140,13 @@ int32_t AudioDeviceWindowsCore::SetMicrophoneMute(bool enable) {
1138
1140
HRESULT hr = S_OK;
1139
1141
IAudioEndpointVolume* pVolume = NULL ;
1140
1142
1143
+ const BOOL mute (enable);
1144
+
1141
1145
// Set the microphone system mute state.
1142
1146
hr = _ptrDeviceIn->Activate (__uuidof (IAudioEndpointVolume), CLSCTX_ALL, NULL ,
1143
1147
reinterpret_cast <void **>(&pVolume));
1144
1148
EXIT_ON_ERROR (hr);
1145
1149
1146
- const BOOL mute (enable);
1147
1150
hr = pVolume->SetMute (mute, NULL );
1148
1151
EXIT_ON_ERROR (hr);
1149
1152
@@ -1286,11 +1289,12 @@ int32_t AudioDeviceWindowsCore::MicrophoneVolumeIsAvailable(bool& available) {
1286
1289
HRESULT hr = S_OK;
1287
1290
IAudioEndpointVolume* pVolume = NULL ;
1288
1291
1292
+ float volume (0 .0f );
1293
+
1289
1294
hr = _ptrDeviceIn->Activate (__uuidof (IAudioEndpointVolume), CLSCTX_ALL, NULL ,
1290
1295
reinterpret_cast <void **>(&pVolume));
1291
1296
EXIT_ON_ERROR (hr);
1292
1297
1293
- float volume (0 .0f );
1294
1298
hr = pVolume->GetMasterVolumeLevelScalar (&volume);
1295
1299
if (FAILED (hr)) {
1296
1300
available = false ;
@@ -1878,6 +1882,11 @@ int32_t AudioDeviceWindowsCore::InitPlayout() {
1878
1882
WAVEFORMATEX Wfx = WAVEFORMATEX ();
1879
1883
WAVEFORMATEX* pWfxClosestMatch = NULL ;
1880
1884
1885
+ UINT bufferFrameCount (0 );
1886
+ REFERENCE_TIME hnsBufferDuration =
1887
+ 0 ; // ask for minimum buffer size (default)
1888
+ const int freqs[] = {48000 , 44100 , 16000 , 96000 , 32000 , 8000 };
1889
+
1881
1890
// Create COM object with IAudioClient interface.
1882
1891
SAFE_RELEASE (_ptrClientOut);
1883
1892
hr = _ptrDeviceOut->Activate (__uuidof (IAudioClient), CLSCTX_ALL, NULL ,
@@ -1911,7 +1920,6 @@ int32_t AudioDeviceWindowsCore::InitPlayout() {
1911
1920
Wfx.wBitsPerSample = 16 ;
1912
1921
Wfx.cbSize = 0 ;
1913
1922
1914
- const int freqs[] = {48000 , 44100 , 16000 , 96000 , 32000 , 8000 };
1915
1923
hr = S_FALSE;
1916
1924
1917
1925
// Iterate over frequencies and channels, in order of priority
@@ -1997,8 +2005,7 @@ int32_t AudioDeviceWindowsCore::InitPlayout() {
1997
2005
// buffer.
1998
2006
// ****************************************************************************
1999
2007
//
2000
- REFERENCE_TIME hnsBufferDuration =
2001
- 0 ; // ask for minimum buffer size (default)
2008
+
2002
2009
if (_devicePlaySampleRate == 44100 ) {
2003
2010
// Ask for a larger buffer size (30ms) when using 44.1kHz as render rate.
2004
2011
// There seems to be a larger risk of underruns for 44.1 compared
@@ -2008,6 +2015,7 @@ int32_t AudioDeviceWindowsCore::InitPlayout() {
2008
2015
// read by GetBufferSize() and it is 20ms on most machines.
2009
2016
hnsBufferDuration = 30 * 10000 ;
2010
2017
}
2018
+
2011
2019
hr = _ptrClientOut->Initialize (
2012
2020
AUDCLNT_SHAREMODE_SHARED, // share Audio Engine with other applications
2013
2021
AUDCLNT_STREAMFLAGS_EVENTCALLBACK, // processing of the audio buffer by
@@ -2038,7 +2046,6 @@ int32_t AudioDeviceWindowsCore::InitPlayout() {
2038
2046
2039
2047
// Get the actual size of the shared (endpoint buffer).
2040
2048
// Typical value is 960 audio frames <=> 20ms @ 48kHz sample rate.
2041
- UINT bufferFrameCount (0 );
2042
2049
hr = _ptrClientOut->GetBufferSize (&bufferFrameCount);
2043
2050
if (SUCCEEDED (hr)) {
2044
2051
RTC_LOG (LS_VERBOSE) << " IAudioClient::GetBufferSize() => "
@@ -2195,6 +2202,10 @@ int32_t AudioDeviceWindowsCore::InitRecording() {
2195
2202
WAVEFORMATEXTENSIBLE Wfx = WAVEFORMATEXTENSIBLE ();
2196
2203
WAVEFORMATEX* pWfxClosestMatch = NULL ;
2197
2204
2205
+ UINT bufferFrameCount (0 );
2206
+
2207
+ const int freqs[6 ] = {48000 , 44100 , 16000 , 96000 , 32000 , 8000 };
2208
+
2198
2209
// Create COM object with IAudioClient interface.
2199
2210
SAFE_RELEASE (_ptrClientIn);
2200
2211
hr = _ptrDeviceIn->Activate (__uuidof (IAudioClient), CLSCTX_ALL, NULL ,
@@ -2231,7 +2242,6 @@ int32_t AudioDeviceWindowsCore::InitRecording() {
2231
2242
Wfx.Samples .wValidBitsPerSample = Wfx.Format .wBitsPerSample ;
2232
2243
Wfx.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
2233
2244
2234
- const int freqs[6 ] = {48000 , 44100 , 16000 , 96000 , 32000 , 8000 };
2235
2245
hr = S_FALSE;
2236
2246
2237
2247
// Iterate over frequencies and channels, in order of priority
@@ -2328,7 +2338,6 @@ int32_t AudioDeviceWindowsCore::InitRecording() {
2328
2338
2329
2339
// Get the actual size of the shared (endpoint buffer).
2330
2340
// Typical value is 960 audio frames <=> 20ms @ 48kHz sample rate.
2331
- UINT bufferFrameCount (0 );
2332
2341
hr = _ptrClientIn->GetBufferSize (&bufferFrameCount);
2333
2342
if (SUCCEEDED (hr)) {
2334
2343
RTC_LOG (LS_VERBOSE) << " IAudioClient::GetBufferSize() => "
@@ -2734,6 +2743,14 @@ DWORD AudioDeviceWindowsCore::DoRenderThread() {
2734
2743
//
2735
2744
UINT32 bufferLength = 0 ;
2736
2745
hr = _ptrClientOut->GetBufferSize (&bufferLength);
2746
+
2747
+ REFERENCE_TIME devPeriod = 0 ;
2748
+ REFERENCE_TIME devPeriodMin = 0 ;
2749
+ double endpointBufferSizeMS =
2750
+ 10.0 * ((double )bufferLength / (double )_devicePlayBlockSize);
2751
+ BYTE* pData = NULL ;
2752
+ int playout_delay = 0 ;
2753
+
2737
2754
EXIT_ON_ERROR (hr);
2738
2755
RTC_LOG (LS_VERBOSE) << " [REND] size of buffer : " << bufferLength;
2739
2756
@@ -2755,29 +2772,24 @@ DWORD AudioDeviceWindowsCore::DoRenderThread() {
2755
2772
// an audio application can achieve. Typical value: 100000 <=> 0.01 sec =
2756
2773
// 10ms.
2757
2774
//
2758
- REFERENCE_TIME devPeriod = 0 ;
2759
- REFERENCE_TIME devPeriodMin = 0 ;
2760
2775
_ptrClientOut->GetDevicePeriod (&devPeriod, &devPeriodMin);
2761
2776
RTC_LOG (LS_VERBOSE) << " [REND] device period : " << (DWORD)devPeriod
2762
2777
<< " (" << (double )(devPeriod / 10000.0 ) << " ms)" ;
2763
2778
2764
2779
// Derive initial rendering delay.
2765
2780
// Example: 10*(960/480) + 15 = 20 + 15 = 35ms
2766
2781
//
2767
- int playout_delay = 10 * (bufferLength / _playBlockSize) +
2782
+ playout_delay = 10 * (bufferLength / _playBlockSize) +
2768
2783
(int )((latency + devPeriod) / 10000 );
2769
2784
_sndCardPlayDelay = playout_delay;
2770
2785
_writtenSamples = 0 ;
2771
2786
RTC_LOG (LS_VERBOSE) << " [REND] initial delay : " << playout_delay;
2772
2787
2773
- double endpointBufferSizeMS =
2774
- 10.0 * ((double )bufferLength / (double )_devicePlayBlockSize);
2775
2788
RTC_LOG (LS_VERBOSE) << " [REND] endpointBufferSizeMS : "
2776
2789
<< endpointBufferSizeMS;
2777
2790
2778
2791
// Before starting the stream, fill the rendering buffer with silence.
2779
2792
//
2780
- BYTE* pData = NULL ;
2781
2793
hr = _ptrRenderClient->GetBuffer (bufferLength, &pData);
2782
2794
EXIT_ON_ERROR (hr);
2783
2795
@@ -3152,6 +3164,9 @@ DWORD AudioDeviceWindowsCore::DoCaptureThread() {
3152
3164
3153
3165
_Lock ();
3154
3166
3167
+ double endpointBufferSizeMS = 0 ;
3168
+ double extraDelayMS = 0 ;
3169
+
3155
3170
// Get size of capturing buffer (length is expressed as the number of audio
3156
3171
// frames the buffer can hold). This value is fixed during the capturing
3157
3172
// session.
@@ -3163,14 +3178,18 @@ DWORD AudioDeviceWindowsCore::DoCaptureThread() {
3163
3178
return 1 ;
3164
3179
}
3165
3180
hr = _ptrClientIn->GetBufferSize (&bufferLength);
3181
+
3182
+ const UINT32 syncBufferSize = 2 * (bufferLength * _recAudioFrameSize);
3183
+ REFERENCE_TIME devPeriod = 0 ;
3184
+ REFERENCE_TIME devPeriodMin = 0 ;
3185
+
3166
3186
EXIT_ON_ERROR (hr);
3167
3187
RTC_LOG (LS_VERBOSE) << " [CAPT] size of buffer : " << bufferLength;
3168
3188
3169
3189
// Allocate memory for sync buffer.
3170
3190
// It is used for compensation between native 44.1 and internal 44.0 and
3171
3191
// for cases when the capture buffer is larger than 10ms.
3172
3192
//
3173
- const UINT32 syncBufferSize = 2 * (bufferLength * _recAudioFrameSize);
3174
3193
syncBuffer = new BYTE[syncBufferSize];
3175
3194
if (syncBuffer == NULL ) {
3176
3195
return (DWORD)E_POINTER;
@@ -3189,16 +3208,14 @@ DWORD AudioDeviceWindowsCore::DoCaptureThread() {
3189
3208
// Get the length of the periodic interval separating successive processing
3190
3209
// passes by the audio engine on the data in the endpoint buffer.
3191
3210
//
3192
- REFERENCE_TIME devPeriod = 0 ;
3193
- REFERENCE_TIME devPeriodMin = 0 ;
3194
3211
_ptrClientIn->GetDevicePeriod (&devPeriod, &devPeriodMin);
3195
3212
RTC_LOG (LS_VERBOSE) << " [CAPT] device period : " << (DWORD)devPeriod
3196
3213
<< " (" << (double )(devPeriod / 10000.0 ) << " ms)" ;
3197
3214
3198
- double extraDelayMS = (double )((latency + devPeriod) / 10000.0 );
3215
+ extraDelayMS = (double )((latency + devPeriod) / 10000.0 );
3199
3216
RTC_LOG (LS_VERBOSE) << " [CAPT] extraDelayMS : " << extraDelayMS;
3200
3217
3201
- double endpointBufferSizeMS =
3218
+ endpointBufferSizeMS =
3202
3219
10.0 * ((double )bufferLength / (double )_recBlockSize);
3203
3220
RTC_LOG (LS_VERBOSE) << " [CAPT] endpointBufferSizeMS : "
3204
3221
<< endpointBufferSizeMS;
@@ -4012,6 +4029,10 @@ int32_t AudioDeviceWindowsCore::_EnumerateEndpointDevicesAll(
4012
4029
IAudioEndpointVolume* pEndpointVolume = NULL ;
4013
4030
LPWSTR pwszID = NULL ;
4014
4031
4032
+ DWORD dwHwSupportMask = 0 ;
4033
+ UINT count = 0 ;
4034
+ UINT nChannelCount (0 );
4035
+
4015
4036
// Generate a collection of audio endpoint devices in the system.
4016
4037
// Get states for *all* endpoint devices.
4017
4038
// Output: IMMDeviceCollection interface.
@@ -4024,8 +4045,6 @@ int32_t AudioDeviceWindowsCore::_EnumerateEndpointDevicesAll(
4024
4045
4025
4046
// use the IMMDeviceCollection interface...
4026
4047
4027
- UINT count = 0 ;
4028
-
4029
4048
// Retrieve a count of the devices in the device collection.
4030
4049
hr = pCollection->GetCount (&count);
4031
4050
EXIT_ON_ERROR (hr);
@@ -4092,7 +4111,6 @@ int32_t AudioDeviceWindowsCore::_EnumerateEndpointDevicesAll(
4092
4111
<< " ) : UNPLUGGED" ;
4093
4112
4094
4113
// Check the hardware volume capabilities.
4095
- DWORD dwHwSupportMask = 0 ;
4096
4114
hr = pEndpoint->Activate (__uuidof (IAudioEndpointVolume), CLSCTX_ALL, NULL ,
4097
4115
(void **)&pEndpointVolume);
4098
4116
CONTINUE_ON_ERROR (hr);
@@ -4113,7 +4131,6 @@ int32_t AudioDeviceWindowsCore::_EnumerateEndpointDevicesAll(
4113
4131
4114
4132
// Check the channel count (#channels in the audio stream that enters or
4115
4133
// leaves the audio endpoint device)
4116
- UINT nChannelCount (0 );
4117
4134
hr = pEndpointVolume->GetChannelCount (&nChannelCount);
4118
4135
CONTINUE_ON_ERROR (hr);
4119
4136
RTC_LOG (LS_VERBOSE) << " #channels : " << nChannelCount;
0 commit comments