Merge generic part of Android microphone changes (#5624)
This commit is contained in:
parent
e6ef00b41d
commit
5f1eb7146d
|
@ -86,7 +86,7 @@ void CubebInput::StartSampling(const Frontend::Mic::Parameters& params) {
|
|||
input_params.format = CUBEB_SAMPLE_S16LE;
|
||||
input_params.rate = params.sample_rate;
|
||||
|
||||
u32 latency_frames;
|
||||
u32 latency_frames = 512; // Firefox default
|
||||
if (cubeb_get_min_latency(impl->ctx, &input_params, &latency_frames) != CUBEB_OK) {
|
||||
LOG_ERROR(Audio, "Could not get minimum latency");
|
||||
}
|
||||
|
@ -189,4 +189,11 @@ std::vector<std::string> ListCubebInputDevices() {
|
|||
cubeb_destroy(ctx);
|
||||
return device_list;
|
||||
}
|
||||
|
||||
CubebFactory::~CubebFactory() = default;
|
||||
|
||||
std::unique_ptr<Frontend::Mic::Interface> CubebFactory::Create(std::string mic_device_name) {
|
||||
return std::make_unique<CubebInput>(std::move(mic_device_name));
|
||||
}
|
||||
|
||||
} // namespace AudioCore
|
||||
|
|
|
@ -31,4 +31,11 @@ private:
|
|||
|
||||
std::vector<std::string> ListCubebInputDevices();
|
||||
|
||||
class CubebFactory final : public Frontend::Mic::RealMicFactory {
|
||||
public:
|
||||
~CubebFactory() override;
|
||||
|
||||
std::unique_ptr<Frontend::Mic::Interface> Create(std::string mic_device_name) override;
|
||||
};
|
||||
|
||||
} // namespace AudioCore
|
||||
|
|
|
@ -5,6 +5,10 @@
|
|||
#include <array>
|
||||
#include "core/frontend/mic.h"
|
||||
|
||||
#ifdef HAVE_CUBEB
|
||||
#include "audio_core/cubeb_input.h"
|
||||
#endif
|
||||
|
||||
namespace Frontend::Mic {
|
||||
|
||||
constexpr std::array<u8, 16> NOISE_SAMPLE_8_BIT = {0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
|
@ -57,4 +61,26 @@ Samples StaticMic::Read() {
|
|||
return (sample_size == 8) ? CACHE_8_BIT : CACHE_16_BIT;
|
||||
}
|
||||
|
||||
RealMicFactory::~RealMicFactory() = default;
|
||||
|
||||
NullFactory::~NullFactory() = default;
|
||||
|
||||
std::unique_ptr<Interface> NullFactory::Create([[maybe_unused]] std::string mic_device_name) {
|
||||
return std::make_unique<NullMic>();
|
||||
}
|
||||
|
||||
#ifdef HAVE_CUBEB
|
||||
static std::unique_ptr<RealMicFactory> g_factory = std::make_unique<AudioCore::CubebFactory>();
|
||||
#else
|
||||
static std::unique_ptr<RealMicFactory> g_factory = std::make_unique<NullFactory>();
|
||||
#endif
|
||||
|
||||
void RegisterRealMicFactory(std::unique_ptr<RealMicFactory> factory) {
|
||||
g_factory = std::move(factory);
|
||||
}
|
||||
|
||||
std::unique_ptr<Interface> CreateRealMic(std::string mic_device_name) {
|
||||
return g_factory->Create(std::move(mic_device_name));
|
||||
}
|
||||
|
||||
} // namespace Frontend::Mic
|
||||
|
|
|
@ -115,4 +115,23 @@ private:
|
|||
std::vector<u8> CACHE_16_BIT;
|
||||
};
|
||||
|
||||
/// Factory for creating a real Mic input device;
|
||||
class RealMicFactory {
|
||||
public:
|
||||
virtual ~RealMicFactory();
|
||||
|
||||
virtual std::unique_ptr<Interface> Create(std::string mic_device_name) = 0;
|
||||
};
|
||||
|
||||
class NullFactory final : public RealMicFactory {
|
||||
public:
|
||||
~NullFactory() override;
|
||||
|
||||
std::unique_ptr<Interface> Create(std::string mic_device_name) override;
|
||||
};
|
||||
|
||||
void RegisterRealMicFactory(std::unique_ptr<RealMicFactory> factory);
|
||||
|
||||
std::unique_ptr<Interface> CreateRealMic(std::string mic_device_name);
|
||||
|
||||
} // namespace Frontend::Mic
|
||||
|
|
|
@ -3,9 +3,6 @@
|
|||
// Refer to the license.txt file included.
|
||||
|
||||
#include <boost/serialization/weak_ptr.hpp>
|
||||
#ifdef HAVE_CUBEB
|
||||
#include "audio_core/cubeb_input.h"
|
||||
#endif
|
||||
#include "common/archives.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "core/core.h"
|
||||
|
@ -359,11 +356,7 @@ struct MIC_U::Impl {
|
|||
new_mic = std::make_unique<Frontend::Mic::NullMic>();
|
||||
break;
|
||||
case Settings::MicInputType::Real:
|
||||
#if HAVE_CUBEB
|
||||
new_mic = std::make_unique<AudioCore::CubebInput>(Settings::values.mic_input_device);
|
||||
#else
|
||||
new_mic = std::make_unique<Frontend::Mic::NullMic>();
|
||||
#endif
|
||||
new_mic = Frontend::Mic::CreateRealMic(Settings::values.mic_input_device);
|
||||
break;
|
||||
case Settings::MicInputType::Static:
|
||||
new_mic = std::make_unique<Frontend::Mic::StaticMic>();
|
||||
|
|
Loading…
Reference in New Issue