Skip to content

Commit 7859814

Browse files
committed
fix(audio) refactor to match bits-per-sample to default device in all cases
1 parent b0db65c commit 7859814

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

src/platform/windows/audio.cpp

+10-15
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ namespace {
131131
};
132132
} else if (channel_count == 6) {
133133
auto channel_mask1 = waveformat_mask_surround51_with_backspeakers;
134-
auto channel_mask2 = waveformat_mask_surround51_with_sidespeakers; // XXX will never be used, but is probably the better 5.1 layout
134+
auto channel_mask2 = waveformat_mask_surround51_with_sidespeakers; // XXX will never be used, but is probably the better 5.1 layout
135135
return {
136136
create_waveformat(sample_format_e::f32, channel_count, channel_mask1),
137137
create_waveformat(sample_format_e::f32, channel_count, channel_mask2),
@@ -798,25 +798,20 @@ namespace platf::audio {
798798
// When switching to a Steam virtual speaker device, try to retain the bit depth of the
799799
// default audio device. Switching from a 16-bit device to a 24-bit one has been known to
800800
// cause glitches for some users.
801-
bool use_16bit = false;
801+
int wanted_bits_per_sample = 32;
802802
auto current_default_dev = default_device(device_enum);
803803
if (current_default_dev) {
804804
audio::prop_t prop;
805805
prop_var_t current_device_format;
806-
prop_var_t current_device_friendly_name;
807806

808-
current_default_dev->OpenPropertyStore(STGM_READ, &prop);
809-
810-
if (SUCCEEDED(prop->GetValue(PKEY_AudioEngine_DeviceFormat, &current_device_format.prop))) {
811-
WAVEFORMATEXTENSIBLE *format = (WAVEFORMATEXTENSIBLE *)current_device_format.prop.blob.pBlobData;
812-
if (format->Format.wBitsPerSample < 24) {
813-
if (SUCCEEDED(prop->GetValue(PKEY_Device_FriendlyName, &current_device_friendly_name.prop))) {
814-
auto friendly_name = to_utf8(std::wstring(current_device_friendly_name.prop.pwszVal));
815-
BOOST_LOG(info) << "Steam Streaming Speakers will use 16-bit to match default audio device: "sv << friendly_name;
816-
use_16bit = true;
817-
}
818-
}
807+
// clang-format off: avoid a long line and warnings about nested if statements
808+
if ( SUCCEEDED(current_default_dev->OpenPropertyStore(STGM_READ, &prop))
809+
&& SUCCEEDED(prop->GetValue(PKEY_AudioEngine_DeviceFormat, &current_device_format.prop)) )
810+
{
811+
auto *format = (WAVEFORMATEXTENSIBLE *)current_device_format.prop.blob.pBlobData;
812+
wanted_bits_per_sample = format->Samples.wValidBitsPerSample;
819813
}
814+
// clang-format on
820815
}
821816

822817
auto &device_id = virtual_sink_info->first;
@@ -828,7 +823,7 @@ namespace platf::audio {
828823
auto waveformat_copy = waveformat;
829824
auto waveformat_copy_pointer = reinterpret_cast<WAVEFORMATEX *>(&waveformat_copy);
830825

831-
if (use_16bit && waveformat.Samples.wValidBitsPerSample != 16) {
826+
if (wanted_bits_per_sample != waveformat.Samples.wValidBitsPerSample) {
832827
continue;
833828
}
834829

0 commit comments

Comments
 (0)