mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-06 06:51:18 +12:00
Implement proper microphone support (#251)
This commit is contained in:
parent
dfa7774c4c
commit
d4e14d2b05
13 changed files with 682 additions and 36 deletions
66
src/audio/IAudioInputAPI.cpp
Normal file
66
src/audio/IAudioInputAPI.cpp
Normal file
|
@ -0,0 +1,66 @@
|
|||
#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));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue