From 1a56e9d9e096db7e7f0e219776c3bbc8397cd296 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 31 May 2019 07:01:44 -0400 Subject: [PATCH 1/3] AudioCommon: Use std::string_view with feature querying functions Provides the same behavior, but allows passed in strings to be non-allocating in calling code. --- Source/Core/AudioCommon/AudioCommon.cpp | 6 +++--- Source/Core/AudioCommon/AudioCommon.h | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Source/Core/AudioCommon/AudioCommon.cpp b/Source/Core/AudioCommon/AudioCommon.cpp index 1ffc377c56..79a89f83f9 100644 --- a/Source/Core/AudioCommon/AudioCommon.cpp +++ b/Source/Core/AudioCommon/AudioCommon.cpp @@ -117,7 +117,7 @@ std::vector GetSoundBackends() return backends; } -bool SupportsDPL2Decoder(const std::string& backend) +bool SupportsDPL2Decoder(std::string_view backend) { #ifndef __APPLE__ if (backend == BACKEND_OPENAL) @@ -132,12 +132,12 @@ bool SupportsDPL2Decoder(const std::string& backend) return false; } -bool SupportsLatencyControl(const std::string& backend) +bool SupportsLatencyControl(std::string_view backend) { return backend == BACKEND_OPENAL || backend == BACKEND_WASAPI; } -bool SupportsVolumeChanges(const std::string& backend) +bool SupportsVolumeChanges(std::string_view backend) { // FIXME: this one should ask the backend whether it supports it. // but getting the backend from string etc. is probably diff --git a/Source/Core/AudioCommon/AudioCommon.h b/Source/Core/AudioCommon/AudioCommon.h index 6925fe3d7b..d4dbd84a48 100644 --- a/Source/Core/AudioCommon/AudioCommon.h +++ b/Source/Core/AudioCommon/AudioCommon.h @@ -6,6 +6,7 @@ #include #include +#include #include #include "AudioCommon/SoundStream.h" @@ -20,9 +21,9 @@ void InitSoundStream(); void ShutdownSoundStream(); std::string GetDefaultSoundBackend(); std::vector GetSoundBackends(); -bool SupportsDPL2Decoder(const std::string& backend); -bool SupportsLatencyControl(const std::string& backend); -bool SupportsVolumeChanges(const std::string& backend); +bool SupportsDPL2Decoder(std::string_view backend); +bool SupportsLatencyControl(std::string_view backend); +bool SupportsVolumeChanges(std::string_view backend); void UpdateSoundStream(); void SetSoundStreamRunning(bool running); void SendAIBuffer(const short* samples, unsigned int num_samples); From 15397e2a8909eb226e169d496852b6e5625fc4fb Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 31 May 2019 07:03:52 -0400 Subject: [PATCH 2/3] AudioCommon: Use emplace_back instead of push_back in GetSoundBackends() Constructs the strings directly within the container instead of performing a construction, then a copy. The reasoning is that the BACKEND_* strings are const char arrays, so the push_back code is equivalent to: push_back(std::string(BACKEND_WHATEVER)) instead of forwarding the arguments to a constructed instance directly in the container. --- Source/Core/AudioCommon/AudioCommon.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/Core/AudioCommon/AudioCommon.cpp b/Source/Core/AudioCommon/AudioCommon.cpp index 79a89f83f9..ec68ef87aa 100644 --- a/Source/Core/AudioCommon/AudioCommon.cpp +++ b/Source/Core/AudioCommon/AudioCommon.cpp @@ -99,20 +99,20 @@ std::vector GetSoundBackends() { std::vector backends; - backends.push_back(BACKEND_NULLSOUND); - backends.push_back(BACKEND_CUBEB); + backends.emplace_back(BACKEND_NULLSOUND); + backends.emplace_back(BACKEND_CUBEB); if (XAudio2_7::isValid() || XAudio2::isValid()) - backends.push_back(BACKEND_XAUDIO2); + backends.emplace_back(BACKEND_XAUDIO2); if (AlsaSound::isValid()) - backends.push_back(BACKEND_ALSA); + backends.emplace_back(BACKEND_ALSA); if (PulseAudio::isValid()) - backends.push_back(BACKEND_PULSEAUDIO); + backends.emplace_back(BACKEND_PULSEAUDIO); if (OpenALStream::isValid()) - backends.push_back(BACKEND_OPENAL); + backends.emplace_back(BACKEND_OPENAL); if (OpenSLESStream::isValid()) - backends.push_back(BACKEND_OPENSLES); + backends.emplace_back(BACKEND_OPENSLES); if (WASAPIStream::isValid()) - backends.push_back(BACKEND_WASAPI); + backends.emplace_back(BACKEND_WASAPI); return backends; } From 78e96230b2b37accf7daf16af6810be55754bed3 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 31 May 2019 07:07:14 -0400 Subject: [PATCH 3/3] AudioCommon: Move static locals into the AudioCommon namespace Given these are locals, they can be moved out of the global namespace. While we're at it, turn the constants below it into constexpr variables. --- Source/Core/AudioCommon/AudioCommon.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Core/AudioCommon/AudioCommon.cpp b/Source/Core/AudioCommon/AudioCommon.cpp index ec68ef87aa..11d50d9d01 100644 --- a/Source/Core/AudioCommon/AudioCommon.cpp +++ b/Source/Core/AudioCommon/AudioCommon.cpp @@ -21,13 +21,13 @@ // This shouldn't be a global, at least not here. std::unique_ptr g_sound_stream; +namespace AudioCommon +{ static bool s_audio_dump_start = false; static bool s_sound_stream_running = false; -namespace AudioCommon -{ -static const int AUDIO_VOLUME_MIN = 0; -static const int AUDIO_VOLUME_MAX = 100; +constexpr int AUDIO_VOLUME_MIN = 0; +constexpr int AUDIO_VOLUME_MAX = 100; void InitSoundStream() {