mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-18 05:05:46 -04:00
FrontendCommon: Drop SDL2 audio output
This commit is contained in:
@ -3,8 +3,6 @@ add_library(frontend-common
|
||||
achievements.h
|
||||
common_host.cpp
|
||||
common_host.h
|
||||
cubeb_audio_stream.cpp
|
||||
cubeb_audio_stream.h
|
||||
fullscreen_ui.cpp
|
||||
fullscreen_ui.h
|
||||
game_list.cpp
|
||||
@ -32,7 +30,15 @@ add_library(frontend-common
|
||||
postprocessing_shadergen.h
|
||||
)
|
||||
|
||||
target_link_libraries(frontend-common PUBLIC core common cubeb imgui tinyxml2 rapidjson scmversion)
|
||||
target_link_libraries(frontend-common PUBLIC core common imgui tinyxml2 rapidjson scmversion)
|
||||
|
||||
if(ENABLE_CUBEB)
|
||||
target_sources(frontend-common PRIVATE
|
||||
cubeb_audio_stream.cpp
|
||||
cubeb_audio_stream.h
|
||||
)
|
||||
target_link_libraries(frontend-common PRIVATE cubeb)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
target_sources(frontend-common PRIVATE
|
||||
@ -82,8 +88,6 @@ endif()
|
||||
|
||||
if(SDL2_FOUND)
|
||||
target_sources(frontend-common PRIVATE
|
||||
sdl_audio_stream.cpp
|
||||
sdl_audio_stream.h
|
||||
sdl_input_source.cpp
|
||||
sdl_input_source.h
|
||||
sdl_initializer.cpp
|
||||
|
@ -42,14 +42,6 @@
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
|
||||
#ifndef _UWP
|
||||
#include "cubeb_audio_stream.h"
|
||||
#endif
|
||||
|
||||
#ifdef WITH_SDL2
|
||||
#include "sdl_audio_stream.h"
|
||||
#endif
|
||||
|
||||
#ifdef WITH_DISCORD_PRESENCE
|
||||
#include "discord_rpc.h"
|
||||
#endif
|
||||
@ -60,7 +52,6 @@
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "common/windows_headers.h"
|
||||
#include "xaudio2_audio_stream.h"
|
||||
#include <KnownFolders.h>
|
||||
#include <ShlObj.h>
|
||||
#include <mmsystem.h>
|
||||
@ -158,11 +149,6 @@ std::unique_ptr<AudioStream> Host::CreateAudioStream(AudioBackend backend, u32 s
|
||||
return CommonHost::CreateXAudio2Stream(sample_rate, channels, buffer_ms, latency_ms, stretch);
|
||||
#endif
|
||||
|
||||
#ifdef WITH_SDL2
|
||||
case AudioBackend::SDL:
|
||||
return CommonHost::CreateSDLAudioStream(sample_rate, channels, buffer_ms, latency_ms, stretch);
|
||||
#endif
|
||||
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -34,10 +34,6 @@ void ReleaseHostDisplayResources();
|
||||
std::unique_ptr<AudioStream> CreateXAudio2Stream(u32 sample_rate, u32 channels, u32 buffer_ms, u32 latency_ms,
|
||||
AudioStretchMode stretch);
|
||||
#endif
|
||||
#ifdef WITH_SDL2
|
||||
std::unique_ptr<AudioStream> CreateSDLAudioStream(u32 sample_rate, u32 channels, u32 buffer_ms, u32 latency_ms,
|
||||
AudioStretchMode stretch);
|
||||
#endif
|
||||
#ifndef _UWP
|
||||
std::unique_ptr<AudioStream> CreateCubebAudioStream(u32 sample_rate, u32 channels, u32 buffer_ms, u32 latency_ms,
|
||||
AudioStretchMode stretch);
|
||||
|
@ -34,9 +34,6 @@
|
||||
<ClCompile Include="postprocessing_chain.cpp" />
|
||||
<ClCompile Include="postprocessing_shader.cpp" />
|
||||
<ClCompile Include="postprocessing_shadergen.cpp" />
|
||||
<ClCompile Include="sdl_audio_stream.cpp">
|
||||
<ExcludedFromBuild Condition="'$(BuildingForUWP)'=='true'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sdl_initializer.cpp">
|
||||
<ExcludedFromBuild Condition="'$(BuildingForUWP)'=='true'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
@ -80,9 +77,6 @@
|
||||
<ClInclude Include="postprocessing_chain.h" />
|
||||
<ClInclude Include="postprocessing_shader.h" />
|
||||
<ClInclude Include="postprocessing_shadergen.h" />
|
||||
<ClInclude Include="sdl_audio_stream.h">
|
||||
<ExcludedFromBuild Condition="'$(BuildingForUWP)'=='true'">true</ExcludedFromBuild>
|
||||
</ClInclude>
|
||||
<ClInclude Include="sdl_initializer.h">
|
||||
<ExcludedFromBuild Condition="'$(BuildingForUWP)'=='true'">true</ExcludedFromBuild>
|
||||
</ClInclude>
|
||||
|
@ -2,7 +2,6 @@
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="icon.cpp" />
|
||||
<ClCompile Include="sdl_audio_stream.cpp" />
|
||||
<ClCompile Include="sdl_initializer.cpp" />
|
||||
<ClCompile Include="common_host.cpp" />
|
||||
<ClCompile Include="vulkan_host_display.cpp" />
|
||||
@ -35,7 +34,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="icon.h" />
|
||||
<ClInclude Include="sdl_audio_stream.h" />
|
||||
<ClInclude Include="sdl_initializer.h" />
|
||||
<ClInclude Include="common_host.h" />
|
||||
<ClInclude Include="vulkan_host_display.h" />
|
||||
|
@ -1,98 +0,0 @@
|
||||
#include "sdl_audio_stream.h"
|
||||
#include "common/assert.h"
|
||||
#include "common/log.h"
|
||||
#include "common_host.h"
|
||||
#include "sdl_initializer.h"
|
||||
#include <SDL.h>
|
||||
Log_SetChannel(SDLAudioStream);
|
||||
|
||||
SDLAudioStream::SDLAudioStream(u32 sample_rate, u32 channels, u32 buffer_ms, AudioStretchMode stretch)
|
||||
: AudioStream(sample_rate, channels, buffer_ms, stretch)
|
||||
{
|
||||
}
|
||||
|
||||
SDLAudioStream::~SDLAudioStream()
|
||||
{
|
||||
if (IsOpen())
|
||||
SDLAudioStream::CloseDevice();
|
||||
}
|
||||
|
||||
std::unique_ptr<AudioStream> CommonHost::CreateSDLAudioStream(u32 sample_rate, u32 channels, u32 buffer_ms,
|
||||
u32 latency_ms, AudioStretchMode stretch)
|
||||
{
|
||||
std::unique_ptr<SDLAudioStream> stream(std::make_unique<SDLAudioStream>(sample_rate, channels, buffer_ms, stretch));
|
||||
if (!stream->OpenDevice(latency_ms))
|
||||
stream.reset();
|
||||
return stream;
|
||||
}
|
||||
|
||||
bool SDLAudioStream::OpenDevice(u32 latency_ms)
|
||||
{
|
||||
DebugAssert(!IsOpen());
|
||||
|
||||
FrontendCommon::EnsureSDLInitialized();
|
||||
|
||||
if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
|
||||
{
|
||||
Log_ErrorPrintf("SDL_InitSubSystem(SDL_INIT_AUDIO) failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
SDL_AudioSpec spec = {};
|
||||
spec.freq = m_sample_rate;
|
||||
spec.channels = static_cast<Uint8>(m_channels);
|
||||
spec.format = AUDIO_S16;
|
||||
spec.samples = static_cast<Uint16>(GetBufferSizeForMS(m_sample_rate, (latency_ms == 0) ? m_buffer_ms : latency_ms));
|
||||
spec.callback = AudioCallback;
|
||||
spec.userdata = static_cast<void*>(this);
|
||||
|
||||
SDL_AudioSpec obtained_spec = {};
|
||||
m_device_id = SDL_OpenAudioDevice(nullptr, 0, &spec, &obtained_spec, SDL_AUDIO_ALLOW_SAMPLES_CHANGE);
|
||||
if (m_device_id == 0)
|
||||
{
|
||||
Log_ErrorPrintf("SDL_OpenAudioDevice() failed: %s", SDL_GetError());
|
||||
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
||||
return false;
|
||||
}
|
||||
|
||||
Log_DevPrintf("Requested %u frame buffer, got %u frame buffer", spec.samples, obtained_spec.samples);
|
||||
|
||||
BaseInitialize();
|
||||
m_volume = 100;
|
||||
m_paused = false;
|
||||
SDL_PauseAudioDevice(m_device_id, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SDLAudioStream::SetPaused(bool paused)
|
||||
{
|
||||
if (m_paused == paused)
|
||||
return;
|
||||
|
||||
SDL_PauseAudioDevice(m_device_id, paused ? 1 : 0);
|
||||
m_paused = paused;
|
||||
}
|
||||
|
||||
void SDLAudioStream::CloseDevice()
|
||||
{
|
||||
SDL_CloseAudioDevice(m_device_id);
|
||||
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
||||
m_device_id = 0;
|
||||
}
|
||||
|
||||
void SDLAudioStream::AudioCallback(void* userdata, uint8_t* stream, int len)
|
||||
{
|
||||
SDLAudioStream* const this_ptr = static_cast<SDLAudioStream*>(userdata);
|
||||
const u32 num_frames = len / sizeof(SampleType) / this_ptr->m_channels;
|
||||
|
||||
this_ptr->ReadFrames(reinterpret_cast<SampleType*>(stream), num_frames);
|
||||
}
|
||||
|
||||
void SDLAudioStream::SetOutputVolume(u32 volume)
|
||||
{
|
||||
if (m_volume == volume)
|
||||
return;
|
||||
|
||||
Panic("Fixme");
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
#pragma once
|
||||
#include "util/audio_stream.h"
|
||||
#include <cstdint>
|
||||
|
||||
class SDLAudioStream final : public AudioStream
|
||||
{
|
||||
public:
|
||||
SDLAudioStream(u32 sample_rate, u32 channels, u32 buffer_ms, AudioStretchMode stretch);
|
||||
~SDLAudioStream();
|
||||
|
||||
void SetPaused(bool paused) override;
|
||||
void SetOutputVolume(u32 volume) override;
|
||||
|
||||
bool OpenDevice(u32 latency_ms);
|
||||
void CloseDevice();
|
||||
|
||||
protected:
|
||||
ALWAYS_INLINE bool IsOpen() const { return (m_device_id != 0); }
|
||||
|
||||
static void AudioCallback(void* userdata, uint8_t* stream, int len);
|
||||
|
||||
u32 m_device_id = 0;
|
||||
};
|
Reference in New Issue
Block a user