Initial Mic setup
This commit is contained in:
parent
ad1cfc8d50
commit
7fccc995ce
15 changed files with 528 additions and 59 deletions
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "common/logging/log.h"
|
||||
#include "core/core.h"
|
||||
#include "core/frontend/mic.h"
|
||||
#include "core/hle/ipc.h"
|
||||
#include "core/hle/ipc_helpers.h"
|
||||
#include "core/hle/kernel/event.h"
|
||||
|
@ -14,20 +15,37 @@
|
|||
|
||||
namespace Service::MIC {
|
||||
|
||||
/// Microphone audio encodings.
|
||||
enum class Encoding : u8 {
|
||||
PCM8 = 0,
|
||||
PCM16 = 1,
|
||||
PCM8Signed = 2,
|
||||
PCM16Signed = 3,
|
||||
PCM8 = 0, ///< Unsigned 8-bit PCM.
|
||||
PCM16 = 1, ///< Unsigned 16-bit PCM.
|
||||
PCM8Signed = 2, ///< Signed 8-bit PCM.
|
||||
PCM16Signed = 3, ///< Signed 16-bit PCM.
|
||||
};
|
||||
|
||||
/// Microphone audio sampling rates.
|
||||
enum class SampleRate : u8 {
|
||||
SampleRate32730 = 0,
|
||||
SampleRate16360 = 1,
|
||||
SampleRate10910 = 2,
|
||||
SampleRate8180 = 3
|
||||
Rate32730 = 0, ///< 32728.498 Hz
|
||||
Rate16360 = 1, ///< 16364.479 Hz
|
||||
Rate10910 = 2, ///< 10909.499 Hz
|
||||
Rate8180 = 3 ///< 8182.1245 Hz
|
||||
};
|
||||
|
||||
constexpr u32 GetSampleRateInHz(SampleRate sample_rate) {
|
||||
switch (sample_rate) {
|
||||
case SampleRate::Rate8180:
|
||||
return 8180;
|
||||
case SampleRate::Rate10910:
|
||||
return 10910;
|
||||
case SampleRate::Rate16360:
|
||||
return 16360;
|
||||
case SampleRate::Rate32730:
|
||||
return 32730;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
struct MIC_U::Impl {
|
||||
explicit Impl(Core::System& system) {
|
||||
buffer_full_event =
|
||||
|
@ -43,10 +61,12 @@ struct MIC_U::Impl {
|
|||
shared_memory->SetName("MIC_U:shared_memory");
|
||||
}
|
||||
|
||||
mic->SetBackingMemory(shared_memory->GetPointer(), size);
|
||||
|
||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
|
||||
LOG_WARNING(Service_MIC, "called, size=0x{:X}", size);
|
||||
LOG_TRACE(Service_MIC, "MIC:U MapSharedMem called, size=0x{:X}", size);
|
||||
}
|
||||
|
||||
void UnmapSharedMem(Kernel::HLERequestContext& ctx) {
|
||||
|
@ -54,55 +74,68 @@ struct MIC_U::Impl {
|
|||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||
shared_memory = nullptr;
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
LOG_WARNING(Service_MIC, "called");
|
||||
LOG_TRACE(Service_MIC, "MIC:U UnmapSharedMem called");
|
||||
}
|
||||
|
||||
void StartSampling(Kernel::HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx, 0x03, 5, 0};
|
||||
|
||||
encoding = rp.PopEnum<Encoding>();
|
||||
sample_rate = rp.PopEnum<SampleRate>();
|
||||
audio_buffer_offset = rp.PopRaw<s32>();
|
||||
audio_buffer_size = rp.Pop<u32>();
|
||||
audio_buffer_loop = rp.Pop<bool>();
|
||||
Encoding encoding = rp.PopEnum<Encoding>();
|
||||
SampleRate sample_rate = rp.PopEnum<SampleRate>();
|
||||
u32 audio_buffer_offset = rp.PopRaw<u32>();
|
||||
u32 audio_buffer_size = rp.Pop<u32>();
|
||||
bool audio_buffer_loop = rp.Pop<bool>();
|
||||
|
||||
auto sign = encoding == Encoding::PCM8Signed || encoding == Encoding::PCM16Signed
|
||||
? Frontend::Mic::Signedness::Signed
|
||||
: Frontend::Mic::Signedness::Unsigned;
|
||||
u8 sample_size = encoding == Encoding::PCM8Signed || encoding == Encoding::PCM8 ? 8 : 16;
|
||||
|
||||
mic->StartSampling({sign, sample_size, audio_buffer_loop, GetSampleRateInHz(sample_rate),
|
||||
audio_buffer_offset, audio_buffer_size});
|
||||
|
||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
is_sampling = true;
|
||||
LOG_WARNING(Service_MIC,
|
||||
"(STUBBED) called, encoding={}, sample_rate={}, "
|
||||
"audio_buffer_offset={}, audio_buffer_size={}, audio_buffer_loop={}",
|
||||
static_cast<u32>(encoding), static_cast<u32>(sample_rate), audio_buffer_offset,
|
||||
audio_buffer_size, audio_buffer_loop);
|
||||
LOG_TRACE(Service_MIC,
|
||||
"MIC:U StartSampling called, encoding={}, sample_rate={}, "
|
||||
"audio_buffer_offset={}, audio_buffer_size={}, audio_buffer_loop={}",
|
||||
static_cast<u32>(encoding), static_cast<u32>(sample_rate), audio_buffer_offset,
|
||||
audio_buffer_size, audio_buffer_loop);
|
||||
}
|
||||
|
||||
void AdjustSampling(Kernel::HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx, 0x04, 1, 0};
|
||||
sample_rate = rp.PopEnum<SampleRate>();
|
||||
SampleRate sample_rate = rp.PopEnum<SampleRate>();
|
||||
mic->AdjustSampleRate(GetSampleRateInHz(sample_rate));
|
||||
|
||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
LOG_WARNING(Service_MIC, "(STUBBED) called, sample_rate={}", static_cast<u32>(sample_rate));
|
||||
LOG_TRACE(Service_MIC, "MIC:U AdjustSampling sample_rate={}",
|
||||
static_cast<u32>(sample_rate));
|
||||
}
|
||||
|
||||
void StopSampling(Kernel::HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx, 0x05, 0, 0};
|
||||
|
||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
is_sampling = false;
|
||||
LOG_WARNING(Service_MIC, "(STUBBED) called");
|
||||
mic->StopSampling();
|
||||
LOG_TRACE(Service_MIC, "MIC:U StopSampling called");
|
||||
}
|
||||
|
||||
void IsSampling(Kernel::HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx, 0x06, 0, 0};
|
||||
|
||||
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
bool is_sampling = mic->IsSampling();
|
||||
rb.Push<bool>(is_sampling);
|
||||
LOG_WARNING(Service_MIC, "(STUBBED) called");
|
||||
LOG_TRACE(Service_MIC, "MIC:U IsSampling: {}", is_sampling);
|
||||
}
|
||||
|
||||
void GetBufferFullEvent(Kernel::HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx, 0x07, 0, 0};
|
||||
|
||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
rb.PushCopyObjects(buffer_full_event);
|
||||
|
@ -111,11 +144,12 @@ struct MIC_U::Impl {
|
|||
|
||||
void SetGain(Kernel::HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx, 0x08, 1, 0};
|
||||
mic_gain = rp.Pop<u8>();
|
||||
u8 gain = rp.Pop<u8>();
|
||||
mic->SetGain(gain);
|
||||
|
||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
LOG_WARNING(Service_MIC, "(STUBBED) called, mic_gain={}", mic_gain);
|
||||
LOG_TRACE(Service_MIC, "MIC:U SetGain gain={}", gain);
|
||||
}
|
||||
|
||||
void GetGain(Kernel::HLERequestContext& ctx) {
|
||||
|
@ -123,25 +157,29 @@ struct MIC_U::Impl {
|
|||
|
||||
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
rb.Push<u8>(mic_gain);
|
||||
LOG_WARNING(Service_MIC, "(STUBBED) called");
|
||||
u8 gain = mic->GetGain();
|
||||
rb.Push<u8>(gain);
|
||||
LOG_TRACE(Service_MIC, "MIC:U GetGain gain={}", gain);
|
||||
}
|
||||
|
||||
void SetPower(Kernel::HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx, 0x0A, 1, 0};
|
||||
mic_power = rp.Pop<bool>();
|
||||
bool power = rp.Pop<bool>();
|
||||
mic->SetPower(power);
|
||||
|
||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
LOG_WARNING(Service_MIC, "(STUBBED) called, mic_power={}", mic_power);
|
||||
LOG_TRACE(Service_MIC, "MIC:U SetPower mic_power={}", power);
|
||||
}
|
||||
|
||||
void GetPower(Kernel::HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx, 0x0B, 0, 0};
|
||||
|
||||
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
bool mic_power = mic->GetPower();
|
||||
rb.Push<u8>(mic_power);
|
||||
LOG_WARNING(Service_MIC, "(STUBBED) called");
|
||||
LOG_TRACE(Service_MIC, "MIC:U GetPower called");
|
||||
}
|
||||
|
||||
void SetIirFilterMic(Kernel::HLERequestContext& ctx) {
|
||||
|
@ -167,6 +205,7 @@ struct MIC_U::Impl {
|
|||
|
||||
void GetClamp(Kernel::HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx, 0x0E, 0, 0};
|
||||
|
||||
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
rb.Push<bool>(clamp);
|
||||
|
@ -184,27 +223,20 @@ struct MIC_U::Impl {
|
|||
|
||||
void SetClientVersion(Kernel::HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx, 0x10, 1, 0};
|
||||
|
||||
const u32 version = rp.Pop<u32>();
|
||||
LOG_WARNING(Service_MIC, "(STUBBED) called, version: 0x{:08X}", version);
|
||||
|
||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
u32 client_version = 0;
|
||||
Kernel::SharedPtr<Kernel::Event> buffer_full_event;
|
||||
Kernel::SharedPtr<Kernel::Event> buffer_full_event =
|
||||
Core::System::GetInstance().Kernel().CreateEvent(Kernel::ResetType::OneShot,
|
||||
"MIC_U::buffer_full_event");
|
||||
Kernel::SharedPtr<Kernel::SharedMemory> shared_memory;
|
||||
u8 mic_gain = 0;
|
||||
bool mic_power = false;
|
||||
bool is_sampling = false;
|
||||
bool allow_shell_closed;
|
||||
u32 client_version = 0;
|
||||
bool allow_shell_closed = false;
|
||||
bool clamp = false;
|
||||
Encoding encoding = Encoding::PCM8;
|
||||
SampleRate sample_rate = SampleRate::SampleRate32730;
|
||||
s32 audio_buffer_offset = 0;
|
||||
u32 audio_buffer_size = 0;
|
||||
bool audio_buffer_loop = false;
|
||||
std::shared_ptr<Frontend::Mic::Interface> mic;
|
||||
};
|
||||
|
||||
void MIC_U::MapSharedMem(Kernel::HLERequestContext& ctx) {
|
||||
|
@ -292,10 +324,13 @@ MIC_U::MIC_U(Core::System& system)
|
|||
{0x00100040, &MIC_U::SetClientVersion, "SetClientVersion"},
|
||||
};
|
||||
|
||||
impl->mic = Frontend::GetCurrentMic();
|
||||
RegisterHandlers(functions);
|
||||
}
|
||||
|
||||
MIC_U::~MIC_U() = default;
|
||||
MIC_U::~MIC_U() {
|
||||
impl->mic->StopSampling();
|
||||
}
|
||||
|
||||
void InstallInterfaces(Core::System& system) {
|
||||
auto& service_manager = system.ServiceManager();
|
||||
|
|
|
@ -192,4 +192,6 @@ private:
|
|||
|
||||
void InstallInterfaces(Core::System& system);
|
||||
|
||||
void ChangeMicImpl();
|
||||
|
||||
} // namespace Service::MIC
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue