Merge pull request #8148 from lioncash/view

AudioCommon: Use std::string_view with feature querying functions
This commit is contained in:
Léo Lam 2019-05-31 14:01:15 +02:00 committed by GitHub
commit 2cb59ab055
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 18 deletions

View File

@ -21,13 +21,13 @@
// This shouldn't be a global, at least not here. // This shouldn't be a global, at least not here.
std::unique_ptr<SoundStream> g_sound_stream; std::unique_ptr<SoundStream> g_sound_stream;
namespace AudioCommon
{
static bool s_audio_dump_start = false; static bool s_audio_dump_start = false;
static bool s_sound_stream_running = false; static bool s_sound_stream_running = false;
namespace AudioCommon constexpr int AUDIO_VOLUME_MIN = 0;
{ constexpr int AUDIO_VOLUME_MAX = 100;
static const int AUDIO_VOLUME_MIN = 0;
static const int AUDIO_VOLUME_MAX = 100;
void InitSoundStream() void InitSoundStream()
{ {
@ -99,25 +99,25 @@ std::vector<std::string> GetSoundBackends()
{ {
std::vector<std::string> backends; std::vector<std::string> backends;
backends.push_back(BACKEND_NULLSOUND); backends.emplace_back(BACKEND_NULLSOUND);
backends.push_back(BACKEND_CUBEB); backends.emplace_back(BACKEND_CUBEB);
if (XAudio2_7::isValid() || XAudio2::isValid()) if (XAudio2_7::isValid() || XAudio2::isValid())
backends.push_back(BACKEND_XAUDIO2); backends.emplace_back(BACKEND_XAUDIO2);
if (AlsaSound::isValid()) if (AlsaSound::isValid())
backends.push_back(BACKEND_ALSA); backends.emplace_back(BACKEND_ALSA);
if (PulseAudio::isValid()) if (PulseAudio::isValid())
backends.push_back(BACKEND_PULSEAUDIO); backends.emplace_back(BACKEND_PULSEAUDIO);
if (OpenALStream::isValid()) if (OpenALStream::isValid())
backends.push_back(BACKEND_OPENAL); backends.emplace_back(BACKEND_OPENAL);
if (OpenSLESStream::isValid()) if (OpenSLESStream::isValid())
backends.push_back(BACKEND_OPENSLES); backends.emplace_back(BACKEND_OPENSLES);
if (WASAPIStream::isValid()) if (WASAPIStream::isValid())
backends.push_back(BACKEND_WASAPI); backends.emplace_back(BACKEND_WASAPI);
return backends; return backends;
} }
bool SupportsDPL2Decoder(const std::string& backend) bool SupportsDPL2Decoder(std::string_view backend)
{ {
#ifndef __APPLE__ #ifndef __APPLE__
if (backend == BACKEND_OPENAL) if (backend == BACKEND_OPENAL)
@ -132,12 +132,12 @@ bool SupportsDPL2Decoder(const std::string& backend)
return false; return false;
} }
bool SupportsLatencyControl(const std::string& backend) bool SupportsLatencyControl(std::string_view backend)
{ {
return backend == BACKEND_OPENAL || backend == BACKEND_WASAPI; 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. // FIXME: this one should ask the backend whether it supports it.
// but getting the backend from string etc. is probably // but getting the backend from string etc. is probably

View File

@ -6,6 +6,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <string_view>
#include <vector> #include <vector>
#include "AudioCommon/SoundStream.h" #include "AudioCommon/SoundStream.h"
@ -20,9 +21,9 @@ void InitSoundStream();
void ShutdownSoundStream(); void ShutdownSoundStream();
std::string GetDefaultSoundBackend(); std::string GetDefaultSoundBackend();
std::vector<std::string> GetSoundBackends(); std::vector<std::string> GetSoundBackends();
bool SupportsDPL2Decoder(const std::string& backend); bool SupportsDPL2Decoder(std::string_view backend);
bool SupportsLatencyControl(const std::string& backend); bool SupportsLatencyControl(std::string_view backend);
bool SupportsVolumeChanges(const std::string& backend); bool SupportsVolumeChanges(std::string_view backend);
void UpdateSoundStream(); void UpdateSoundStream();
void SetSoundStreamRunning(bool running); void SetSoundStreamRunning(bool running);
void SendAIBuffer(const short* samples, unsigned int num_samples); void SendAIBuffer(const short* samples, unsigned int num_samples);