audio: provide live NGS2 system info

This commit is contained in:
nmzik
2026-08-16 19:47:03 +02:00
parent 01a1036640
commit 7d8ee8b6b5
3 changed files with 90 additions and 14 deletions
+86 -14
View File
@@ -1491,6 +1491,22 @@ struct Ngs2ContextBufferInfo {
uintptr_t user_data = 0; uintptr_t user_data = 0;
}; };
struct Ngs2SystemInfo {
char name[64] = {};
uintptr_t system_handle = 0;
Ngs2ContextBufferInfo buffer_info;
uint32_t uid = 0;
uint32_t min_grain_samples = 0;
uint32_t max_grain_samples = 0;
uint32_t state_flags = 0;
uint32_t rack_count = 0;
float last_render_ratio = 0.0f;
uint64_t last_render_tick = 0;
uint64_t render_count = 0;
uint32_t sample_rate = 0;
uint32_t num_grain_samples = 0;
};
struct Ngs2RenderBufferInfo { struct Ngs2RenderBufferInfo {
void* buffer = nullptr; void* buffer = nullptr;
size_t buffer_size = 0; size_t buffer_size = 0;
@@ -1624,10 +1640,13 @@ struct Ngs2BufferAllocator {
}; };
struct Ngs2Internal { struct Ngs2Internal {
Ngs2SystemOption option; Ngs2SystemOption option;
Ngs2BufferAllocator allocator; Ngs2ContextBufferInfo buffer_info;
Ngs2Internal* next = nullptr; Ngs2BufferAllocator allocator;
Common::Mutex mutex; Ngs2Internal* next = nullptr;
uint64_t render_count = 0;
uint32_t uid = 0;
Common::Mutex mutex;
}; };
enum class Ngs2RackType { enum class Ngs2RackType {
@@ -1742,11 +1761,13 @@ struct Ngs2SamplerVoiceState {
const void* waveform_data; const void* waveform_data;
}; };
static Ngs2Internal* g_ngs_list = nullptr; static Ngs2Internal* g_ngs_list = nullptr;
static Ngs2RackInternal* g_racks_list = nullptr; static Ngs2RackInternal* g_racks_list = nullptr;
static Common::Mutex g_racks_mutex; static std::atomic_uint32_t g_next_ngs_uid = 1;
static Common::Mutex g_racks_mutex;
static_assert(sizeof(Ngs2SystemOption) == 144); static_assert(sizeof(Ngs2SystemOption) == 144);
static_assert(sizeof(Ngs2SystemInfo) == 184);
static_assert(sizeof(Ngs2RackOption) == 176); static_assert(sizeof(Ngs2RackOption) == 176);
static_assert(sizeof(Ngs2VoiceState) == 8); static_assert(sizeof(Ngs2VoiceState) == 8);
static_assert(sizeof(Ngs2SubmixerVoiceState) == 20); static_assert(sizeof(Ngs2SubmixerVoiceState) == 20);
@@ -1782,12 +1803,15 @@ int KYTY_SYSV_ABI Ngs2SystemResetOption(Ngs2SystemOption* option) {
return OK; return OK;
} }
static Ngs2Internal* Ngs2CreateSystemInternal(const Ngs2SystemOption* option, void* host_buffer) { static Ngs2Internal* Ngs2CreateSystemInternal(const Ngs2SystemOption* option,
auto* ngs = new (host_buffer) Ngs2Internal; const Ngs2ContextBufferInfo* buffer_info) {
auto* ngs = new (buffer_info->host_buffer) Ngs2Internal;
ngs->option = *option; ngs->option = *option;
ngs->next = g_ngs_list; ngs->buffer_info = *buffer_info;
g_ngs_list = ngs; ngs->uid = g_next_ngs_uid.fetch_add(1, std::memory_order_relaxed);
ngs->next = g_ngs_list;
g_ngs_list = ngs;
return ngs; return ngs;
} }
@@ -1838,7 +1862,7 @@ int KYTY_SYSV_ABI Ngs2SystemCreate(const Ngs2SystemOption* option,
EXIT_NOT_IMPLEMENTED(option->size != sizeof(Ngs2SystemOption)); EXIT_NOT_IMPLEMENTED(option->size != sizeof(Ngs2SystemOption));
auto* ngs = Ngs2CreateSystemInternal(option, buffer_info->host_buffer); auto* ngs = Ngs2CreateSystemInternal(option, buffer_info);
*handle = reinterpret_cast<uintptr_t>(ngs); *handle = reinterpret_cast<uintptr_t>(ngs);
@@ -2001,7 +2025,7 @@ int KYTY_SYSV_ABI Ngs2SystemCreateWithAllocator(const Ngs2SystemOption* optio
EXIT_NOT_IMPLEMENTED(result != OK); EXIT_NOT_IMPLEMENTED(result != OK);
EXIT_NOT_IMPLEMENTED(buf.host_buffer == nullptr); EXIT_NOT_IMPLEMENTED(buf.host_buffer == nullptr);
auto* ngs = Ngs2CreateSystemInternal(option, buf.host_buffer); auto* ngs = Ngs2CreateSystemInternal(option, &buf);
ngs->allocator = *allocator; ngs->allocator = *allocator;
*handle = reinterpret_cast<uintptr_t>(ngs); *handle = reinterpret_cast<uintptr_t>(ngs);
@@ -2009,6 +2033,52 @@ int KYTY_SYSV_ABI Ngs2SystemCreateWithAllocator(const Ngs2SystemOption* optio
return OK; return OK;
} }
int KYTY_SYSV_ABI Ngs2SystemGetInfo(uintptr_t system_handle, Ngs2SystemInfo* info,
size_t info_size) {
constexpr int32_t ERROR_INVALID_OUT_ADDRESS = static_cast<int32_t>(0x804a8010u);
constexpr int32_t ERROR_INVALID_OUT_SIZE = static_cast<int32_t>(0x804a8011u);
constexpr int32_t ERROR_INVALID_SYSTEM_HANDLE = static_cast<int32_t>(0x804a8201u);
if (info == nullptr) {
return ERROR_INVALID_OUT_ADDRESS;
}
if (info_size != sizeof(Ngs2SystemInfo)) {
return ERROR_INVALID_OUT_SIZE;
}
auto* ngs = reinterpret_cast<Ngs2Internal*>(system_handle);
auto* current = g_ngs_list;
while (current != nullptr && current != ngs) {
current = current->next;
}
if (current == nullptr) {
return ERROR_INVALID_SYSTEM_HANDLE;
}
Common::LockGuard lock(ngs->mutex);
*info = {};
std::memcpy(info->name, ngs->option.name, sizeof(info->name));
info->system_handle = system_handle;
info->buffer_info = ngs->buffer_info;
info->uid = ngs->uid;
info->min_grain_samples = 64;
info->max_grain_samples = ngs->option.max_grain_samples;
info->state_flags = 1;
info->render_count = ngs->render_count;
info->sample_rate = ngs->option.sample_rate;
info->num_grain_samples = ngs->option.num_grain_samples;
Common::LockGuard racks_lock(g_racks_mutex);
for (auto* rack = g_racks_list; rack != nullptr; rack = rack->next) {
if (rack->ngs == ngs) {
info->rack_count++;
}
}
return OK;
}
int KYTY_SYSV_ABI Ngs2SystemSetGrainSamples(uintptr_t system_handle, uint32_t num_samples) { int KYTY_SYSV_ABI Ngs2SystemSetGrainSamples(uintptr_t system_handle, uint32_t num_samples) {
PRINT_NAME(); PRINT_NAME();
LOGF("\t system_handle = 0x%016" PRIx64 "\n" LOGF("\t system_handle = 0x%016" PRIx64 "\n"
@@ -2368,6 +2438,8 @@ int KYTY_SYSV_ABI Ngs2SystemRender(uintptr_t system_handle, const Ngs2RenderBuff
} }
} }
ngs->render_count++;
return OK; return OK;
} }
+3
View File
@@ -288,6 +288,7 @@ int KYTY_SYSV_ABI Audio3dPortPush(uint32_t port_id, uint32_t blocking);
namespace Ngs2 { namespace Ngs2 {
struct Ngs2SystemOption; struct Ngs2SystemOption;
struct Ngs2SystemInfo;
struct Ngs2RackOption; struct Ngs2RackOption;
struct Ngs2BufferAllocator; struct Ngs2BufferAllocator;
struct Ngs2VoiceParamHeader; struct Ngs2VoiceParamHeader;
@@ -309,6 +310,8 @@ int KYTY_SYSV_ABI Ngs2SystemQueryBufferSize(const Ngs2SystemOption* option,
Ngs2ContextBufferInfo* buffer_info); Ngs2ContextBufferInfo* buffer_info);
int KYTY_SYSV_ABI Ngs2SystemCreate(const Ngs2SystemOption* option, int KYTY_SYSV_ABI Ngs2SystemCreate(const Ngs2SystemOption* option,
const Ngs2ContextBufferInfo* buffer_info, uintptr_t* handle); const Ngs2ContextBufferInfo* buffer_info, uintptr_t* handle);
int KYTY_SYSV_ABI Ngs2SystemGetInfo(uintptr_t system_handle, Ngs2SystemInfo* info,
size_t info_size);
int KYTY_SYSV_ABI Ngs2SystemSetGrainSamples(uintptr_t system_handle, uint32_t num_samples); int KYTY_SYSV_ABI Ngs2SystemSetGrainSamples(uintptr_t system_handle, uint32_t num_samples);
int KYTY_SYSV_ABI Ngs2RackQueryBufferSize(uint32_t rack_id, const Ngs2RackOption* option, int KYTY_SYSV_ABI Ngs2RackQueryBufferSize(uint32_t rack_id, const Ngs2RackOption* option,
Ngs2ContextBufferInfo* buffer_info); Ngs2ContextBufferInfo* buffer_info);
+1
View File
@@ -1092,6 +1092,7 @@ LIB_DEFINE(InitAudio_1_Ngs2) {
LIB_FUNC("koBbCMvOKWw", Ngs2::Ngs2SystemCreate); LIB_FUNC("koBbCMvOKWw", Ngs2::Ngs2SystemCreate);
LIB_FUNC("mPYgU4oYpuY", Ngs2::Ngs2SystemCreateWithAllocator); LIB_FUNC("mPYgU4oYpuY", Ngs2::Ngs2SystemCreateWithAllocator);
LIB_FUNC("u-WrYDaJA3k", Ngs2::Ngs2SystemDestroy); LIB_FUNC("u-WrYDaJA3k", Ngs2::Ngs2SystemDestroy);
LIB_FUNC("vU7TQ62pItw", Ngs2::Ngs2SystemGetInfo);
LIB_FUNC("U546k6orxQo", Ngs2::Ngs2RackCreateWithAllocator); LIB_FUNC("U546k6orxQo", Ngs2::Ngs2RackCreateWithAllocator);
LIB_FUNC("cLV4aiT9JpA", Ngs2::Ngs2RackCreate); LIB_FUNC("cLV4aiT9JpA", Ngs2::Ngs2RackCreate);
LIB_FUNC("0eFLVCfWVds", Ngs2::Ngs2RackQueryBufferSize); LIB_FUNC("0eFLVCfWVds", Ngs2::Ngs2RackQueryBufferSize);