2022-11-03 00:24:34 +01:00
|
|
|
#include "IAudioInputAPI.h"
|
2023-02-24 23:35:58 +01:00
|
|
|
#if HAS_CUBEB
|
2022-11-03 00:24:34 +01:00
|
|
|
#include "CubebInputAPI.h"
|
2023-02-24 23:35:58 +01:00
|
|
|
#endif
|
2022-11-03 00:24:34 +01:00
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2023-04-12 16:31:34 +02:00
|
|
|
cemuLog_log(LogType::Force, "------- Init Audio input backend -------");
|
|
|
|
cemuLog_log(LogType::Force, "Cubeb: {}", s_availableApis[Cubeb] ? "available" : "not supported");
|
2022-11-03 00:24:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void IAudioInputAPI::InitializeStatic()
|
|
|
|
{
|
2023-02-24 23:35:58 +01:00
|
|
|
#if HAS_CUBEB
|
2022-11-03 00:24:34 +01:00
|
|
|
s_availableApis[Cubeb] = CubebInputAPI::InitializeStatic();
|
2023-02-24 23:35:58 +01:00
|
|
|
#endif
|
2022-11-03 00:24:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2023-02-24 23:35:58 +01:00
|
|
|
#if HAS_CUBEB
|
2022-11-03 00:24:34 +01:00
|
|
|
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);
|
|
|
|
}
|
2023-02-24 23:35:58 +01:00
|
|
|
#endif
|
2022-11-03 00:24:34 +01:00
|
|
|
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)
|
|
|
|
{
|
2023-02-24 23:35:58 +01:00
|
|
|
#if HAS_CUBEB
|
2022-11-03 00:24:34 +01:00
|
|
|
case Cubeb:
|
|
|
|
{
|
|
|
|
return CubebInputAPI::GetDevices();
|
|
|
|
}
|
2023-02-24 23:35:58 +01:00
|
|
|
#endif
|
2022-11-03 00:24:34 +01:00
|
|
|
default:
|
|
|
|
throw std::runtime_error(fmt::format("invalid audio api: {}", api));
|
|
|
|
}
|
|
|
|
}
|