mirror of
https://github.com/cemu-project/Cemu.git
synced 2024-12-04 15:04:24 +01:00
67 lines
1.9 KiB
C++
67 lines
1.9 KiB
C++
|
#include "IAudioInputAPI.h"
|
||
|
#include "CubebInputAPI.h"
|
||
|
|
||
|
std::shared_mutex g_audioInputMutex;
|
||
|
AudioInputAPIPtr g_inputAudio;
|
||
|
|
||
|
std::array<bool, IAudioInputAPI::AudioInputAPIEnd> IAudioInputAPI::s_availableApis{};
|
||
|
|
||
|
IAudioInputAPI::IAudioInputAPI(uint32 samplerate, uint32 channels, uint32 samples_per_block, uint32 bits_per_sample)
|
||
|
: m_samplerate(samplerate), m_channels(channels), m_samplesPerBlock(samples_per_block), m_bitsPerSample(bits_per_sample)
|
||
|
{
|
||
|
m_bytesPerBlock = samples_per_block * channels * (bits_per_sample / 8);
|
||
|
}
|
||
|
|
||
|
void IAudioInputAPI::PrintLogging()
|
||
|
{
|
||
|
forceLog_printf("------- Init Audio Input backend -------");
|
||
|
forceLog_printf("Cubeb: %s", s_availableApis[Cubeb] ? "available" : "not supported");
|
||
|
}
|
||
|
|
||
|
void IAudioInputAPI::InitializeStatic()
|
||
|
{
|
||
|
s_availableApis[Cubeb] = CubebInputAPI::InitializeStatic();
|
||
|
}
|
||
|
|
||
|
bool IAudioInputAPI::IsAudioInputAPIAvailable(AudioInputAPI api)
|
||
|
{
|
||
|
if ((size_t)api < s_availableApis.size())
|
||
|
return s_availableApis[api];
|
||
|
|
||
|
cemu_assert_debug(false);
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
AudioInputAPIPtr IAudioInputAPI::CreateDevice(AudioInputAPI api, const DeviceDescriptionPtr& device, sint32 samplerate, sint32 channels, sint32 samples_per_block, sint32 bits_per_sample)
|
||
|
{
|
||
|
if (!IsAudioInputAPIAvailable(api))
|
||
|
return {};
|
||
|
|
||
|
switch(api)
|
||
|
{
|
||
|
case Cubeb:
|
||
|
{
|
||
|
const auto tmp = std::dynamic_pointer_cast<CubebInputAPI::CubebDeviceDescription>(device);
|
||
|
return std::make_unique<CubebInputAPI>(tmp->GetDeviceId(), samplerate, channels, samples_per_block, bits_per_sample);
|
||
|
}
|
||
|
default:
|
||
|
throw std::runtime_error(fmt::format("invalid audio api: {}", api));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
std::vector<IAudioInputAPI::DeviceDescriptionPtr> IAudioInputAPI::GetDevices(AudioInputAPI api)
|
||
|
{
|
||
|
if (!IsAudioInputAPIAvailable(api))
|
||
|
return {};
|
||
|
|
||
|
switch(api)
|
||
|
{
|
||
|
case Cubeb:
|
||
|
{
|
||
|
return CubebInputAPI::GetDevices();
|
||
|
}
|
||
|
default:
|
||
|
throw std::runtime_error(fmt::format("invalid audio api: {}", api));
|
||
|
}
|
||
|
}
|