Skip to content

Commit

Permalink
AudioCommon: Implement WASAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
spycrab committed May 26, 2018
1 parent 92ec97f commit a196dfe
Show file tree
Hide file tree
Showing 10 changed files with 600 additions and 7 deletions.
13 changes: 10 additions & 3 deletions Source/Core/AudioCommon/AudioCommon.cpp
Expand Up @@ -10,6 +10,7 @@
#include "AudioCommon/OpenALStream.h"
#include "AudioCommon/OpenSLESStream.h"
#include "AudioCommon/PulseAudioStream.h"
#include "AudioCommon/WASAPIStream.h"
#include "AudioCommon/XAudio2Stream.h"
#include "AudioCommon/XAudio2_7Stream.h"
#include "Common/Common.h"
Expand Down Expand Up @@ -50,6 +51,8 @@ void InitSoundStream()
g_sound_stream = std::make_unique<PulseAudio>();
else if (backend == BACKEND_OPENSLES && OpenSLESStream::isValid())
g_sound_stream = std::make_unique<OpenSLESStream>();
else if (backend == BACKEND_WASAPI && WASAPIStream::isValid())
g_sound_stream = std::make_unique<WASAPIStream>();

if (!g_sound_stream || !g_sound_stream->Init())
{
Expand Down Expand Up @@ -110,6 +113,9 @@ std::vector<std::string> GetSoundBackends()
backends.push_back(BACKEND_OPENAL);
if (OpenSLESStream::isValid())
backends.push_back(BACKEND_OPENSLES);
if (WASAPIStream::isValid())
backends.push_back(BACKEND_WASAPI);

return backends;
}

Expand All @@ -128,15 +134,16 @@ bool SupportsDPL2Decoder(const std::string& backend)

bool SupportsLatencyControl(const std::string& backend)
{
return backend == BACKEND_OPENAL;
return backend == BACKEND_OPENAL || backend == BACKEND_WASAPI;
}

bool SupportsVolumeChanges(const std::string& backend)
{
// FIXME: this one should ask the backend whether it supports it.
// but getting the backend from string etc. is probably
// too much just to enable/disable a stupid slider...
return backend == BACKEND_CUBEB || backend == BACKEND_OPENAL || backend == BACKEND_XAUDIO2;
return backend == BACKEND_CUBEB || backend == BACKEND_OPENAL || backend == BACKEND_XAUDIO2 ||
backend == BACKEND_WASAPI;
}

void UpdateSoundStream()
Expand Down Expand Up @@ -231,4 +238,4 @@ void ToggleMuteVolume()
isMuted = !isMuted;
UpdateSoundStream();
}
}
} // namespace AudioCommon
4 changes: 3 additions & 1 deletion Source/Core/AudioCommon/AudioCommon.vcxproj
Expand Up @@ -44,6 +44,7 @@
<ClCompile Include="Mixer.cpp" />
<ClCompile Include="NullSoundStream.cpp" />
<ClCompile Include="OpenALStream.cpp" />
<ClCompile Include="WASAPIStream.cpp" />
<ClCompile Include="WaveFile.cpp" />
<ClCompile Include="XAudio2Stream.cpp" />
<ClCompile Include="XAudio2_7Stream.cpp">
Expand All @@ -63,6 +64,7 @@
<ClInclude Include="OpenSLESStream.h" />
<ClInclude Include="PulseAudioStream.h" />
<ClInclude Include="SoundStream.h" />
<ClInclude Include="WASAPIStream.h" />
<ClInclude Include="WaveFile.h" />
<ClInclude Include="XAudio2Stream.h" />
<ClInclude Include="XAudio2_7Stream.h" />
Expand All @@ -81,4 +83,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
8 changes: 7 additions & 1 deletion Source/Core/AudioCommon/AudioCommon.vcxproj.filters
Expand Up @@ -27,6 +27,9 @@
<ClCompile Include="CubebStream.cpp">
<Filter>SoundStreams</Filter>
</ClCompile>
<ClCompile Include="WASAPIStream.cpp">
<Filter>SoundStreams</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="AudioCommon.h" />
Expand Down Expand Up @@ -62,8 +65,11 @@
<ClInclude Include="CubebStream.h">
<Filter>SoundStreams</Filter>
</ClInclude>
<ClInclude Include="WASAPIStream.h">
<Filter>SoundStreams</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="CMakeLists.txt" />
</ItemGroup>
</Project>
</Project>
1 change: 1 addition & 0 deletions Source/Core/AudioCommon/CMakeLists.txt
Expand Up @@ -47,6 +47,7 @@ else()
endif()

if(WIN32)
target_sources(audiocommon PRIVATE WASAPIStream.cpp)
target_sources(audiocommon PRIVATE XAudio2Stream.cpp)

add_library(audiocommon_xaudio27 "XAudio2_7Stream.cpp")
Expand Down

0 comments on commit a196dfe

Please sign in to comment.